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@react-spectrum/s2/src/Form.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 {createContext, forwardRef, ReactNode, useContext, useMemo} from 'react';\nimport {DOMRef, SpectrumLabelableProps} from '@react-types/shared';\nimport {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {Form as RACForm, FormProps as RACFormProps} from 'react-aria-components';\nimport {style} from '../style' with {type: 'macro'};\nimport {useDOMRef} from '@react-spectrum/utils';\nimport {useIsSkeleton} from './Skeleton';\n\ninterface FormStyleProps extends Omit<SpectrumLabelableProps, 'label' | 'contextualHelp'> {\n /**\n * Size of the Form elements.\n * @default 'M'\n */\n size?: 'S' | 'M' | 'L' | 'XL',\n /** Whether the Form elements are disabled. */\n isDisabled?: boolean,\n /** Whether the Form elements are rendered with their emphasized style. */\n isEmphasized?: boolean\n}\n\nexport interface FormProps extends FormStyleProps, Omit<RACFormProps, 'className' | 'style' | 'children'>, StyleProps {\n children: ReactNode\n}\n\nexport const FormContext = createContext<Partial<FormStyleProps | null>>(null);\nexport function useFormProps<T extends FormStyleProps>(props: T): T {\n let ctx = useContext(FormContext);\n let isSkeleton = useIsSkeleton();\n return useMemo(() => {\n let result: T = props;\n if (ctx || isSkeleton) {\n result = {...props};\n }\n\n if (ctx) {\n // This is a subset of mergeProps. We just need to merge non-undefined values.\n for (let key in ctx) {\n if (result[key] === undefined) {\n result[key] = ctx[key];\n }\n }\n }\n\n // Skeleton always wins over local props.\n if (isSkeleton) {\n result.isDisabled = true;\n }\n\n return result;\n }, [ctx, props, isSkeleton]);\n}\n\n/**\n * Forms allow users to enter data that can be submitted while providing alignment and styling for form fields.\n */\nexport const Form = /*#__PURE__*/ forwardRef(function Form(props: FormProps, ref: DOMRef<HTMLFormElement>) {\n let {\n labelPosition = 'top',\n labelAlign,\n necessityIndicator,\n isRequired,\n isDisabled,\n isEmphasized,\n size = 'M',\n ...formProps\n } = props;\n let domRef = useDOMRef(ref);\n\n return (\n <RACForm\n {...formProps}\n ref={domRef}\n style={props.UNSAFE_style}\n className={(props.UNSAFE_className || '') + style({\n display: 'grid',\n gridTemplateColumns: {\n labelPosition: {\n top: ['[field] 1fr'],\n side: ['[label] auto', '[field] 1fr']\n }\n },\n // TODO: confirm when we have tokens\n rowGap: {\n size: {\n XS: 16,\n S: 20,\n M: 24,\n L: 32,\n XL: 40\n }\n },\n columnGap: 'text-to-control'\n }, getAllowedOverrides())({labelPosition, size}, props.styles)}>\n <FormContext.Provider\n value={{\n labelPosition,\n labelAlign,\n necessityIndicator,\n isRequired,\n isDisabled,\n isEmphasized,\n size\n }}>\n {props.children}\n </FormContext.Provider>\n </RACForm>\n );\n});\n"],"names":[],"version":3,"file":"Form.cjs.map"}