UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

38 lines (37 loc) 1.51 kB
/** * Give warnings based on component composition (which slot/parent a child is rendered in). * * Used when child components need to know which slot/parent they are rendered in * (e.g. `FormSummary.Header` vs `FormSummary.Footer`) and should warn or error in development * if placed in a discouraged or forbidden slot. * * Usage: * - Wrap slot components with <CompositionWarning.Root name="FormSummary.Header">...</CompositionWarning.Root> * - In child: `<CompositionWarning.Forbidden name="FormSummary.Header" />` to forbid slot. * * This is guidance only: warnings are logged to the console in development, never enforced at runtime. */ import React from "react"; type CompositionName = string; type CompositionWarningContextType = { /** * Name of the slot component we want to check. */ name: CompositionName; }; declare const CompositionWarning: React.ForwardRefExoticComponent<CompositionWarningContextType & { children: React.ReactNode; } & React.RefAttributes<unknown>>; type CompositionWarningForbiddenProps = { children?: React.ReactElement; /** * Name of the parent slot component where the child is not allowed. */ name: CompositionName; /** * Warning message to display if the child is found. */ message: string; }; declare function CompositionWarningForbidden({ children, name, message, }: CompositionWarningForbiddenProps): React.JSX.Element; export { CompositionWarningForbidden as Forbidden, CompositionWarning as Root };