@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
69 lines (68 loc) • 6.37 kB
JavaScript
;
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 layout_1 = require("@workday/canvas-kit-react/layout");
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
const canvas_tokens_web_1 = require("@workday/canvas-tokens-web");
const switchContainerStencil = (0, canvas_kit_styling_1.createStencil)({
base: { name: "2uha99", styles: "box-sizing:border-box;position:relative;height:var(--cnvs-sys-size-xs, var(--cnvs-sys-space-x6, 1.5rem));width:var(--cnvs-sys-size-sm, var(--cnvs-sys-space-x8, 2rem));" }
}, "switch-container-438704");
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: "2ypg0t", styles: "box-sizing:border-box;display:flex;position:absolute;height:var(--cnvs-sys-size-xs, var(--cnvs-sys-space-x6, 1.5rem));width:var(--cnvs-sys-size-sm, var(--cnvs-sys-space-x8, 2rem));border-radius:var(--cnvs-sys-shape-full, var(--cnvs-sys-shape-round, 65rem));opacity:0;cursor:pointer;&:checked, &.checked{& ~ div:first-of-type{background-color:var(--cnvs-sys-color-brand-accent-primary, var(--cnvs-brand-primary-base, oklch(0.5198 0.1782 256.11 / 1)));}&: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-default, var(--cnvs-base-palette-neutral-0)), 0 0 0 4px var(--cnvs-brand-common-focus-outline, rgba(8,117,225,1));}}" },
modifiers: {
error: {
error: { name: "1xh2ad", styles: "& ~ div:first-of-type{box-shadow:\n 0 0 0 0.125rem var(--cnvs-sys-color-focus-inverse, var(--cnvs-sys-color-border-input-inverse, oklch(1 0 0 / 1))),\n 0 0 0 0.25rem var(--cnvs-sys-color-brand-focus-critical, var(--cnvs-brand-common-error-inner, oklch(0.6495 0.2369 30.04 / 1))),\n 0 0 0 0.3125rem transparent;}" },
caution: { name: "3e0v3j", styles: "& ~ div:first-of-type{box-shadow:\n 0 0 0 0.125rem var(--cnvs-sys-color-focus-inverse, var(--cnvs-sys-color-border-input-inverse, oklch(1 0 0 / 1))),\n 0 0 0 0.25rem var(--cnvs-sys-color-brand-focus-caution-inner, var(--cnvs-brand-common-alert-inner, oklch(0.7909 0.1711 70.15 / 1))),\n 0 0 0 0.3125rem var(--cnvs-sys-color-brand-border-caution, var(--cnvs-brand-alert-dark, oklch(0.6601 0.1537 60.7 / 1)));}" }
}
}
}, "switch-input-a3e5c3");
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: "3upwqt", styles: "box-sizing:border-box;position:absolute;display:flex;align-items:center;pointer-events:none;margin-block-start:var(--cnvs-sys-gap-xs, var(--cnvs-sys-space-x1, 0.25rem));width:var(--cnvs-sys-size-sm, var(--cnvs-sys-space-x8, 2rem));height:var(--cnvs-sys-size-xxxs, var(--cnvs-sys-space-x4, 1rem));border-radius:var(--cnvs-sys-shape-full, var(--cnvs-sys-shape-round, 65rem));padding:0 0.125rem;transition:background-color 200ms ease;background-color:var(--cnvs-sys-color-accent-muted-soft, var(--cnvs-sys-color-bg-muted-softer, oklch(0.754 0.0181 256.33 / 1)));" }
}, "switch-background-f23362");
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: "lcj5c", styles: "box-sizing:border-box;width:var(--cnvs-base-size-150, 0.75rem);height:var(--cnvs-base-size-150, 0.75rem);border-radius:var(--cnvs-sys-shape-full, var(--cnvs-sys-shape-round, 65rem));box-shadow:var(--cnvs-sys-depth-1);transition:transform 150ms ease;pointer-events:none;background-color:var(--cnvs-sys-color-fg-inverse);transform:translateX(0);" },
modifiers: {
checked: {
true: { name: "34d3wa", styles: "transform:translateX(var(--cnvs-sys-size-xxxs, var(--cnvs-sys-space-x4, 1rem)));:dir(rtl){transform:translateX(calc(var(--cnvs-sys-size-xxxs, var(--cnvs-sys-space-x4, 1rem)) * -1));}" }
}
}
}, "switch-circle-6833a8");
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 })) });
},
});
/**
* @deprecated ⚠️ `Switch` in Main has been deprecated in v15 and will be removed in a future major version. Please use [`Switch` in Preview](https://workday.github.io/canvas-kit/?path=/docs/preview-inputs-switch--docs) instead.
*/
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,
},
});