diff --git a/apps/storybook-react/stories/Button.stories.jsx b/apps/storybook-react/stories/Button.stories.tsx similarity index 81% rename from apps/storybook-react/stories/Button.stories.jsx rename to apps/storybook-react/stories/Button.stories.tsx index 56c7bdcd46..eb2c7201c6 100644 --- a/apps/storybook-react/stories/Button.stories.jsx +++ b/apps/storybook-react/stories/Button.stories.tsx @@ -1,30 +1,11 @@ import React from 'react' -import { Button, Icon } from '@equinor/eds-core-react' +import { Button, Icon, ButtonProps } from '@equinor/eds-core-react' import styled from 'styled-components' -import { withKnobs, select, text } from '@storybook/addon-knobs' +import { Meta, Story } from '@storybook/react' import { action } from '@storybook/addon-actions' import './../style.css' import './button.css' -export default { - title: 'Components/Button', - component: Button, -} - -const VARIANT = { - CONTAINED: 'contained', - OUTLINED: 'outlined', - GHOST: 'ghost', - GHOST_ICON: 'ghost_icon', -} - -const COLOR = { - PRIMARY: 'primary', - SECONDARY: 'secondary', - DANGER: 'danger', - DISABLED: 'disabled', -} - const Wrapper = styled.div` margin: 32px; display: grid; @@ -32,7 +13,16 @@ const Wrapper = styled.div` grid-template-columns: repeat(4, fit-content(100%)); ` -export const allButtons = () => ( +export default { + title: 'Components/Button', + component: Button, +} as Meta + +export const Default: Story = (args) => ( + +) + +export const All: Story = () => ( @@ -72,7 +62,8 @@ export const allButtons = () => ( ) -export const contained = () => ( + +export const Contained: Story = () => ( @@ -108,9 +99,7 @@ export const contained = () => ( ) -contained.storyName = 'Contained (default)' - -export const outlined = () => ( +export const Outlined: Story = () => ( - -) - -export const form = () => { - const handleSubmit = (e) => { +export const Form: Story = () => { + const handleSubmit = (e: React.FormEvent) => { e.preventDefault() // to prevent navigation from storybook action('onSubmit')(e) } return ( -
+
) } -export const fileUpload = () => { - return ( - - - - - ) -} +export const FileUpload: Story = () => ( + + + + +) -export const link = () => ( +export const Link: Story = () => ( ) - -knobs.storyName = 'With knobs' -knobs.decorators = [withKnobs] diff --git a/apps/storybook-react/stories/Divider.stories.tsx b/apps/storybook-react/stories/Divider.stories.tsx index 984b2a89a5..fd30b5c78f 100644 --- a/apps/storybook-react/stories/Divider.stories.tsx +++ b/apps/storybook-react/stories/Divider.stories.tsx @@ -9,20 +9,6 @@ import { Story, Meta } from '@storybook/react/types-6-0' export default { title: 'Components/Divider', component: Divider, - argTypes: { - color: { - control: { - type: 'radio', - options: ['lighter', 'light', 'medium'], - }, - }, - variant: { - control: { - type: 'radio', - options: ['medium', 'small'], - }, - }, - }, } as Meta const Wrapper = styled.div` diff --git a/libraries/core-react/src/Button/Button.tsx b/libraries/core-react/src/Button/Button.tsx index b23b948efd..7e925b25c4 100644 --- a/libraries/core-react/src/Button/Button.tsx +++ b/libraries/core-react/src/Button/Button.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef, ElementType } from 'react' +import React, { forwardRef, ElementType, ButtonHTMLAttributes } from 'react' import styled, { css } from 'styled-components' import { button, Button as ButtonType, ButtonGroups } from './Button.tokens' import { typographyTemplate } from '../_common/templates' @@ -109,7 +109,7 @@ const ButtonBase = styled.button` content: ''; } ` -type Props = { +export type ButtonProps = { /** Specifies color */ color?: 'primary' | 'secondary' | 'danger' /** Specifies which variant to use */ @@ -119,50 +119,54 @@ type Props = { * If defined, an 'a' element is used as root instead of 'button' */ href?: string - /** Is disabled */ + /** Is the button disabled */ disabled?: boolean - /** Change html element */ + /** Change html element. */ as?: ElementType - /** ttype */ + /** Type of button + * @default 'button' + */ type?: string -} & React.HTMLAttributes - -export const Button = forwardRef(function Button( - { - color = 'primary', - variant = 'contained', - children, - disabled, - href, - ...other - }, - ref, -) { - const colorBase: ButtonGroups | Partial = colors[color] || {} - const token = colorBase[variant] || {} - const disabledToken = colors.disabled[variant] || {} - - const as: ElementType = href ? 'a' : other.as ? other.as : 'button' - const type = href || other.as ? undefined : 'button' - const tabIndex = disabled ? -1 : other.tabIndex - - const buttonProps = { +} & ButtonHTMLAttributes + +export const Button = forwardRef( + function Button( + { + color = 'primary', + variant = 'contained', + children, + disabled = false, + href, + ...other + }, ref, - as, - href, - type, - token, - disabledToken, - disabled, - tabIndex, - ...other, - } + ) { + const colorBase: ButtonGroups | Partial = colors[color] || {} + const token = colorBase[variant] || {} + const disabledToken = colors.disabled[variant] || {} + + const as: ElementType = href ? 'a' : other.as ? other.as : 'button' + const type = href || other.as ? undefined : 'button' + const tabIndex = disabled ? -1 : other.tabIndex + + const buttonProps = { + ref, + as, + href, + type, + token, + disabledToken, + disabled, + tabIndex, + ...other, + } - return ( - - {children} - - ) -}) + return ( + + {children} + + ) + }, +) // Button.displayName = 'Button' diff --git a/libraries/core-react/src/Button/index.ts b/libraries/core-react/src/Button/index.ts index 4d0a670f4a..8486fd6d62 100644 --- a/libraries/core-react/src/Button/index.ts +++ b/libraries/core-react/src/Button/index.ts @@ -1 +1 @@ -export { Button } from './Button' +export * from './Button' diff --git a/libraries/core-react/src/index.ts b/libraries/core-react/src/index.ts index 4613a152a4..74e95223c7 100644 --- a/libraries/core-react/src/index.ts +++ b/libraries/core-react/src/index.ts @@ -1,5 +1,5 @@ /* eslint-disable import/prefer-default-export */ -export { Button } from './Button' +export * from './Button' export * from './Typography' export { Table } from './Table' export { Divider, DividerProps } from './Divider'