( context: Context<SlottedContextValue<T>>, slot?: string | null )
| 289 | } |
| 290 | |
| 291 | export function useSlottedContext<T>( |
| 292 | context: Context<SlottedContextValue<T>>, |
| 293 | slot?: string | null |
| 294 | ): T | null | undefined { |
| 295 | let ctx = useContext(context); |
| 296 | if (slot === null) { |
| 297 | // An explicit `null` slot means don't use context. |
| 298 | return null; |
| 299 | } |
| 300 | if (ctx && typeof ctx === 'object' && 'slots' in ctx && ctx.slots) { |
| 301 | let slotKey = slot || DEFAULT_SLOT; |
| 302 | if (!ctx.slots[slotKey]) { |
| 303 | let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map(p => `"${p}"`)); |
| 304 | let errorMessage = slot ? `Invalid slot "${slot}".` : 'A slot prop is required.'; |
| 305 | |
| 306 | throw new Error(`${errorMessage} Valid slot names are ${availableSlots}.`); |
| 307 | } |
| 308 | return ctx.slots[slotKey]; |
| 309 | } |
| 310 | // @ts-ignore |
| 311 | return ctx; |
| 312 | } |
| 313 | |
| 314 | export function useContextProps<T, U extends SlotProps, E extends Element>( |
| 315 | props: T & SlotProps, |
no test coverage detected