mirror of
https://github.com/yldio/copilot.git
synced 2024-12-29 05:10:05 +02:00
Widget - implimenting widget
This commit is contained in:
parent
54b9601d9c
commit
b933eff47b
25
ui/.postcss.js
Normal file
25
ui/.postcss.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = function (postcss) {
|
||||
return postcss([
|
||||
require('postcss-import')(),
|
||||
require('postcss-at-rules-variables')(),
|
||||
require('postcss-modules-values'),
|
||||
require('postcss-functions')({
|
||||
functions: {
|
||||
remCalc: function(values) {
|
||||
values = values.replace('px', '');
|
||||
values = values.split(' ');
|
||||
let outputRems = '';
|
||||
const base = 16;
|
||||
values.forEach( (value, i) => {
|
||||
const remValue = value / base;
|
||||
outputRems += i === 0 ? `${remValue}rem` : ` ${remValue}rem`;
|
||||
});
|
||||
return outputRems;
|
||||
}
|
||||
},
|
||||
}),
|
||||
require('postcss-mixins')(),
|
||||
require('postcss-for'),
|
||||
require('postcss-cssnext')()
|
||||
])
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
.button {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: remCalc(16);
|
||||
border-radius: 4px;
|
||||
box-shadow: remCalc(0 2 0 0) rgba(0,0,0,0.05);
|
||||
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: remCalc(16);
|
||||
min-width: remCalc(120);
|
||||
padding: remCalc(18 24);
|
||||
|
||||
&.primary {
|
||||
background: #3B47CC;
|
||||
|
42
ui/src/components/widget/index.js
Normal file
42
ui/src/components/widget/index.js
Normal file
@ -0,0 +1,42 @@
|
||||
const classNames = require('classnames');
|
||||
const React = require('react');
|
||||
const styles = require('./style.css');
|
||||
|
||||
const Widget = ({
|
||||
children,
|
||||
selectable = 'single',
|
||||
name,
|
||||
className,
|
||||
style
|
||||
}) => {
|
||||
|
||||
const cn = classNames(
|
||||
className,
|
||||
styles.widget
|
||||
);
|
||||
|
||||
const type = selectable === 'single' ? 'radio' : 'checkbox';
|
||||
|
||||
return (
|
||||
<label className={cn} htmlFor={name}>
|
||||
<input
|
||||
className={styles.input}
|
||||
name={name}
|
||||
type={type}
|
||||
/>
|
||||
<div className={styles.content}>
|
||||
{children}
|
||||
</div>
|
||||
</label>
|
||||
);
|
||||
};
|
||||
|
||||
Widget.propTypes = {
|
||||
children: React.PropTypes.object,
|
||||
className: React.PropTypes.string,
|
||||
name: React.PropTypes.string,
|
||||
selectable: React.PropTypes.string,
|
||||
style: React.PropTypes.object
|
||||
};
|
||||
|
||||
module.exports = Widget;
|
73
ui/src/components/widget/readme.md
Normal file
73
ui/src/components/widget/readme.md
Normal file
@ -0,0 +1,73 @@
|
||||
# `<Widget>`
|
||||
|
||||
## demo
|
||||
|
||||
```embed
|
||||
const React = require('react');
|
||||
const ReactDOM = require('react-dom/server');
|
||||
const Base = require('../base');
|
||||
const Container = require('../container');
|
||||
const Row = require('../row');
|
||||
const Column = require('../column');
|
||||
const Widget = require('./index.js');
|
||||
const styles = require('./style.css');
|
||||
|
||||
nmodule.exports = ReactDOM.renderToString(
|
||||
<Base>
|
||||
<h2>Single Option Select</h2>
|
||||
<Row>
|
||||
<Column xs={2}>
|
||||
<Widget selectable="single" name='flag1'>
|
||||
<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>
|
||||
</Column>
|
||||
|
||||
<Column xs={2}>
|
||||
<Widget selectable="single" name='flag2'>
|
||||
<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>
|
||||
</Column>
|
||||
</Row>
|
||||
|
||||
<h2>Multi Option Select</h2>
|
||||
<Row>
|
||||
<Column xs={2}>
|
||||
<Widget selectable="multiple" name='flag1'>
|
||||
<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>
|
||||
</Column>
|
||||
|
||||
<Column xs={2}>
|
||||
<Widget selectable="multiple" name='flag2'>
|
||||
<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>
|
||||
</Column>
|
||||
</Row>
|
||||
</Base>
|
||||
);
|
||||
```
|
||||
|
||||
## usage
|
||||
|
||||
```js
|
||||
const React = require('react');
|
||||
const Widget = require('ui/widget');
|
||||
|
||||
module.exports = () => {
|
||||
return (
|
||||
<Widget selectable="single" name='flag1'>
|
||||
<img src="someimage.png" />
|
||||
<p>Some text</p>
|
||||
</Widget>
|
||||
|
||||
<Widget selectable="multiple" name='flag2'>
|
||||
<img src="someimage.png" />
|
||||
<p>Some text</p>
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
```
|
19
ui/src/components/widget/style.css
Normal file
19
ui/src/components/widget/style.css
Normal file
@ -0,0 +1,19 @@
|
||||
.content {
|
||||
border-radius: 4px;
|
||||
border: 1px solid #d8d8d8;
|
||||
padding: remCalc(36);
|
||||
& img {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
|
||||
&:checked {
|
||||
& ~ .content {
|
||||
border: 1px solid #2532bb;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@ module.exports = {
|
||||
Toggle: require('./components/toggle/readme.md'),
|
||||
Checkbox: require('./components/checkbox/readme.md'),
|
||||
Tab: require('./components/tab/readme.md'),
|
||||
Tabs: require('./components/tabs/readme.md')
|
||||
Tabs: require('./components/tabs/readme.md'),
|
||||
Widget: require('./components/widget/readme.md')
|
||||
},
|
||||
FAQ: require('./faq.md')
|
||||
};
|
||||
|
@ -10,5 +10,6 @@ module.exports = {
|
||||
Tabs: require('./components/tabs'),
|
||||
Toggle: require('./components/toggle'),
|
||||
Radio: require('./components/radio'),
|
||||
RadioGroup: require('./components/radio-group')
|
||||
RadioGroup: require('./components/radio-group'),
|
||||
Widget: require('./components/widget')
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user