import React from 'react'; import type { ReactNode } from 'react'; import type { IconOrContent } from '../../util/utility-types'; import type { Status } from '../../util/variant-types'; /** * The roles a component fills with an icon it picks itself. * * These are not slots a consumer fills per instance. Each one has a single, well-defined * job, so the same role has to look the same everywhere it appears: every close button in * an app is the same glyph, whether it closes a `Modal`, an `InputChip`, or a * `PageNotification`. * * The four status names are the `Status` union, so a component holding a `Status` can * look its icon up directly. */ export type SemanticIconName = Status | 'back' | 'close' | 'collapse' | 'copy' | 'expand' | 'forward' | 'menu' | 'open-in-new'; /** * A full set of semantic icons. Each role takes an EDS icon name or a node, on the same * terms as any other content slot. * * A string here cannot be narrowed to `IconName` by the type system: `IconOrContent` unions * it with `ReactNode`, and even excluding `ReactNode`'s own `string` member leaves * `Iterable`, which a string satisfies structurally. So a name that is not in the * spritemap type-checks, and `Icon` warns and renders nothing when it reaches one. */ export type SemanticIconMap = Record; /** * The icons EDS draws each semantic role with when no provider supplies its own. * * Exported so a consumer can build a partial override on top of the set EDS ships, and * so they can point at a single role's default without hard-coding the glyph. Read it, * spread it, index it — but it is frozen, because it is also the context's default value: * assigning to it would change what every tree without an override renders, from anywhere * in an app, which is the opposite of the consistency the provider is for. Build a new * object and hand it to an `IconProvider` instead. */ export declare const defaultSemanticIcons: Readonly; export type IconProviderProps = { /** * The tree the icon set applies to. */ children?: ReactNode; /** * Semantic roles to draw with something other than the EDS default. Anything left out * keeps the icon it inherits, so overriding one role does not mean restating the rest. * * Each value takes an EDS icon name or a node, matching the content slots elsewhere in * the system. * * Every entry has to draw something. An icon name the spritemap does not have, or a value * that renders nothing — `null`, `false`, `undefined`, `[]`, `<>` — throws rather than * quietly falling back, because a role resolving to nothing leaves whatever draws it in a * state no component can make sense of, and inheriting instead would hide the mistake * behind an icon nobody chose. * * So to leave a role alone, leave it out. Build a conditional override by adding the key * only when it applies: * * ```tsx * }) }}> * ``` * * There is deliberately no way to turn a role off here. A role says which glyph draws it, * not whether the thing drawing it exists — and most of these sit in controls whose only * content is the icon, so an empty one is a button a person can still click and no longer * see. Whether such a control exists belongs to the component that owns it: * `Modal`'s `hideCloseButton`, a notification's `onDismiss`, `CodeBlock`'s `copyStyle`. * * @example * ```tsx * }}> * * * ``` */ icons?: Partial; }; /** * ## Usage * * Swaps the icons EDS uses for the roles it fills on its own behalf: the chevron on a * `Menu.Button`, the close button in a `Modal`, the status icon on a `ToastNotification`, * and so on. Wrap the app once and every component below it picks the new glyph up. * * This is how those icons are set. The components that draw them do not take a per-instance * override, because a role that renders one glyph in one place and a different one two * screens over stops reading as that role at all. * * One exception: `FieldNote.icon` still wins over the `warning` and `critical` defaults for * a single note. That slot predates these roles and stays a content slot, so a note can * carry the status treatment and its own content at once. It warns when used without a * status, since an icon on a note with nothing to report reads as a status the note does * not have. * * Nesting merges: an inner provider only has to name the roles it changes, and inherits * the rest from the provider around it. * * ### Don'ts * * * Don't give a role a glyph that reads as a different role (a checkmark for `close`). * * Don't define the map inline in render if the tree below it is large. A new object * every render re-renders every component reading from it; hoist it to a module * constant instead. */ export declare const IconProvider: { ({ children, icons }: IconProviderProps): React.JSX.Element; displayName: string; }; /** * Reads the icon in effect for one semantic role. * * For EDS components' own use. Consumers change what this returns with `IconProvider` * rather than calling it themselves, so it is not exported from the package root. * * Takes `undefined` for the components whose role depends on runtime state and is * sometimes no role at all, so they can resolve the icon in one unconditional call * instead of reading a role they will not render. * * Anything it returns draws something. A value that would not render cannot be in the map: * `IconProvider` throws for one, and the shipped defaults are all real icons. So the two * ways to get `undefined` back are both about the role asked for, not the value found — no * role was asked for, or the name is not a role at all, which untyped code can reach and * which is reported here as a usage error. * * @param name the semantic role being drawn, or `undefined` to draw nothing * @returns the icon name or node to hand to `IconSlot`, or `undefined` when `name` is * `undefined` or names no role */ export declare function useSemanticIcon(name: SemanticIconName | undefined): IconOrContent;