generated from timelessco/react-components-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added storyTemplate utils (#39)
* chore: added storyTemplate util * chore: added createControls utility * refactor(story): ♻️ remove console logs & added default args * chore: move storybook utils to storybook folder Co-authored-by: Navin <[email protected]>
- Loading branch information
1 parent
a6858ce
commit 8933d29
Showing
3 changed files
with
128 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as React from "react"; | ||
import { Story } from "@storybook/react"; | ||
|
||
import theme from "../src/theme/defaultTheme"; | ||
|
||
export const storyTemplate = <ComponentProps,>( | ||
Component: React.FC, | ||
defaultArgs?: Partial<ComponentProps>, | ||
) => (props: ComponentProps) => { | ||
const base: Story<ComponentProps> = args => <Component {...args} />; | ||
base.args = { ...defaultArgs, ...props }; | ||
return base; | ||
}; | ||
|
||
export const createUnionControl = (keys: any) => { | ||
return { | ||
control: { type: "inline-radio", options: Object.keys(keys) }, | ||
}; | ||
}; | ||
|
||
export const createControls = ( | ||
component: string, | ||
options?: { unions: string[]; ignore: string[] }, | ||
) => { | ||
const controls = options?.unions.reduce((cur, key) => { | ||
return { | ||
...cur, | ||
[key]: createUnionControl((theme as Record<string, any>)[component][key]), | ||
}; | ||
}, {}); | ||
|
||
const ignoredControls = options?.ignore.reduce((cur, key) => { | ||
return { | ||
...cur, | ||
[key]: { table: { disable: true } }, | ||
}; | ||
}, {}); | ||
|
||
return { ...controls, ...ignoredControls }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,5 @@ export const AlertIcon = forwardRefWithAs< | |
</Role> | ||
); | ||
}); | ||
|
||
export default Alert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8933d29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: