( props: T & SlotProps, ref: ForwardedRef<E> | undefined, context: Context<ContextValue<U, E>> )
| 312 | } |
| 313 | |
| 314 | export function useContextProps<T, U extends SlotProps, E extends Element>( |
| 315 | props: T & SlotProps, |
| 316 | ref: ForwardedRef<E> | undefined, |
| 317 | context: Context<ContextValue<U, E>> |
| 318 | ): [T, RefObject<E | null>] { |
| 319 | let ctx = useSlottedContext(context, props.slot) || {}; |
| 320 | let {ref: contextRef, ...contextProps} = ctx as any; |
| 321 | let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef])); |
| 322 | let mergedProps = mergeProps(contextProps, props) as unknown as T; |
| 323 | |
| 324 | // mergeProps does not merge `style`. Adding this there might be a breaking change. |
| 325 | if ('style' in contextProps && contextProps.style && 'style' in props && props.style) { |
| 326 | if (typeof contextProps.style === 'function' || typeof props.style === 'function') { |
| 327 | // @ts-ignore |
| 328 | mergedProps.style = renderProps => { |
| 329 | let contextStyle = |
| 330 | typeof contextProps.style === 'function' |
| 331 | ? contextProps.style(renderProps) |
| 332 | : contextProps.style; |
| 333 | let defaultStyle = {...renderProps.defaultStyle, ...contextStyle}; |
| 334 | let style = |
| 335 | typeof props.style === 'function' |
| 336 | ? props.style({...renderProps, defaultStyle}) |
| 337 | : props.style; |
| 338 | return {...defaultStyle, ...style}; |
| 339 | }; |
| 340 | } else { |
| 341 | // @ts-ignore |
| 342 | mergedProps.style = {...contextProps.style, ...props.style}; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | return [mergedProps, mergedRef]; |
| 347 | } |
| 348 | |
| 349 | export function useSlot( |
| 350 | initialState: boolean | (() => boolean) = true |
no test coverage detected