( props: T & SlotProps, ref: ForwardedRef<E> | undefined, context: Context<ContextValue<U, E>> )
| 327 | } |
| 328 | |
| 329 | export function useContextProps<T, U extends SlotProps, E extends Element>( |
| 330 | props: T & SlotProps, |
| 331 | ref: ForwardedRef<E> | undefined, |
| 332 | context: Context<ContextValue<U, E>> |
| 333 | ): [T, RefObject<E | null>] { |
| 334 | let ctx = useSlottedContext(context, props.slot) || {}; |
| 335 | let {ref: contextRef, ...contextProps} = ctx as any; |
| 336 | let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef])); |
| 337 | let mergedProps = mergeProps(contextProps, props) as unknown as T; |
| 338 | |
| 339 | // mergeProps does not merge `style`. Adding this there might be a breaking change. |
| 340 | if ('style' in contextProps && contextProps.style && 'style' in props && props.style) { |
| 341 | if (typeof contextProps.style === 'function' || typeof props.style === 'function') { |
| 342 | // @ts-ignore |
| 343 | mergedProps.style = renderProps => { |
| 344 | let contextStyle = |
| 345 | typeof contextProps.style === 'function' |
| 346 | ? contextProps.style(renderProps) |
| 347 | : contextProps.style; |
| 348 | let defaultStyle = {...renderProps.defaultStyle, ...contextStyle}; |
| 349 | let style = |
| 350 | typeof props.style === 'function' |
| 351 | ? props.style({...renderProps, defaultStyle}) |
| 352 | : props.style; |
| 353 | return {...defaultStyle, ...style}; |
| 354 | }; |
| 355 | } else { |
| 356 | // @ts-ignore |
| 357 | mergedProps.style = {...contextProps.style, ...props.style}; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return [mergedProps, mergedRef]; |
| 362 | } |
| 363 | |
| 364 | export function useSlot( |
| 365 | initialState: boolean | (() => boolean) = true |
no test coverage detected