UNPKG

@navinc/base-react-components

Version:
49 lines (48 loc) 2 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const styled_components_1 = __importDefault(require("styled-components")); const ToggleChannel = styled_components_1.default.label ` display: flex; border-radius: 1.5em; line-height: 1; height: 1.5em; width: 3em; background: ${({ checked, disabled, theme }) => disabled ? theme.neutral300 : checked ? theme.azure : theme.neutral400}; padding: 0.25em; `; const ToggleIndicator = styled_components_1.default.input.attrs(() => ({ type: 'checkbox' })) ` box-sizing: border-box; border-radius: 50%; background: ${({ theme }) => theme.white}; height: 1em; width: 1em; transition: transform 0.2s ease-in-out; transform: translateX(${({ checked }) => (checked ? '150%' : '0')}); appearance: none; margin: 0; font-size: inherit; :focus { outline: 0; } `; const Toggle = (_a) => { var { checked, disabled } = _a, props = __rest(_a, ["checked", "disabled"]); return ((0, jsx_runtime_1.jsx)(ToggleChannel, Object.assign({ "data-testid": "toggle-channel" }, { checked, disabled }, { children: (0, jsx_runtime_1.jsx)(ToggleIndicator, Object.assign({}, { checked, disabled }, props), void 0) }), void 0)); }; exports.default = (0, styled_components_1.default)(Toggle) ``; //# sourceMappingURL=toggle.js.map