( context: Context<SlottedContextValue<T>>, slot?: string | null )
| 304 | } |
| 305 | |
| 306 | export function useSlottedContext<T>( |
| 307 | context: Context<SlottedContextValue<T>>, |
| 308 | slot?: string | null |
| 309 | ): T | null | undefined { |
| 310 | let ctx = useContext(context); |
| 311 | if (slot === null) { |
| 312 | // An explicit `null` slot means don't use context. |
| 313 | return null; |
| 314 | } |
| 315 | if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) { |
| 316 | let slotKey = slot || DEFAULT_SLOT; |
| 317 | if (!ctx.slots[slotKey]) { |
| 318 | let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`)); |
| 319 | let errorMessage = slot ? `Invalid slot "${slot}".` : 'A slot prop is required.'; |
| 320 | |
| 321 | throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`); |
| 322 | } |
| 323 | return ctx.slots[slotKey]; |
| 324 | } |
| 325 | // @ts-ignore |
| 326 | return ctx; |
| 327 | } |
| 328 | |
| 329 | export function useContextProps<T, U extends SlotProps, E extends Element>( |
| 330 | props: T & SlotProps, |
no test coverage detected