feat(ui-toolkit): toggles implementation according to spec

This commit is contained in:
Sara Vieira 2017-10-10 11:15:35 +01:00 committed by Sérgio Ramos
parent 68834c31f4
commit 4baf6647d5
10 changed files with 75 additions and 74 deletions

View File

@ -2,8 +2,8 @@ import { css } from 'styled-components';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
export const borderRadius = remcalc(4); export const borderRadius = remcalc(4);
export const bottomShaddow = `0 ${remcalc(2)} 0 0 rgba(0, 0, 0, 0.05)`; export const bottomShadow = `0 ${remcalc(2)} 0 0 rgba(0, 0, 0, 0.05)`;
export const bottomShaddowDarker = `0 ${remcalc(2)} 0 0 rgba(0, 0, 0, 0.1)`; export const bottomShadowDarker = `0 ${remcalc(2)} 0 0 rgba(0, 0, 0, 0.1)`;
export const insetShaddow = `inset 0 ${remcalc(3)} 0 0 rgba(0, 0, 0, 0.05)`; export const insetShaddow = `inset 0 ${remcalc(3)} 0 0 rgba(0, 0, 0, 0.05)`;
export const tooltipShadow = `0 ${remcalc(2)} ${remcalc(6)} ${remcalc( export const tooltipShadow = `0 ${remcalc(2)} ${remcalc(6)} ${remcalc(
1 1

View File

@ -1,7 +1,7 @@
import { Broadcast, Subscriber } from 'joy-react-broadcast'; import { Broadcast, Subscriber } from 'joy-react-broadcast';
import Baseline from '../baseline'; import Baseline from '../baseline';
import paperEffect from '../paper-effect'; import paperEffect from '../paper-effect';
import { bottomShaddow, bottomShaddowDarker } from '../boxes'; import { bottomShadow, bottomShadowDarker } from '../boxes';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import is, { isNot } from 'styled-is'; import is, { isNot } from 'styled-is';
import { Row } from 'react-styled-flexboxgrid'; import { Row } from 'react-styled-flexboxgrid';
@ -15,7 +15,7 @@ const StyledCard = Row.extend`
margin-bottom: ${remcalc(10)}; margin-bottom: ${remcalc(10)};
border: ${remcalc(1)} solid ${props => props.theme.grey}; border: ${remcalc(1)} solid ${props => props.theme.grey};
background-color: ${props => props.theme.white}; background-color: ${props => props.theme.white};
box-shadow: ${bottomShaddow}; box-shadow: ${bottomShadow};
flex-direction: column; flex-direction: column;
margin-right: ${remcalc(0)}; margin-right: ${remcalc(0)};
@ -28,7 +28,7 @@ const StyledCard = Row.extend`
`}; `};
${is('collapsed', 'headed')` ${is('collapsed', 'headed')`
box-shadow: ${bottomShaddowDarker}; box-shadow: ${bottomShadowDarker};
`}; `};
${is('flat')` ${is('flat')`

View File

@ -1,13 +1,13 @@
import React from 'react'; import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { Input } from 'normalized-styled-components'; import { Input } from 'normalized-styled-components';
import { Subscriber } from 'joy-react-broadcast';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import unitcalc from 'unitcalc'; import unitcalc from 'unitcalc';
import rndId from 'rnd-id'; import rndId from 'rnd-id';
import is from 'styled-is'; import is from 'styled-is';
import { Subscriber } from 'joy-react-broadcast';
import { bottomShaddow, border, borderRadius } from '../boxes'; import { bottomShadow, border, borderRadius } from '../boxes';
import Baseline from '../baseline'; import Baseline from '../baseline';
import BaseInput from './base/input'; import BaseInput from './base/input';
import typography from '../typography'; import typography from '../typography';
@ -16,36 +16,40 @@ const StyledInput = Input.extend`
display: none; display: none;
&:checked + label { &:checked + label {
border-radius: ${remcalc(4)};
background-color: ${props => props.theme.white};
box-shadow: ${bottomShaddow};
color: ${props => props.theme.secondary}; color: ${props => props.theme.secondary};
font-weight: bold;
width: 100%;
position: relative;
} }
&:selected + label { &:selected + label {
border-radius: ${remcalc(4)};
background-color: ${props => props.theme.white};
box-shadow: ${bottomShaddow};
color: ${props => props.theme.secondary}; color: ${props => props.theme.secondary};
font-weight: bold;
width: 100%;
} }
&:disabled + label { &:disabled + label {
color: ${props => props.theme.grey}; color: ${props => props.theme.grey};
& + .background {
display: none;
}
} }
`; `;
const Label = styled.label` const Label = styled.label`
${typography.normal}; ${typography.normal};
position: absolute;
box-sizing: border-box; box-sizing: border-box;
width: ${unitcalc(20)}; height: 100%;
height: ${unitcalc(8)}; display: flex;
top: 0; align-items: center;
left: 0; justify-content: center;
text-align: center;
padding-top: ${unitcalc(2)};
color: ${props => props.theme.text}; color: ${props => props.theme.text};
cursor: pointer;
user-select: none;
position: relative;
z-index: 1;
${is('error')` ${is('error')`
border-color: ${props => props.theme.redDark} border-color: ${props => props.theme.redDark}
@ -74,24 +78,49 @@ const InputContainer = styled.div`
const Li = BaseInput(styled.li` const Li = BaseInput(styled.li`
display: inline-block; display: inline-block;
list-style-type: none; list-style-type: none;
vertical-align: text-bottom; box-sizing: border-box;
border-top: ${border.unchecked};
border-bottom: ${border.unchecked};
border-left: ${border.unchecked};
&:first-of-type {
border-radius: ${borderRadius} 0 0 ${borderRadius};
}
&:last-of-type {
border-radius: 0 ${borderRadius} ${borderRadius} 0;
border-right: ${border.unchecked};
}
`); `);
const Background = styled.span`
border-right: ${border.unchecked};
background-color: ${props => props.theme.white};
display: block;
border-radius: ${borderRadius};
position: absolute;
height: 100%;
width: 100%;
z-index: 0;
transition: ${props => props.theme.transition};
border: ${props => `${remcalc(1)} solid ${props.theme.grey}`};
top: ${remcalc(-1)};
`;
const Ul = styled.ul` const Ul = styled.ul`
display: inline-block; display: inline-block;
margin: 0; margin: 0;
padding: 0; padding: 0;
box-shadow: ${bottomShaddow}; height: ${remcalc(48)};
display: inline-flex;
align-items: flex-end;
background-color: ${props => props.theme.disabled};
border-radius: ${borderRadius};
border: ${border.unchecked};
position: relative;
margin-top: ${unitcalc(1)};
li:first-of-type {
input + label + .background {
transform: translateX(calc(100% - ${remcalc(3)}));
}
input:checked + label + .background {
transform: translateX(${remcalc(-1)});
}
}
li:last-of-type .background {
display: none;
}
`; `;
const BaseToggle = BaseInput(({ children, ...rest }) => { const BaseToggle = BaseInput(({ children, ...rest }) => {
@ -100,13 +129,7 @@ const BaseToggle = BaseInput(({ children, ...rest }) => {
return ( return (
<Li> <Li>
<InputContainer> <InputContainer>
<StyledInput <StyledInput {...value} {...rest} id={id} type="radio" />
checked={value.value === rest.value}
{...value}
{...rest}
id={id}
type="radio"
/>
<Label <Label
htmlFor={id} htmlFor={id}
error={rest.error} error={rest.error}
@ -115,6 +138,7 @@ const BaseToggle = BaseInput(({ children, ...rest }) => {
> >
{children} {children}
</Label> </Label>
<Background className="background" />
</InputContainer> </InputContainer>
</Li> </Li>
); );

View File

@ -3,23 +3,7 @@ const { ToggleList } = require('./toggle');
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Legend = require('./legend').default; const Legend = require('./legend').default;
<FormGroup name='who-killed'> <FormGroup name='who-killed-1'>
<Legend>Who killed the radio star?</Legend>
<ToggleList>
<Toggle value='video'>Video</Toggle>
<Toggle value='tv'>TV</Toggle>
</ToggleList>
</FormGroup>
```
#### selected
```
const { ToggleList } = require('./toggle');
const FormGroup = require('./group').default;
const Legend = require('./legend').default;
<FormGroup name='who-killed'>
<Legend>Who killed the radio star?</Legend> <Legend>Who killed the radio star?</Legend>
<ToggleList> <ToggleList>
<Toggle value='video' checked>Video</Toggle> <Toggle value='video' checked>Video</Toggle>
@ -28,14 +12,14 @@ const Legend = require('./legend').default;
</FormGroup> </FormGroup>
``` ```
#### `disabled` #### Toggle > Disabled
``` ```
const { ToggleList } = require('./toggle'); const { ToggleList } = require('./toggle');
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Legend = require('./legend').default; const Legend = require('./legend').default;
<FormGroup name='who-killed' disabled> <FormGroup name='who-killed-2' disabled>
<Legend>Who killed the radio star?</Legend> <Legend>Who killed the radio star?</Legend>
<ToggleList> <ToggleList>
<Toggle value='video'>Video</Toggle> <Toggle value='video'>Video</Toggle>

View File

@ -1,7 +0,0 @@
```
const CloseIcon = require('../icons/close').default;
<IconButton>
<CloseIcon/>
</IconButton>
```

View File

@ -38,8 +38,8 @@ export {
export { export {
borderRadius, borderRadius,
bottomShaddow, bottomShadow,
bottomShaddowDarker, bottomShadowDarker,
insetShaddow, insetShaddow,
tooltipShadow, tooltipShadow,
border border

View File

@ -8,13 +8,13 @@ import remcalc from 'remcalc';
import { H4 } from '../text/headings'; import { H4 } from '../text/headings';
import P from '../text/p'; import P from '../text/p';
import CloseButton from '../close-button'; import CloseButton from '../close-button';
import { border, bottomShaddow } from '../boxes'; import { border, bottomShadow } from '../boxes';
const Container = styled.div` const Container = styled.div`
position: relative; position: relative;
margin-bottom: ${unitcalc(2)}; margin-bottom: ${unitcalc(2)};
background-color: ${props => props.theme.white}; background-color: ${props => props.theme.white};
box-shadow: ${bottomShaddow}; box-shadow: ${bottomShadow};
border: ${border.confirmed}; border: ${border.confirmed};
width: 100%; width: 100%;
display: flex; display: flex;

View File

@ -105,6 +105,8 @@ export const seperator = '#D9DEF3'; */
export const topologyBackground = base.secondaryActive; export const topologyBackground = base.secondaryActive;
export const transition = 'all 200ms ease-out';
export default { export default {
...base, ...base,
fonts, fonts,
@ -113,5 +115,6 @@ export default {
inputError, inputError,
inputWarning, inputWarning,
topologyBackground, topologyBackground,
brandBackground brandBackground,
transition
}; };

View File

@ -97,7 +97,6 @@ module.exports = {
'src/card/card.js', 'src/card/card.js',
'src/form/checkbox.js', 'src/form/checkbox.js',
'src/header/index.js', 'src/header/index.js',
'src/icon-button/index.js',
'src/icons/icons.js', 'src/icons/icons.js',
'src/form/input.js', 'src/form/input.js',
'src/message/index.js', 'src/message/index.js',
@ -105,10 +104,8 @@ module.exports = {
'src/form/radio.js', 'src/form/radio.js',
'src/section-list/index.js', 'src/section-list/index.js',
'src/form/select.js', 'src/form/select.js',
'src/slider/index.js',
'src/form/toggle.js', 'src/form/toggle.js',
'src/topology/index.js', 'src/topology/index.js'
'src/form/number-input.js'
] ]
} }
], ],