convert select

This commit is contained in:
Sérgio Ramos 2016-12-09 15:34:10 +00:00
parent 5cd0656393
commit 95f01e8854
5 changed files with 77 additions and 49 deletions

View File

@ -1,6 +1,37 @@
const classNames = require('classnames'); const fns = require('../../shared/functions');
const React = require('react'); const React = require('react');
const styles = require('./style.css'); const Styled = require('styled-components');
const {
rndId
} = fns;
const {
default: styled
} = Styled;
// TODO: this should be a constant
const StyledLabel = styled.div`
color: #464646;
`;
const StyledSelect = styled.select`
color: #464646;
/* select[multiple] is valid CSS syntax - not added to lint library yet */
/* stylelint-disable */
&[multiple] {
/* stylelint-enable */
padding-left: 0;
padding-right: 0;
& :global option {
padding-left: 15px;
padding-right: 15px;
width: 100%;
}
}
`;
const Select = ({ const Select = ({
autoFocus, autoFocus,
@ -8,24 +39,20 @@ const Select = ({
className, className,
disabled, disabled,
form, form,
id, id = rndId(),
label, label,
multiple, multiple,
name, name,
required, required,
selected selected
}) => { }) => {
const cn = classNames(
className,
styles['select-group']
);
return ( return (
<div className={cn}> <div className={className}>
<label className={styles.label} htmlFor={id}>{label}</label> <StyledLabel htmlFor={id}>
<select {label}
</StyledLabel>
<StyledSelect
autoFocus={autoFocus} autoFocus={autoFocus}
className={styles.select}
disabled={disabled} disabled={disabled}
form={form} form={form}
id={id} id={id}
@ -36,7 +63,7 @@ const Select = ({
selected={selected} selected={selected}
> >
{children} {children}
</select> </StyledSelect>
</div> </div>
); );
}; };

View File

@ -1,28 +0,0 @@
.select {
composes: input from "../input/style.css";
/* select[multiple] is valid CSS syntax - not added to lint library yet */
/* stylelint-disable */
&[multiple] {
/* stylelint-enable */
padding-left: 0;
padding-right: 0;
& :global option {
padding-left: 15px;
padding-right: 15px;
width: 100%;
}
/* this doesn't seem to work, research further
&:-internal-list-box :global option:checked,
& :global option:checked {
background-color: white;
}
*/
}
}
.label {
composes: label from "../input/style.css";
}

View File

@ -10,8 +10,7 @@ const {
} = composers; } = composers;
const { const {
boxes, boxes
colors
} = constants; } = constants;
const { const {

View File

@ -16,7 +16,7 @@ module.exports = {
// RangeSlider: require('./components/range-slider'), // RangeSlider: require('./components/range-slider'),
Radio: require('./components/radio'), Radio: require('./components/radio'),
// RadioGroup: require('./components/radio-group'), // RadioGroup: require('./components/radio-group'),
// Select: require('./components/select'), Select: require('./components/select'),
Widget: require('./components/widget'), Widget: require('./components/widget'),
// Pagination: require('./components/pagination'), // Pagination: require('./components/pagination'),
// Modal: require('./components/modal') // Modal: require('./components/modal')

View File

@ -13,6 +13,7 @@ const {
Row, Row,
Column, Column,
Avatar, Avatar,
Select,
Tabs, Tabs,
Tab, Tab,
Toggle, Toggle,
@ -142,6 +143,26 @@ storiesOf('Radio', module)
<Radio disabled /> <Radio disabled />
)); ));
storiesOf('Select', module)
.add('Default', () => (
<Select label='example select'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</Select>
))
.add('multiple', () => (
<Select label='example multiple select' multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</Select>
));
storiesOf('Tabs', module) storiesOf('Tabs', module)
.add('Default', () => ( .add('Default', () => (
<Tabs name='my-tab-group'> <Tabs name='my-tab-group'>
@ -152,7 +173,7 @@ storiesOf('Tabs', module)
<h1>User</h1> <h1>User</h1>
</Tab> </Tab>
</Tabs> </Tabs>
)) ));
storiesOf('Toggle', module) storiesOf('Toggle', module)
.add('checked', () => ( .add('checked', () => (
@ -166,12 +187,21 @@ storiesOf('Toggle', module)
)) ))
.add('no props', () => ( .add('no props', () => (
<Toggle /> <Toggle />
)) ));
storiesOf('Widget', module) storiesOf('Widget', module)
.add('single', () => ( .add('single', () => (
<Widget checked selectable='single' name='flag' value='flag_1'> <Widget
<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Union_flag_1606_(Kings_Colors).svg/2000px-Union_flag_1606_(Kings_Colors).svg.png' /> checked
name='flag'
selectable='single'
value='flag_1'
>
<img
alt='england flag'
// eslint-disable-next-line max-len
src='https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Union_flag_1606_(Kings_Colors).svg/2000px-Union_flag_1606_(Kings_Colors).svg.png'
/>
<p>Some text</p> <p>Some text</p>
</Widget> </Widget>
)) ));