Add a type on CatalogDecorator (#1742)

* Add a type on CatalogDecorator

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>

* Type more catalogs

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>

---------

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>
This commit is contained in:
gitstart-twenty
2023-09-28 12:44:55 +03:00
committed by GitHub
parent aa0c61bed9
commit b2bac0b217
29 changed files with 101 additions and 54 deletions

View File

@ -1,3 +1,4 @@
import { ComponentProps, JSX } from 'react';
import styled from '@emotion/styled';
import { Decorator } from '@storybook/react';
@ -74,10 +75,12 @@ const emptyDimension = {
props: () => ({}),
} as CatalogDimension;
export type CatalogDimension = {
export type CatalogDimension<
ComponentType extends React.ElementType = () => JSX.Element,
> = {
name: string;
values: any[];
props: (value: any) => Record<string, any>;
props: (value: any) => Partial<ComponentProps<ComponentType>>;
labels?: (value: any) => string;
};

View File

@ -0,0 +1,24 @@
import { ElementType } from 'react';
import { StoryObj } from '@storybook/react';
import type {
CatalogDimension,
CatalogOptions,
} from './decorators/CatalogDecorator';
export type CatalogStory<
StoryType extends StoryObj<ComponentType>,
ComponentType extends ElementType,
> = {
args?: StoryType['args'];
argTypes?: StoryType['argTypes'];
play?: StoryType['play'];
render?: StoryType['render'];
parameters: StoryType['parameters'] & {
catalog: {
dimensions: CatalogDimension<ComponentType>[];
options?: CatalogOptions;
};
};
decorators: StoryType['decorators'];
};