diff --git a/.storybook/main.js b/.storybook/main.js index 2317524d87..2c3ee5eb93 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -15,10 +15,6 @@ const config = { options: {}, }, - docs: { - defaultName: 'Docs' - }, - features: { measure: false } diff --git a/.storybook/preview.js b/.storybook/preview.js index 2342b64454..c1de799ae4 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -23,7 +23,6 @@ const preview = { }, viewport: { viewports: INITIAL_VIEWPORTS }, }, - tags: ['autodocs'], }; export default preview; diff --git a/stories/components-playground/ButtonPlayground.stories.js b/stories/components-playground/ButtonPlayground.stories.js new file mode 100644 index 0000000000..fa18ad39ba --- /dev/null +++ b/stories/components-playground/ButtonPlayground.stories.js @@ -0,0 +1,123 @@ +// Playground for Button + +const buttonVariants = ['default', 'strong', 'brand', 'minimal', 'negative'] +const layouts = ['Text only', 'Text + Icon', 'Icon only'] +const states = ['enabled', 'disabled', 'loading'] +const roundedOptions = [false, true] + +const defaultIcon = '' + +const loadingLoader = `` + +const renderIcon = (icon, hidden = false) => { + if (!icon) { + return '' + } + + return `${icon}` +} + +const renderButton = ({ label, variant, layout, state, icon, rounded }) => { + const isIconOnly = layout === 'Icon only' + const shouldRenderIcon = layout !== 'Text only' + const isLoading = state === 'loading' + const isDisabled = state === 'disabled' + const classes = ['btn'] + + classes.push(`btn-${variant}`) + + if (isIconOnly) { + classes.push('btn-icon') + } + + if (isLoading) { + classes.push('loading-indeterminate') + } + + const iconMarkup = renderIcon(icon || defaultIcon, true) + const loadingMarkup = isLoading + ? `${loadingLoader} + Loading ${label}` + : '' + + const buttonMarkup = `` + + if (rounded) { + return `
${buttonMarkup}
` + } + + return buttonMarkup +} + +export default { + title: 'Playground/Button', + argTypes: { + label: { + control: 'text', + }, + variant: { + control: 'select', + options: buttonVariants, + }, + layout: { + control: 'select', + options: layouts, + }, + state: { + control: 'select', + options: states, + }, + rounded: { + control: 'boolean', + }, + icon: { + control: 'text', + } + } +} + +export const PlaygroundButton = { + parameters: { + docs: { + codePanel: true, + source: { + transform: (_src, context) => { + const { label, variant, layout, state, icon, rounded } = context.args + + return renderButton({ + label, + variant: buttonVariants.includes(variant) ? variant : 'default', + layout, + state, + icon, + rounded, + }) + }, + }, + }, + }, + render: ({ label, variant, layout, state, icon, rounded }) => { + return renderButton({ + label, + variant: buttonVariants.includes(variant) ? variant : 'default', + layout, + state, + icon, + rounded, + }) + }, + args: { + label: 'Label', + variant: 'default', + layout: 'Text + Icon', + state: 'enabled', + rounded: false, + icon: '' + }, +} diff --git a/stories/create-stories-from-doc.js b/stories/create-stories-from-doc.js index ba3a5a4f52..659d6d58c7 100644 --- a/stories/create-stories-from-doc.js +++ b/stories/create-stories-from-doc.js @@ -31,6 +31,7 @@ function createTemplate(component) { toc: true \n\ }\n\ },\n\ + tags: ['autodocs'], }\n\ \n\ `