UNPKG

@react-spectrum/s2

Version:
1 lines 2.83 kB
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AASM,SAAS,0CAAmD,KAAoB,EAAE,GAAoB,EAAE,OAAoC;IACjJ,IAAI,MAAM,CAAA,GAAA,wBAAgB,EAAE,SAAS,MAAM,IAAI,KAAK,CAAC;IACrD,IAAI,EAAC,KAAK,UAAU,EAAE,GAAG,cAAa,GAAG;IACzC,IAAI,YAAY,CAAA,GAAA,mBAAW,EAAE,CAAA,GAAA,cAAM,EAAE,IAAM,CAAA,GAAA,gBAAQ,EAAE,KAAK,aAAa;QAAC;QAAK;KAAW;IACxF,IAAI,cAAc,CAAA,GAAA,iBAAS,EAAE,cAAc;IAE3C,2CAA2C;IAC3C,IACE,kBAAkB,gBAClB,aAAa,YAAY,IACzB,kBAAkB,SAClB,MAAM,YAAY,EAElB,aAAa;IACb,YAAY,YAAY,GAAG;QAAC,GAAG,aAAa,YAAY;QAAE,GAAG,MAAM,YAAY;IAAA;IAGjF,sBAAsB;IACtB,IAAI,YAAY,gBAAgB,aAAa,MAAM,IAAI,YAAY,SAAS,MAAM,MAAM,EACtF,aAAa;IACb,YAAY,MAAM,GAAG,CAAA,GAAA,yCAAU,EAAE,aAAa,MAAM,EAAE,MAAM,MAAM;IAGpE,OAAO;QAAC;QAAa;KAAU;AACjC","sources":["packages/@react-spectrum/s2/src/useSpectrumContextProps.ts"],"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 {Context, ForwardedRef, useMemo} from 'react';\nimport {ContextValue, SlotProps, useSlottedContext} from 'react-aria-components';\nimport {mergeProps, useObjectRef} from 'react-aria';\nimport {mergeRefs} from '@react-aria/utils';\nimport {mergeStyles} from '../style/runtime';\nimport {RefObject} from '@react-types/shared';\n\nexport function useSpectrumContextProps<T, U extends SlotProps, E>(props: T & SlotProps, ref: ForwardedRef<E>, context: Context<ContextValue<U, E>>): [T, RefObject<E | null>] {\n let ctx = useSlottedContext(context, props.slot) || {};\n let {ref: contextRef, ...contextProps} = ctx as any;\n let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));\n let mergedProps = mergeProps(contextProps, props) as unknown as T;\n\n // mergeProps does not merge `UNSAFE_style`\n if (\n 'UNSAFE_style' in contextProps &&\n contextProps.UNSAFE_style &&\n 'UNSAFE_style' in props &&\n props.UNSAFE_style\n ) {\n // @ts-ignore\n mergedProps.UNSAFE_style = {...contextProps.UNSAFE_style, ...props.UNSAFE_style};\n }\n\n // Merge macro styles.\n if ('styles' in contextProps && contextProps.styles && 'styles' in props && props.styles) {\n // @ts-ignore\n mergedProps.styles = mergeStyles(contextProps.styles, props.styles);\n }\n\n return [mergedProps, mergedRef];\n}\n"],"names":[],"version":3,"file":"useSpectrumContextProps.mjs.map"}