UNPKG

use-styled

Version:

A powerful library for creating React/React Native components

46 lines 2.42 kB
/** * A unique symbol used to mark components that have been processed by `useSlot`. * This helps in determining if a component needs to be cloned or can be mutated directly. */ declare const Decorated: unique symbol; /** * Interface for properties that can be attached to a component via `useSlot`. * It includes the internal `Decorated` symbol and allows for arbitrary string-keyed properties. */ interface DecoratedComponentProps { /** * A flag indicating that the component has been decorated by `useSlot`. */ [Decorated]?: boolean; /** * Allows attaching any other static properties (slots) to the component. */ [key: string]: any; } /** * A utility type that combines two types, A and B. * In the context of `useSlot`, it represents the original component type `A` augmented with static properties from `B`. * @template A - The base type (typically a React component function). * @template B - The type of the static properties to be added (an object рекорд). */ type Combined<A, B> = A & B; /** * A React hook that allows attaching static components (slots) as properties to a given component. * * This enables a compositional pattern where sub-components can be accessed as properties of a main component, * for example: `MainComponent.SlotComponent`. * * If the provided `component` has already been processed by `useSlot` (identified by the `Decorated` symbol), * it will be cloned to prevent unintended side effects on the original component. Otherwise, the original component * is used and modified directly. * * @template A - The type of the base component. Must be a function and extend `DecoratedComponentProps` to allow property assignment. * @template B - The type of the object containing the static slot components to attach. * @param {A} component - The base React component (e.g., a function component or a `React.forwardRef` component) to which slots will be attached. * @param {B} staticProps - An object where keys are slot names and values are the slot components themselves. * @returns {Combined<A, B>} The original component `A` augmented with the static properties from `B`. */ export declare const useSlot: <A extends Function & DecoratedComponentProps, // A is now a function with DecoratedComponentProps B extends object>(component: A, staticProps: B) => Combined<A, B>; export {}; //# sourceMappingURL=useSlot.d.ts.map