Eine Zeile mit einer Auswahl aus wenigen Werten.
(props: {
kind: 'setting' | 'effect';
name: string;
label: string;
detail: string;
value: T;
/*
* Die Werte heissen `option` und nicht `value`, und das ist kein Geschmack:
* `value` gilt dem Chrome-Scan (tools/lib/chrome-scan.mjs) als
* beschriftende Eigenschaft, weil es an fast jeder anderen Stelle eine ist.
* Hier ist es ein Schaltwert wie `flat` oder `dim`, den niemand liest; die
* Beschriftung steht daneben und kommt aus dem Katalog.
*/
options: readonly { option: T; label: string }[];
onPick: (value: T) => void;
children: ReactNode;
})
| 186 | |
| 187 | /** Eine Zeile mit einer Auswahl aus wenigen Werten. */ |
| 188 | function Choice<T extends string | number | boolean>(props: { |
| 189 | kind: 'setting' | 'effect'; |
| 190 | name: string; |
| 191 | label: string; |
| 192 | detail: string; |
| 193 | value: T; |
| 194 | /* |
| 195 | * Die Werte heissen `option` und nicht `value`, und das ist kein Geschmack: |
| 196 | * `value` gilt dem Chrome-Scan (tools/lib/chrome-scan.mjs) als |
| 197 | * beschriftende Eigenschaft, weil es an fast jeder anderen Stelle eine ist. |
| 198 | * Hier ist es ein Schaltwert wie `flat` oder `dim`, den niemand liest; die |
| 199 | * Beschriftung steht daneben und kommt aus dem Katalog. |
| 200 | */ |
| 201 | options: readonly { option: T; label: string }[]; |
| 202 | onPick: (value: T) => void; |
| 203 | children: ReactNode; |
| 204 | }): JSX.Element { |
| 205 | return ( |
| 206 | <div |
| 207 | className="atlas-settings-choice" |
| 208 | data-testid={props.kind === 'effect' ? 'atlas-settings-effect' : 'atlas-settings-choice'} |
| 209 | data-setting={props.name} |
| 210 | data-effect={props.kind === 'effect' ? props.name : undefined} |
| 211 | data-value={String(props.value)} |
| 212 | > |
| 213 | <div className="atlas-settings-choice-head"> |
| 214 | <span className="atlas-settings-choice-label">{props.label}</span> |
| 215 | <span className="atlas-settings-choice-options" role="group" aria-label={props.label}> |
| 216 | {props.options.map((option) => ( |
| 217 | <button |
| 218 | key={String(option.option)} |
| 219 | type="button" |
| 220 | className="atlas-settings-option" |
| 221 | data-testid="atlas-settings-option" |
| 222 | data-option={String(option.option)} |
| 223 | data-active={props.value === option.option} |
| 224 | aria-pressed={props.value === option.option} |
| 225 | onClick={() => props.onPick(option.option)} |
| 226 | > |
| 227 | {option.label} |
| 228 | </button> |
| 229 | ))} |
| 230 | </span> |
| 231 | </div> |
| 232 | <p className="atlas-settings-choice-detail">{props.detail}</p> |
| 233 | {props.children} |
| 234 | </div> |
| 235 | ); |
| 236 | } |
| 237 | |
| 238 | /** Eine Zahl der Bildrate, wie sie auf dem Schirm steht. */ |
| 239 | function fps(value: number): string { |
nothing calls this directly
no outgoing calls
no test coverage detected