Make Tailwind work with Storybook. Have it use our Button
This commit is contained in:
parent
398bfa879e
commit
f02a035911
7 changed files with 60 additions and 59 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import sharedConfig from '../webpack/shared';
|
||||||
|
|
||||||
import type { StorybookConfig } from '@storybook/core-common';
|
import type { StorybookConfig } from '@storybook/core-common';
|
||||||
|
|
||||||
const config: StorybookConfig = {
|
const config: StorybookConfig = {
|
||||||
|
@ -9,11 +11,32 @@ const config: StorybookConfig = {
|
||||||
'@storybook/addon-links',
|
'@storybook/addon-links',
|
||||||
'@storybook/addon-essentials',
|
'@storybook/addon-essentials',
|
||||||
'@storybook/addon-interactions',
|
'@storybook/addon-interactions',
|
||||||
|
{
|
||||||
|
name: '@storybook/addon-postcss',
|
||||||
|
options: {
|
||||||
|
postcssLoaderOptions: {
|
||||||
|
implementation: require('postcss'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
framework: '@storybook/react',
|
framework: '@storybook/react',
|
||||||
core: {
|
core: {
|
||||||
builder: '@storybook/builder-webpack5',
|
builder: '@storybook/builder-webpack5',
|
||||||
},
|
},
|
||||||
|
webpackFinal: async (config) => {
|
||||||
|
config.resolve!.alias = {
|
||||||
|
...sharedConfig.resolve!.alias,
|
||||||
|
...config.resolve!.alias,
|
||||||
|
};
|
||||||
|
|
||||||
|
config.resolve!.modules = [
|
||||||
|
...sharedConfig.resolve!.modules!,
|
||||||
|
...config.resolve!.modules!,
|
||||||
|
];
|
||||||
|
|
||||||
|
return config;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
|
@ -1,3 +1,5 @@
|
||||||
|
import '../app/styles/tailwind.css';
|
||||||
|
|
||||||
export const parameters = {
|
export const parameters = {
|
||||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||||
controls: {
|
controls: {
|
||||||
|
|
|
@ -200,6 +200,7 @@
|
||||||
"@storybook/addon-essentials": "^6.5.16",
|
"@storybook/addon-essentials": "^6.5.16",
|
||||||
"@storybook/addon-interactions": "^6.5.16",
|
"@storybook/addon-interactions": "^6.5.16",
|
||||||
"@storybook/addon-links": "^6.5.16",
|
"@storybook/addon-links": "^6.5.16",
|
||||||
|
"@storybook/addon-postcss": "^2.0.0",
|
||||||
"@storybook/builder-webpack5": "^6.5.16",
|
"@storybook/builder-webpack5": "^6.5.16",
|
||||||
"@storybook/manager-webpack5": "^6.5.16",
|
"@storybook/manager-webpack5": "^6.5.16",
|
||||||
"@storybook/react": "^6.5.16",
|
"@storybook/react": "^6.5.16",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Button } from './Button';
|
import Button from 'soapbox/components/ui/button/button';
|
||||||
|
|
||||||
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
||||||
export default {
|
export default {
|
||||||
|
@ -9,7 +9,19 @@ export default {
|
||||||
component: Button,
|
component: Button,
|
||||||
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
||||||
argTypes: {
|
argTypes: {
|
||||||
backgroundColor: { control: 'color' },
|
theme: {
|
||||||
|
control: 'select',
|
||||||
|
options: [
|
||||||
|
'primary',
|
||||||
|
'secondary',
|
||||||
|
'tertiary',
|
||||||
|
'accent',
|
||||||
|
'danger',
|
||||||
|
'transparent',
|
||||||
|
'outline',
|
||||||
|
'muted',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
} as ComponentMeta<typeof Button>;
|
} as ComponentMeta<typeof Button>;
|
||||||
|
|
||||||
|
@ -19,23 +31,23 @@ const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />;
|
||||||
export const Primary = Template.bind({});
|
export const Primary = Template.bind({});
|
||||||
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
||||||
Primary.args = {
|
Primary.args = {
|
||||||
primary: true,
|
theme: 'primary',
|
||||||
label: 'Button',
|
text: 'Button',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Secondary = Template.bind({});
|
export const Secondary = Template.bind({});
|
||||||
Secondary.args = {
|
Secondary.args = {
|
||||||
label: 'Button',
|
text: 'Button',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Large = Template.bind({});
|
export const Large = Template.bind({});
|
||||||
Large.args = {
|
Large.args = {
|
||||||
size: 'large',
|
size: 'lg',
|
||||||
label: 'Button',
|
text: 'Button',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Small = Template.bind({});
|
export const Small = Template.bind({});
|
||||||
Small.args = {
|
Small.args = {
|
||||||
size: 'small',
|
size: 'sm',
|
||||||
label: 'Button',
|
text: 'Button',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
import './button.css';
|
|
||||||
|
|
||||||
interface ButtonProps {
|
|
||||||
/**
|
|
||||||
* Is this the principal call to action on the page?
|
|
||||||
*/
|
|
||||||
primary?: boolean;
|
|
||||||
/**
|
|
||||||
* What background color to use
|
|
||||||
*/
|
|
||||||
backgroundColor?: string;
|
|
||||||
/**
|
|
||||||
* How large should the button be?
|
|
||||||
*/
|
|
||||||
size?: 'small' | 'medium' | 'large';
|
|
||||||
/**
|
|
||||||
* Button contents
|
|
||||||
*/
|
|
||||||
label: string;
|
|
||||||
/**
|
|
||||||
* Optional click handler
|
|
||||||
*/
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Primary UI component for user interaction
|
|
||||||
*/
|
|
||||||
export const Button = ({
|
|
||||||
primary = false,
|
|
||||||
size = 'medium',
|
|
||||||
backgroundColor,
|
|
||||||
label,
|
|
||||||
...props
|
|
||||||
}: ButtonProps) => {
|
|
||||||
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
type='button'
|
|
||||||
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
||||||
style={{ backgroundColor }}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
};
|
|
Binary file not shown.
15
yarn.lock
15
yarn.lock
|
@ -3028,6 +3028,17 @@
|
||||||
regenerator-runtime "^0.13.7"
|
regenerator-runtime "^0.13.7"
|
||||||
ts-dedent "^2.0.0"
|
ts-dedent "^2.0.0"
|
||||||
|
|
||||||
|
"@storybook/addon-postcss@^2.0.0":
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@storybook/addon-postcss/-/addon-postcss-2.0.0.tgz#ec61cb9bb2662f408072b35c466c7df801c28498"
|
||||||
|
integrity sha512-Nt82A7e9zJH4+A+VzLKKswUfru+T6FJTakj4dccP0i8DSn7a0CkzRPrLuZBq8tg4voV6gD74bcDf3gViCVBGtA==
|
||||||
|
dependencies:
|
||||||
|
"@storybook/node-logger" "^6.1.14"
|
||||||
|
css-loader "^3.6.0"
|
||||||
|
postcss "^7.0.35"
|
||||||
|
postcss-loader "^4.2.0"
|
||||||
|
style-loader "^1.3.0"
|
||||||
|
|
||||||
"@storybook/addon-toolbars@6.5.16":
|
"@storybook/addon-toolbars@6.5.16":
|
||||||
version "6.5.16"
|
version "6.5.16"
|
||||||
resolved "https://registry.yarnpkg.com/@storybook/addon-toolbars/-/addon-toolbars-6.5.16.tgz#9de04f9cc64b68d6cb680aa1c4fbf874e11afa32"
|
resolved "https://registry.yarnpkg.com/@storybook/addon-toolbars/-/addon-toolbars-6.5.16.tgz#9de04f9cc64b68d6cb680aa1c4fbf874e11afa32"
|
||||||
|
@ -3571,7 +3582,7 @@
|
||||||
prettier ">=2.2.1 <=2.3.0"
|
prettier ">=2.2.1 <=2.3.0"
|
||||||
ts-dedent "^2.0.0"
|
ts-dedent "^2.0.0"
|
||||||
|
|
||||||
"@storybook/node-logger@6.5.16":
|
"@storybook/node-logger@6.5.16", "@storybook/node-logger@^6.1.14":
|
||||||
version "6.5.16"
|
version "6.5.16"
|
||||||
resolved "https://registry.yarnpkg.com/@storybook/node-logger/-/node-logger-6.5.16.tgz#d57fd6204c2abfbc297551d98ad5475dd73207cc"
|
resolved "https://registry.yarnpkg.com/@storybook/node-logger/-/node-logger-6.5.16.tgz#d57fd6204c2abfbc297551d98ad5475dd73207cc"
|
||||||
integrity sha512-YjhBKrclQtjhqFNSO+BZK+RXOx6EQypAELJKoLFaawg331e8VUfvUuRCNB3fcEWp8G9oH13PQQte0OTjLyyOYg==
|
integrity sha512-YjhBKrclQtjhqFNSO+BZK+RXOx6EQypAELJKoLFaawg331e8VUfvUuRCNB3fcEWp8G9oH13PQQte0OTjLyyOYg==
|
||||||
|
@ -14002,7 +14013,7 @@ postcss-value-parser@^4.1.0:
|
||||||
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.1.0.tgz#443f6a20ced6481a2bda4fa8532a6e55d789a2cb"
|
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.1.0.tgz#443f6a20ced6481a2bda4fa8532a6e55d789a2cb"
|
||||||
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==
|
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==
|
||||||
|
|
||||||
postcss@^7.0.14, postcss@^7.0.26, postcss@^7.0.32, postcss@^7.0.36, postcss@^7.0.5, postcss@^7.0.6:
|
postcss@^7.0.14, postcss@^7.0.26, postcss@^7.0.32, postcss@^7.0.35, postcss@^7.0.36, postcss@^7.0.5, postcss@^7.0.6:
|
||||||
version "7.0.39"
|
version "7.0.39"
|
||||||
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.39.tgz#9624375d965630e2e1f2c02a935c82a59cb48309"
|
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.39.tgz#9624375d965630e2e1f2c02a935c82a59cb48309"
|
||||||
integrity sha512-yioayjNbHn6z1/Bywyb2Y4s3yvDAeXGOyxqD+LnVOinq6Mdmd++SW2wUNVzavyyHxd6+DxzWGIuosg6P1Rj8uA==
|
integrity sha512-yioayjNbHn6z1/Bywyb2Y4s3yvDAeXGOyxqD+LnVOinq6Mdmd++SW2wUNVzavyyHxd6+DxzWGIuosg6P1Rj8uA==
|
||||||
|
|
Loading…
Reference in a new issue