Skip to content

Commit

Permalink
Add resize to leftover Breadcrumbs overflow stories (#2133)
Browse files Browse the repository at this point in the history
Co-authored-by: Rohan <[email protected]>
  • Loading branch information
r100-stack and r100-stack authored Jul 8, 2024
1 parent 9673bf6 commit a164f99
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 73 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 92 additions & 71 deletions apps/react-workshop/src/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
DropdownMenu,
MenuItem,
Input,
Tooltip,
Text,
} from '@itwin/itwinui-react';
import {
Expand Down Expand Up @@ -117,39 +116,51 @@ export const CustomOverflowBackButton = () => {
));

return (
<div
style={{
width: '50%',
maxWidth: 725,
minWidth: 150,
border: '1px solid lightpink',
padding: 8,
<Breadcrumbs
overflowButton={(visibleCount: number) => {
const previousBreadcrumb =
visibleCount > 1 ? items.length - visibleCount : items.length - 2;
return (
<IconButton
aria-label={`Item ${previousBreadcrumb}`}
onClick={() => {
console.log(`Visit breadcrumb ${previousBreadcrumb}`);
}}
styleType='borderless'
label={`Item ${previousBreadcrumb}`}
labelProps={{
placement: 'bottom',
}}
>
<SvgMore />
</IconButton>
);
}}
>
<Breadcrumbs
overflowButton={(visibleCount: number) => {
const previousBreadcrumb =
visibleCount > 1 ? items.length - visibleCount : items.length - 2;
return (
<Tooltip content={`Item ${previousBreadcrumb}`} placement='bottom'>
<IconButton
aria-label={`Item ${previousBreadcrumb}`}
onClick={() => {
console.log(`Visit breadcrumb ${previousBreadcrumb}`);
}}
styleType='borderless'
>
<SvgMore />
</IconButton>
</Tooltip>
);
}}
>
{items}
</Breadcrumbs>
</div>
{items}
</Breadcrumbs>
);
};
CustomOverflowBackButton.decorators = [
(Story: () => React.ReactNode) => (
<>
<Text variant='small' as='small' isMuted>
Resize the container to see overflow behavior.
</Text>
<div
style={{
width: 'min(30rem, 100%)',
border: '1px solid lightpink',
padding: 8,
resize: 'inline',
overflow: 'hidden',
}}
>
<Story />
</div>
</>
),
];

export const CustomOverflowDropdown = () => {
const items = Array(10)
Expand All @@ -164,50 +175,60 @@ export const CustomOverflowDropdown = () => {
));

return (
<div
style={{
width: '50%',
maxWidth: 725,
minWidth: 150,
border: '1px solid lightpink',
padding: 8,
}}
>
<Breadcrumbs
overflowButton={(visibleCount: number) => (
<DropdownMenu
menuItems={(close) =>
Array(items.length - visibleCount)
.fill(null)
.map((_, _index) => {
const index = visibleCount > 1 ? _index + 1 : _index;
const onClick = () => {
console.log(`Visit breadcrumb ${index}`);
close();
};
return (
<MenuItem key={index} onClick={onClick}>
Item {index}
</MenuItem>
);
})
}
<Breadcrumbs
overflowButton={(visibleCount: number) => (
<DropdownMenu
menuItems={(close) =>
Array(items.length - visibleCount)
.fill(null)
.map((_, _index) => {
const index = visibleCount > 1 ? _index + 1 : _index;
const onClick = () => {
console.log(`Visit breadcrumb ${index}`);
close();
};
return (
<MenuItem key={index} onClick={onClick}>
Item {index}
</MenuItem>
);
})
}
>
<IconButton
aria-label='Dropdown with more breadcrumbs'
onClick={() => console.log('Clicked on overflow icon')}
styleType='borderless'
>
<IconButton
aria-label='Dropdown with more breadcrumbs'
onClick={() => console.log('Clicked on overflow icon')}
styleType='borderless'
>
<SvgMore />
</IconButton>
</DropdownMenu>
)}
>
{items}
</Breadcrumbs>
</div>
<SvgMore />
</IconButton>
</DropdownMenu>
)}
>
{items}
</Breadcrumbs>
);
};
CustomOverflowDropdown.decorators = [
(Story: () => React.ReactNode) => (
<>
<Text variant='small' as='small' isMuted>
Resize the container to see overflow behavior.
</Text>
<div
style={{
width: 'min(30rem, 100%)',
border: '1px solid lightpink',
padding: 8,
resize: 'inline',
overflow: 'hidden',
}}
>
<Story />
</div>
</>
),
];

export const FolderNavigation = () => {
const items = useMemo(
Expand Down
10 changes: 8 additions & 2 deletions apps/react-workshop/src/Breadcrumbs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Breadcrumbs', () => {
'Folder Navigation',
'Links',
'Overflow',
// 'Custom Overflow Dropdown', // excluding because these fellas keep failing in CI
// 'Custom Overflow Back Button',
'Custom Overflow Dropdown',
'Custom Overflow Back Button',
];

tests.forEach((testName) => {
Expand All @@ -23,6 +23,12 @@ describe('Breadcrumbs', () => {
cy.get('small').hide();
}

if (testName === 'Custom Overflow Dropdown') {
cy.get('button').eq(1).click();
} else if (testName === 'Custom Overflow Back Button') {
cy.get('button').eq(1).trigger('mouseenter');
}

cy.compareSnapshot(testName);
});
});
Expand Down

0 comments on commit a164f99

Please sign in to comment.