Skip to content

Commit

Permalink
fix(components): fix typing of stories
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtatranta committed Feb 13, 2025
1 parent 01a0053 commit 3812b75
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/components/Box/Box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const Box: StoryObj = {
export const Box: StoryObj<typeof BoxComponent> = {
render: props => (
<BoxComponent {...props}>
<Content />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const BulletList: StoryObj = {
export const BulletList: StoryObj<typeof BulletListComponent> = {
render: props => (
<BulletListComponent {...props}>
<BulletListComponent.Item title="Lorem ipsum" state="done">
Expand All @@ -40,7 +40,7 @@ export const BulletList: StoryObj = {
isOrdered: true,
bulletSize: 'large',
width: 400,
margin: { vertical: spacings.lg, horizontal: 'auto ' },
margin: { vertical: spacings.lg, horizontal: 'auto' },
},
argTypes: {
isOrdered: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const Collapsible: StoryObj = {
export const Collapsible: StoryObj<typeof CollapsibleComponent> = {
render: args => (
<CollapsibleComponent {...args}>
<CollapsibleComponent.Toggle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const Divider: StoryObj = {
export const Divider: StoryObj<typeof DividerComponent> = {
render: props => (
<Container>
<DividerComponent {...props} />
Expand Down
15 changes: 6 additions & 9 deletions packages/components/src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import {
icons as iconsDeprecated,
} from '@suite-common/icons-deprecated';

import {
Icon as IconComponent,
IconProps,
allowedIconFrameProps,
iconSizes,
iconVariants,
} from './Icon';
import { Icon as IconComponent, allowedIconFrameProps, iconSizes, iconVariants } from './Icon';
import { getFramePropsStory } from '../../utils/frameProps';

const meta: Meta = {
Expand All @@ -27,7 +21,7 @@ const allIcons = new Set(
[...iconNames, ...iconsDeprecatedNames].sort((a, b) => a.localeCompare(b)),
);

export const Icon: StoryObj<IconProps> = {
export const Icon: StoryObj<typeof IconComponent> = {
args: {
name: 'discover',
variant: 'primary',
Expand Down Expand Up @@ -62,9 +56,12 @@ export const Icon: StoryObj<IconProps> = {
control: 'color',
},
size: {
options: iconSizes,
options: Object.values(iconSizes),
control: {
type: 'select',
labels: Object.fromEntries(
Object.entries(iconSizes).map(([key, value]) => [value, `${key}: ${value}`]),
),
},
},
...getFramePropsStory(allowedIconFrameProps).argTypes,
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/components/Icon/icons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ export const AllIcons: StoryObj<IconProps> = {
control: 'color',
},
size: {
options: iconSizes,
options: Object.values(iconSizes),
control: {
type: 'select',
labels: iconSizes,
},
},
...getFramePropsStory(allowedIconFrameProps).argTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const IconCircle: StoryObj = {
export const IconCircle: StoryObj<IconCircleProps> = {
render: props => <IconCircleComponent {...(props as IconCircleProps)} />,
args: {
variant: 'primary',
Expand Down
11 changes: 5 additions & 6 deletions packages/components/src/components/InfoItem/InfoItem.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ const meta: Meta = {
} as Meta;
export default meta;

export const InfoItem: StoryObj = {
render: props => (
<InfoItemComponent label={undefined} {...props}>
Lorem ipsum
</InfoItemComponent>
),
export const InfoItem: StoryObj<typeof InfoItemComponent> = {
render: props => <InfoItemComponent {...props}>Lorem ipsum</InfoItemComponent>,
args: {
...getTextPropsStory(allowedInfoItemTextProps).args,
...getFramePropsStory(allowedInfoItemFrameProps).args,
Expand Down Expand Up @@ -77,6 +73,9 @@ export const InfoItem: StoryObj = {
options: Object.values(spacings),
control: {
type: 'select',
labels: Object.fromEntries(
Object.entries(spacings).map(([key, value]) => [value, `${key}: ${value}`]),
),
},
},
...getTextPropsStory(allowedInfoItemTextProps).argTypes,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/List/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const iconProps = {
variant: 'primary',
} as Partial<IconProps>;

export const List: StoryObj = {
export const List: StoryObj<typeof ListComponent> = {
render: props => (
<ListComponent {...props}>
<ListComponent.Item bulletComponent={<Icon name="butterfly" {...iconProps} />}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const SubTabsApp = (props: Partial<SubTabsProps>) => {
);
};

export const SubTabs: StoryObj = {
export const SubTabs: StoryObj<typeof SubTabsComponent> = {
render: props => <SubTabsApp {...props} />,
args: {
...getFramePropsStory(allowedSubTabsFrameProps).args,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const TabsApp = (props: Partial<TabsProps>) => {
);
};

export const Tabs: StoryObj = {
export const Tabs: StoryObj<typeof TabsComponent> = {
render: props => <TabsApp {...props} />,
args: {
hasBorder: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export const Button: StoryObj<ButtonProps> = {
},
},
icon: {
options: {
'No icon': null,
...variables.ICONS.reduce((acc, icon) => ({ ...acc, [icon]: icon }), {}),
},
options: [null, ...variables.ICONS],
control: {
type: 'select',
labels: {
'No icon': null,
...variables.ICONS.reduce((acc, icon) => ({ ...acc, [icon]: icon }), {}),
},
},
},
iconSize: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export const TextButton: StoryObj<TextButtonProps> = {
},
},
icon: {
options: {
'No icon': null,
...variables.ICONS.reduce((acc, icon) => ({ ...acc, [icon]: icon }), {}),
},
options: [null, ...variables.ICONS],
control: {
type: 'select',
labels: {
'No icon': null,
...variables.ICONS.reduce((acc, icon) => ({ ...acc, [icon]: icon }), {}),
},
},
},
iconAlignment: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const FormCell: StoryObj = {
export const FormCell: StoryObj<typeof FormCellComponent> = {
render: props => (
<FormCellComponent {...props}>
<SkeletonRectangle width="100%" height={40} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const Range: StoryObj<RangeProps> = {
},
labels: {
control: {
type: 'array',
type: 'object',
},
table: {
type: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const RangeSegment: StoryObj<RangeProps> = {
},
labels: {
control: {
type: 'array',
type: 'object',
},
table: {
type: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const meta: Meta<typeof SelectBarComponent> = {
},
options: {
control: {
type: 'array',
type: 'object',
},
table: {
type: {
Expand All @@ -43,8 +43,13 @@ const meta: Meta<typeof SelectBarComponent> = {
},
},
selectedOption: {
options: Object.values(options).map(({ value }) => value),
control: {
type: 'text',
type: 'select',
labels: options.reduce(
(acc, option) => ({ ...acc, [option.value]: option.label }),
{},
),
},
},
isDisabled: {
Expand Down Expand Up @@ -74,6 +79,13 @@ export const SelectBar: StoryObj<typeof SelectBarComponent> = {
const [_, updateArgs] = useArgs<SelectBarProps<string>>();
const setOption = (selectedOption: string) => updateArgs({ selectedOption });

return <SelectBarComponent {...args} onChange={setOption} options={options} />;
return (
<SelectBarComponent
{...args}
onChange={setOption}
options={options}
selectedOption={args.selectedOption as string | undefined}
/>
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ export const DialogModal: StoryObj<DialogModalProps> = {
control: 'text',
},
bottomBarComponents: {
control: 'none',
control: {
type: undefined,
},
},
className: {
control: 'none',
control: {
type: undefined,
},
},
'data-testid': {
control: 'none',
control: {
type: undefined,
},
},
icon: {
options: variables.ICONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ export const Modal: StoryObj<ModalProps> = {
},
},
className: {
control: 'none',
control: {
type: undefined,
},
},
'data-testid': {
control: 'none',
control: {
type: undefined,
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const meta: Meta = {
} as Meta;
export default meta;

export const Heading: StoryObj = {
export const Heading: StoryObj<typeof H1> = {
render: props => (
<Wrapper>
<H1 {...props}>This is heading 1</H1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const meta: Meta = {
export default meta;

export const Text: StoryObj = {
// @ts-expect-error: the type of Textcomponent is union of objects and hence hard to fullfill
render: props => (
<Wrapper>
<ColoredBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export const RotateDeviceImage: StoryObj<RotateDeviceImageProps> = {
},
argTypes: {
deviceModel: {
options: DeviceModelInternal,
options: Object.values(DeviceModelInternal),
control: {
type: 'select',
labels: DeviceModelInternal,
},
},
deviceColor: {
Expand Down

0 comments on commit 3812b75

Please sign in to comment.