From f5f30f787976b4198bfb064e08fa7775382160f3 Mon Sep 17 00:00:00 2001 From: Matt Wood Date: Thu, 27 May 2021 11:14:48 -0500 Subject: [PATCH 1/2] fix: add button sizes to styled-system variants --- .eslintrc.js | 13 ++-- docs/pages/components/Icon.mdx | 4 +- docs/pages/components/Menu.mdx | 4 +- docs/pages/examples/Buttons.mdx | 2 +- docs/pages/examples/Forms.mdx | 106 ++++++++++++++++---------------- docs/pages/index.mdx | 4 +- docs/theme/index.js | 2 + src/Button/Button.stories.tsx | 11 +++- src/Button/index.tsx | 70 +++++++++------------ src/layout.tsx | 13 +++- src/theme.ts | 8 +-- 11 files changed, 126 insertions(+), 111 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 264876d2..69a6be64 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,12 +8,13 @@ module.exports = { ], rules: { 'import/no-unresolved': [2, { ignore: ['minerva-ui', '@docusaurus', '@theme'] }], - "import/no-unused-modules": [ - 1, - { - "unusedExports": true, - } - ], + 'import/no-unused-modules': 0, + // "import/no-unused-modules": [ + // 1, + // { + // "unusedExports": true, + // } + // ], 'react/display-name': 1, 'react/react-in-jsx-scope': 0, }, diff --git a/docs/pages/components/Icon.mdx b/docs/pages/components/Icon.mdx index faff3559..d498ee87 100644 --- a/docs/pages/components/Icon.mdx +++ b/docs/pages/components/Icon.mdx @@ -31,8 +31,8 @@ const customTheme = { icons: { // declare the key and component in your theme, then you can use the key as name in the component warning: Warning, - } -} + }, +}; const App = () => ( diff --git a/docs/pages/components/Menu.mdx b/docs/pages/components/Menu.mdx index bd2d4bc4..f7b108fd 100644 --- a/docs/pages/components/Menu.mdx +++ b/docs/pages/components/Menu.mdx @@ -8,7 +8,9 @@ Built on top of the [Reach UI Menu Button](https://reacttraining.com/reach-ui/me When you need to trigger actions from a dropdown (such as when clicking in the menu of a desktop application). -Do _not_ use this if you need to store a value. Use a `` component + instead. ```js diff --git a/docs/pages/examples/Buttons.mdx b/docs/pages/examples/Buttons.mdx index 96dabaf0..b0f16dee 100644 --- a/docs/pages/examples/Buttons.mdx +++ b/docs/pages/examples/Buttons.mdx @@ -23,7 +23,7 @@ render( + diff --git a/docs/pages/examples/Forms.mdx b/docs/pages/examples/Forms.mdx index fa019274..dc6a51bd 100644 --- a/docs/pages/examples/Forms.mdx +++ b/docs/pages/examples/Forms.mdx @@ -181,64 +181,66 @@ Recreated from [Tailwind CSS example](https://tailwindcss.com/components/forms) return ( {items.map(plan => ( - - ))} - - ) + + ))} + + ); }; ``` diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index e3483988..1d7f351e 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -69,8 +69,8 @@ const customTheme = { icons: { // declare the key and component in your theme, then you can use the key as name in the component warning: Warning, - } -} + }, +}; const App = () => ( diff --git a/docs/theme/index.js b/docs/theme/index.js index 105f3772..294bb584 100644 --- a/docs/theme/index.js +++ b/docs/theme/index.js @@ -232,6 +232,7 @@ const Layout = ({ filename, config: _config, pageMap, children }) => { className="text-current p-2 -mr-2" href={config.github} target="_blank" + rel="noreferrer" > @@ -304,6 +305,7 @@ const Layout = ({ filename, config: _config, pageMap, children }) => { filepathWithName } target="_blank" + rel="noreferrer" > Edit this page on GitHub diff --git a/src/Button/Button.stories.tsx b/src/Button/Button.stories.tsx index 93566d98..ab5e334f 100644 --- a/src/Button/Button.stories.tsx +++ b/src/Button/Button.stories.tsx @@ -20,7 +20,9 @@ const meta: Meta = { export default meta; -const Template: Story = (args: Omit) => + + +); + export const LoadingButton = Template.bind({}); LoadingButton.args = { children: 'Basic Button', diff --git a/src/Button/index.tsx b/src/Button/index.tsx index e8d3568d..c349da4f 100644 --- a/src/Button/index.tsx +++ b/src/Button/index.tsx @@ -45,35 +45,38 @@ export interface ButtonProps extends MinervaProps, PseudoBoxProps { name?: string; /** Button variant styles inherited from theme */ variant?: string; + /** Size variants defined using Styled System variants (https://styled-system.com/variants) */ + size?: string; /** HTML Button Type (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) */ type?: 'button' | 'reset' | 'submit'; } -// export const Button = forwardRefWithAs(function Button( -// { -// children, -// disabled = false, -// as: Comp = 'button', -// isLoading = false, -// name, -// variant, -// ...props -// }, -// forwardedRef -// ) { +export function useVariant(componentName: string, variant?: string) { + const theme = useTheme(); + + const componentVariants = theme?.variants?.[componentName]; + + const variantExistsInTheme = + variant && + componentVariants && + Object.keys(componentVariants).includes(variant); + + // if a variant is provided and it doesn't exist in the current theme, warn in development + warning( + !variant || variantExistsInTheme, + `Variant "${variant}" not found in theme variants for