import React, { ComponentType } from 'react'; import { BoxContext } from '@bento/box'; /** * Interface representing the arguments required for replacing a component. * * @interface ReplaceArgs * @property {Props} props - The properties of the component. * @property {ComponentType} Component - The component which should be rendered. * @property {SlotContext} context - The current Slot context. * @property {string} name - The name of the component. * @private */ interface ReplaceArgs { props: Props; Component: ComponentType; context: BoxContext; name: string; } /** * Replaces a component in the context with the specified name and props. * * @param args.props - The properties to be passed to the component. * @param args.name - The name of the component to be replaced. * @param args.context - The context containing the components. * @returns An object containing the updated props, the component to be replaced, and the updated context. * @public */ declare function replace>({ props, name, context }: ReplaceArgs): any; /** * Interface representing a collection of slots. */ interface Slots { /** * A named part of a component that can be customized. This is implemented by the consuming component. * The exposed slot names of a component are available in the components documentation. */ slot?: string; /** * An object that contains the customizations for the slots. * The main way you interact with the slot system as a consumer. */ slots?: Record; } declare const library: Set; /** * Higher-order component that wraps a given component with slot functionality. * This allows components to be dynamically replaced or overridden based on the provided context and slots. * * @param name - The unique name of the component. This is used to identify the component for slot overrides. * @param Component - The component that should be rendered. * @param modifiers - The modifier functions that should be applied to the component. * @returns The wrapped component. * @public * * @throws {BentoError} If the component name has already been registered (in development mode). * @throws {BentoError} If any of the supplied modifiers are not functions. * * @example * ```tsx * const MyComponent = () =>
My Component
; * const SlottedMyComponent = withSlots('MyComponent', MyComponent); * ``` */ declare function withSlots(name: string, Component: React.ComponentType, modifiers?: (typeof replace)[]): React.MemoExoticComponent>; /** * Interface representing the arguments required to override a component. * * @private */ interface OverrideArgs { /** The properties of the component. */ props: Props; /** The component which should be rendered. */ Component: ComponentType; /** The current Slot context. */ context: BoxContext; /** The name of the component. */ name: string; } /** * Represents the result of an override operation. * * @private */ interface OverrideResult { /** The properties of the override result. */ props: { /** A string indicating the override data. */ 'data-override'?: string; }; } /** * Overrides the properties of a given context based on certain conditions. * * @param args.context - The context object. * @param args.props - The properties object. * @returns The result containing the updated properties or undefined if no overrides are applied. * @public */ declare function override>({ context, props }: OverrideArgs): OverrideResult | undefined; /** * Checks if children contain all required slot assignments, including namespaced paths. * * This utility iterates through React children to verify that all required * slot names are present. It supports both simple slot names ('trigger') and * namespaced paths ('submit.icon') for deeply nested slot validation. * * **Important:** Only components wrapped with `withSlots()` are validated. Raw HTML * elements with `slot` props are ignored, as they are not part of the Bento slot system. * * @param slotNames - Array of required slot names to check for (e.g., ['trigger', 'submit.icon']) * @param children - React children to search through * @returns true if all required slots are found, false otherwise. Returns true * for render prop functions since slots can't be validated until executed. * * @example * ```tsx * // Simple slot validation * function MyComponent({ children }) { * if (!contains(['trigger', 'content'], children)) { * throw new BentoError({ * name: 'my-component', * method: 'MyComponent', * message: 'Missing required slots: trigger and content' * }); * } * return
{children}
; * } * * // Namespaced slot validation * function Form({ children }) { * if (!contains(['submit.icon'], children)) { * throw new Error('Submit button must have an icon'); * } * return
{children}
; * } * ``` * * @public */ declare function contains(slotNames: string[], children: React.ReactNode): boolean; export { type Slots, contains, library, override, replace, withSlots };