convert Widget

This commit is contained in:
Sérgio Ramos 2016-12-09 10:40:57 +00:00
parent 5a6a7ae53b
commit 1ec268b28f
4 changed files with 55 additions and 51 deletions

View File

@ -1,6 +1,44 @@
const classNames = require('classnames');
const React = require('react'); const React = require('react');
const styles = require('./style.css'); const constants = require('../../shared/constants');
const Styled = require('styled-components');
const {
boxes
} = constants;
const {
default: styled,
} = Styled;
const StyledInput = styled.input`
display: none;
visibility: hidden;
&:checked {
& ~ .content {
border: ${boxes.border.checked};
}
}
&:disabled {
& ~ .content {
cursor: not-allowed;
filter: grayscale(80%);
opacity: 0.4;
}
}
`;
const StyledContent = styled.div`
border: ${boxes.border.unchecked};
border-radius: 4px;
cursor: pointer;
padding: remcalc(36);
& img {
max-width: 100%;
}
`;
const Widget = ({ const Widget = ({
checked = false, checked = false,
@ -12,28 +50,21 @@ const Widget = ({
style, style,
value = name value = name
}) => { }) => {
const cn = classNames(
className,
styles.widget
);
const type = selectable === 'single' ? 'radio' : 'checkbox'; const type = selectable === 'single' ? 'radio' : 'checkbox';
return ( return (
<label className={cn} htmlFor={value}> <label className={className} htmlFor={value}>
<input <StyledInput
checked={checked} checked={checked}
className={styles.input}
disabled={disabled} disabled={disabled}
id={value} id={value}
name={name} name={name}
type={type} type={type}
value={value} value={value}
/> />
<div className={styles.content}> <StyledContent>
{children} {children}
</div> </StyledContent>
</label> </label>
); );
}; };

View File

@ -1,36 +0,0 @@
~boxes: "../../shared/constants.js";
:root {
--border-checked: ~boxes.border.checked;
--border-unchecked: ~boxes.border.unchecked;
}
.content {
border: var(--border-unchecked);
border-radius: 4px;
cursor: pointer;
padding: remcalc(36);
& img {
max-width: 100%;
}
}
.input {
display: none;
visibility: hidden;
&:checked {
& ~ .content {
border: var(--border-checked);
}
}
&:disabled {
& ~ .content {
cursor: not-allowed;
filter: grayscale(80%);
opacity: 0.4;
}
}
}

View File

@ -17,7 +17,7 @@ module.exports = {
// 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

@ -12,7 +12,8 @@ const {
Checkbox, Checkbox,
Row, Row,
Column, Column,
Avatar Avatar,
Widget
} = require('../src/'); } = require('../src/');
const styles = { const styles = {
@ -123,3 +124,11 @@ storiesOf('Checkbox', module)
.add('Disabled', () => ( .add('Disabled', () => (
<Checkbox disabled /> <Checkbox disabled />
)); ));
storiesOf('Widget', module)
.add('single', () => (
<Widget checked selectable='single' name='flag' value='flag_1'>
<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' />
<p>Some text</p>
</Widget>
))