@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1 lines • 5.41 kB
Source Map (JSON)
{"mappings":"ACkFoC;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;;EAAA;;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAyBb;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;AAzBa;EAAA;;;;;AAAA;EAAA;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA","sources":["c8770acef16e2ce8","packages/@react-spectrum/s2/src/RadioGroup.tsx"],"sourcesContent":["@import \"759b4f838d0febfe\";\n@import \"c4a9a0d82a5b8e9f\";\n","/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n RadioGroup as AriaRadioGroup,\n RadioGroupProps as AriaRadioGroupProps,\n ContextValue\n} from 'react-aria-components';\nimport {DOMRef, DOMRefValue, HelpTextProps, Orientation, SpectrumLabelableProps} from '@react-types/shared';\nimport {field, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {FieldLabel, HelpText} from './Field';\nimport {FormContext, useFormProps} from './Form';\nimport React, {createContext, forwardRef, ReactNode, useContext} from 'react';\nimport {style} from '../style' with {type: 'macro'};\nimport {useDOMRef} from '@react-spectrum/utils';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\nexport interface RadioGroupProps extends Omit<AriaRadioGroupProps, 'className' | 'style' | 'children'>, StyleProps, SpectrumLabelableProps, HelpTextProps {\n /**\n * The Radios contained within the RadioGroup.\n */\n children: ReactNode,\n /**\n * The size of the RadioGroup.\n *\n * @default 'M'\n */\n size?: 'S' | 'M' | 'L' | 'XL',\n /**\n * The axis the radio elements should align with.\n *\n * @default 'vertical'\n */\n orientation?: Orientation,\n /**\n * Whether the RadioGroup should be displayed with an emphasized style.\n */\n isEmphasized?: boolean\n}\n\nexport const RadioGroupContext = createContext<ContextValue<Partial<RadioGroupProps>, DOMRefValue<HTMLDivElement>>>(null);\n\n/**\n * Radio groups allow users to select a single option from a list of mutually exclusive options.\n * All possible options are exposed up front for users to compare.\n */\nexport const RadioGroup = /*#__PURE__*/ forwardRef(function RadioGroup(props: RadioGroupProps, ref: DOMRef<HTMLDivElement>) {\n [props, ref] = useSpectrumContextProps(props, ref, RadioGroupContext);\n let formContext = useContext(FormContext);\n props = useFormProps(props);\n let domRef = useDOMRef(ref);\n\n let {\n label,\n description,\n errorMessage,\n children,\n isEmphasized,\n labelPosition = 'top',\n labelAlign = 'start',\n necessityIndicator = 'icon',\n size = 'M',\n orientation = 'vertical',\n UNSAFE_className = '',\n UNSAFE_style,\n ...groupProps\n } = props;\n\n return (\n <AriaRadioGroup\n {...groupProps}\n ref={domRef}\n style={UNSAFE_style}\n className={UNSAFE_className + style({\n ...field(),\n // Double the usual gap because of the internal padding within checkbox that spectrum has.\n '--field-gap': {\n type: 'rowGap',\n value: 'calc(var(--field-height) - 1lh)'\n }\n }, getAllowedOverrides())({\n size,\n labelPosition,\n isInForm: !!formContext\n }, props.styles)}>\n {({isDisabled, isInvalid}) => (\n <>\n <FieldLabel\n isDisabled={isDisabled}\n isRequired={props.isRequired}\n size={size}\n labelPosition={labelPosition}\n labelAlign={labelAlign}\n necessityIndicator={necessityIndicator}\n contextualHelp={props.contextualHelp}>\n {label}\n </FieldLabel>\n <div\n className={style({\n gridArea: 'input',\n display: 'flex',\n flexDirection: {\n orientation: {\n vertical: 'column',\n horizontal: 'row'\n }\n },\n flexWrap: 'wrap',\n // Spectrum uses a fixed spacing value for horizontal (column),\n // but the gap changes depending on t-shirt size in vertical (row).\n columnGap: 16,\n rowGap: '--field-gap'\n })({orientation})}>\n <FormContext.Provider value={{...formContext, size, isEmphasized}}>\n {children}\n </FormContext.Provider>\n </div>\n <HelpText\n size={size}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n description={description}\n showErrorIcon>\n {errorMessage}\n </HelpText>\n </>\n )}\n </AriaRadioGroup>\n );\n});\n"],"names":[],"version":3,"file":"RadioGroup.css.map"}