@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1 lines • 7.36 kB
Source Map (JSON)
{"mappings":"AC6CgB;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAqBG;;;;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;;;;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;;;;EA6CO;;;;;AAlEV;EAAA;;;;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;;;;;AAAA;EAAA;IAAA;;;;IAqBG;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IAAA;;;;IA6CO","sources":["547feb480bf9b133","packages/@react-spectrum/s2/src/Checkbox.tsx"],"sourcesContent":["@import \"bc01646daa9aaa9a\";\n@import \"4050adff4afc0e3e\";\n@import \"57a225a6b7ca79cd\";\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 {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, GlobalDOMAttributes} 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' | 'onClick' | keyof GlobalDOMAttributes>, 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.css.map"}