@propellerads/switch 3.0.0 → 4.0.1
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/dist/switch.cjs.development.js +1 -1
- package/dist/switch.cjs.development.js.map +1 -1
- package/dist/switch.cjs.production.min.js +1 -1
- package/dist/switch.cjs.production.min.js.map +1 -1
- package/dist/switch.esm.js +1 -1
- package/dist/switch.esm.js.map +1 -1
- package/package.json +7 -9
- package/src/style.tsx +52 -59
- package/CHANGELOG.md +0 -34
|
@@ -19,7 +19,7 @@ var black15 = /*#__PURE__*/stylevariables.hslToHsla(stylevariables.black, '0.15'
|
|
|
19
19
|
var black25 = /*#__PURE__*/stylevariables.hslToHsla(stylevariables.black, '0.5');
|
|
20
20
|
var action50 = /*#__PURE__*/stylevariables.hslToHsla(stylevariables.actionColor, '0.5');
|
|
21
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
|
|
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 0.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 0.2s ease;\n animation: ", " 0.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: ", " 0.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
23
|
var _props$theme;
|
|
24
24
|
return (props == null || (_props$theme = props.theme) == null || (_props$theme = _props$theme.actionColor) == null ? void 0 : _props$theme.main) || stylevariables.actionColor;
|
|
25
25
|
}, action50, switchOn, function (props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.cjs.development.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {
|
|
1
|
+
{"version":3,"file":"switch.cjs.development.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {gray50, gray95, actionColor, black, fontSmall, hslToHsla} 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 0.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 0.2s ease;\n animation: ${switchOn} 0.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} 0.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":";;;;;;;;;;;;;;;;AAGA,IAAMA,QAAQ,gBAAGC,gBAAS,CAAAC,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L,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;;;;"}
|
|
@@ -1,2 +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
|
|
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 0.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 0.2s ease;\n animation: "," 0.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: "," 0.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
2
|
//# sourceMappingURL=switch.cjs.production.min.js.map
|
|
@@ -1 +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 {
|
|
1
|
+
{"version":3,"file":"switch.cjs.production.min.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {gray50, gray95, actionColor, black, fontSmall, hslToHsla} 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 0.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 0.2s ease;\n animation: ${switchOn} 0.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} 0.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":"6SAGA,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,ssCAEjBa,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,0BChErD,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"}
|
package/dist/switch.esm.js
CHANGED
|
@@ -12,7 +12,7 @@ var black15 = /*#__PURE__*/hslToHsla(black, '0.15');
|
|
|
12
12
|
var black25 = /*#__PURE__*/hslToHsla(black, '0.5');
|
|
13
13
|
var action50 = /*#__PURE__*/hslToHsla(actionColor, '0.5');
|
|
14
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
|
|
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 0.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 0.2s ease;\n animation: ", " 0.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: ", " 0.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
16
|
var _props$theme;
|
|
17
17
|
return (props == null || (_props$theme = props.theme) == null || (_props$theme = _props$theme.actionColor) == null ? void 0 : _props$theme.main) || actionColor;
|
|
18
18
|
}, action50, switchOn, function (props) {
|
package/dist/switch.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.esm.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {
|
|
1
|
+
{"version":3,"file":"switch.esm.js","sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import styled, {keyframes} from 'styled-components';\nimport {gray50, gray95, actionColor, black, fontSmall, hslToHsla} 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 0.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 0.2s ease;\n animation: ${switchOn} 0.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} 0.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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BA,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/switch",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/switch.esm.js",
|
|
@@ -15,23 +15,21 @@
|
|
|
15
15
|
"url": "https://github.com/propellerads/ui-components/issues"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"prepublishOnly": "tsdx build",
|
|
19
18
|
"start": "tsdx watch",
|
|
20
19
|
"build": "tsdx build"
|
|
21
20
|
},
|
|
22
21
|
"homepage": "https://github.com/propellerads/ui-components#readme",
|
|
23
22
|
"private": false,
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@propellerads/stylevariables": "^
|
|
24
|
+
"@propellerads/stylevariables": "^2.0.1"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"tsdx": "
|
|
29
|
-
"tslib": "
|
|
30
|
-
"typescript": "
|
|
27
|
+
"tsdx": "0.14.1",
|
|
28
|
+
"tslib": "2.8.1",
|
|
29
|
+
"typescript": "4.9.5"
|
|
31
30
|
},
|
|
32
31
|
"peerDependencies": {
|
|
33
|
-
"react": "
|
|
34
|
-
"styled-components": "5.1.1"
|
|
35
|
-
"prop-types": "15.7.2"
|
|
32
|
+
"react": ">=18 <19",
|
|
33
|
+
"styled-components": "5.1.1"
|
|
36
34
|
}
|
|
37
35
|
}
|
package/src/style.tsx
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
import {gray50, gray95, actionColor, black, fontSmall, hslToHsla} from '@propellerads/stylevariables';
|
|
10
3
|
|
|
11
4
|
const switchOn = keyframes`
|
|
12
5
|
50% {
|
|
@@ -24,68 +17,68 @@ const StyledSwitch = styled.div`
|
|
|
24
17
|
`;
|
|
25
18
|
|
|
26
19
|
const SwitchControl = styled.div`
|
|
20
|
+
display: block;
|
|
21
|
+
font-size: ${fontSmall}px;
|
|
22
|
+
color: ${gray50};
|
|
23
|
+
|
|
24
|
+
label {
|
|
25
|
+
position: relative;
|
|
27
26
|
display: block;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
width: 40px;
|
|
28
|
+
height: 20px;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
|
|
31
|
+
&:before {
|
|
32
|
+
position: absolute;
|
|
34
33
|
width: 40px;
|
|
35
34
|
height: 20px;
|
|
36
|
-
|
|
35
|
+
content: '';
|
|
36
|
+
transition: background 0.1s ease;
|
|
37
|
+
border-radius: 50px;
|
|
38
|
+
background: ${gray95};
|
|
39
|
+
box-shadow: inset 0 0 3px ${black15};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&:after {
|
|
43
|
+
position: absolute;
|
|
44
|
+
z-index: 2;
|
|
45
|
+
top: 4px;
|
|
46
|
+
left: 4px;
|
|
47
|
+
width: 12px;
|
|
48
|
+
height: 12px;
|
|
49
|
+
content: '';
|
|
50
|
+
transition: all 0.2s ease;
|
|
51
|
+
animation: ${switchOn} 0.3s ease-out;
|
|
52
|
+
border-radius: 50px;
|
|
53
|
+
background: white;
|
|
54
|
+
box-shadow: 0 0 3px 0 ${black25};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
input {
|
|
59
|
+
&[type='checkbox'] {
|
|
60
|
+
display: none;
|
|
61
|
+
visibility: hidden;
|
|
37
62
|
|
|
38
|
-
&:
|
|
39
|
-
|
|
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};
|
|
63
|
+
&:disabled + label {
|
|
64
|
+
cursor: not-allowed;
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
&:
|
|
50
|
-
|
|
51
|
-
|
|
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};
|
|
67
|
+
&:checked + label:before {
|
|
68
|
+
background: ${(props) => props?.theme?.actionColor?.main || actionColor};
|
|
69
|
+
box-shadow: inset 0 0 1px ${action50};
|
|
62
70
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
input {
|
|
66
|
-
&[type=checkbox] {
|
|
67
|
-
display: none;
|
|
68
|
-
visibility: hidden;
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
&:checked + label:before {
|
|
75
|
-
background: ${(props) => props?.theme?.actionColor?.main || actionColor};
|
|
76
|
-
box-shadow: inset 0 0 1px ${action50};
|
|
77
|
-
}
|
|
72
|
+
&:checked + label:after {
|
|
73
|
+
left: 24px;
|
|
74
|
+
animation: ${switchOn} 0.2s ease-out;
|
|
75
|
+
}
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
}
|
|
77
|
+
&:checked:disabled + label:before {
|
|
78
|
+
background: ${(props) => hslToHsla(props?.theme?.actionColor?.main || actionColor, '0.3')};
|
|
87
79
|
}
|
|
88
80
|
}
|
|
81
|
+
}
|
|
89
82
|
`;
|
|
90
83
|
|
|
91
84
|
export {StyledSwitch, SwitchControl};
|
package/CHANGELOG.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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`
|
|
15
|
-
|
|
16
|
-
* updated peerDependencies
|
|
17
|
-
|
|
18
|
-
## `2.1.0`
|
|
19
|
-
|
|
20
|
-
* update dependencies
|
|
21
|
-
|
|
22
|
-
## `2.0.0`
|
|
23
|
-
|
|
24
|
-
* Compiled version
|
|
25
|
-
|
|
26
|
-
## `1.2.0`
|
|
27
|
-
|
|
28
|
-
* add disabled state
|
|
29
|
-
* add disabled styles
|
|
30
|
-
* change switch off color
|
|
31
|
-
|
|
32
|
-
## `1.1.0`
|
|
33
|
-
|
|
34
|
-
* remove label property
|