Browse Source
Co-authored-by: david <[email protected]> Reviewed-on: https://git.poyner.page/david/drcl/pulls/2 Co-authored-by: david <[email protected]> Co-committed-by: david <[email protected]>pull/3/head
david
2 years ago
14 changed files with 953 additions and 1761 deletions
@ -1,4 +1,32 @@
|
||||
const path = require('path'); |
||||
const fs = require('fs'); |
||||
|
||||
module.exports = { |
||||
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], |
||||
addons: ['@storybook/addon-links', '@storybook/addon-essentials'], |
||||
|
||||
webpackFinal: async (config) => { |
||||
config.resolve.alias = { |
||||
'@emotion/core': getPackageDir('@emotion/react'), |
||||
'@emotion/styled': getPackageDir('@emotion/styled'), |
||||
}; |
||||
return config; |
||||
}, |
||||
}; |
||||
|
||||
// Fix for package resolution
|
||||
function getPackageDir(filepath) { |
||||
let currDir = path.dirname(require.resolve(filepath)); |
||||
while (true) { |
||||
if (fs.existsSync(path.join(currDir, 'package.json'))) { |
||||
return currDir; |
||||
} |
||||
const { dir, root } = path.parse(currDir); |
||||
if (dir === root) { |
||||
throw new Error( |
||||
`Could not find package.json in the parent directories starting from ${filepath}.` |
||||
); |
||||
} |
||||
currDir = dir; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,26 @@
|
||||
import { Meta } from '@storybook/react/types-6-0'; |
||||
import { Story } from '@storybook/react'; |
||||
import StyledButton from './StyledButton'; |
||||
|
||||
export default { |
||||
title: 'Components/StyledButton', |
||||
component: StyledButton, |
||||
} as Meta; |
||||
|
||||
// Create a master template for mapping args to render the Button component
|
||||
const Template: Story = (args) => <StyledButton {...args} />; |
||||
|
||||
// Reuse that template for creating different stories
|
||||
export const Primary = Template.bind({}); |
||||
Primary.args = { label: 'Primary 😃', size: 'lg' }; |
||||
|
||||
export const Secondary = Template.bind({}); |
||||
Secondary.args = { |
||||
...Primary.args, |
||||
variant: 'secondary', |
||||
label: 'Secondary 😇', |
||||
size: 'lg', |
||||
}; |
||||
|
||||
export const isSmall = Template.bind({}); |
||||
isSmall.args = { label: 'isSmall 😃', isSmall }; |
@ -0,0 +1,30 @@
|
||||
import tw, { styled, css, theme } from 'twin.macro'; |
||||
|
||||
const StyledButton = styled.button(({ variant, isSmall }) => [ |
||||
// The common button styles added with the tw import
|
||||
tw`px-8 py-2 rounded focus:outline-none transform duration-75`, |
||||
|
||||
// Use the variant grouping feature to add variants to multiple classes
|
||||
tw`hocus:(scale-105 text-yellow-400)`, |
||||
|
||||
// Use props to conditionally style your components
|
||||
variant === 'primary' && tw`bg-black text-white border-black`, |
||||
|
||||
// Combine regular css with tailwind classes within backticks
|
||||
variant === 'secondary' && [ |
||||
css` |
||||
box-shadow: 0 0.1em 0 0 rgba(0, 0, 0, 0.25); |
||||
`,
|
||||
tw`border-2 border-yellow-600`, |
||||
], |
||||
|
||||
// Conditional props can be used
|
||||
isSmall ? tw`text-sm` : tw`text-lg`, |
||||
|
||||
// The theme import can supply values from your tailwind.config.js
|
||||
css` |
||||
color: ${theme`colors.white`}; |
||||
`,
|
||||
]); |
||||
|
||||
export default StyledButton; |
@ -0,0 +1 @@
|
||||
export { default } from './StyledButton'; |
@ -1,3 +1,3 @@
|
||||
import Button from './components/Button'; |
||||
|
||||
export { Button }; |
||||
import StyledButton from './components/StyledButton'; |
||||
export { Button, StyledButton }; |
||||
|
@ -0,0 +1,11 @@
|
||||
module.exports = { |
||||
theme: { |
||||
extend: { |
||||
colors: { |
||||
electric: '#db00ff', |
||||
ribbon: '#0047ff', |
||||
}, |
||||
}, |
||||
}, |
||||
plugins: [], |
||||
}; |
@ -0,0 +1,9 @@
|
||||
import 'twin.macro'; |
||||
import styledImport from '@emotion/styled'; |
||||
import { css as cssImport } from '@emotion/react'; |
||||
|
||||
declare module 'twin.macro' { |
||||
// The styled and css imports
|
||||
const styled: typeof styledImport; |
||||
const css: typeof cssImport; |
||||
} |
Loading…
Reference in new issue