mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Hiding prefixed unless the draft mode was copy made the option hard to discover, and a user who left copy mode with prefixed drafted kept a naming the server would reject on save. Following the approved design, the naming control now always lists flat, standard and prefixed; prefixed is a disabled segment with a "Needs copy mode" tooltip and an info line saying why. Leaving copy mode resets a drafted prefixed back to the saved naming (or flat when prefixed was saved), and a pending tag marks an unsaved naming change. SegmentedControl gains a per-option disabled flag. Its title no longer replaces a text label's accessible name, so the disabled segment is still announced as "prefixed"; icon-only options keep title as name.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import type { ReactNode } from 'react';
|
|
|
|
interface Option<T extends string> {
|
|
value: T;
|
|
label: ReactNode;
|
|
count?: number;
|
|
/** Tooltip; also the accessible name of an icon-only option. */
|
|
title?: string;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
interface SegmentedControlProps<T extends string> {
|
|
value: T;
|
|
onChange: (value: T) => void;
|
|
options: Option<T>[];
|
|
size?: 'sm' | 'md';
|
|
/** @deprecated Every segmented control now uses the connected look. */
|
|
connected?: boolean;
|
|
/** Custom active text colour per option (for severity tabs, etc.) */
|
|
colorFn?: (value: T) => string | undefined;
|
|
className?: string;
|
|
}
|
|
|
|
export default function SegmentedControl<T extends string>({ value, onChange, options, colorFn, className = '' }: SegmentedControlProps<T>) {
|
|
return (
|
|
<div className={`ss-seg flex-wrap ${className}`}>
|
|
{options.map((opt) => {
|
|
const on = value === opt.value;
|
|
const color = on ? colorFn?.(opt.value) : undefined;
|
|
return (
|
|
<button
|
|
key={opt.value}
|
|
type="button"
|
|
onClick={() => onChange(opt.value)}
|
|
disabled={opt.disabled}
|
|
className={`whitespace-nowrap ${on ? 'on' : ''}`}
|
|
style={color ? { color } : undefined}
|
|
aria-pressed={on}
|
|
title={opt.title}
|
|
aria-label={typeof opt.label === 'string' ? undefined : opt.title}
|
|
>
|
|
{opt.label}
|
|
{opt.count != null && <span className="ss-cnt">{opt.count}</span>}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|