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.

65 lines (64 loc) 3.1 kB
import React from 'react'; import { createContainer } from '@workday/canvas-kit-react/common'; import { useRadioModel } from './hooks/useRadioModel'; import { mergeStyles } from '@workday/canvas-kit-react/layout'; import { RadioLabel } from './RadioLabel'; import { RadioButton } from './RadioButton'; import { createStencil, calc, px2rem } from '@workday/canvas-kit-styling'; import { brand, system } from '@workday/canvas-tokens-web'; /** * Styles for RadioGroup */ const radioGroupStencil = createStencil({ base: { name: "xrlqw", 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: "xrlqx", styles: "box-shadow:inset 0 0 0 0.125rem var(--cnvs-brand-error-base);" }, alert: { name: "xrlqy", 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> * ``` */ export const RadioGroup = createContainer('div')({ displayName: 'RadioGroup', modelHook: 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, /** * 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, }, })(({ children, error, theme, ...elemProps }, Element) => { return React.createElement(Element, { ...mergeStyles(elemProps, radioGroupStencil({ error })) }, children); });