Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
refactor(toggle-group): split into composable components (#388)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Renames ToggleGroup to FieldSet to match intended
usage.
  • Loading branch information
HendrikThePendric authored and varl committed Nov 25, 2019
1 parent eb104f5 commit e4beb91
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 239 deletions.
22 changes: 22 additions & 0 deletions src/FieldSet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import propTypes from 'prop-types'

const FieldSet = ({ className, children }) => (
<fieldset className={className}>
{children}
<style jsx>{`
fieldset {
border: none;
margin: 0;
padding: 0;
}
`}</style>
</fieldset>
)

FieldSet.propTypes = {
className: propTypes.string,
children: propTypes.node.isRequired,
}

export { FieldSet }
29 changes: 29 additions & 0 deletions src/Legend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import propTypes from 'prop-types'
import cx from 'classnames'
import { theme, spacers } from '../theme.js'

const Legend = ({ className, children, required }) => (
<legend className={cx(className, { required })}>
{children}
<style jsx>{`
legend {
font-size: 16px;
color: ${theme.default};
margin: ${spacers.dp12} 0 ${spacers.dp12};
}
legend.required::after {
padding-left: ${spacers.dp4};
content: '*';
}
`}</style>
</legend>
)

Legend.propTypes = {
className: propTypes.string,
children: propTypes.node.isRequired,
required: propTypes.bool,
}

export { Legend }
126 changes: 0 additions & 126 deletions src/RadioGroup/index.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export { ComponentCover } from './ComponentCover'
export { Divider } from './Divider'
export { FileField } from './FileField'
export { Help } from './Help'
export { FieldSet } from './FieldSet'
export { FormControl } from './FormControl'
export { Help } from './Help'
export { Input } from './Input'
export { Legend } from './Legend'
export { LinearLoader } from './LinearLoader'
export { Logo, LogoIcon, LogoIconWhite, LogoWhite } from './Logo'
export { MenuList } from './MenuList'
export { MenuItem } from './MenuItem'
export { Radio } from './Radio'
export { RadioGroup } from './RadioGroup'
export { ScreenCover } from './ScreenCover'
export { Select } from './Select'
export { Switch } from './Switch'
Expand Down
57 changes: 57 additions & 0 deletions stories/FieldSet.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import { FieldSet, FormControl, Radio, Help, Legend } from '../src'

import markdown from './info/atoms/fieldSet.md'

const onChange = () => {
console.log('Radio was clicked, nothing else will happen')
}

storiesOf('FieldSet', module)
.addParameters({
notes: {
markdown,
},
})
.add('Default', () => (
<FieldSet>
It renders something in a fieldset element without the browser
styles
</FieldSet>
))
.add('Usage example - a radio button group with error status', () => (
<FieldSet>
<Legend required>Choose an option</Legend>
<FormControl>
<Radio
onChange={onChange}
name="radio"
value="first"
label="First"
error
/>
</FormControl>
<FormControl>
<Radio
onChange={onChange}
name="radio"
value="second"
label="Second"
error
/>
</FormControl>
<FormControl>
<Radio
onChange={onChange}
name="radio"
value="third"
label="Third"
error
/>
</FormControl>
<Help error indent={false}>
You really have to choose something!
</Help>
</FieldSet>
))
4 changes: 1 addition & 3 deletions stories/InputField.stories.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { storiesOf } from '@storybook/react'
import { resolve } from 'styled-jsx/css'
import React, { Fragment } from 'react'
import React from 'react'

import { Input, Help } from '../src'
import { colors } from '../src/theme'

const logger = ({ target }) => console.info(`${target.name}: ${target.value}`)

Expand Down
20 changes: 20 additions & 0 deletions stories/Legend.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import { Legend } from '../src'

import markdown from './info/atoms/legend.md'

storiesOf('Legend', module)
.addParameters({
notes: {
markdown,
},
})
.add('Default', () => (
<Legend>I am wrapped in a legend which has some styling</Legend>
))
.add('Required', () => (
<Legend required>
I am wrapped in a legend which has some styling
</Legend>
))
105 changes: 0 additions & 105 deletions stories/RadioGroup.stories.js

This file was deleted.

2 changes: 1 addition & 1 deletion stories/SelectField.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment } from 'react'
import React from 'react'
import { storiesOf } from '@storybook/react'
import { Select, Help } from '../src'

Expand Down
Loading

0 comments on commit e4beb91

Please sign in to comment.