From 07ee904c968fda244fd4200af75740094bba871f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Fri, 9 Dec 2016 11:24:22 +0000 Subject: [PATCH] convert toggle --- ui/package.json | 3 +- ui/src/components/toggle/index.js | 132 ++++++++++++++++++++++------- ui/src/components/toggle/style.css | 83 ------------------ ui/src/index.js | 2 +- ui/stories/index.js | 15 ++++ ui/yarn.lock | 8 +- 6 files changed, 122 insertions(+), 121 deletions(-) delete mode 100644 ui/src/components/toggle/style.css diff --git a/ui/package.json b/ui/package.json index b6e4ad5c..d0bbdc2a 100644 --- a/ui/package.json +++ b/ui/package.json @@ -27,7 +27,8 @@ "react-dom": "^15.4.1", "react-icons": "^2.2.1", "reduce-css-calc": "^1.3.0", - "styled-components": "^1.1.3" + "styled-components": "^1.1.3", + "uuid": "^3.0.1" }, "devDependencies": { "@kadira/storybook": "^2.34.0", diff --git a/ui/src/components/toggle/index.js b/ui/src/components/toggle/index.js index 78e3929b..5e6dfe19 100644 --- a/ui/src/components/toggle/index.js +++ b/ui/src/components/toggle/index.js @@ -1,48 +1,116 @@ -// TODO: use a checkbox - -const classNames = require('classnames'); +const constants = require('../../shared/constants'); +const fns = require('../../shared/functions'); const React = require('react'); -const styles = require('./style.css'); +const Styled = require('styled-components'); +const uuid = require('uuid').v4; + +const { + boxes, + colors +} = constants; + +const { + remcalc +} = fns; + +const { + default: styled +} = Styled; + +const StyledLabel = styled.label` + border-radius: ${boxes.borderRadius}; + color: #464646; + height: 2.5rem; + width: 110px; +`; + +const StyledToggleLabel = styled.div` + background-color: #E6E6E6; + border: solid 1px #D8D8D8; + border-radius: ${boxes.borderRadius}; + color: #000000; + height: ${remcalc(54)}; + margin: 0.125rem; + padding: ${remcalc('12 12 12 0')}; + position: relative; + text-align: right; + width: ${remcalc(106)}; + + &::before { + content: "Off"; + font-family: inherit; + font-size: inherit; + font-weight: bold; + position: absolute; + right: 14px; + top: 13px; + } + + &::after { + background-color: #FFFFFF; + border-radius: ${boxes.borderRadius}; + content: ""; + height: ${remcalc(46)}; + left: 3px; + position: absolute; + top: 3px; + width: ${remcalc(46)}; + } +`; + +const StyledInput = styled.input` + display: none; + + &:checked { + & + .tgl-label { + background: ${colors.confirmation}; + border: ${boxes.border.confirmed}; + color: #FFFFFF; + padding: ${remcalc('12 0 12 12')}; + text-align: left; + + &::before { + content: "On"; + left: 14px; + right: auto; + } + + &::after { + left: auto; + right: 3px; + } + } + } +`; const Toggle = ({ - checked = false, + checked, className, + defaultChecked, + id = uuid(), style }) => { - const tgl = classNames( - className, - styles.tgl, - checked ? styles.on : styles.off, - ); - - const input = classNames( - className, - styles.input - ); - - const label = classNames( - className, - styles['tgl-label'] - ); - return ( -
-