Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat(react): add LeftNavigation component #25

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions packages/react/src/components/LeftNavigation/LeftNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import clsx from 'clsx';
import {FC, isValidElement, ReactElement} from 'react';
import './left-navigation.scss';
import {MuiWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import Box, {BoxProps} from '../Box';
import LeftNavigationItem, {LeftNavigationItemProps} from '../LeftNavigationItem';
import List from '../List';
import Tooltip from '../Tooltip';

export interface LeftNavigationProps extends BoxProps {
listItems?: LeftNavigationItemProps[] | ReactElement;
open?: boolean;
}
const COMPONENT_NAME: string = 'LeftNavigation';

const LeftNavigation: FC<LeftNavigationProps> & MuiWrapperProps = (props: LeftNavigationProps): ReactElement => {
const {className, open, listItems, ...rest} = props;
const classes: string = clsx(
'oxygen-left-navigation',
{
expanded: open,
},
className,
);

return (
<Box role="presentation" className={classes} {...rest}>
{isValidElement(listItems) ? (
listItems
) : (
<List>
{listItems?.map((item: LeftNavigationItemProps) => {
const {label, onClick, selected, icon, ...itemProps} = item;

return (
<Tooltip title={item.label} placement="right" disableHoverListener={open}>
<LeftNavigationItem
open={open}
selected={selected}
onClick={onClick}
label={label}
icon={icon}
{...itemProps}
/>
</Tooltip>
);
})}
</List>
)}
</Box>
);
};

LeftNavigation.displayName = composeComponentDisplayName(COMPONENT_NAME);
LeftNavigation.muiName = COMPONENT_NAME;

export default LeftNavigation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {render} from '@unit-testing';
import LeftNavigation from '../LeftNavigation';

describe('LeftNavigation', () => {
it('should render successfully', () => {
const {baseElement} = render(<LeftNavigation />);
expect(baseElement).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions packages/react/src/components/LeftNavigation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {default} from './LeftNavigation';
export type {LeftNavigationProps} from './LeftNavigation';
34 changes: 34 additions & 0 deletions packages/react/src/components/LeftNavigation/left-navigation.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

.oxygen-left-navigation {
padding: 2em 0;
background-color: #465867;
display: flex;
overflow: hidden;
flex-direction: column;
max-width: 64px;
transition: all 0.5s;
white-space: nowrap;
height: 100vh;

&.expanded {
width: auto;
max-width: 250px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import clsx from 'clsx';
import {FC, ReactElement, ReactNode} from 'react';
import {MuiWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import ListItemButton, {ListItemButtonProps} from '../ListItemButton';
import ListItemIcon from '../ListItemIcon';
import ListItemText from '../ListItemText';
import './left-navigation-item.scss';

export interface LeftNavigationItemProps extends ListItemButtonProps {
icon?: ReactNode;
iconSelected?: ReactNode;
label?: ReactNode;
onClick?: () => void;
open?: boolean;
selected?: boolean;
}

const COMPONENT_NAME: string = 'LeftNavigationItem';

const LeftNavigationItem: FC<LeftNavigationItemProps> & MuiWrapperProps = (
props: LeftNavigationItemProps,
): ReactElement => {
const {className, icon, iconSelected, label, onClick, selected, open, ...rest} = props;
const classes: string = clsx(
'oxygen-left-navigation-item',
{
expanded: open,
},
className,
);

return (
<ListItemButton selected={selected} className={classes} onClick={onClick} {...rest}>
<ListItemIcon>{selected ? iconSelected ?? icon : icon}</ListItemIcon>
<ListItemText>{label}</ListItemText>
</ListItemButton>
);
};

LeftNavigationItem.displayName = composeComponentDisplayName(COMPONENT_NAME);
LeftNavigationItem.muiName = COMPONENT_NAME;

export default LeftNavigationItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {render} from '@unit-testing';
import LeftNavigationItem from '../LeftNavigationItem';

describe('LeftNavigationItem', () => {
it('should render successfully', () => {
const {baseElement} = render(<LeftNavigationItem />);
expect(baseElement).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions packages/react/src/components/LeftNavigationItem/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {default} from './LeftNavigationItem';
export type {LeftNavigationItemProps} from './LeftNavigationItem';
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

.oxygen-left-navigation-item {
transition: all 0.3s;
margin-left: 8px;
margin-right: 8px;
border-radius: 6px;
justify-content: center;

.MuiListItemIcon-root {
display: flex;
justify-content: center;
min-width: 20px;
}

.MuiListItemText-root {
display: none;
color: #fff;
}

&.expanded {
.MuiListItemText-root {
display: flex;
margin: 0 0.7rem;
}
}

&.Mui-selected {
background-color: #fff;

.MuiListItemText-root {
color: #465867;
}
}

&.Mui-selected:hover {
text-decoration: none;
background-color: #fff;
}
}

.oxygen-left-nav-item:hover {
text-decoration: none;
}
Loading