import type { HTMLAttributes, InputHTMLAttributes, ReactNode } from "react"; import { createContext, useContext, useId, useState } from "react"; import { cx } from "../../utils/cx.utils"; import { FormContext } from "../form/form.context"; import { Icon } from "../icons/icon"; import { Label } from "../label/label.component"; import "./checkbox.component.css"; interface CheckboxGroupContextValue { isChecked: (value: string) => boolean; toggle: (value: string) => void; disabled: boolean; } const CheckboxGroupContext = createContext(null); /** Props accepted by {@link Checkbox.Group}. */ export interface CheckboxGroupProps extends Omit, "onChange"> { /** Label rendered above the group, via {@link Label.Form}. */ label: ReactNode; /** * Field name to bind to the enclosing `
`. When provided, the group * reads/writes its value (an array of the checked {@link Checkbox} * `value`s) through the form context and the `value`/`onChange` props are * ignored. */ name?: string; /** Currently checked values for standalone use, outside a ``. */ value?: string[]; /** Initial checked values for uncontrolled standalone use. */ defaultValue?: string[]; /** Called with the next array of checked values whenever it changes. Ignored when `name` is set. */ onChange?: (value: string[]) => void; /** Disables every {@link Checkbox} inside the group. Defaults to `false`. */ disabled?: boolean; /** {@link Checkbox} elements making up the group, each with its own `value`. */ children: ReactNode; } /** * Groups {@link Checkbox} items into a single multi-select field. Renders as * a `role="group"` labeled via {@link Label.Form} (associated through * `aria-labelledby`, since a `