diff --git a/app/components/UI/Radio.js b/app/components/UI/Radio.js new file mode 100644 index 00000000..5989e178 --- /dev/null +++ b/app/components/UI/Radio.js @@ -0,0 +1,88 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { Radio as InformedRadio } from 'informed' +import styled from 'styled-components' +import { Label, Text } from 'components/UI' +import { Box } from 'rebass' + +const Wrapper = styled(Box)` + /* The container */ + .container { + display: block; + position: relative; + padding-left: 30px; + cursor: pointer; + user-select: none; + } + + /* Hide the browser's default radio button */ + .container input { + position: absolute; + opacity: 0; + cursor: pointer; + } + + /* Create a custom radio button */ + .selection { + position: absolute; + top: 1px; + left: 0; + height: 16px; + width: 16px; + border: 1px solid ${props => props.theme.colors.gray}; + border-radius: 50%; + } + + /* On mouse-over, add an orange border color */ + .container:hover input ~ .selection { + border: 1px solid ${props => props.theme.colors.lightningOrange}; + } + + /* When the radio button is checked, make the border orange */ + .container input:checked ~ .selection { + border: 1px solid ${props => props.theme.colors.lightningOrange}; + } + + /* Create the indicator (the dot/circle - hidden when not checked) */ + .selection:after { + content: ''; + position: absolute; + display: none; + } + + /* Show the indicator (dot/circle) when checked */ + .container input:checked ~ .selection:after { + display: block; + } + + /* Style the indicator (dot/circle) */ + .container .selection:after { + top: 3px; + left: 3px; + width: 8px; + height: 8px; + border-radius: 50%; + background: ${props => props.theme.colors.lightningOrange}; + } +` +const Radio = ({ value, label, description, fontWeight, onChange, onBlur, ...rest }) => ( + + + +) +Radio.propTypes = { + value: PropTypes.string.isRequired, + label: PropTypes.node, + description: PropTypes.node +} + +export default Radio diff --git a/app/components/UI/RadioGroup.js b/app/components/UI/RadioGroup.js new file mode 100644 index 00000000..5dd81580 --- /dev/null +++ b/app/components/UI/RadioGroup.js @@ -0,0 +1,3 @@ +import { RadioGroup } from 'informed' + +export default RadioGroup diff --git a/app/components/UI/index.js b/app/components/UI/index.js index 95dc31cd..8b2960d7 100644 --- a/app/components/UI/index.js +++ b/app/components/UI/index.js @@ -26,6 +26,8 @@ export Notification from './Notification' export Panel, { PanelHeader, PanelBody, PanelFooter } from './Panel' export Page from './Page' export QRCode from './QRCode' +export Radio from './Radio' +export RadioGroup from './RadioGroup' export Range from './Range' export Select from './Select' export Sidebar from './Sidebar' diff --git a/stories/forms/form.stories.js b/stories/forms/form.stories.js index e0e74e7a..89388543 100644 --- a/stories/forms/form.stories.js +++ b/stories/forms/form.stories.js @@ -15,6 +15,8 @@ import { TextArea, Button, Toggle, + Radio, + RadioGroup, Range } from 'components/UI' @@ -120,6 +122,15 @@ storiesOf('Forms', module) + +
+ Radio buttons +
+ + +
+ +
+
+ +
+ +`;