UNPKG

@navinc/base-react-components

Version:
47 lines (45 loc) 2.26 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import styled, { css } from 'styled-components'; import isRebrand from './is-rebrand.js'; const visuallyHiddenStyles = css ` clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; `; const OptionCard = styled.div.withConfig({ displayName: "brc-sc-OptionCard", componentId: "brc-sc-3txhnn" }) ` border-radius: 8px; padding: 13px 16px; background: white; margin-bottom: 10px; border: ${({ theme, checked }) => `3px solid ${checked ? theme.navPrimary : theme.navNeutral200}`}; transition: border 250ms; &:hover { border-color: ${({ theme }) => theme.navPrimary}; } `; const VisuallyHiddenRadioInput = styled.input.withConfig({ displayName: "brc-sc-VisuallyHiddenRadioInput", componentId: "brc-sc-t9y4at" }) ` ${visuallyHiddenStyles} &:focus { + ${OptionCard} { box-shadow: ${({ theme }) => `0 0 0 4px ${isRebrand(theme) ? theme.navStatusPositive500 : theme.bubbleBlue300}`}; } } `; const HiddenLegend = styled.legend.withConfig({ displayName: "brc-sc-HiddenLegend", componentId: "brc-sc-1emf8sh" }) ` ${visuallyHiddenStyles} `; const Fieldset = styled.fieldset.withConfig({ displayName: "brc-sc-Fieldset", componentId: "brc-sc-1ko2gfc" }) ` border: none; padding: 0; margin: 0; `; export const OptionsGroup = ({ options, renderOption, value: selectedVal, onChange = () => { }, name, className, }) => { return (_jsxs(Fieldset, Object.assign({ 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, Object.assign({ checked: selectedVal === props.value, "data-testid": `options-group:option-wrapper ${props.value}` }, { children: renderOption(props) }))] }, props.value)))] }))); }; export default styled(OptionsGroup).withConfig({ componentId: "brc-sc-s0qqt8" }) ``; //# sourceMappingURL=options-group.js.map