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AAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;IAAA","sources":["e0c4e8faec553462","packages/@react-spectrum/s2/src/SelectBoxGroup.tsx"],"sourcesContent":["@import \"6c115799477d85f3\";\n@import \"76c5b1a079443994\";\n@import \"57b5eb6b4b0308a7\";\n@import \"c7f260d858a15199\";\n@import \"c9c8eebe8c33c5fb\";\n@import \"183428cb2b58de79\";\n","/*\n * Copyright 2025 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 CONDITIONS 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 {baseColor, focusRing, style} from '../style' with {type: 'macro'};\nimport {box, iconStyles} from './Checkbox';\nimport Checkmark from '../ui-icons/Checkmark';\nimport {\n ContextValue,\n DEFAULT_SLOT,\n ListBox,\n ListBoxItem,\n ListBoxProps,\n Provider\n} from 'react-aria-components';\nimport {DOMRef, DOMRefValue, GlobalDOMAttributes, Key, Orientation} from '@react-types/shared';\nimport {forwardRefType} from './types';\nimport {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {IllustrationContext} from '../src/Icon';\nimport {pressScale} from './pressScale';\nimport React, {createContext, forwardRef, ReactNode, useContext, useMemo, useRef} from 'react';\nimport {TextContext} from './Content';\nimport {useFocusVisible} from 'react-aria';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\nexport interface SelectBoxGroupProps<T> extends StyleProps, Omit<ListBoxProps<T>, keyof GlobalDOMAttributes | 'layout' | 'dragAndDropHooks' | 'dependencies' | 'renderEmptyState' | 'children' | 'onAction' | 'shouldFocusOnHover' | 'selectionBehavior' | 'shouldSelectOnPressUp' | 'shouldFocusWrap' | 'style' | 'className'> {\n /**\n * The SelectBox elements contained within the SelectBoxGroup.\n */\n children: ReactNode | ((item: T) => ReactNode),\n /**\n * The layout direction of the content in each SelectBox.\n * @default 'vertical'\n */\n orientation?: Orientation,\n /**\n * The selection mode for the SelectBoxGroup.\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple',\n /**\n * Whether the SelectBoxGroup is disabled.\n */\n isDisabled?: boolean\n}\n\nexport interface SelectBoxProps extends StyleProps {\n /** The unique id of the SelectBox. */\n id?: Key,\n /** A string representation of the SelectBox's contents, used for features like typeahead. */\n textValue?: string,\n /** An accessibility label for this item. */\n 'aria-label'?: string,\n /**\n * The contents of the SelectBox.\n */\n children: ReactNode,\n /**\n * Whether the SelectBox is disabled.\n */\n isDisabled?: boolean\n}\n\ninterface SelectBoxContextValue {\n allowMultiSelect?: boolean,\n orientation?: Orientation,\n isDisabled?: boolean\n}\n\nconst SelectBoxContext = createContext<SelectBoxContextValue>({orientation: 'vertical'});\nexport const SelectBoxGroupContext = createContext<ContextValue<Partial<SelectBoxGroupProps<any>>, DOMRefValue<HTMLDivElement>>>(null);\n\nconst labelOnly = ':has([slot=label]):not(:has([slot=description]))';\nconst noIllustration = ':not(:has([slot=illustration]))';\nconst selectBoxStyles = style({\n ...focusRing(),\n display: 'grid',\n gridAutoRows: '1fr',\n position: 'relative',\n font: 'ui',\n cursor: 'default',\n boxSizing: 'border-box',\n overflow: 'hidden',\n width: {\n default: 170,\n orientation: {\n horizontal: 368\n }\n },\n height: {\n default: 170,\n orientation: {\n horizontal: 'auto'\n }\n },\n minWidth: {\n default: 144,\n orientation: {\n horizontal: 188\n }\n },\n '--select-box-max-width': {\n type: 'width',\n value: {\n default: 170,\n orientation: {\n horizontal: 480\n }\n }\n },\n maxWidth: 'min(100%, var(--select-box-max-width))',\n minHeight: {\n default: 144,\n orientation: {\n horizontal: 80\n }\n },\n maxHeight: {\n default: 170,\n orientation: {\n horizontal: 240\n }\n },\n padding: {\n default: 24,\n orientation: {\n horizontal: 16\n }\n },\n paddingStart: {\n orientation: {\n horizontal: 32\n }\n },\n paddingEnd: {\n orientation: {\n horizontal: 24\n }\n },\n gridTemplateAreas: {\n orientation: {\n vertical: [\n 'illustration',\n '.',\n 'label'\n ],\n horizontal: {\n default: [\n 'illustration . label',\n 'illustration . description'\n ],\n [labelOnly]: [\n 'illustration . label'\n ]\n }\n }\n },\n gridTemplateRows: {\n orientation: {\n vertical: ['min-content', 8, 'min-content'],\n horizontal: {\n default: ['min-content', 2, 'min-content'],\n [noIllustration]: ['min-content']\n }\n }\n },\n gridTemplateColumns: {\n orientation: {\n horizontal: 'min-content 10px 1fr'\n }\n },\n alignContent: {\n orientation: {\n vertical: 'center'\n }\n },\n borderRadius: 'lg',\n borderStyle: 'solid',\n borderColor: {\n default: 'transparent',\n isSelected: 'gray-900',\n isDisabled: 'transparent'\n },\n backgroundColor: {\n default: 'layer-2',\n isDisabled: 'disabled'\n },\n color: {\n isDisabled: 'disabled'\n },\n boxShadow: {\n default: 'emphasized',\n isHovered: 'elevated',\n isSelected: 'elevated',\n isDisabled: 'none'\n },\n borderWidth: 2,\n transition: 'default'\n}, getAllowedOverrides());\n\nconst illustrationContainer = style({\n gridArea: 'illustration',\n alignSelf: 'center',\n justifySelf: 'center',\n minSize: 48,\n '--iconPrimary': {\n type: 'color',\n value: {\n default: baseColor('neutral'),\n isDisabled: 'disabled'\n }\n }\n});\n\nconst descriptionText = style({\n gridArea: 'description',\n alignSelf: 'center',\n display: {\n default: 'block',\n orientation: {\n vertical: 'none'\n }\n },\n overflow: 'hidden',\n textAlign: {\n default: 'center',\n orientation: {\n horizontal: 'start'\n }\n },\n color: {\n default: baseColor('neutral'),\n isDisabled: 'disabled'\n }\n});\n\nconst labelText = style({\n gridArea: 'label',\n alignSelf: 'center',\n justifySelf: {\n default: 'center',\n orientation: {\n horizontal: 'start'\n }\n },\n width: '100%',\n overflow: 'hidden',\n minWidth: 0,\n textAlign: {\n default: 'center',\n orientation: {\n horizontal: 'start'\n }\n },\n whiteSpace: 'nowrap',\n textOverflow: 'ellipsis',\n fontWeight: {\n orientation: {\n horizontal: 'bold'\n }\n },\n color: {\n default: baseColor('neutral'),\n isDisabled: 'disabled'\n }\n});\n\nconst gridStyles = style<{orientation?: Orientation}>({\n display: 'grid',\n gridAutoRows: '1fr',\n gap: 24,\n justifyContent: 'center',\n '--select-box-group-width': {\n type: 'width',\n value: {\n orientation: {\n horizontal: 368,\n vertical: 170\n }\n }\n },\n '--select-box-group-min-width': {\n type: 'width',\n value: {\n orientation: {\n horizontal: 188,\n vertical: 144\n }\n }\n },\n gridTemplateColumns: {\n orientation: {\n horizontal: 'repeat(auto-fit, minmax(var(--select-box-group-min-width), min(var(--select-box-group-width), 100%)))',\n vertical: 'repeat(auto-fit, minmax(var(--select-box-group-min-width), min(var(--select-box-group-width), 100%)))'\n }\n }\n}, getAllowedOverrides());\n\n/**\n * SelectBox is a single selectable item in a SelectBoxGroup.\n */\nexport function SelectBox(props: SelectBoxProps): ReactNode {\n let {children, isDisabled: individualDisabled = false, UNSAFE_style, UNSAFE_className, styles, ...otherProps} = props;\n\n let {\n orientation = 'vertical',\n isDisabled: groupDisabled = false\n } = useContext(SelectBoxContext);\n\n const isDisabled = individualDisabled || groupDisabled;\n const ref = useRef<HTMLDivElement>(null);\n let {isFocusVisible} = useFocusVisible();\n\n return (\n <ListBoxItem\n isDisabled={isDisabled}\n ref={ref}\n className={renderProps => (UNSAFE_className || '') + selectBoxStyles({\n ...renderProps,\n isFocusVisible: isFocusVisible && renderProps.isFocused,\n orientation\n }, styles)}\n style={pressScale(ref, UNSAFE_style)}\n {...otherProps}>\n {({isSelected, isDisabled, isHovered, selectionMode}) => {\n return (\n <>\n <div\n className={style({\n position: 'absolute',\n top: 8,\n insetStart: 8,\n pointerEvents: 'none'\n })}\n aria-hidden=\"true\">\n {!isDisabled && selectionMode === 'multiple' && (\n <div\n className={box({\n isSelected,\n isDisabled,\n size: 'M'\n } as any)}>\n <Checkmark\n size=\"S\"\n className={iconStyles} />\n </div>\n )}\n </div>\n <Provider\n values={[\n [IllustrationContext, {\n size: 'S',\n styles: illustrationContainer({size: 'S', orientation, isDisabled, isHovered})\n }],\n [TextContext, {\n slots: {\n [DEFAULT_SLOT]: {\n styles: labelText({orientation, isDisabled, isHovered})\n },\n label: {\n styles: labelText({orientation, isDisabled, isHovered})\n },\n description: {\n styles: descriptionText({orientation, isDisabled, isHovered})\n }\n }\n }]\n ]}>\n {children}\n </Provider>\n </>\n );\n }}\n </ListBoxItem>\n );\n}\n\n/**\n * SelectBoxGroup allows users to select one or more options from a list.\n */\nexport const SelectBoxGroup = /*#__PURE__*/ (forwardRef as forwardRefType)(function SelectBoxGroup<T extends object>(props: SelectBoxGroupProps<T>, ref: DOMRef<HTMLDivElement>) {\n [props, ref] = useSpectrumContextProps(props, ref, SelectBoxGroupContext);\n\n let {\n children,\n selectionMode = 'single',\n orientation = 'vertical',\n isDisabled = false,\n UNSAFE_className,\n UNSAFE_style,\n styles,\n ...otherProps\n } = props;\n\n const selectBoxContextValue = useMemo(() => ({\n orientation,\n isDisabled\n }), [orientation, isDisabled]);\n\n return (\n <SelectBoxContext.Provider value={selectBoxContextValue}>\n <ListBox\n selectionMode={selectionMode}\n layout=\"grid\"\n orientation={orientation}\n className={(UNSAFE_className || '') + gridStyles({orientation}, styles)}\n style={UNSAFE_style}\n {...otherProps}>\n {children}\n </ListBox>\n </SelectBoxContext.Provider>\n );\n});\n"],"names":[],"version":3,"file":"SelectBoxGroup.css.map"}