import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode } from "react";
import { createContext, useContext, useState } from "react";
import { cx } from "../../utils/cx.utils";
import { FormContext } from "../form/form.context";
import { Icon } from "../icons/icon";
import type { IconName } from "../icons/icons";
import "./chip.component.css";
interface ChipGroupContextValue {
isSelected: (value: string) => boolean;
toggle: (value: string) => void;
disabled: boolean;
}
const ChipGroupContext = createContext(null);
function normalizeValues(value: string | string[] | undefined): string[] {
if (value === undefined) return [];
return Array.isArray(value) ? value : [value];
}
/** Props accepted by {@link Chip}. */
export interface ChipProps
extends Omit, "value" | "onSelect"> {
/** Text shown inside the chip. */
children: ReactNode;
/** Name of an icon rendered on the left side of the chip. */
icon?: IconName;
/**
* Identifies this chip inside a {@link Chip.Group}. Required when nested in
* a group; ignored for standalone use.
*/
value?: string;
/** Controlled selected state for standalone use, outside a {@link Chip.Group}. */
selected?: boolean;
/** Initial selected state for uncontrolled standalone use. Defaults to `false`. */
defaultSelected?: boolean;
/**
* Called with the next selected state when clicked. Ignored inside a
* {@link Chip.Group}, which reports selection through its own `onChange`.
*/
onSelect?: (selected: boolean) => void;
}
/**
* Toggleable, pill-shaped filter button for e-ink displays. Renders as a
* native `