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

Side Navigation customization #1458

Merged
merged 28 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
487b78a
initial commit
xman343 Jul 28, 2023
a1d1b38
sideNav, sideNavContent, sideNavTop, sideNavBottom
xman343 Jul 28, 2023
29fa685
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Jul 31, 2023
1553978
unit tests
xman343 Jul 31, 2023
6c78a53
node modules
xman343 Jul 31, 2023
e8d878f
yarn lockfile fix
xman343 Jul 31, 2023
de813ef
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 1, 2023
105d3f9
Merge branch 'dev' of https://github.com/iTwin/iTwinUI into xander/si…
xman343 Aug 1, 2023
d6b43f3
Merge branch 'xander/side-navigation--x]Props' of https://github.com/…
xman343 Aug 1, 2023
fcf1751
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 1, 2023
f7e7396
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 1, 2023
7470784
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 2, 2023
56040c3
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 2, 2023
fe9611b
prop names edited
xman343 Aug 2, 2023
220b795
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 2, 2023
83f6c2b
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 7, 2023
d781fb0
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 9, 2023
495e6ee
wrapperProps implemented
xman343 Aug 10, 2023
2eae953
props moved to button
xman343 Aug 10, 2023
089eae7
Revert "props moved to button"
xman343 Aug 10, 2023
91b8af5
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 10, 2023
a6b86b9
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 11, 2023
c0ac3c5
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 11, 2023
d5fc0ca
changeset added
xman343 Aug 14, 2023
86892ac
Merge branch 'xander/side-navigation--x]Props' of https://github.com/…
xman343 Aug 14, 2023
29e7a2e
updated unit test
xman343 Aug 14, 2023
5035a6f
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 14, 2023
efd2df0
Merge branch 'dev' into xander/side-navigation--x]Props
xman343 Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,52 @@ it('should not show submenu if isSubmenuOpen is false', () => {
expect(wrapper.querySelector('.iui-side-navigation-submenu')).toBeFalsy();
expect(screen.queryByText('submenu content')).toBeFalsy();
});

it('passes custom props to subcomponents', () => {
const { container } = renderComponent({
sideNavProps: {
className: 'custom-sidenav-class',
style: { width: 70 },
},
sideNavContentProps: {
className: 'custom-sidenav-content-class',
style: { width: 80 },
},
sideNavTopProps: {
className: 'custom-sidenav-top-class',
style: { width: 90 },
},
sideNavBottomProps: {
className: 'custom-sidenav-bottom-class',
style: { width: 100 },
},
});

// sideNav props test
const sideNavElement = container.querySelector(
'.iui-side-navigation.iui-collapsed.custom-sidenav-class',
) as HTMLElement;
expect(sideNavElement).toBeTruthy();
expect(sideNavElement.style.width).toBe('70px');

// content props test
const contentElement = container.querySelector(
'.iui-sidenav-content.custom-sidenav-content-class',
) as HTMLElement;
expect(contentElement).toBeTruthy();
expect(contentElement.style.width).toBe('80px');

// top props test
const topElement = container.querySelector(
'.iui-top.custom-sidenav-top-class',
) as HTMLElement;
expect(topElement).toBeTruthy();
expect(topElement.style.width).toBe('90px');

// bottom props test
const bottomElement = container.querySelector(
'.iui-bottom.custom-sidenav-bottom-class',
) as HTMLElement;
expect(bottomElement).toBeTruthy();
expect(bottomElement.style.width).toBe('100px');
});
52 changes: 45 additions & 7 deletions packages/itwinui-react/src/core/SideNavigation/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ type SideNavigationProps = {
* @default false
*/
isSubmenuOpen?: boolean;
/**
* Passes props for SideNav.
*/
sideNavProps?: React.ComponentProps<'div'>;
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Passes props for SideNav content.
*/
sideNavContentProps?: React.ComponentProps<'div'>;
/**
* Passes props for SideNav top.
*/
sideNavTopProps?: React.ComponentProps<'div'>;
/**
* Passes props for SideNav bottom.
*/
sideNavBottomProps?: React.ComponentProps<'div'>;
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand All @@ -83,6 +99,10 @@ export const SideNavigation = React.forwardRef((props, forwardedRef) => {
onExpanderClick,
submenu,
isSubmenuOpen = false,
sideNavProps,
sideNavContentProps,
sideNavTopProps,
sideNavBottomProps,
...rest
} = props;

Expand Down Expand Up @@ -110,14 +130,28 @@ export const SideNavigation = React.forwardRef((props, forwardedRef) => {
{...rest}
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
>
<Box
className={cx('iui-side-navigation', {
'iui-expanded': _isExpanded,
'iui-collapsed': !_isExpanded,
})}
as='div'
{...sideNavProps}
className={cx(
'iui-side-navigation',
{
'iui-expanded': _isExpanded,
'iui-collapsed': !_isExpanded,
},
sideNavProps?.className,
)}
>
{expanderPlacement === 'top' && ExpandButton}
<Box className='iui-sidenav-content'>
<Box className='iui-top'>
<Box
as='div'
{...sideNavContentProps}
className={cx('iui-sidenav-content', sideNavContentProps?.className)}
>
<Box
as='div'
{...sideNavTopProps}
className={cx('iui-top', sideNavTopProps?.className)}
>
{items.map((sidenavButton: JSX.Element, index) =>
!_isExpanded ? (
<Tooltip
Expand All @@ -132,7 +166,11 @@ export const SideNavigation = React.forwardRef((props, forwardedRef) => {
),
)}
</Box>
<Box className='iui-bottom'>
<Box
as='div'
{...sideNavBottomProps}
className={cx('iui-bottom', sideNavBottomProps?.className)}
>
{secondaryItems?.map((sidenavButton: JSX.Element, index) =>
!_isExpanded ? (
<Tooltip
Expand Down