UNPKG

@workday/canvas-kit-preview-react

Version:

Canvas Kit Preview is made up of components that have the full design and a11y review, are part of the DS ecosystem and are approved for use in product. The API's could be subject to change, but not without strong communication and migration strategies.

71 lines (70 loc) 3.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RadioGroup = void 0; const react_1 = __importDefault(require("react")); const common_1 = require("@workday/canvas-kit-react/common"); const useRadioModel_1 = require("./hooks/useRadioModel"); const layout_1 = require("@workday/canvas-kit-react/layout"); const RadioLabel_1 = require("./RadioLabel"); const RadioButton_1 = require("./RadioButton"); const canvas_kit_styling_1 = require("@workday/canvas-kit-styling"); const canvas_tokens_web_1 = require("@workday/canvas-tokens-web"); /** * Styles for RadioGroup */ const radioGroupStencil = (0, canvas_kit_styling_1.createStencil)({ base: { name: "nzjww", styles: "box-sizing:border-box;display:flex;flex-direction:column;border-radius:var(--cnvs-sys-shape-x1);gap:var(--cnvs-sys-space-x2);padding:0.625rem var(--cnvs-sys-space-x3) var(--cnvs-sys-space-x2);margin:0 calc(var(--cnvs-sys-space-x3) * -1);transition:100ms box-shadow;width:fit-content;" }, modifiers: { error: { error: { name: "nzjwx", styles: "box-shadow:inset 0 0 0 0.125rem var(--cnvs-brand-error-base);" }, alert: { name: "nzjwy", styles: "box-shadow:inset 0 0 0 0.0625rem var(--cnvs-brand-alert-darkest), inset 0 0 0 0.1875rem var(--cnvs-brand-alert-base);" } } } }, "radio-group-ce2b62"); /** * Use `RadioGroup` to group a collection of `RadioGroup.RadioButton` components under a common `name`. * * ```tsx * <RadioGroup name="pizza-crust" value="thin"> * <RadioGroup.RadioButton value="deep-dish">Deep dish</RadioGroup.RadioButton> * <RadioGroup.RadioButton value="thin">Thin</RadioGroup.RadioButton> * </RadioGroup> * ``` */ exports.RadioGroup = (0, common_1.createContainer)('div')({ displayName: 'RadioGroup', modelHook: useRadioModel_1.useRadioModel, subComponents: { /** * `RadioGroup.RadioButton` renders an `<input type="radio" />` and its associated `<label>` (using `children` as the label's contents). * This component should satisfy most use cases; use `RadioGroup.Label` and its sub components if you require more flexibility. * * ```tsx * <RadioGroup name="pizza-crust" value="thin"> * <RadioGroup.RadioButton value="deep-dish">Deep dish</RadioGroup.RadioButton> * <RadioGroup.RadioButton value="thin">Thin</RadioGroup.RadioButton> * </RadioGroup> * ``` */ RadioButton: RadioButton_1.RadioButton, /** * Use `RadioGroup.Label` instead of `RadioGroup.Radio` if you need direct access to the label and the radio input. * This will render a `<label>` that wraps an `<input type="radio" />` and a `<span>` for the label text. * * ```tsx * <RadioGroup name"pizza-crust" value="deep-dish"> * <RadioGroup.Label> * <RadioGroup.Label.Input value="deep-dish" /> * <RadioGroup.Label.Text>Deep dish</RadioGroup.Label.Text> * </RadioGroup.Label> * </RadioGroup> * ``` */ Label: RadioLabel_1.RadioLabel, }, })(({ children, error, theme, ...elemProps }, Element) => { return react_1.default.createElement(Element, { ...(0, layout_1.mergeStyles)(elemProps, radioGroupStencil({ error })) }, children); });