UNPKG

@octopusdeploy/design-system-components

Version:
93 lines (92 loc) 4.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkboxButtonSize = exports.CheckboxInput = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const css_1 = require("@emotion/css"); const design_system_icons_1 = require("@octopusdeploy/design-system-icons"); const design_system_tokens_1 = require("@octopusdeploy/design-system-tokens"); const react_1 = require("react"); exports.CheckboxInput = (0, react_1.forwardRef)(function CheckboxInput({ id, name, value, checked, onChange, disabled, autoFocus, isIndeterminate, ariaLabel, ariaDescribedBy }, ref) { return ((0, jsx_runtime_1.jsxs)("div", { className: checkboxWrapperStyles, children: [(0, jsx_runtime_1.jsx)("input", { ref: ref, type: "checkbox", name: name, value: value, disabled: disabled, className: checkboxInputStyles, checked: checked, onChange: onChange, id: id, autoFocus: autoFocus, "aria-checked": isIndeterminate ? "mixed" : checked ? "true" : "false", "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy }), (0, jsx_runtime_1.jsx)("div", { className: checkboxIconStyles, children: isIndeterminate ? (0, jsx_runtime_1.jsx)(design_system_icons_1.MinusIcon, { size: 16, color: "currentColor" }) : (0, jsx_runtime_1.jsx)(design_system_icons_1.CheckIcon, { size: 16, color: "currentColor" }) })] })); }); const borderWidthValue = design_system_tokens_1.borderWidth[1]; exports.checkboxButtonSize = "1.25rem"; const checkboxWrapperStyles = (0, css_1.css)({ position: "relative", }); const checkboxInputStyles = (0, css_1.css)({ position: "relative", display: "grid", placeContent: "center", margin: 0, appearance: "none", width: exports.checkboxButtonSize, height: exports.checkboxButtonSize, backgroundColor: design_system_tokens_1.themeTokens.color.background.primary.default, border: `${borderWidthValue} solid ${design_system_tokens_1.themeTokens.color.border.bold}`, borderRadius: design_system_tokens_1.borderRadius.extraSmall, cursor: "pointer", font: "inherit", color: "currentcolor", "&:before": { content: `""`, position: "absolute", inset: 0, backgroundColor: design_system_tokens_1.themeTokens.color.background.selected, // It needs to be 1px as its nested inside a 2px radius. Have flagged for design token. borderRadius: "1px", scale: 0, transformOrigin: "center center", opacity: 0, transition: "scale 100ms ease-in, opacity 100ms ease-in", "@media (prefers-reduced-motion: reduce)": { transition: "none", }, }, "&:checked:before, &:indeterminate:before": { scale: "1", opacity: 1, transition: "scale 100ms ease-out, opacity 100ms ease-out", "@media (prefers-reduced-motion: reduce)": { transition: "none", }, }, "&:checked, &:indeterminate": { borderColor: design_system_tokens_1.themeTokens.color.border.selected, }, "&:disabled": { backgroundColor: design_system_tokens_1.themeTokens.color.background.disabled, cursor: "not-allowed", }, "&:checked:disabled, &:indeterminate:disabled": { borderColor: design_system_tokens_1.themeTokens.color.border.bold, }, "&:checked:disabled:before, &:indeterminate:disabled:before": { backgroundColor: design_system_tokens_1.themeTokens.color.background.disabled, }, "&:focus": { outline: `max(2px, 0.15em) solid ${design_system_tokens_1.themeTokens.color.border.selected}`, outlineOffset: `max(2px, 0.15em)`, }, }); const checkboxIconStyles = (0, css_1.css)({ display: "grid", placeContent: "center", position: "absolute", top: 0, width: exports.checkboxButtonSize, height: exports.checkboxButtonSize, opacity: 0, color: design_system_tokens_1.themeTokens.color.icon.inverse.primary, pointerEvents: "none", transition: "opacity 100ms ease-in-out", "@media (prefers-reduced-motion: reduce)": { transition: "none", }, "input:checked + &, input:indeterminate + &": { opacity: 1, }, "input:disabled:checked + &, input:disabled:indeterminate + &": { color: design_system_tokens_1.themeTokens.color.icon.tertiary, }, });