UNPKG

@navinc/base-react-components

Version:
30 lines (29 loc) 2.13 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { styled } from 'styled-components'; import { visuallyHiddenStyles, Fieldset, HiddenLegend } from './form-elements/shared.js'; const StyledFieldset = styled(Fieldset).withConfig({ displayName: "brc-sc-StyledFieldset", componentId: "brc-sc-hdxoyf" }) ` display: flex; flex-direction: column; gap: 10px; `; const OptionCard = styled.div.withConfig({ displayName: "brc-sc-OptionCard", componentId: "brc-sc-ohaibt" }) ` border-radius: 8px; padding: 12px 16px; background: ${({ theme }) => theme.background}; border: ${({ theme, checked }) => `1px solid ${checked ? theme.primary : theme.outlineVariant}`}; transition: border 250ms; &:hover { border-color: ${({ theme }) => theme.primary}; } `; const VisuallyHiddenRadioInput = styled.input.withConfig({ displayName: "brc-sc-VisuallyHiddenRadioInput", componentId: "brc-sc-wly9cj" }) ` ${visuallyHiddenStyles} `; const _OptionsGroup = ({ options, renderOption, value: selectedVal, onChange = () => { }, name, className, }) => { return (_jsxs(StyledFieldset, { className: className, "data-testid": `options-group:${name}`, children: [_jsx(HiddenLegend, { children: name }), options.map((props) => (_jsxs("label", { children: [_jsx(VisuallyHiddenRadioInput, { type: "radio", id: props.value, name: name, value: props.value, checked: selectedVal === props.value, onChange: onChange, "data-testid": `options-group:hidden-radio ${props.value}` }), _jsx(OptionCard, { checked: selectedVal === props.value, "data-testid": `options-group:option-wrapper ${props.value}`, children: renderOption(props) })] }, props.value)))] })); }; /** * A controlled component that takes `options` array of objects and renders a list of items using `renderOptions` with some pre-styling: border radius, border color, hover, spacing, etc. It uses a radio input under the hood so we have full browser default accessibility. */ export const OptionsGroup = styled(_OptionsGroup).withConfig({ displayName: "brc-sc-OptionsGroup", componentId: "brc-sc-ppqvsd" }) ``; //# sourceMappingURL=options-group.js.map