From 49612769da71c6b2625436d877408b67173b071f Mon Sep 17 00:00:00 2001 From: JUDIT GRESKOVITS Date: Fri, 24 Feb 2017 17:10:44 +0000 Subject: [PATCH] Toggle --- ui/src/components/form/checkbox/index.js | 4 +- ui/src/components/form/radio/index.js | 4 +- ui/src/components/form/radio/story.js | 13 +- .../form/{toggle.js => toggle-base.js} | 32 ++- ui/src/components/form/toggle/index.js | 131 ++++++++++++ ui/src/components/form/toggle/story.js | 190 ++++++++++++++++++ ui/src/components/toggle/story.js | 4 +- 7 files changed, 352 insertions(+), 26 deletions(-) rename ui/src/components/form/{toggle.js => toggle-base.js} (82%) create mode 100644 ui/src/components/form/toggle/index.js create mode 100644 ui/src/components/form/toggle/story.js diff --git a/ui/src/components/form/checkbox/index.js b/ui/src/components/form/checkbox/index.js index c64d9e62..8e09a2e1 100644 --- a/ui/src/components/form/checkbox/index.js +++ b/ui/src/components/form/checkbox/index.js @@ -1,8 +1,8 @@ import { Baseline } from '../../../shared/composers'; import BaseInput from '../base-input'; -import Toggle from '../toggle'; +import ToggleBase from '../toggle-base'; -const Checkbox = Toggle({ +const Checkbox = ToggleBase({ type: 'checkbox' }); diff --git a/ui/src/components/form/radio/index.js b/ui/src/components/form/radio/index.js index fd83bb2f..ccee7b9a 100644 --- a/ui/src/components/form/radio/index.js +++ b/ui/src/components/form/radio/index.js @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import Toggle from '../toggle'; +import ToggleBase from '../toggle-base'; import { Baseline } from '../../../shared/composers'; import BaseInput from '../base-input'; @@ -12,7 +12,7 @@ const StyledUl = styled.ul` padding: 0; `; -const Radio = Toggle({ +const Radio = ToggleBase({ container: RadioItem, type: 'radio' }); diff --git a/ui/src/components/form/radio/story.js b/ui/src/components/form/radio/story.js index eff48311..e2695682 100644 --- a/ui/src/components/form/radio/story.js +++ b/ui/src/components/form/radio/story.js @@ -4,15 +4,22 @@ import Legend from '../legend'; import Radio, { RadioList } from '../radio'; import FormGroup from '../group'; import FormMeta from '../meta'; +import FormLabel from '../label'; storiesOf('Radio', module) .add('Default', () => ( Who killed the radio star? - Video - TV - Netflix + + Video + + + TV + + + Netflix + )) diff --git a/ui/src/components/form/toggle.js b/ui/src/components/form/toggle-base.js similarity index 82% rename from ui/src/components/form/toggle.js rename to ui/src/components/form/toggle-base.js index bada8a75..e50a902c 100644 --- a/ui/src/components/form/toggle.js +++ b/ui/src/components/form/toggle-base.js @@ -1,4 +1,4 @@ -import { remcalc, is } from '../../shared/functions'; +import { remcalc, unitcalc, is } from '../../shared/functions'; import { Subscriber } from 'react-broadcast'; import { boxes, colors } from '../../shared/constants'; import BaseInput from './base-input'; @@ -61,14 +61,12 @@ const Label = styled.label` opacity: 0; content: ''; position: absolute; - width: ${remcalc(8)}; - height: ${remcalc(8)}; - border-radius: ${remcalc(4)}; - background-color: ${colors.base.secondaryDark}; - border-top: none; - border-right: none; - top: ${remcalc(8)}; - left: ${remcalc(8)}; + width: ${remcalc(10)}; + height: ${remcalc(10)}; + border-radius: ${remcalc(5)}; + background-color: ${colors.base.secondaryActive}; + top: ${remcalc(6)}; + left: ${remcalc(6)}; } `}; @@ -77,12 +75,12 @@ const Label = styled.label` opacity: 0; content: ''; position: absolute; - width: ${remcalc(9)}; + width: ${unitcalc(1.5)}; height: ${remcalc(4)}; background: transparent; top: ${remcalc(7)}; left: ${remcalc(7)}; - border: ${remcalc(3)} solid #333; + border: ${unitcalc(0.5)} solid ${colors.base.secondaryActive}; border-top: none; border-right: none; transform: rotate(-45deg); @@ -98,14 +96,14 @@ const Label = styled.label` const InnerContainer = styled.div` display: inline-block; - margin-right: ${remcalc(12)} vertical-align: text-bottom; - width: ${remcalc(24)}; - height: ${remcalc(24)}; + margin-right: ${unitcalc(2)}; + width: ${unitcalc(4)}; + height: ${unitcalc(4)}; position: relative; `; -const Toggle = ({ +const ToggleBase = ({ container = null, type = 'radio' }) => BaseInput(({ @@ -122,7 +120,7 @@ const Toggle = ({ const render = (value) => { const toggle = ( - + { + const render = (value) => { + return ( + + + + + + + ); + }; + + return ( + + {render} + + ); +}); + +export default Baseline( + Toggle +); + +export const ToggleList = Baseline( + StyledUl +); diff --git a/ui/src/components/form/toggle/story.js b/ui/src/components/form/toggle/story.js new file mode 100644 index 00000000..90039d6c --- /dev/null +++ b/ui/src/components/form/toggle/story.js @@ -0,0 +1,190 @@ +import { storiesOf } from '@kadira/storybook'; +import React from 'react'; +import Legend from '../legend'; +import Toggle, { ToggleList } from '../toggle'; +import FormGroup from '../group'; +import FormMeta from '../meta'; + +storiesOf('Toggle', module) +.add('Default', () => ( + + Who killed the radio star? + + Video + TV + Netflix + + + )) + .add('Selected', () => ( + + Who killed the radio star? + + Video + TV + Netflix + + + )) + .add('Two items', () => ( + + Who killed the radio star? + + TV + Netflix + + + )) + .add('Disabled', () => ( + + Who killed the radio star? + + Video + TV + Netflix + + + )) + .add('Error', () => ( +
+ + Who killed the radio star? + + + Video + TV + Netflix + + + + Who killed the radio star? + + + Video + TV + Netflix + + + {/* eslint-disable object-curly-newline */} + + {/* eslint-enable object-curly-newline */} + Who killed the radio star? + + + Video + TV + Netflix + + + + Who killed the radio star? + + Unexpected children error! + + + Video + TV + Netflix + + +
+ )) + .add('Warning', () => ( +
+ + Who killed the radio star? + + + Video + TV + Netflix + + + + Who killed the radio star? + + + Video + TV + Netflix + + + {/* eslint-disable object-curly-newline */} + + {/* eslint-enable object-curly-newline */} + Who killed the radio star? + + + Video + TV + Netflix + + + + Who killed the radio star? + + Unexpected children warning! + + + Video + TV + Netflix + + +
+ )) + .add('Success', () => ( +
+ + Who killed the radio star? + + + Video + TV + Netflix + + + + Who killed the radio star? + + + Video + TV + Netflix + + + {/* eslint-disable object-curly-newline */} + + {/* eslint-enable object-curly-newline */} + Who killed the radio star? + + + Video + TV + Netflix + + + + Who killed the radio star? + + Unexpected children success! + + + Video + TV + Netflix + + +
+ )) + .add('Base meta', () => ( + + Who killed the radio star? + I'm a children of meta + + Video + TV + Netflix + + + )); diff --git a/ui/src/components/toggle/story.js b/ui/src/components/toggle/story.js index 6c685ab0..05b28bc5 100644 --- a/ui/src/components/toggle/story.js +++ b/ui/src/components/toggle/story.js @@ -1,4 +1,4 @@ -import React from 'react'; +/*import React from 'react'; import { storiesOf } from '@kadira/storybook'; import Toggle from './'; @@ -20,4 +20,4 @@ storiesOf('Toggle', module) )) .add('no props', () => ( - )); + ));*/