From 18978abf08a3e7313acee1db6aa9b22e92cec969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Fri, 9 Dec 2016 14:56:34 +0000 Subject: [PATCH] random local classNames use styled-components className generator for that --- ui/package.json | 4 ++-- ui/src/components/toggle/index.js | 14 +++++++++----- ui/src/components/widget/index.js | 23 +++++++++++++++++++---- ui/src/shared/functions.js | 21 +++++++++++++++++---- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/ui/package.json b/ui/package.json index 83a41431..dab71054 100644 --- a/ui/package.json +++ b/ui/package.json @@ -22,12 +22,12 @@ "lodash.isstring": "^4.0.1", "lodash.isundefined": "^3.0.1", "param-case": "^2.1.0", + "random-natural": "^1.0.3", "react": "^15.4.1", "react-dom": "^15.4.1", "react-icons": "^2.2.1", "reduce-css-calc": "^1.3.0", - "styled-components": "^1.1.3", - "uuid": "^3.0.1" + "styled-components": "^1.1.3" }, "devDependencies": { "@kadira/storybook": "^2.34.0", diff --git a/ui/src/components/toggle/index.js b/ui/src/components/toggle/index.js index 5e6dfe19..399411ee 100644 --- a/ui/src/components/toggle/index.js +++ b/ui/src/components/toggle/index.js @@ -2,7 +2,6 @@ const constants = require('../../shared/constants'); const fns = require('../../shared/functions'); const React = require('react'); const Styled = require('styled-components'); -const uuid = require('uuid').v4; const { boxes, @@ -10,13 +9,18 @@ const { } = constants; const { - remcalc + remcalc, + rndId } = fns; const { default: styled } = Styled; +const classNames = { + label: rndId() +}; + const StyledLabel = styled.label` border-radius: ${boxes.borderRadius}; color: #464646; @@ -62,7 +66,7 @@ const StyledInput = styled.input` display: none; &:checked { - & + .tgl-label { + & + .${classNames.label} { background: ${colors.confirmation}; border: ${boxes.border.confirmed}; color: #FFFFFF; @@ -87,7 +91,7 @@ const Toggle = ({ checked, className, defaultChecked, - id = uuid(), + id = rndId(), style }) => { return ( @@ -101,7 +105,7 @@ const Toggle = ({ id={id} type='checkbox' /> - + ); }; diff --git a/ui/src/components/widget/index.js b/ui/src/components/widget/index.js index 20e8b06d..cedf32d9 100644 --- a/ui/src/components/widget/index.js +++ b/ui/src/components/widget/index.js @@ -1,27 +1,36 @@ const React = require('react'); const constants = require('../../shared/constants'); +const fns = require('../../shared/functions'); const Styled = require('styled-components'); const { boxes } = constants; +const { + rndId +} = fns; + const { default: styled, } = Styled; +const classNames = { + content: rndId() +}; + const StyledInput = styled.input` display: none; visibility: hidden; &:checked { - & ~ .content { + & ~ .${classNames.content} { border: ${boxes.border.checked}; } } &:disabled { - & ~ .content { + & ~ .${classNames.content} { cursor: not-allowed; filter: grayscale(80%); opacity: 0.4; @@ -45,6 +54,7 @@ const Widget = ({ children, className, disabled = false, + id, name, selectable = 'single', style, @@ -53,7 +63,11 @@ const Widget = ({ const type = selectable === 'single' ? 'radio' : 'checkbox'; return ( -