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AA,MAAM,gBAAgB,IAAI,EAAC,IAAK,8BAAQ;gBAAC,GAAG,WAAW;0BAAE;gBAAU,MAAM,MAAM,IAAI,IAAI;YAAG,GAAG,MAAM,MAAM;kBACnI,CAAA;YACC,IAAI,yBACF,iBAAC;gBACC,KAAK;gBACL,OAAO,CAAA,GAAA,yCAAS,EAAE,QAAQ;gBAC1B,WAAW,wCAAI;oBACb,GAAG,WAAW;oBACd,YAAY,YAAY,UAAU,IAAI,YAAY,eAAe;oBACjE,MAAM,MAAM,IAAI,IAAI;oBACpB,cAAc,oBAAoB,KAAK,eAAe,MAAM,YAAY;gBAC1E;;oBACC,YAAY,eAAe,kBAC1B,gBAAC,CAAA,GAAA,wCAAO;wBAAE,MAAM,8BAAQ,CAAC,MAAM,IAAI,IAAI,IAAI;wBAAE,WAAW;;oBAEzD,YAAY,UAAU,IAAI,CAAC,YAAY,eAAe,kBACrD,gBAAC,CAAA,GAAA,wCAAY;wBAAE,MAAM,8BAAQ,CAAC,MAAM,IAAI,IAAI,IAAI;wBAAE,WAAW;;;;YAKnE,4DAA4D;YAC5D,uEAAuE;YACvE,IAAI,CAAC,UACH,OAAO;YAGT,qBACE;;kCACE,gBAAC,CAAA,GAAA,yCAAa;kCACX;;oBAEF;;;QAGP;;AAGN","sources":["packages/@react-spectrum/s2/src/Checkbox.tsx"],"sourcesContent":["/*\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 {Checkbox as AriaCheckbox, CheckboxProps as AriaCheckboxProps, CheckboxGroupStateContext, CheckboxRenderProps, ContextValue, useSlottedContext} from 'react-aria-components';\nimport {baseColor, focusRing, space, style} from '../style' with {type: 'macro'};\nimport {CenterBaseline} from './CenterBaseline';\nimport CheckmarkIcon from '../ui-icons/Checkmark';\nimport {controlBorderRadius, controlFont, controlSize, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {createContext, forwardRef, ReactNode, useContext, useRef} from 'react';\nimport DashIcon from '../ui-icons/Dash';\nimport {FocusableRef, FocusableRefValue} from '@react-types/shared';\nimport {FormContext, useFormProps} from './Form';\nimport {pressScale} from './pressScale';\nimport {useFocusableRef} from '@react-spectrum/utils';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\ninterface CheckboxStyleProps {\n /**\n * The size of the Checkbox.\n *\n * @default 'M'\n */\n size?: 'S' | 'M' | 'L' | 'XL',\n /** Whether the Checkbox should be displayed with an emphasized style. */\n isEmphasized?: boolean\n}\n\ninterface RenderProps extends CheckboxRenderProps, CheckboxStyleProps {}\n\nexport interface CheckboxProps extends Omit<AriaCheckboxProps, 'className' | 'style' | 'children' | 'onHover' | 'onHoverStart' | 'onHoverEnd' | 'onHoverChange'>, StyleProps, CheckboxStyleProps {\n /** The label for the element. */\n children?: ReactNode\n}\n\nexport const CheckboxContext = createContext<ContextValue<Partial<CheckboxProps>, FocusableRefValue<HTMLLabelElement>>>(null);\n\nconst wrapper = style({\n display: 'flex',\n position: 'relative',\n columnGap: 'text-to-control',\n alignItems: 'baseline',\n width: 'fit',\n font: controlFont(),\n transition: 'colors',\n color: {\n default: baseColor('neutral'),\n isDisabled: {\n default: 'disabled',\n forcedColors: 'GrayText'\n }\n },\n gridColumnStart: {\n isInForm: 'field'\n },\n disableTapHighlight: true\n}, getAllowedOverrides());\n\nexport const box = style<RenderProps>({\n ...focusRing(),\n ...controlBorderRadius('sm'),\n size: controlSize('sm'),\n flexShrink: 0,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n borderWidth: space(2),\n boxSizing: 'border-box',\n borderStyle: 'solid',\n transition: 'default',\n forcedColorAdjust: 'none',\n backgroundColor: {\n default: 'gray-25',\n forcedColors: 'Background',\n isSelected: {\n default: baseColor('neutral'),\n isEmphasized: baseColor('accent-900'),\n forcedColors: 'Highlight',\n isInvalid: {\n default: baseColor('negative-900'),\n forcedColors: 'Mark'\n },\n isDisabled: {\n default: 'gray-400',\n forcedColors: 'GrayText'\n }\n }\n },\n borderColor: {\n default: baseColor('gray-800'),\n forcedColors: 'ButtonBorder',\n isInvalid: {\n default: baseColor('negative'),\n forcedColors: 'Mark'\n },\n isDisabled: {\n default: 'gray-400',\n forcedColors: 'GrayText'\n },\n isSelected: 'transparent'\n }\n});\n\nexport const iconStyles = style({\n '--iconPrimary': {\n type: 'fill',\n value: {\n default: 'gray-25',\n forcedColors: 'HighlightText'\n }\n }\n});\n\nconst iconSize = {\n S: 'XS',\n M: 'S',\n L: 'M',\n XL: 'L'\n} as const;\n\n/**\n * Checkboxes allow users to select multiple items from a list of individual items,\n * or to mark one individual item as selected.\n */\nexport const Checkbox = forwardRef(function Checkbox({children, ...props}: CheckboxProps, ref: FocusableRef<HTMLLabelElement>) {\n [props, ref] = useSpectrumContextProps(props, ref, CheckboxContext);\n let boxRef = useRef(null);\n let inputRef = useRef<HTMLInputElement | null>(null);\n let domRef = useFocusableRef(ref, inputRef);\n let isInForm = !!useContext(FormContext);\n props = useFormProps(props);\n let isInCheckboxGroup = !!useContext(CheckboxGroupStateContext);\n let ctx = useSlottedContext(CheckboxContext, props.slot);\n\n return (\n <AriaCheckbox\n {...props}\n ref={domRef}\n inputRef={inputRef}\n style={props.UNSAFE_style}\n className={renderProps => (props.UNSAFE_className || '') + wrapper({...renderProps, isInForm, size: props.size || 'M'}, props.styles)}>\n {renderProps => {\n let checkbox = (\n <div\n ref={boxRef}\n style={pressScale(boxRef)(renderProps)}\n className={box({\n ...renderProps,\n isSelected: renderProps.isSelected || renderProps.isIndeterminate,\n size: props.size || 'M',\n isEmphasized: isInCheckboxGroup ? ctx?.isEmphasized : props.isEmphasized\n })}>\n {renderProps.isIndeterminate &&\n <DashIcon size={iconSize[props.size || 'M']} className={iconStyles} />\n }\n {renderProps.isSelected && !renderProps.isIndeterminate &&\n <CheckmarkIcon size={iconSize[props.size || 'M']} className={iconStyles} />\n }\n </div>\n );\n\n // Only render checkbox without center baseline if no label.\n // This avoids expanding the checkbox height to the font's line height.\n if (!children) {\n return checkbox;\n }\n\n return (\n <>\n <CenterBaseline>\n {checkbox}\n </CenterBaseline>\n {children}\n </>\n );\n }}\n </AriaCheckbox>\n );\n});\n"],"names":[],"version":3,"file":"Checkbox.mjs.map"}