Skip to content

Commit

Permalink
Add resize to Breadcrumbs and ButtonGroup overflow stories (#2128)
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 3, 2024
1 parent 1205baa commit 7f73ff0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 46 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 22 additions & 5 deletions apps/react-workshop/src/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MenuItem,
Input,
Tooltip,
Text,
} from '@itwin/itwinui-react';
import {
SvgChevronRightDouble,
Expand Down Expand Up @@ -80,12 +81,28 @@ export const Overflow = () => {
</Breadcrumbs.Item>
));

return (
<div style={{ maxWidth: '50%', border: '1px solid lightpink', padding: 8 }}>
<Breadcrumbs>{items}</Breadcrumbs>
</div>
);
return <Breadcrumbs>{items}</Breadcrumbs>;
};
Overflow.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 CustomOverflowBackButton = () => {
const items = Array(10)
Expand Down
4 changes: 4 additions & 0 deletions apps/react-workshop/src/Breadcrumbs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ describe('Breadcrumbs', () => {
const id = Cypress.storyId(storyPath, testName);
cy.visit('/', { qs: { mode: 'preview', story: id } });

if (testName.includes('Overflow')) {
cy.get('small').hide();
}

cy.compareSnapshot(testName);
});
});
Expand Down
97 changes: 56 additions & 41 deletions apps/react-workshop/src/ButtonGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
SvgPlaceholder,
SvgMore,
} from '@itwin/itwinui-icons-react';
import { StoryDecorator } from '@ladle/react';

export default {
title: 'ButtonGroup',
Expand Down Expand Up @@ -60,53 +59,60 @@ export const Overflow = () => {
));

return (
<ButtonGroup
orientation='horizontal'
overflowButton={(overflowStart) => {
return (
<DropdownMenu
menuItems={(close) => {
const length = items.length - overflowStart;

return Array.from({ length }, (_, _index) => {
const index = overflowStart + _index;

return (
<MenuItem
key={index}
onClick={close}
icon={<SvgPlaceholder />}
>
Item #{index}
</MenuItem>
);
});
}}
>
<IconButton label='More'>
<SvgMore />
</IconButton>
</DropdownMenu>
);
}}
>
{items}
</ButtonGroup>
);
};
Overflow.decorators = [
(Story: () => React.ReactNode) => (
<>
<Text variant='small' as='small' isMuted>
Resize the viewport to see overflow behavior.
Resize the container to see overflow behavior.
</Text>
<div
style={{
maxWidth: 'clamp(300px, 50%, 100%)',
width: 'min(30rem, 100%)',
border: '1px solid hotpink',
padding: 8,
overflow: 'hidden',
resize: 'inline',
}}
>
<ButtonGroup
orientation='horizontal'
overflowButton={(overflowStart) => {
return (
<DropdownMenu
menuItems={(close) => {
const length = items.length - overflowStart;

return Array.from({ length }, (_, _index) => {
const index = overflowStart + _index;

return (
<MenuItem
key={index}
onClick={close}
icon={<SvgPlaceholder />}
>
Item #{index}
</MenuItem>
);
});
}}
>
<IconButton label='More'>
<SvgMore />
</IconButton>
</DropdownMenu>
);
}}
>
{items}
</ButtonGroup>
<Story />
</div>
</>
);
};
),
];

export const InputButtonCombo = () => {
return (
Expand Down Expand Up @@ -208,14 +214,23 @@ export const VerticalOverflow = () => {
);
};
VerticalOverflow.decorators = [
(Story) => (
(Story: () => React.ReactNode) => (
<>
<Text variant='small' as='small' isMuted>
Resize the viewport to see overflow behavior.
Resize the container to see overflow behavior.
</Text>
<div style={{ border: '1px solid hotpink', padding: 8 }}>
<div
style={{
blockSize: 'min(20rem, 100vh)',
inlineSize: 'min(20rem, 100vw)',
border: '1px solid hotpink',
padding: 8,
resize: 'block',
overflow: 'hidden',
}}
>
<Story />
</div>
</>
),
] satisfies StoryDecorator[];
];

0 comments on commit 7f73ff0

Please sign in to comment.