import type { HTMLAttributes } from "react"; import { cx } from "../../utils/cx.utils"; import { Button } from "../button/button.component"; import { Container } from "../container/container.component"; import { Icon } from "../icons/icon"; import type { IconName } from "../icons/icons"; import { Text } from "../text/text.component"; import { Title } from "../title/title.component"; import "./state.component.css"; /** Action button shown at the bottom of a state, given a label and a callback. */ export interface StateAction { /** Label shown on the action button. */ label: string; /** Called when the action button is clicked. */ onClick: () => void; } /** Props shared by {@link State.Empty} and {@link State.Error}. */ export interface StateVariantProps extends Omit, "title"> { /** Title shown below the icon. */ title: string; /** Optional subtitle shown below the title. */ subtitle?: string; /** Optional longer description shown below the subtitle. */ description?: string; /** Optional action button, given a label and a callback. */ action?: StateAction; /** Renders a border around the state. Defaults to `true`. */ withBorder?: boolean; } interface BaseStateProps extends StateVariantProps { icon: IconName; actionVariant: "filled" | "outlined"; } function BaseState({ className, icon, title, subtitle, description, action, actionVariant, withBorder = true, ...rest }: BaseStateProps) { const ActionButton = actionVariant === "outlined" ? Button.Outlined : Button; return (
); } /** * Full-width, full-height, centered empty state: a large search-ipad icon, * a required title, and optional subtitle, description, and action button * (rendered as {@link Button.Outlined}). * * @example * ```tsx * * ``` */ function Empty(props: StateVariantProps) { return ( ); } /** * Full-width, full-height, centered error state: a large bug icon, a * required title, and optional subtitle, description, and action button * (rendered as the filled {@link Button}). * * @example * ```tsx * * ``` */ function ErrorState(props: StateVariantProps) { return ( ); } /** * Namespace for the {@link Empty} and {@link ErrorState} state components — full * page/section placeholders shown when there is no content or a failure * occurred. Both render inside a full-width, full-height, centered * {@link Container} with a large icon, a required title, and optional * subtitle, description, and action button. * * @example * ```tsx * * * ``` */ export const State = { Empty, Error: ErrorState, };