@propellerads/switch 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -5
- package/README.md +29 -8
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -0
- package/dist/style.d.ts +3 -0
- package/dist/switch.cjs.development.js +61 -0
- package/dist/switch.cjs.development.js.map +1 -0
- package/dist/switch.cjs.production.min.js +2 -0
- package/dist/switch.cjs.production.min.js.map +1 -0
- package/dist/switch.esm.js +54 -0
- package/dist/switch.esm.js.map +1 -0
- package/package.json +15 -17
- package/src/index.tsx +42 -0
- package/src/style.tsx +91 -0
- package/dist/index.esm.js +0 -97
- package/dist/index.esm.min.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
## `3.0.0`
|
|
2
|
+
|
|
3
|
+
- Migrated to TypeScript
|
|
4
|
+
|
|
5
|
+
Breaking changes:
|
|
6
|
+
- Prop `model` renamed to `isActive`.
|
|
7
|
+
- Prop `commonStyle` renamed to `containerClassName`.
|
|
8
|
+
- Prop `activeStyle` renamed to `controlClassName`.
|
|
9
|
+
|
|
10
|
+
## `2.3.0`
|
|
11
|
+
|
|
12
|
+
* updated active and disabled colors
|
|
13
|
+
|
|
14
|
+
## `2.2.0`
|
|
2
15
|
|
|
3
16
|
* updated peerDependencies
|
|
4
17
|
|
|
5
|
-
|
|
18
|
+
## `2.1.0`
|
|
19
|
+
|
|
6
20
|
* update dependencies
|
|
7
21
|
|
|
8
|
-
|
|
22
|
+
## `2.0.0`
|
|
23
|
+
|
|
9
24
|
* Compiled version
|
|
10
25
|
|
|
11
|
-
|
|
26
|
+
## `1.2.0`
|
|
12
27
|
|
|
13
28
|
* add disabled state
|
|
14
29
|
* add disabled styles
|
|
15
30
|
* change switch off color
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
## `1.1.0`
|
|
33
|
+
|
|
18
34
|
* remove label property
|
package/README.md
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
# Switch
|
|
2
2
|
|
|
3
|
-

|
|
4
3
|

|
|
5
4
|
|
|
6
|
-
[NPM](https://www.npmjs.com/package/@propellerads/switch)
|
|
7
|
-
[Github](https://github.com/propellerads/ui-components/tree/master/Components/Switch)
|
|
5
|
+
Links: [NPM](https://www.npmjs.com/package/@propellerads/switch) · [GitHub](https://github.com/propellerads/ui-components/tree/master/Components/Switch)
|
|
8
6
|
|
|
9
|
-
##
|
|
10
|
-
* `yarn add @propellerads/switch` or `npm install @propellerads/switch -S`
|
|
7
|
+
## Install
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
- `yarn add @propellerads/switch`
|
|
10
|
+
or
|
|
11
|
+
- `npm install @propellerads/switch --save`
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import Switch from '@propellerads/switch';
|
|
17
|
+
|
|
18
|
+
<Switch
|
|
19
|
+
isActive={true}
|
|
20
|
+
onChange={(next) => console.log('changed:', next)}
|
|
21
|
+
elementId="switch-id"
|
|
22
|
+
isDisabled={false}
|
|
23
|
+
containerClassName="my-root"
|
|
24
|
+
controlClassName="my-control"
|
|
25
|
+
/>;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Props
|
|
29
|
+
|
|
30
|
+
- isActive (boolean, required): current switch value
|
|
31
|
+
- onChange (function, required): called with next `boolean` value
|
|
32
|
+
- elementId (string): id to link `input` and `label`
|
|
33
|
+
- isDisabled (boolean, default: false): disables the control
|
|
34
|
+
- containerClassName (string): custom class for root container
|
|
35
|
+
- controlClassName (string): custom class for inner control
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface SwitchProps {
|
|
3
|
+
isActive: boolean;
|
|
4
|
+
onChange: (nextValue: boolean) => void;
|
|
5
|
+
containerClassName?: string;
|
|
6
|
+
controlClassName?: string;
|
|
7
|
+
elementId?: string;
|
|
8
|
+
isDisabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const Switch: React.FC<SwitchProps>;
|
|
11
|
+
export default Switch;
|
package/dist/index.js
ADDED
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = _interopDefault(require('react'));
|
|
8
|
+
var styled = require('styled-components');
|
|
9
|
+
var styled__default = _interopDefault(styled);
|
|
10
|
+
var stylevariables = require('@propellerads/stylevariables');
|
|
11
|
+
|
|
12
|
+
function _taggedTemplateLiteralLoose(e, t) {
|
|
13
|
+
return t || (t = e.slice(0)), e.raw = t, e;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
17
|
+
var switchOn = /*#__PURE__*/styled.keyframes(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n 50% {\n transform: scaleX(1.1);\n }\n"])));
|
|
18
|
+
var black15 = /*#__PURE__*/stylevariables.hslToHsla(stylevariables.black, '0.15');
|
|
19
|
+
var black25 = /*#__PURE__*/stylevariables.hslToHsla(stylevariables.black, '0.5');
|
|
20
|
+
var action50 = /*#__PURE__*/stylevariables.hslToHsla(stylevariables.actionColor, '0.5');
|
|
21
|
+
var StyledSwitch = /*#__PURE__*/styled__default.div(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n"])));
|
|
22
|
+
var SwitchControl = /*#__PURE__*/styled__default.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: block;\n font-size: ", "px;\n color: ", ";\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ", ";\n box-shadow: inset 0 0 3px ", ";\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: ", " .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ", ";\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ", ";\n box-shadow: inset 0 0 1px ", ";\n }\n\n &:checked + label:after {\n left: 24px;\n animation: ", " .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ", ";\n }\n }\n }\n"])), stylevariables.fontSmall, stylevariables.gray50, stylevariables.gray95, black15, switchOn, black25, function (props) {
|
|
23
|
+
var _props$theme;
|
|
24
|
+
return (props == null || (_props$theme = props.theme) == null || (_props$theme = _props$theme.actionColor) == null ? void 0 : _props$theme.main) || stylevariables.actionColor;
|
|
25
|
+
}, action50, switchOn, function (props) {
|
|
26
|
+
var _props$theme2;
|
|
27
|
+
return stylevariables.hslToHsla((props == null || (_props$theme2 = props.theme) == null || (_props$theme2 = _props$theme2.actionColor) == null ? void 0 : _props$theme2.main) || stylevariables.actionColor, '0.3');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
var Switch = function Switch(_ref) {
|
|
31
|
+
var isActive = _ref.isActive,
|
|
32
|
+
onChange = _ref.onChange,
|
|
33
|
+
_ref$containerClassNa = _ref.containerClassName,
|
|
34
|
+
containerClassName = _ref$containerClassNa === void 0 ? '' : _ref$containerClassNa,
|
|
35
|
+
_ref$controlClassName = _ref.controlClassName,
|
|
36
|
+
controlClassName = _ref$controlClassName === void 0 ? '' : _ref$controlClassName,
|
|
37
|
+
_ref$elementId = _ref.elementId,
|
|
38
|
+
elementId = _ref$elementId === void 0 ? '' : _ref$elementId,
|
|
39
|
+
_ref$isDisabled = _ref.isDisabled,
|
|
40
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled;
|
|
41
|
+
var handleToggleCheckbox = function handleToggleCheckbox() {
|
|
42
|
+
onChange(!isActive);
|
|
43
|
+
};
|
|
44
|
+
return React.createElement(StyledSwitch, {
|
|
45
|
+
className: containerClassName
|
|
46
|
+
}, React.createElement(SwitchControl, {
|
|
47
|
+
className: controlClassName
|
|
48
|
+
}, React.createElement("input", {
|
|
49
|
+
type: "checkbox",
|
|
50
|
+
checked: isActive,
|
|
51
|
+
onChange: handleToggleCheckbox,
|
|
52
|
+
id: elementId,
|
|
53
|
+
disabled: isDisabled
|
|
54
|
+
}), React.createElement("label", {
|
|
55
|
+
htmlFor: elementId,
|
|
56
|
+
role: "presentation"
|
|
57
|
+
})));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.default = Switch;
|
|
61
|
+
//# sourceMappingURL=switch.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.cjs.development.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {\n gray50,\n gray95,\n actionColor,\n black,\n fontSmall,\n hslToHsla,\n} from '@propellerads/stylevariables';\n\nconst switchOn = keyframes`\n 50% {\n transform: scaleX(1.1);\n }\n`;\n\nconst black15 = hslToHsla(black, '0.15');\nconst black25 = hslToHsla(black, '0.5');\nconst action50 = hslToHsla(actionColor, '0.5');\n\nconst StyledSwitch = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst SwitchControl = styled.div`\n display: block;\n font-size: ${fontSmall}px;\n color: ${gray50};\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ${gray95};\n box-shadow: inset 0 0 3px ${black15};\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: ${switchOn} .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ${black25};\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ${(props) => props?.theme?.actionColor?.main || actionColor};\n box-shadow: inset 0 0 1px ${action50};\n }\n\n &:checked + label:after {\n left: 24px;\n animation: ${switchOn} .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ${(props) => hslToHsla(props?.theme?.actionColor?.main || actionColor, '0.3')};\n }\n }\n }\n`;\n\nexport {StyledSwitch, SwitchControl};\n","import React from 'react';\n\nimport {StyledSwitch, SwitchControl} from './style';\n\ninterface SwitchProps {\n isActive: boolean;\n onChange: (nextValue: boolean) => void;\n containerClassName?: string;\n controlClassName?: string;\n elementId?: string;\n isDisabled?: boolean;\n}\n\nconst Switch: React.FC<SwitchProps> = ({\n isActive,\n onChange,\n containerClassName = '',\n controlClassName = '',\n elementId = '',\n isDisabled = false,\n}) => {\n const handleToggleCheckbox = () => {\n onChange(!isActive);\n };\n\n return (\n <StyledSwitch className={containerClassName}>\n <SwitchControl className={controlClassName}>\n <input\n type=\"checkbox\"\n checked={isActive}\n onChange={handleToggleCheckbox}\n id={elementId}\n disabled={isDisabled}\n />\n <label htmlFor={elementId} role=\"presentation\" />\n </SwitchControl>\n </StyledSwitch>\n );\n};\n\nexport default Switch;\n"],"names":["switchOn","keyframes","_templateObject","_taggedTemplateLiteralLoose","black15","hslToHsla","black","black25","action50","actionColor","StyledSwitch","styled","div","_templateObject2","SwitchControl","_templateObject3","fontSmall","gray50","gray95","props","_props$theme","theme","main","_props$theme2","Switch","_ref","isActive","onChange","_ref$containerClassNa","containerClassName","_ref$controlClassName","controlClassName","_ref$elementId","elementId","_ref$isDisabled","isDisabled","handleToggleCheckbox","React","className","type","checked","id","disabled","htmlFor","role"],"mappings":";;;;;;;;;;;;;;;;AAUA,IAAMA,QAAQ,gBAAGC,gBAAS,CAAAC,eAAA,KAAAA,eAAA,gBAAAC,2BAAA,qDAIzB;AAED,IAAMC,OAAO,gBAAGC,wBAAS,CAACC,oBAAK,EAAE,MAAM,CAAC;AACxC,IAAMC,OAAO,gBAAGF,wBAAS,CAACC,oBAAK,EAAE,KAAK,CAAC;AACvC,IAAME,QAAQ,gBAAGH,wBAAS,CAACI,0BAAW,EAAE,KAAK,CAAC;AAE9C,IAAMC,YAAY,gBAAGC,eAAM,CAACC,GAAG,CAAAC,gBAAA,KAAAA,gBAAA,gBAAAV,2BAAA,oDAG9B;AAED,IAAMW,aAAa,gBAAGH,eAAM,CAACC,GAAG,CAAAG,gBAAA,KAAAA,gBAAA,gBAAAZ,2BAAA,80CAEfa,wBAAS,EACbC,qBAAM,EAgBGC,qBAAM,EACQd,OAAO,EAYtBJ,QAAQ,EAGGO,OAAO,EAcf,UAACY,KAAK;EAAA,IAAAC,YAAA;EAAA,OAAK,CAAAD,KAAK,aAAAC,YAAA,GAALD,KAAK,CAAEE,KAAK,cAAAD,YAAA,GAAZA,YAAA,CAAcX,WAAW,qBAAzBW,YAAA,CAA2BE,IAAI,KAAIb,0BAAW;AAAA,GAC3CD,QAAQ,EAKvBR,QAAQ,EAIP,UAACmB,KAAK;EAAA,IAAAI,aAAA;EAAA,OAAKlB,wBAAS,CAAC,CAAAc,KAAK,aAAAI,aAAA,GAALJ,KAAK,CAAEE,KAAK,cAAAE,aAAA,GAAZA,aAAA,CAAcd,WAAW,qBAAzBc,aAAA,CAA2BD,IAAI,KAAIb,0BAAW,EAAE,KAAK,CAAC;AAAA,EAIlG;;AC3ED,IAAMe,MAAM,GAA0B,SAAhCA,MAAMA,CAAAC,IAAA;MACVC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAAC,qBAAA,GAAAH,IAAA,CACRI,kBAAkB;IAAlBA,kBAAkB,GAAAD,qBAAA,cAAG,EAAE,GAAAA,qBAAA;IAAAE,qBAAA,GAAAL,IAAA,CACvBM,gBAAgB;IAAhBA,gBAAgB,GAAAD,qBAAA,cAAG,EAAE,GAAAA,qBAAA;IAAAE,cAAA,GAAAP,IAAA,CACrBQ,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,EAAE,GAAAA,cAAA;IAAAE,eAAA,GAAAT,IAAA,CACdU,UAAU;IAAVA,UAAU,GAAAD,eAAA,cAAG,KAAK,GAAAA,eAAA;EAElB,IAAME,oBAAoB,GAAG,SAAvBA,oBAAoBA;IACxBT,QAAQ,CAAC,CAACD,QAAQ,CAAC;GACpB;EAED,OACEW,oBAAC3B,YAAY;IAAC4B,SAAS,EAAET;KACvBQ,oBAACvB,aAAa;IAACwB,SAAS,EAAEP;KACxBM;IACEE,IAAI,EAAC,UAAU;IACfC,OAAO,EAAEd,QAAQ;IACjBC,QAAQ,EAAES,oBAAoB;IAC9BK,EAAE,EAAER,SAAS;IACbS,QAAQ,EAAEP;IACV,EACFE;IAAOM,OAAO,EAAEV,SAAS;IAAEW,IAAI,EAAC;IAAiB,CACnC,CACH;AAEnB,CAAC;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function n(n){return n&&"object"==typeof n&&"default"in n?n.default:n}Object.defineProperty(exports,"__esModule",{value:!0});var e,o,t,a=n(require("react")),l=require("styled-components"),i=n(l),r=require("@propellerads/stylevariables");function s(n,e){return e||(e=n.slice(0)),n.raw=e,n}var c=l.keyframes(e||(e=s(["\n 50% {\n transform: scaleX(1.1);\n }\n"]))),d=r.hslToHsla(r.black,"0.15"),u=r.hslToHsla(r.black,"0.5"),p=r.hslToHsla(r.actionColor,"0.5"),b=i.div(o||(o=s(["\n display: flex;\n align-items: center;\n"]))),h=i.div(t||(t=s(["\n display: block;\n font-size: ","px;\n color: ",";\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ",";\n box-shadow: inset 0 0 3px ",";\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: "," .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ",";\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ",";\n box-shadow: inset 0 0 1px ",";\n }\n\n &:checked + label:after {\n left: 24px;\n animation: "," .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ",";\n }\n }\n }\n"])),r.fontSmall,r.gray50,r.gray95,d,c,u,(function(n){var e;return(null==n||null==(e=n.theme)||null==(e=e.actionColor)?void 0:e.main)||r.actionColor}),p,c,(function(n){var e;return r.hslToHsla((null==n||null==(e=n.theme)||null==(e=e.actionColor)?void 0:e.main)||r.actionColor,"0.3")}));exports.default=function(n){var e=n.isActive,o=n.onChange,t=n.containerClassName,l=n.controlClassName,i=n.elementId,r=void 0===i?"":i,s=n.isDisabled;return a.createElement(b,{className:void 0===t?"":t},a.createElement(h,{className:void 0===l?"":l},a.createElement("input",{type:"checkbox",checked:e,onChange:function(){o(!e)},id:r,disabled:void 0!==s&&s}),a.createElement("label",{htmlFor:r,role:"presentation"})))};
|
|
2
|
+
//# sourceMappingURL=switch.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.cjs.production.min.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {\n gray50,\n gray95,\n actionColor,\n black,\n fontSmall,\n hslToHsla,\n} from '@propellerads/stylevariables';\n\nconst switchOn = keyframes`\n 50% {\n transform: scaleX(1.1);\n }\n`;\n\nconst black15 = hslToHsla(black, '0.15');\nconst black25 = hslToHsla(black, '0.5');\nconst action50 = hslToHsla(actionColor, '0.5');\n\nconst StyledSwitch = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst SwitchControl = styled.div`\n display: block;\n font-size: ${fontSmall}px;\n color: ${gray50};\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ${gray95};\n box-shadow: inset 0 0 3px ${black15};\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: ${switchOn} .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ${black25};\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ${(props) => props?.theme?.actionColor?.main || actionColor};\n box-shadow: inset 0 0 1px ${action50};\n }\n\n &:checked + label:after {\n left: 24px;\n animation: ${switchOn} .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ${(props) => hslToHsla(props?.theme?.actionColor?.main || actionColor, '0.3')};\n }\n }\n }\n`;\n\nexport {StyledSwitch, SwitchControl};\n","import React from 'react';\n\nimport {StyledSwitch, SwitchControl} from './style';\n\ninterface SwitchProps {\n isActive: boolean;\n onChange: (nextValue: boolean) => void;\n containerClassName?: string;\n controlClassName?: string;\n elementId?: string;\n isDisabled?: boolean;\n}\n\nconst Switch: React.FC<SwitchProps> = ({\n isActive,\n onChange,\n containerClassName = '',\n controlClassName = '',\n elementId = '',\n isDisabled = false,\n}) => {\n const handleToggleCheckbox = () => {\n onChange(!isActive);\n };\n\n return (\n <StyledSwitch className={containerClassName}>\n <SwitchControl className={controlClassName}>\n <input\n type=\"checkbox\"\n checked={isActive}\n onChange={handleToggleCheckbox}\n id={elementId}\n disabled={isDisabled}\n />\n <label htmlFor={elementId} role=\"presentation\" />\n </SwitchControl>\n </StyledSwitch>\n );\n};\n\nexport default Switch;\n"],"names":["switchOn","keyframes","_templateObject","_taggedTemplateLiteralLoose","black15","hslToHsla","black","black25","action50","actionColor","StyledSwitch","styled","div","_templateObject2","SwitchControl","_templateObject3","fontSmall","gray50","gray95","props","_props$theme","theme","main","_props$theme2","_ref","isActive","onChange","_ref$containerClassNa","containerClassName","_ref$controlClassName","controlClassName","_ref$elementId","elementId","_ref$isDisabled","isDisabled","React","className","type","checked","id","disabled","htmlFor","role"],"mappings":"6SAUA,IAAMA,EAAWC,YAASC,IAAAA,EAAAC,uDAMpBC,EAAUC,YAAUC,QAAO,QAC3BC,EAAUF,YAAUC,QAAO,OAC3BE,EAAWH,YAAUI,cAAa,OAElCC,EAAeC,EAAOC,IAAGC,IAAAA,EAAAV,sDAKzBW,EAAgBH,EAAOC,IAAGG,IAAAA,EAAAZ,o0CAEfa,YACJC,SAgBSC,SACcd,EAYfJ,EAGWO,GAcR,SAACY,GAAK,IAAAC,EAAA,aAAKD,UAAKC,EAALD,EAAOE,eAAKD,EAAZA,EAAcX,oBAAdW,EAA2BE,OAAQb,gBAChCD,EAKfR,GAIC,SAACmB,GAAK,IAAAI,EAAA,OAAKlB,mBAAUc,UAAKI,EAALJ,EAAOE,eAAKE,EAAZA,EAAcd,oBAAdc,EAA2BD,OAAQb,cAAa,0BCvEvD,SAA1Be,OACVC,EAAQD,EAARC,SACAC,EAAQF,EAARE,SAAQC,EAAAH,EACRI,mBAAuBC,EAAAL,EACvBM,iBAAqBC,EAAAP,EACrBQ,UAAAA,WAASD,EAAG,GAAEA,EAAAE,EAAAT,EACdU,WAMA,OACEC,gBAACzB,GAAa0B,mBAVET,EAAG,GAAEA,GAWnBQ,gBAACrB,GAAcsB,mBAVHP,EAAG,GAAEA,GAWfM,yBACEE,KAAK,WACLC,QAASb,EACTC,SAVqB,WAC3BA,GAAUD,IAUJc,GAAIP,EACJQ,kBAdEP,GAAQA,IAgBZE,yBAAOM,QAAST,EAAWU,KAAK"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled, { keyframes } from 'styled-components';
|
|
3
|
+
import { fontSmall, gray50, gray95, actionColor, hslToHsla, black } from '@propellerads/stylevariables';
|
|
4
|
+
|
|
5
|
+
function _taggedTemplateLiteralLoose(e, t) {
|
|
6
|
+
return t || (t = e.slice(0)), e.raw = t, e;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
10
|
+
var switchOn = /*#__PURE__*/keyframes(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n 50% {\n transform: scaleX(1.1);\n }\n"])));
|
|
11
|
+
var black15 = /*#__PURE__*/hslToHsla(black, '0.15');
|
|
12
|
+
var black25 = /*#__PURE__*/hslToHsla(black, '0.5');
|
|
13
|
+
var action50 = /*#__PURE__*/hslToHsla(actionColor, '0.5');
|
|
14
|
+
var StyledSwitch = /*#__PURE__*/styled.div(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n"])));
|
|
15
|
+
var SwitchControl = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: block;\n font-size: ", "px;\n color: ", ";\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ", ";\n box-shadow: inset 0 0 3px ", ";\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: ", " .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ", ";\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ", ";\n box-shadow: inset 0 0 1px ", ";\n }\n\n &:checked + label:after {\n left: 24px;\n animation: ", " .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ", ";\n }\n }\n }\n"])), fontSmall, gray50, gray95, black15, switchOn, black25, function (props) {
|
|
16
|
+
var _props$theme;
|
|
17
|
+
return (props == null || (_props$theme = props.theme) == null || (_props$theme = _props$theme.actionColor) == null ? void 0 : _props$theme.main) || actionColor;
|
|
18
|
+
}, action50, switchOn, function (props) {
|
|
19
|
+
var _props$theme2;
|
|
20
|
+
return hslToHsla((props == null || (_props$theme2 = props.theme) == null || (_props$theme2 = _props$theme2.actionColor) == null ? void 0 : _props$theme2.main) || actionColor, '0.3');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
var Switch = function Switch(_ref) {
|
|
24
|
+
var isActive = _ref.isActive,
|
|
25
|
+
onChange = _ref.onChange,
|
|
26
|
+
_ref$containerClassNa = _ref.containerClassName,
|
|
27
|
+
containerClassName = _ref$containerClassNa === void 0 ? '' : _ref$containerClassNa,
|
|
28
|
+
_ref$controlClassName = _ref.controlClassName,
|
|
29
|
+
controlClassName = _ref$controlClassName === void 0 ? '' : _ref$controlClassName,
|
|
30
|
+
_ref$elementId = _ref.elementId,
|
|
31
|
+
elementId = _ref$elementId === void 0 ? '' : _ref$elementId,
|
|
32
|
+
_ref$isDisabled = _ref.isDisabled,
|
|
33
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled;
|
|
34
|
+
var handleToggleCheckbox = function handleToggleCheckbox() {
|
|
35
|
+
onChange(!isActive);
|
|
36
|
+
};
|
|
37
|
+
return React.createElement(StyledSwitch, {
|
|
38
|
+
className: containerClassName
|
|
39
|
+
}, React.createElement(SwitchControl, {
|
|
40
|
+
className: controlClassName
|
|
41
|
+
}, React.createElement("input", {
|
|
42
|
+
type: "checkbox",
|
|
43
|
+
checked: isActive,
|
|
44
|
+
onChange: handleToggleCheckbox,
|
|
45
|
+
id: elementId,
|
|
46
|
+
disabled: isDisabled
|
|
47
|
+
}), React.createElement("label", {
|
|
48
|
+
htmlFor: elementId,
|
|
49
|
+
role: "presentation"
|
|
50
|
+
})));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default Switch;
|
|
54
|
+
//# sourceMappingURL=switch.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.esm.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {\n gray50,\n gray95,\n actionColor,\n black,\n fontSmall,\n hslToHsla,\n} from '@propellerads/stylevariables';\n\nconst switchOn = keyframes`\n 50% {\n transform: scaleX(1.1);\n }\n`;\n\nconst black15 = hslToHsla(black, '0.15');\nconst black25 = hslToHsla(black, '0.5');\nconst action50 = hslToHsla(actionColor, '0.5');\n\nconst StyledSwitch = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst SwitchControl = styled.div`\n display: block;\n font-size: ${fontSmall}px;\n color: ${gray50};\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ${gray95};\n box-shadow: inset 0 0 3px ${black15};\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: ${switchOn} .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ${black25};\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ${(props) => props?.theme?.actionColor?.main || actionColor};\n box-shadow: inset 0 0 1px ${action50};\n }\n\n &:checked + label:after {\n left: 24px;\n animation: ${switchOn} .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ${(props) => hslToHsla(props?.theme?.actionColor?.main || actionColor, '0.3')};\n }\n }\n }\n`;\n\nexport {StyledSwitch, SwitchControl};\n","import React from 'react';\n\nimport {StyledSwitch, SwitchControl} from './style';\n\ninterface SwitchProps {\n isActive: boolean;\n onChange: (nextValue: boolean) => void;\n containerClassName?: string;\n controlClassName?: string;\n elementId?: string;\n isDisabled?: boolean;\n}\n\nconst Switch: React.FC<SwitchProps> = ({\n isActive,\n onChange,\n containerClassName = '',\n controlClassName = '',\n elementId = '',\n isDisabled = false,\n}) => {\n const handleToggleCheckbox = () => {\n onChange(!isActive);\n };\n\n return (\n <StyledSwitch className={containerClassName}>\n <SwitchControl className={controlClassName}>\n <input\n type=\"checkbox\"\n checked={isActive}\n onChange={handleToggleCheckbox}\n id={elementId}\n disabled={isDisabled}\n />\n <label htmlFor={elementId} role=\"presentation\" />\n </SwitchControl>\n </StyledSwitch>\n );\n};\n\nexport default Switch;\n"],"names":["switchOn","keyframes","_templateObject","_taggedTemplateLiteralLoose","black15","hslToHsla","black","black25","action50","actionColor","StyledSwitch","styled","div","_templateObject2","SwitchControl","_templateObject3","fontSmall","gray50","gray95","props","_props$theme","theme","main","_props$theme2","Switch","_ref","isActive","onChange","_ref$containerClassNa","containerClassName","_ref$controlClassName","controlClassName","_ref$elementId","elementId","_ref$isDisabled","isDisabled","handleToggleCheckbox","React","className","type","checked","id","disabled","htmlFor","role"],"mappings":";;;;;;;;;AAUA,IAAMA,QAAQ,gBAAGC,SAAS,CAAAC,eAAA,KAAAA,eAAA,gBAAAC,2BAAA,qDAIzB;AAED,IAAMC,OAAO,gBAAGC,SAAS,CAACC,KAAK,EAAE,MAAM,CAAC;AACxC,IAAMC,OAAO,gBAAGF,SAAS,CAACC,KAAK,EAAE,KAAK,CAAC;AACvC,IAAME,QAAQ,gBAAGH,SAAS,CAACI,WAAW,EAAE,KAAK,CAAC;AAE9C,IAAMC,YAAY,gBAAGC,MAAM,CAACC,GAAG,CAAAC,gBAAA,KAAAA,gBAAA,gBAAAV,2BAAA,oDAG9B;AAED,IAAMW,aAAa,gBAAGH,MAAM,CAACC,GAAG,CAAAG,gBAAA,KAAAA,gBAAA,gBAAAZ,2BAAA,80CAEfa,SAAS,EACbC,MAAM,EAgBGC,MAAM,EACQd,OAAO,EAYtBJ,QAAQ,EAGGO,OAAO,EAcf,UAACY,KAAK;EAAA,IAAAC,YAAA;EAAA,OAAK,CAAAD,KAAK,aAAAC,YAAA,GAALD,KAAK,CAAEE,KAAK,cAAAD,YAAA,GAAZA,YAAA,CAAcX,WAAW,qBAAzBW,YAAA,CAA2BE,IAAI,KAAIb,WAAW;AAAA,GAC3CD,QAAQ,EAKvBR,QAAQ,EAIP,UAACmB,KAAK;EAAA,IAAAI,aAAA;EAAA,OAAKlB,SAAS,CAAC,CAAAc,KAAK,aAAAI,aAAA,GAALJ,KAAK,CAAEE,KAAK,cAAAE,aAAA,GAAZA,aAAA,CAAcd,WAAW,qBAAzBc,aAAA,CAA2BD,IAAI,KAAIb,WAAW,EAAE,KAAK,CAAC;AAAA,EAIlG;;AC3ED,IAAMe,MAAM,GAA0B,SAAhCA,MAAMA,CAAAC,IAAA;MACVC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAAC,qBAAA,GAAAH,IAAA,CACRI,kBAAkB;IAAlBA,kBAAkB,GAAAD,qBAAA,cAAG,EAAE,GAAAA,qBAAA;IAAAE,qBAAA,GAAAL,IAAA,CACvBM,gBAAgB;IAAhBA,gBAAgB,GAAAD,qBAAA,cAAG,EAAE,GAAAA,qBAAA;IAAAE,cAAA,GAAAP,IAAA,CACrBQ,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,EAAE,GAAAA,cAAA;IAAAE,eAAA,GAAAT,IAAA,CACdU,UAAU;IAAVA,UAAU,GAAAD,eAAA,cAAG,KAAK,GAAAA,eAAA;EAElB,IAAME,oBAAoB,GAAG,SAAvBA,oBAAoBA;IACxBT,QAAQ,CAAC,CAACD,QAAQ,CAAC;GACpB;EAED,OACEW,oBAAC3B,YAAY;IAAC4B,SAAS,EAAET;KACvBQ,oBAACvB,aAAa;IAACwB,SAAS,EAAEP;KACxBM;IACEE,IAAI,EAAC,UAAU;IACfC,OAAO,EAAEd,QAAQ;IACjBC,QAAQ,EAAES,oBAAoB;IAC9BK,EAAE,EAAER,SAAS;IACbS,QAAQ,EAAEP;IACV,EACFE;IAAOM,OAAO,EAAEV,SAAS;IAAEW,IAAI,EAAC;IAAiB,CACnC,CACH;AAEnB,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/switch",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "dist/index.
|
|
5
|
-
"
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"typings": "dist/index.d.ts",
|
|
6
|
+
"module": "dist/switch.esm.js",
|
|
6
7
|
"files": [
|
|
7
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"src"
|
|
8
10
|
],
|
|
9
11
|
"repository": "https://github.com/propellerads/ui-components.git",
|
|
10
12
|
"author": "i.pasyuk@propellerads.net",
|
|
@@ -13,7 +15,9 @@
|
|
|
13
15
|
"url": "https://github.com/propellerads/ui-components/issues"
|
|
14
16
|
},
|
|
15
17
|
"scripts": {
|
|
16
|
-
"prepublishOnly": "
|
|
18
|
+
"prepublishOnly": "tsdx build",
|
|
19
|
+
"start": "tsdx watch",
|
|
20
|
+
"build": "tsdx build"
|
|
17
21
|
},
|
|
18
22
|
"homepage": "https://github.com/propellerads/ui-components#readme",
|
|
19
23
|
"private": false,
|
|
@@ -21,19 +25,13 @@
|
|
|
21
25
|
"@propellerads/stylevariables": "^1.3.0"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"@babel/preset-env": "^7.9.5",
|
|
28
|
-
"@babel/preset-react": "^7.9.4",
|
|
29
|
-
"rollup": "^2.6.1",
|
|
30
|
-
"rollup-plugin-babel": "^4.4.0",
|
|
31
|
-
"rollup-plugin-terser": "^5.3.0"
|
|
28
|
+
"tsdx": "^0.14.1",
|
|
29
|
+
"tslib": "^2.3.1",
|
|
30
|
+
"typescript": "^4.4.2"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
34
|
-
"prop-types": "15.7.2",
|
|
35
33
|
"react": "^17.0.2",
|
|
36
|
-
"styled-components": "5.1.1"
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
"styled-components": "5.1.1",
|
|
35
|
+
"prop-types": "15.7.2"
|
|
36
|
+
}
|
|
39
37
|
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {StyledSwitch, SwitchControl} from './style';
|
|
4
|
+
|
|
5
|
+
interface SwitchProps {
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
onChange: (nextValue: boolean) => void;
|
|
8
|
+
containerClassName?: string;
|
|
9
|
+
controlClassName?: string;
|
|
10
|
+
elementId?: string;
|
|
11
|
+
isDisabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Switch: React.FC<SwitchProps> = ({
|
|
15
|
+
isActive,
|
|
16
|
+
onChange,
|
|
17
|
+
containerClassName = '',
|
|
18
|
+
controlClassName = '',
|
|
19
|
+
elementId = '',
|
|
20
|
+
isDisabled = false,
|
|
21
|
+
}) => {
|
|
22
|
+
const handleToggleCheckbox = () => {
|
|
23
|
+
onChange(!isActive);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<StyledSwitch className={containerClassName}>
|
|
28
|
+
<SwitchControl className={controlClassName}>
|
|
29
|
+
<input
|
|
30
|
+
type="checkbox"
|
|
31
|
+
checked={isActive}
|
|
32
|
+
onChange={handleToggleCheckbox}
|
|
33
|
+
id={elementId}
|
|
34
|
+
disabled={isDisabled}
|
|
35
|
+
/>
|
|
36
|
+
<label htmlFor={elementId} role="presentation" />
|
|
37
|
+
</SwitchControl>
|
|
38
|
+
</StyledSwitch>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default Switch;
|
package/src/style.tsx
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import styled, {keyframes} from 'styled-components';
|
|
2
|
+
import {
|
|
3
|
+
gray50,
|
|
4
|
+
gray95,
|
|
5
|
+
actionColor,
|
|
6
|
+
black,
|
|
7
|
+
fontSmall,
|
|
8
|
+
hslToHsla,
|
|
9
|
+
} from '@propellerads/stylevariables';
|
|
10
|
+
|
|
11
|
+
const switchOn = keyframes`
|
|
12
|
+
50% {
|
|
13
|
+
transform: scaleX(1.1);
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const black15 = hslToHsla(black, '0.15');
|
|
18
|
+
const black25 = hslToHsla(black, '0.5');
|
|
19
|
+
const action50 = hslToHsla(actionColor, '0.5');
|
|
20
|
+
|
|
21
|
+
const StyledSwitch = styled.div`
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const SwitchControl = styled.div`
|
|
27
|
+
display: block;
|
|
28
|
+
font-size: ${fontSmall}px;
|
|
29
|
+
color: ${gray50};
|
|
30
|
+
|
|
31
|
+
label {
|
|
32
|
+
position: relative;
|
|
33
|
+
display: block;
|
|
34
|
+
width: 40px;
|
|
35
|
+
height: 20px;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
|
|
38
|
+
&:before {
|
|
39
|
+
position: absolute;
|
|
40
|
+
width: 40px;
|
|
41
|
+
height: 20px;
|
|
42
|
+
content: '';
|
|
43
|
+
transition: background .1s ease;
|
|
44
|
+
border-radius: 50px;
|
|
45
|
+
background: ${gray95};
|
|
46
|
+
box-shadow: inset 0 0 3px ${black15};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&:after {
|
|
50
|
+
position: absolute;
|
|
51
|
+
z-index: 2;
|
|
52
|
+
top: 4px;
|
|
53
|
+
left: 4px;
|
|
54
|
+
width: 12px;
|
|
55
|
+
height: 12px;
|
|
56
|
+
content: '';
|
|
57
|
+
transition: all .2s ease;
|
|
58
|
+
animation: ${switchOn} .3s ease-out;
|
|
59
|
+
border-radius: 50px;
|
|
60
|
+
background: white;
|
|
61
|
+
box-shadow: 0 0 3px 0 ${black25};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
input {
|
|
66
|
+
&[type=checkbox] {
|
|
67
|
+
display: none;
|
|
68
|
+
visibility: hidden;
|
|
69
|
+
|
|
70
|
+
&:disabled + label {
|
|
71
|
+
cursor: not-allowed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&:checked + label:before {
|
|
75
|
+
background: ${(props) => props?.theme?.actionColor?.main || actionColor};
|
|
76
|
+
box-shadow: inset 0 0 1px ${action50};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&:checked + label:after {
|
|
80
|
+
left: 24px;
|
|
81
|
+
animation: ${switchOn} .2s ease-out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&:checked:disabled + label:before {
|
|
85
|
+
background: ${(props) => hslToHsla(props?.theme?.actionColor?.main || actionColor, '0.3')};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
export {StyledSwitch, SwitchControl};
|
package/dist/index.esm.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import styled, { keyframes } from 'styled-components';
|
|
4
|
-
import { hslToHsla, black, actionColor, fontSmall, gray50, gray95, gray70 } from '@propellerads/stylevariables';
|
|
5
|
-
|
|
6
|
-
function _taggedTemplateLiteral(strings, raw) {
|
|
7
|
-
if (!raw) {
|
|
8
|
-
raw = strings.slice(0);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return Object.freeze(Object.defineProperties(strings, {
|
|
12
|
-
raw: {
|
|
13
|
-
value: Object.freeze(raw)
|
|
14
|
-
}
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _templateObject3() {
|
|
19
|
-
var data = _taggedTemplateLiteral(["\n display: block;\n font-size: ", "px;\n color: ", ";\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ", ";\n box-shadow: inset 0 0 3px ", ";\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: ", " .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ", ";\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ", ";\n box-shadow: inset 0 0 1px ", ";\n }\n\n &:checked + label:after {\n left: 24px;\n animation: ", " .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ", ";\n }\n }\n }\n"]);
|
|
20
|
-
|
|
21
|
-
_templateObject3 = function _templateObject3() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _templateObject2() {
|
|
29
|
-
var data = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n"]);
|
|
30
|
-
|
|
31
|
-
_templateObject2 = function _templateObject2() {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _templateObject() {
|
|
39
|
-
var data = _taggedTemplateLiteral(["\n 50% {\n transform: scaleX(1.1);\n }\n"]);
|
|
40
|
-
|
|
41
|
-
_templateObject = function _templateObject() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
var switchOn = keyframes(_templateObject());
|
|
48
|
-
var black15 = hslToHsla(black, '0.15');
|
|
49
|
-
var black25 = hslToHsla(black, '0.5');
|
|
50
|
-
var action50 = hslToHsla(actionColor, '0.5');
|
|
51
|
-
var StyledSwitch = styled.div(_templateObject2());
|
|
52
|
-
var SwitchControl = styled.div(_templateObject3(), fontSmall, gray50, gray95, black15, switchOn, black25, actionColor, action50, switchOn, gray70);
|
|
53
|
-
|
|
54
|
-
var Switch = function Switch(_ref) {
|
|
55
|
-
var model = _ref.model,
|
|
56
|
-
commonStyle = _ref.commonStyle,
|
|
57
|
-
activeStyle = _ref.activeStyle,
|
|
58
|
-
elementId = _ref.elementId,
|
|
59
|
-
isDisabled = _ref.isDisabled,
|
|
60
|
-
onChange = _ref.onChange;
|
|
61
|
-
|
|
62
|
-
function handleToggleCheckbox() {
|
|
63
|
-
onChange(!model);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return /*#__PURE__*/React.createElement(StyledSwitch, {
|
|
67
|
-
className: commonStyle
|
|
68
|
-
}, /*#__PURE__*/React.createElement(SwitchControl, {
|
|
69
|
-
className: activeStyle
|
|
70
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
71
|
-
type: "checkbox",
|
|
72
|
-
checked: model,
|
|
73
|
-
onChange: handleToggleCheckbox,
|
|
74
|
-
id: elementId,
|
|
75
|
-
disabled: isDisabled
|
|
76
|
-
}), /*#__PURE__*/React.createElement("label", {
|
|
77
|
-
htmlFor: elementId,
|
|
78
|
-
role: "presentation"
|
|
79
|
-
})));
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
Switch.propTypes = {
|
|
83
|
-
model: PropTypes.bool.isRequired,
|
|
84
|
-
commonStyle: PropTypes.string,
|
|
85
|
-
activeStyle: PropTypes.string,
|
|
86
|
-
elementId: PropTypes.string,
|
|
87
|
-
isDisabled: PropTypes.bool,
|
|
88
|
-
onChange: PropTypes.func.isRequired
|
|
89
|
-
};
|
|
90
|
-
Switch.defaultProps = {
|
|
91
|
-
commonStyle: '',
|
|
92
|
-
activeStyle: '',
|
|
93
|
-
elementId: '',
|
|
94
|
-
isDisabled: false
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export default Switch;
|
package/dist/index.esm.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import n from"react";import e from"prop-types";import t,{keyframes as o}from"styled-components";import{hslToHsla as i,black as r,actionColor as a,fontSmall as l,gray50 as s,gray95 as c,gray70 as d}from"@propellerads/stylevariables";function p(n,e){return e||(e=n.slice(0)),Object.freeze(Object.defineProperties(n,{raw:{value:Object.freeze(e)}}))}function b(){var n=p(["\n display: block;\n font-size: ","px;\n color: ",";\n \n label {\n position: relative;\n display: block;\n width: 40px;\n height: 20px;\n cursor: pointer;\n\n &:before {\n position: absolute;\n width: 40px;\n height: 20px;\n content: '';\n transition: background .1s ease;\n border-radius: 50px;\n background: ",";\n box-shadow: inset 0 0 3px ",";\n }\n\n &:after {\n position: absolute;\n z-index: 2;\n top: 4px;\n left: 4px;\n width: 12px;\n height: 12px;\n content: '';\n transition: all .2s ease;\n animation: "," .3s ease-out;\n border-radius: 50px;\n background: white;\n box-shadow: 0 0 3px 0 ",";\n }\n }\n \n input {\n &[type=checkbox] {\n display: none;\n visibility: hidden;\n\n &:disabled + label {\n cursor: not-allowed;\n }\n \n &:checked + label:before {\n background: ",";\n box-shadow: inset 0 0 1px ",";\n }\n\n &:checked + label:after {\n left: 24px;\n animation: "," .2s ease-out;\n }\n \n &:checked:disabled + label:before {\n background: ",";\n }\n }\n }\n"]);return b=function(){return n},n}function u(){var n=p(["\n display: flex;\n align-items: center;\n"]);return u=function(){return n},n}function m(){var n=p(["\n 50% {\n transform: scaleX(1.1);\n }\n"]);return m=function(){return n},n}var f=o(m()),h=i(r,"0.15"),x=i(r,"0.5"),y=i(a,"0.5"),g=t.div(u()),v=t.div(b(),l,s,c,h,f,x,a,y,f,d),k=function(e){var t=e.model,o=e.commonStyle,i=e.activeStyle,r=e.elementId,a=e.isDisabled,l=e.onChange;return n.createElement(g,{className:o},n.createElement(v,{className:i},n.createElement("input",{type:"checkbox",checked:t,onChange:function(){l(!t)},id:r,disabled:a}),n.createElement("label",{htmlFor:r,role:"presentation"})))};k.propTypes={model:e.bool.isRequired,commonStyle:e.string,activeStyle:e.string,elementId:e.string,isDisabled:e.bool,onChange:e.func.isRequired},k.defaultProps={commonStyle:"",activeStyle:"",elementId:"",isDisabled:!1};export default k;
|