chore: consolidate platform split checks
Some checks failed
Dependency Audit / dependency-audit (push) Has been cancelled
Module Matrix / module-matrix (push) Has been cancelled

This commit is contained in:
2026-07-10 12:51:19 +02:00
parent 150b720f12
commit 635d25c74c
216 changed files with 23336 additions and 4077 deletions

View File

@@ -0,0 +1,76 @@
export type SegmentedControlSize = "content" | "equal";
export type SegmentedControlWidth = "inline" | "fill";
export type SegmentedControlOption<TValue extends string = string> = {
id: TValue;
label: React.ReactNode;
disabled?: boolean;
title?: string;
ariaLabel?: string;
};
export type SegmentedControlProps<TValue extends string = string> = {
options: Array<SegmentedControlOption<TValue>>;
value: TValue;
onChange: (value: TValue) => void;
ariaLabel?: string;
ariaLabelledBy?: string;
className?: string;
optionClassName?: string;
disabled?: boolean;
role?: "group" | "tablist";
size?: SegmentedControlSize;
width?: SegmentedControlWidth;
};
export default function SegmentedControl<TValue extends string = string>({
options,
value,
onChange,
ariaLabel,
ariaLabelledBy,
className = "",
optionClassName = "",
disabled = false,
role = "tablist",
size = "content",
width = "inline"
}: SegmentedControlProps<TValue>) {
const rootClassName = [
"segmented-control",
`segmented-control-size-${size}`,
`segmented-control-width-${width}`,
className
].filter(Boolean).join(" ");
const optionRole = role === "tablist" ? "tab" : undefined;
return (
<div className={rootClassName} role={role} aria-label={ariaLabel} aria-labelledby={ariaLabelledBy}>
{options.map((option) => {
const selected = option.id === value;
const buttonClassName = [
"segmented-control-option",
selected ? "is-active" : "",
optionClassName
].filter(Boolean).join(" ");
return (
<button
key={option.id}
type="button"
role={optionRole}
aria-selected={role === "tablist" ? selected : undefined}
aria-pressed={role === "group" ? selected : undefined}
aria-label={option.ariaLabel}
title={option.title}
className={buttonClassName}
disabled={disabled || option.disabled}
onClick={() => onChange(option.id)}
>
{option.label}
</button>
);
})}
</div>
);
}