Skip to content

Commit

Permalink
introduce storybook for Link and Button
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Fidelman committed Oct 29, 2020
1 parent b036b59 commit 27a9ca3
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/preset-typescript',
// '@storybook/preset-typescript',
],
}
26 changes: 13 additions & 13 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const path = require('path')

module.exports = ({ config }) => {
config.module.rules[0].use[0].loader = require.resolve('babel-loader')
config.module.rules[0].use[0].options.presets = [
require.resolve('@babel/preset-react'),
require.resolve('@babel/preset-env'),
]
// config.module.rules[0].use[0].loader = require.resolve('babel-loader')
// config.module.rules[0].use[0].options.presets = [
// require.resolve('@babel/preset-react'),
// require.resolve('@babel/preset-env'),
// ]

config.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
plugins: [],
},
})
// config.module.rules.push({
// test: /\.(ts|tsx)$/,
// loader: require.resolve('babel-loader'),
// options: {
// presets: [['react-app', { flow: false, typescript: true }]],
// plugins: [],
// },
// })

// Remove the existing css rule
config.module.rules = config.module.rules.filter(
Expand Down
60 changes: 60 additions & 0 deletions src/components/Button/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react'
// also exported from '@storybook/react' if you can deal with breaking changes in 6.1
import { Story, Meta } from '@storybook/react'

import Button, { ButtonProps, ButtonSize } from './'

const story: Meta = {
title: 'Button',
component: Button,
argTypes: {
disabled: {
control: {
type: 'boolean',
},
},
size: {
defaultValue: ButtonSize.Normal,
control: {
type: 'select',
options: [ButtonSize.Normal, ButtonSize.Small],
},
},
inverted: {
defaultValue: false,
control: {
type: 'boolean',
},
},
onClick: { action: 'click' },
onFocus: { action: 'focus' },
onBlur: { action: 'blur' },
},
}

const Template: Story<ButtonProps> = (args: ButtonProps) => <Button {...args} />

export const Default = Template.bind({})
Default.args = {
children: 'Button',
}

export const Inverted = Template.bind({})
Inverted.args = {
children: 'Button',
inverted: true,
}

export const Small = Template.bind({})
Small.args = {
children: 'Button',
size: ButtonSize.Small,
}

export const Disabled = Template.bind({})
Disabled.args = {
children: 'Button',
disabled: true,
}

export default story
4 changes: 2 additions & 2 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as React from 'react'
import * as S from './styles'

export enum ButtonSize {
Normal,
Small,
Normal = 'Normal',
Small = 'Small',
}

export interface StyledButtonProps {
Expand Down
5 changes: 5 additions & 0 deletions src/components/ButtonAsLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import styled from 'styled-components'
import { ButtonSize, StyledButtonProps } from '../Button'
import { applyButtonStyles } from '../Button/styles'

/**
* The component is used where we need to have
* a Button which behaves AS a Link
*/

const StyledButton = styled.a<StyledButtonProps>`
${(p) =>
applyButtonStyles({
Expand Down
55 changes: 55 additions & 0 deletions src/components/Link/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react'
// also exported from '@storybook/react' if you can deal with breaking changes in 6.1
import { Story, Meta } from '@storybook/react'

import Link, { LinkProps } from './'
import { ButtonSize } from '../Button'

const story: Meta = {
title: 'Link',
component: Link,
argTypes: {
href: {
defaultValue: 'https://cesko.digital/',
control: {
type: 'text',
},
},
disabled: {
control: {
type: 'boolean',
},
},
size: {
defaultValue: ButtonSize.Normal,
control: {
type: 'select',
options: [ButtonSize.Normal, ButtonSize.Small],
},
},
onClick: { action: 'click' },
onFocus: { action: 'focus' },
onBlur: { action: 'blur' },
},
}

const Template: Story<LinkProps> = (args: LinkProps) => <Link {...args} />

export const Default = Template.bind({})
Default.args = {
children: 'Link',
}

export const Small = Template.bind({})
Small.args = {
children: 'Link',
size: ButtonSize.Small,
}

export const Disabled = Template.bind({})
Disabled.args = {
children: 'Link',
disabled: true,
}

export default story
5 changes: 5 additions & 0 deletions src/components/LinkAsButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import styled from 'styled-components'
import { applyLinkStyles } from '../Link/styles'
import { StyledLinkProps } from '../Link'

/**
* The component is used where we need to have
* a Link which behaves AS a Button
*/

const StyledLink = styled.button<StyledLinkProps>`
${(p) => applyLinkStyles({ size: p.size, disabled: p.disabled })}
`
Expand Down
40 changes: 0 additions & 40 deletions stories/example/Button.stories.tsx

This file was deleted.

52 changes: 0 additions & 52 deletions stories/example/Button.tsx

This file was deleted.

30 changes: 0 additions & 30 deletions stories/example/button.css

This file was deleted.

1 change: 0 additions & 1 deletion stories/postcss.config.js

This file was deleted.

0 comments on commit 27a9ca3

Please sign in to comment.