UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

66 lines (65 loc) 5.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Switch = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const common_1 = require("@workday/canvas-kit-react/common"); const canvas_kit_styling_1 = require("@workday/canvas-kit-styling"); const canvas_tokens_web_1 = require("@workday/canvas-tokens-web"); const layout_1 = require("../../layout"); const switchContainerStencil = (0, canvas_kit_styling_1.createStencil)({ base: { name: "ly4lt", styles: "box-sizing:border-box;position:relative;height:var(--cnvs-sys-space-x6);width:var(--cnvs-sys-space-x8);" } }, "switch-container-debbb0"); const SwitchContainer = (0, common_1.createComponent)('div')({ displayName: 'SwitchContainer', Component: ({ children, ...elemProps }, ref, Element) => { return ((0, jsx_runtime_1.jsx)(Element, { ref: ref, ...(0, layout_1.mergeStyles)(elemProps, switchContainerStencil()), children: children })); }, }); const switchInputStencil = (0, canvas_kit_styling_1.createStencil)({ base: { name: "38vbz8", styles: "box-sizing:border-box;display:flex;position:absolute;height:var(--cnvs-sys-space-x6);width:var(--cnvs-sys-space-x8);margin:var(--cnvs-sys-space-zero);margin-left:var(--cnvs-sys-space-x1);border-radius:var(--cnvs-sys-shape-round);opacity:0;cursor:pointer;&:checked, &.checked{& ~ div:first-of-type{background-color:var(--cnvs-brand-primary-base);}&:disabled, &.disabled{& ~ div:first-of-type{opacity:var(--cnvs-sys-opacity-disabled);}}}&:disabled, &.disabled{cursor:not-allowed;& ~ div:first-of-type{opacity:var(--cnvs-sys-opacity-disabled);}}&:focus-visible, &:focus, &.focus{outline:none;& ~ div:first-of-type{box-shadow:0 0 0 2px var(--cnvs-sys-color-border-inverse, rgba(255,255,255,1)), 0 0 0 4px var(--cnvs-brand-common-focus-outline, rgba(8,117,225,1));}}" }, modifiers: { error: { error: { name: "2tf3ug", styles: "& ~ div:first-of-type{box-shadow:\n 0 0 0 0.125rem var(--cnvs-sys-color-border-inverse),\n 0 0 0 var(--cnvs-sys-space-x1) var(--cnvs-brand-common-error-inner),\n 0 0 0 0.3125rem transparent;}" }, caution: { name: "4vxve", styles: "& ~ div:first-of-type{box-shadow:\n 0 0 0 0.125rem var(--cnvs-sys-color-border-inverse),\n 0 0 0 var(--cnvs-sys-space-x1) var(--cnvs-brand-common-alert-inner),\n 0 0 0 0.3125rem var(--cnvs-brand-common-alert-outer);}" } } } }, "switch-input-7f69d7"); const SwitchInput = (0, common_1.createComponent)('input')({ displayName: 'SwitchInput', Component: ({ error, ...elemProps }, ref, Element) => { return (0, jsx_runtime_1.jsx)(Element, { ref: ref, ...(0, layout_1.mergeStyles)(elemProps, switchInputStencil({ error })) }); }, }); const switchBackgroundStencil = (0, canvas_kit_styling_1.createStencil)({ base: { name: "3fss4y", styles: "box-sizing:border-box;position:absolute;display:flex;align-items:center;pointer-events:none;margin-top:var(--cnvs-sys-space-x1);width:var(--cnvs-sys-space-x8);height:var(--cnvs-sys-space-x4);border-radius:var(--cnvs-sys-shape-round);padding:var(--cnvs-sys-space-zero) 0.125rem;transition:background-color 200ms ease;background-color:var(--cnvs-sys-color-bg-muted-soft);" } }, "switch-background-96fe08"); const SwitchBackground = (0, common_1.createComponent)('div')({ displayName: 'SwitchBackground', Component: ({ children, ...elemProps }, ref, Element) => { return ((0, jsx_runtime_1.jsx)(Element, { ref: ref, ...(0, layout_1.mergeStyles)(elemProps, switchBackgroundStencil()), children: children })); }, }); const switchCircleStencil = (0, canvas_kit_styling_1.createStencil)({ base: { name: "1wgkc6", styles: "box-sizing:border-box;width:var(--cnvs-sys-space-x3);height:var(--cnvs-sys-space-x3);border-radius:var(--cnvs-sys-shape-round);box-shadow:var(--cnvs-sys-depth-1);transition:transform 150ms ease;pointer-events:none;background-color:var(--cnvs-brand-primary-accent);transform:translateX(var(--cnvs-sys-space-zero));" }, modifiers: { checked: { true: { name: "btzrg", styles: "transform:translateX(var(--cnvs-sys-space-x4));:dir(rtl){transform:translateX(calc(var(--cnvs-sys-space-x4) * -1));}" } } } }, "switch-circle-cac9b6"); const SwitchCircle = (0, common_1.createComponent)('div')({ displayName: 'SwitchCircle', Component: ({ checked, ...elemProps }, ref, Element) => { return (0, jsx_runtime_1.jsx)(Element, { ref: ref, ...(0, layout_1.mergeStyles)(elemProps, switchCircleStencil({ checked })) }); }, }); exports.Switch = (0, common_1.createComponent)('input')({ displayName: 'Switch', Component: ({ checked = false, id, disabled = false, onChange, value, ...elemProps }, ref, Element) => { const inputId = (0, common_1.useUniqueId)(id); return ((0, jsx_runtime_1.jsxs)(SwitchContainer, { children: [(0, jsx_runtime_1.jsx)(SwitchInput, { as: Element, checked: checked, disabled: disabled, id: inputId, ref: ref, onChange: onChange, role: "switch", type: "checkbox", value: value, ...elemProps }), (0, jsx_runtime_1.jsx)(SwitchBackground, { children: (0, jsx_runtime_1.jsx)(SwitchCircle, { checked: checked }) })] })); }, subComponents: { ErrorType: common_1.ErrorType, }, });