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

Add resize to Breadcrumbs and ButtonGroup overflow stories #2128

Merged
merged 8 commits into from
Jul 3, 2024
Merged
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
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[];
];
Loading