fix(ui-toolkit): Input/Select disabled styling

fixes #746
This commit is contained in:
Sara Vieira 2017-10-11 15:56:24 +01:00 committed by Sérgio Ramos
parent a761b7da31
commit 8d584459d0
5 changed files with 128 additions and 255 deletions

View File

@ -37,6 +37,18 @@ const style = css`
background-color: ${props => props.theme.white}; background-color: ${props => props.theme.white};
border: ${border.unchecked}; border: ${border.unchecked};
${is('disabled')`
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: ${props => props.theme.grey};
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: ${props => props.theme.grey};
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: ${props => props.theme.grey};
}
`};
${is('error')` ${is('error')`
border-color: ${props => props.theme.redDark} border-color: ${props => props.theme.redDark}
`}; `};

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { Subscriber } from 'joy-react-broadcast'; import { Subscriber } from 'joy-react-broadcast';
import is from 'styled-is';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import Label from '../label'; import Label from '../label';
@ -7,6 +8,9 @@ import Label from '../label';
const StyledLabel = Label.extend` const StyledLabel = Label.extend`
margin-right: ${remcalc(12)}; margin-right: ${remcalc(12)};
font-weight: bold; font-weight: bold;
${is('disabled')`
color: ${props => props.theme.grey};
`};
`; `;
export default props => { export default props => {

View File

@ -1,11 +1,17 @@
import React from 'react'; import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { isNot } from 'styled-is'; import is, { isNot } from 'styled-is';
import remcalc from 'remcalc'; import remcalc from 'remcalc';
import Baseline from '../baseline'; import Baseline from '../baseline';
import BaseInput, { Stylable } from './base/input'; import BaseInput, { Stylable } from './base/input';
const chevron =
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOSIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgOSA2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjx0aXRsZT5hcnJvdzogcmlnaHQ8L3RpdGxlPjxwYXRoIGQ9Ik05IDEuMzg2TDcuNjQ4IDAgNC41IDMuMjI4IDEuMzUyIDAgMCAxLjM4NiA0LjUgNnoiIGZpbGw9IiM0OTQ5NDkiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==';
const chevronDisabled =
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOSIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgOSA2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjx0aXRsZT5hcnJvdzogcmlnaHQ8L3RpdGxlPjxwYXRoIGQ9Ik05IDEuMzg2TDcuNjQ4IDAgNC41IDMuMjI4IDEuMzUyIDAgMCAxLjM4NiA0LjUgNnoiIGZpbGw9IiNEOEQ4RDgiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==';
const Select = Baseline(BaseInput(Stylable('select'))); const Select = Baseline(BaseInput(Stylable('select')));
const SelectWrapper = styled.div` const SelectWrapper = styled.div`
@ -15,29 +21,36 @@ const SelectWrapper = styled.div`
${isNot('fluid')` ${isNot('fluid')`
min-width: ${remcalc(200)}; min-width: ${remcalc(200)};
`}; `};
&:after { &:after {
content: ''; content: '';
width: ${remcalc(10)}; width: ${remcalc(10)};
height: ${remcalc(10)}; height: ${remcalc(10)};
background: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOSIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgOSA2IiB4bWxucz0iaHR0cDo background: url(${chevron}) center center no-repeat;
vL3d3dy53My5vcmcvMjAwMC9zdmciPjx0aXRsZT5hcnJvdzogcmlnaHQ8L3RpdGxlPjxwYXRoIG
Q9Ik05IDEuMzg2TDcuNjQ4IDAgNC41IDMuMjI4IDEuMzUyIDAgMCAxLjM4NiA0LjUgNnoiIGZpb
Gw9IiM0OTQ5NDkiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==')
center center no-repeat;
display: block; display: block;
position: absolute; position: absolute;
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
right: ${remcalc(12)}; right: ${remcalc(12)};
} }
${is('disabled')`
&:after {
background: url(${chevronDisabled}) center center no-repeat;
}
`};
`;
const StyledSelect = Select.extend`
${is('disabled')`
border-color: ${props => props.theme.grey};
color: ${props => props.theme.grey};
`};
`; `;
/** /**
* @example ./usage-select.md * @example ./usage-select.md
*/ */
export default ({ children, fluid, ...rest }) => ( export default ({ children, fluid, ...rest }) => (
<SelectWrapper fluid={fluid}> <SelectWrapper {...rest} fluid={fluid}>
<Select {...rest}>{children}</Select> <StyledSelect {...rest}>{children}</StyledSelect>
</SelectWrapper> </SelectWrapper>
); );

View File

@ -1,6 +1,6 @@
#### `type` #### Input > Email
``` ```jsx
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
@ -10,29 +10,25 @@ const Label = require('./label').default;
</FormGroup> </FormGroup>
``` ```
#### error #### Input > Disabled
```jsx
const FormGroup = require('./group').default;
const Label = require('./label').default;
<FormGroup>
<Label disabled>Username</Label>
<Input disabled placeholder='Example: JarJarBinks' type='email' />
</FormGroup>
``` ```
#### Input > Error
```jsx
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
const FormMeta = require('./meta').default; const FormMeta = require('./meta').default;
<div>
<FormGroup>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta error='Unexpected inline error!' />
</FormGroup>
<FormGroup error='Unexpected group error!'>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta />
</FormGroup>
<FormGroup meta={{error: 'Unexpected meta error!'}}>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta />
</FormGroup>
<FormGroup> <FormGroup>
<Label>Email Address</Label> <Label>Email Address</Label>
<Input placeholder='Enter email' type='email' /> <Input placeholder='Enter email' type='email' />
@ -40,32 +36,15 @@ const FormMeta = require('./meta').default;
Unexpected children error! Unexpected children error!
</FormMeta> </FormMeta>
</FormGroup> </FormGroup>
</div>
``` ```
#### warning #### Input > Warning
``` ```jsx
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
const FormMeta = require('./meta').default; const FormMeta = require('./meta').default;
<div>
<FormGroup>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta warning='Unexpected inline warning!' />
</FormGroup>
<FormGroup warning='Unexpected group warning!'>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta />
</FormGroup>
<FormGroup meta={{warning: 'Unexpected meta warning!'}}>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta />
</FormGroup>
<FormGroup> <FormGroup>
<Label>Email Address</Label> <Label>Email Address</Label>
<Input placeholder='Enter email' type='email' /> <Input placeholder='Enter email' type='email' />
@ -73,32 +52,15 @@ const FormMeta = require('./meta').default;
Unexpected children warning! Unexpected children warning!
</FormMeta> </FormMeta>
</FormGroup> </FormGroup>
</div>
``` ```
#### success #### Input > Success
``` ```jsx
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
const FormMeta = require('./meta').default; const FormMeta = require('./meta').default;
<div>
<FormGroup>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta success='Unexpected inline success!' />
</FormGroup>
<FormGroup success='Unexpected group success!'>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta />
</FormGroup>
<FormGroup meta={{success: 'Unexpected meta success!'}}>
<Label>Email Address</Label>
<Input placeholder='Enter email' type='email' />
<FormMeta />
</FormGroup>
<FormGroup> <FormGroup>
<Label>Email Address</Label> <Label>Email Address</Label>
<Input placeholder='Enter email' type='email' /> <Input placeholder='Enter email' type='email' />
@ -106,5 +68,4 @@ const FormMeta = require('./meta').default;
Unexpected children success! Unexpected children success!
</FormMeta> </FormMeta>
</FormGroup> </FormGroup>
</div>
``` ```

View File

@ -1,4 +1,4 @@
``` ```jsx
<Select> <Select>
<option selected disabled>Select a datacenter</option> <option selected disabled>Select a datacenter</option>
<option>Amsterdam, EU</option> <option>Amsterdam, EU</option>
@ -8,14 +8,14 @@
</Select> </Select>
``` ```
#### `disabled` #### Select > Disabled
``` ```jsx
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
<FormGroup> <FormGroup>
<Label>Your location</Label> <Label disabled>Your location</Label>
<Select disabled> <Select disabled>
<option selected disabled>Select Location</option> <option selected disabled>Select Location</option>
<option value='1'>Amsterdam, EU</option> <option value='1'>Amsterdam, EU</option>
@ -27,44 +27,13 @@ const Label = require('./label').default;
``` ```
#### warning #### Select > Warning
``` ```jsx
const FormMeta = require('./meta').default; const FormMeta = require('./meta').default;
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
<div>
<FormGroup>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta warning='Unexpected inline warning!' />
</FormGroup>
<FormGroup warning='Unexpected group warning!'>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta />
</FormGroup>
<FormGroup meta={{warning: 'Unexpected meta warning!'}}>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta />
</FormGroup>
<FormGroup> <FormGroup>
<Label>Your location</Label> <Label>Your location</Label>
<Select> <Select>
@ -77,47 +46,15 @@ const Label = require('./label').default;
Unexpected children warning! Unexpected children warning!
</FormMeta> </FormMeta>
</FormGroup> </FormGroup>
</div>
``` ```
#### error #### Select > Error
``` ```jsx
const FormMeta = require('./meta').default; const FormMeta = require('./meta').default;
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
<div>
<FormGroup>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta error='Unexpected inline error!' />
</FormGroup>
<FormGroup error='Unexpected group error!'>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta />
</FormGroup>
<FormGroup meta={{error: 'Unexpected meta error!'}}>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta />
</FormGroup>
<FormGroup> <FormGroup>
<Label>Your location</Label> <Label>Your location</Label>
<Select> <Select>
@ -130,47 +67,15 @@ const Label = require('./label').default;
Unexpected children error! Unexpected children error!
</FormMeta> </FormMeta>
</FormGroup> </FormGroup>
</div>
``` ```
#### success #### Select > Success
``` ```jsx
const FormMeta = require('./meta').default; const FormMeta = require('./meta').default;
const FormGroup = require('./group').default; const FormGroup = require('./group').default;
const Label = require('./label').default; const Label = require('./label').default;
<div>
<FormGroup>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta success='Unexpected inline success!' />
</FormGroup>
<FormGroup success='Unexpected group success!'>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta />
</FormGroup>
<FormGroup meta={{success: 'Unexpected meta success!'}}>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta />
</FormGroup>
<FormGroup> <FormGroup>
<Label>Your location</Label> <Label>Your location</Label>
<Select> <Select>
@ -183,26 +88,4 @@ const Label = require('./label').default;
Unexpected children success! Unexpected children success!
</FormMeta> </FormMeta>
</FormGroup> </FormGroup>
</div>
```
#### meta
```
const FormMeta = require('./meta').default;
const FormGroup = require('./group').default;
const Label = require('./label').default;
<FormGroup>
<Label>Your location</Label>
<Select>
<option>Amsterdam, EU</option>
<option>San Francisco, USA</option>
<option>Seoul, South Korea</option>
<option>Tokyo, Japan</option>
</Select>
<FormMeta>
I&#39;m a children of meta!
</FormMeta>
</FormGroup>
``` ```