@linxin666/dsh-liangshen 0.4.10 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +333 -143
- package/lib/client.js.map +1 -1
- package/lib/types/client/PluginSettingsCard.d.ts +75 -24
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/locales.d.ts +0 -4
- package/lib/types/client/plugin-card-seat.d.ts +2 -0
- package/lib/types/client/settings-form.d.ts +73 -51
- package/package.json +1 -1
- package/presets/liangshen/agent.cordis.yml +12 -6
- package/presets/liangshen/paging.mjs +14 -0
- package/presets/liangshen/tool-activate.mjs +41 -15
- package/presets/liangshen/tool-catalog.mjs +56 -0
- package/src/client/LiangShenSettingsCard.tsx +1 -0
- package/src/client/PluginSettingsCard.tsx +252 -98
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/locales.ts +36 -44
- package/src/client/plugin-card-seat.ts +6 -0
- package/src/client/settings-card.module.css +341 -94
- package/src/client/settings-form.ts +102 -60
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
// Generated by scripts/sync-shared.mjs from shared/client/settings/PluginSettingsCard.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
2
|
/**
|
|
3
3
|
* Family-shared chrome for plugin settings cards: a disclosure header naming
|
|
4
|
-
* the plugin and what its settings govern, the controls inside, and the
|
|
5
|
-
* that
|
|
4
|
+
* the plugin and what its settings govern, the controls inside, and the line
|
|
5
|
+
* that reports a refused write. A pick is written the moment it is made and a
|
|
6
|
+
* typed value after a pause, so the card has no save button and nothing waits
|
|
7
|
+
* on the reader. Renders nothing while the namespace is unavailable — a
|
|
6
8
|
* deployment that does not compose the owning plugin should show no trace of
|
|
7
9
|
* it. Inlined into each consumer's client bundle; mirrors the official
|
|
8
10
|
* ui-plugin-config PluginCard in a self-contained slice.
|
|
11
|
+
*
|
|
12
|
+
* Every field inside the body is one settings row: the label and its hint on
|
|
13
|
+
* the left, the control on the right, a hairline between two rows; a narrow
|
|
14
|
+
* card stacks the control under the text (settings-card.module.css).
|
|
9
15
|
*/
|
|
10
16
|
|
|
11
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
|
|
17
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
|
|
12
18
|
import type { CardShell } from './settings-form.ts'
|
|
19
|
+
import { RangeBubble } from './RangeBubble.tsx'
|
|
20
|
+
import { SegmentGroup } from './SegmentGroup.tsx'
|
|
13
21
|
import css from './settings-card.module.css'
|
|
14
22
|
|
|
15
23
|
/** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
|
|
@@ -17,14 +25,17 @@ export const CARD_COPY_KEYS = [
|
|
|
17
25
|
'settings.collapse',
|
|
18
26
|
'settings.expand',
|
|
19
27
|
'settings.notExposed',
|
|
20
|
-
'settings.unsaved',
|
|
21
28
|
'settings.readOnly',
|
|
22
29
|
'settings.saveFailed',
|
|
23
|
-
'settings.discard',
|
|
24
|
-
'settings.save',
|
|
25
|
-
'settings.saving',
|
|
26
30
|
] as const
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* What a text field inside a card reaches without its plugin wiring it: write
|
|
34
|
+
* the pending draft now (Enter, leaving the field) or put it back (Escape).
|
|
35
|
+
* Picks need neither; they are written the moment they are made.
|
|
36
|
+
*/
|
|
37
|
+
const CardApply = createContext<{ commit(): void, revert(): void } | null>(null)
|
|
38
|
+
|
|
28
39
|
/** Copy key the card chrome itself reads. */
|
|
29
40
|
export type CardCopyKey = (typeof CARD_COPY_KEYS)[number]
|
|
30
41
|
|
|
@@ -56,11 +67,11 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
56
67
|
* seat.
|
|
57
68
|
*/
|
|
58
69
|
icon?: ReactNode
|
|
59
|
-
/** The card's form state: availability, writability, and
|
|
70
|
+
/** The card's form state: availability, writability, and how the last write went. */
|
|
60
71
|
state: CardShell
|
|
61
|
-
/** Write every
|
|
72
|
+
/** Write every pending draft now: a text field's Enter or blur. */
|
|
62
73
|
onSave: () => void
|
|
63
|
-
/** Drop every
|
|
74
|
+
/** Drop every pending draft: a text field's Escape. */
|
|
64
75
|
onDiscard: () => void
|
|
65
76
|
/**
|
|
66
77
|
* Id applied to the card's title element, so a header control (an immediate
|
|
@@ -87,21 +98,25 @@ export interface PluginSettingsCardProps<TKey extends string = string> {
|
|
|
87
98
|
*/
|
|
88
99
|
alwaysOpen?: boolean
|
|
89
100
|
/**
|
|
90
|
-
* Hide the
|
|
91
|
-
*
|
|
92
|
-
*
|
|
101
|
+
* Hide the line under the body that reports a refused write: a card whose
|
|
102
|
+
* body applies its own changes (an embedded external settings section)
|
|
103
|
+
* reports its own failures.
|
|
93
104
|
*/
|
|
94
105
|
hideFooter?: boolean
|
|
95
106
|
/**
|
|
96
|
-
* Optional control rendered at the header's trailing edge, before the
|
|
97
|
-
*
|
|
98
|
-
* applies outside the
|
|
107
|
+
* Optional control rendered at the header's trailing edge, before the
|
|
108
|
+
* chevron. A card whose setting is one immediate flip (it
|
|
109
|
+
* applies outside the card's form) puts its ToggleSwitch here, so the control
|
|
99
110
|
* is reachable without opening the card and matches a plugin card's shape.
|
|
100
111
|
*/
|
|
101
112
|
headerAction?: ReactNode
|
|
102
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Render children even when the settings namespace is not exposed by the
|
|
115
|
+
* host. The 'not exposed' notice still explains the card above them; a card
|
|
116
|
+
* that wants the rows alone hides it through `hideNotExposedNotice`.
|
|
117
|
+
*/
|
|
103
118
|
renderChildrenWhenNotExposed?: boolean
|
|
104
|
-
/** Hide the 'not exposed'
|
|
119
|
+
/** Hide the 'not exposed' notice, whichever branch renders the card body. */
|
|
105
120
|
hideNotExposedNotice?: boolean
|
|
106
121
|
/**
|
|
107
122
|
* Compact chrome for a topic card rendered inside another card's body: a
|
|
@@ -162,7 +177,6 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
162
177
|
const title = props.t(props.titleKey)
|
|
163
178
|
const description = props.t(props.descriptionKey)
|
|
164
179
|
const descriptionTitle = props.descriptionTitleKey === undefined ? description : props.t(props.descriptionTitleKey)
|
|
165
|
-
const blocked = !state.dirty || state.invalid || state.saving
|
|
166
180
|
const baseClass = expanded ? `${css.cardOpen} ${css.card}` : css.card
|
|
167
181
|
const cardClass = props.density === 'nested' ? `${baseClass} ${css.cardNested}` : baseClass
|
|
168
182
|
/** The body region both legs share; a hidden phase renders nothing at all. */
|
|
@@ -184,7 +198,6 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
184
198
|
<span className={css.description} title={descriptionTitle}>{props.descriptionNode ?? description}</span>
|
|
185
199
|
</span>
|
|
186
200
|
{props.headerAction !== undefined ? <span className={css.headerAction}>{props.headerAction}</span> : null}
|
|
187
|
-
{state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
|
|
188
201
|
</div>
|
|
189
202
|
)
|
|
190
203
|
: (
|
|
@@ -201,7 +214,6 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
201
214
|
<span className={css.description} title={descriptionTitle}>{props.descriptionNode ?? description}</span>
|
|
202
215
|
</span>
|
|
203
216
|
{props.headerAction !== undefined ? <span className={css.headerAction}>{props.headerAction}</span> : null}
|
|
204
|
-
{state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
|
|
205
217
|
<svg
|
|
206
218
|
width="14"
|
|
207
219
|
height="14"
|
|
@@ -220,13 +232,16 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
220
232
|
// The namespace exists but the Host does not serve it to this client (the
|
|
221
233
|
// official settings allowlist omits third-party namespaces): show a card
|
|
222
234
|
// that explains the gap instead of vanishing, so a missing card never
|
|
223
|
-
// reads as a missing plugin.
|
|
235
|
+
// reads as a missing plugin. A card that keeps its rows anyway keeps the
|
|
236
|
+
// same explanation above them, unless it hides the notice outright.
|
|
237
|
+
const notExposedNotice = state.exposed || props.hideNotExposedNotice === true
|
|
238
|
+
? null
|
|
239
|
+
: <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p>
|
|
224
240
|
if (!state.exposed && props.renderChildrenWhenNotExposed !== true) {
|
|
225
|
-
const showNotice = props.hideNotExposedNotice !== true
|
|
226
241
|
return (
|
|
227
242
|
<li className={cardClass}>
|
|
228
243
|
{header}
|
|
229
|
-
{bodyRegion(
|
|
244
|
+
{bodyRegion(notExposedNotice)}
|
|
230
245
|
</li>
|
|
231
246
|
)
|
|
232
247
|
}
|
|
@@ -239,37 +254,18 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
239
254
|
{bodyVisible
|
|
240
255
|
? bodyRegion(
|
|
241
256
|
<>
|
|
257
|
+
{notExposedNotice}
|
|
242
258
|
{!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
|
|
243
|
-
{props.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
)
|
|
254
|
-
: null}
|
|
255
|
-
<button
|
|
256
|
-
type="button"
|
|
257
|
-
className={css.discard}
|
|
258
|
-
disabled={!state.dirty || state.saving}
|
|
259
|
-
onClick={props.onDiscard}
|
|
260
|
-
>
|
|
261
|
-
{props.t('settings.discard')}
|
|
262
|
-
</button>
|
|
263
|
-
<button
|
|
264
|
-
type="button"
|
|
265
|
-
className={css.save}
|
|
266
|
-
disabled={blocked}
|
|
267
|
-
onClick={props.onSave}
|
|
268
|
-
>
|
|
269
|
-
{props.t(!state.saving ? 'settings.save' : 'settings.saving')}
|
|
270
|
-
</button>
|
|
271
|
-
</div>
|
|
272
|
-
)}
|
|
259
|
+
<CardApply.Provider value={{ commit: props.onSave, revert: props.onDiscard }}>
|
|
260
|
+
{props.children}
|
|
261
|
+
</CardApply.Provider>
|
|
262
|
+
{props.hideFooter !== true && state.failed
|
|
263
|
+
? (
|
|
264
|
+
<p className={css.failed} role="status">
|
|
265
|
+
{props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}
|
|
266
|
+
</p>
|
|
267
|
+
)
|
|
268
|
+
: null}
|
|
273
269
|
</>,
|
|
274
270
|
)
|
|
275
271
|
: null}
|
|
@@ -293,7 +289,7 @@ export interface FieldProps {
|
|
|
293
289
|
hintTitle?: string
|
|
294
290
|
/** Draft text this control renders. */
|
|
295
291
|
text: string
|
|
296
|
-
/** True when
|
|
292
|
+
/** True when the field holds a user-layer entry over the inherited value. */
|
|
297
293
|
overridden: boolean
|
|
298
294
|
/** True when the draft is not a value this field accepts. */
|
|
299
295
|
invalid: boolean
|
|
@@ -305,19 +301,65 @@ export interface FieldProps {
|
|
|
305
301
|
invalidLabel: string
|
|
306
302
|
/** Disables every control (read-only document, or an unavailable namespace). */
|
|
307
303
|
disabled: boolean
|
|
308
|
-
/**
|
|
304
|
+
/** Take new draft text; the card writes it as the field's entry rule says. */
|
|
309
305
|
onEdit: (text: string) => void
|
|
310
|
-
/**
|
|
306
|
+
/** Clear the field at once so it re-inherits the composition layer. */
|
|
311
307
|
onReset: () => void
|
|
312
308
|
}
|
|
313
309
|
|
|
314
|
-
/**
|
|
310
|
+
/**
|
|
311
|
+
* A typed value field. Its draft is written after a pause in typing, at once on
|
|
312
|
+
* Enter or when focus leaves, and Escape puts the stored value back. `numeric`
|
|
313
|
+
* only hints the keypad: which drafts a field accepts is decided by its spec.
|
|
314
|
+
* A field given a `range` also offers the coarse slider bubble: dragging fills
|
|
315
|
+
* the draft live and releasing writes it.
|
|
316
|
+
*/
|
|
315
317
|
export function ValueField(props: FieldProps & {
|
|
316
318
|
/** Hints a numeric keypad without narrowing what the control accepts. */
|
|
317
319
|
numeric?: boolean
|
|
318
320
|
/** Placeholder shown while the draft is empty. */
|
|
319
321
|
placeholder?: string
|
|
322
|
+
/** Bounds of a numeric field, for the coarse slider; the spec still judges every draft. */
|
|
323
|
+
range?: { min: number, max: number, step: number }
|
|
320
324
|
}) {
|
|
325
|
+
const apply = useContext(CardApply)
|
|
326
|
+
// Enter and Escape settle the draft themselves and then leave the field, so
|
|
327
|
+
// the blur they cause is that same settlement reaching the field's edge, not
|
|
328
|
+
// a second write. Without this an Escape reported a discard and then a save,
|
|
329
|
+
// which reads to a consumer as a write still waiting to happen.
|
|
330
|
+
const settledByKey = useRef(false)
|
|
331
|
+
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
332
|
+
if (apply === null || (event.key !== 'Enter' && event.key !== 'Escape')) return
|
|
333
|
+
event.preventDefault()
|
|
334
|
+
settledByKey.current = true
|
|
335
|
+
if (event.key === 'Enter') apply.commit()
|
|
336
|
+
else apply.revert()
|
|
337
|
+
event.currentTarget.blur()
|
|
338
|
+
}
|
|
339
|
+
const input = (
|
|
340
|
+
<input
|
|
341
|
+
id={props.id}
|
|
342
|
+
className={props.invalid ? css.inputInvalid : css.input}
|
|
343
|
+
type="text"
|
|
344
|
+
{...props.numeric === true ? { inputMode: 'numeric' as const } : {}}
|
|
345
|
+
{...props.invalid ? { 'aria-invalid': true } : {}}
|
|
346
|
+
value={props.text}
|
|
347
|
+
placeholder={props.placeholder ?? ''}
|
|
348
|
+
disabled={props.disabled}
|
|
349
|
+
onChange={(event) => { props.onEdit(event.target.value) }}
|
|
350
|
+
onKeyDown={onKeyDown}
|
|
351
|
+
onFocus={() => { settledByKey.current = false }}
|
|
352
|
+
onBlur={() => {
|
|
353
|
+
if (settledByKey.current) {
|
|
354
|
+
settledByKey.current = false
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
apply?.commit()
|
|
358
|
+
}}
|
|
359
|
+
/>
|
|
360
|
+
)
|
|
361
|
+
const { range } = props
|
|
362
|
+
const typed = Number(props.text)
|
|
321
363
|
return (
|
|
322
364
|
<div className={css.field}>
|
|
323
365
|
<div className={css.head}>
|
|
@@ -338,17 +380,25 @@ export function ValueField(props: FieldProps & {
|
|
|
338
380
|
)
|
|
339
381
|
: null}
|
|
340
382
|
</div>
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
383
|
+
{range === undefined
|
|
384
|
+
? input
|
|
385
|
+
: (
|
|
386
|
+
<RangeBubble
|
|
387
|
+
min={range.min}
|
|
388
|
+
max={range.max}
|
|
389
|
+
step={range.step}
|
|
390
|
+
value={props.text.trim() === '' || Number.isNaN(typed) ? range.min : typed}
|
|
391
|
+
label={`${props.label} ${range.min}–${range.max}`}
|
|
392
|
+
disabled={props.disabled}
|
|
393
|
+
onInput={(value) => { props.onEdit(String(value)) }}
|
|
394
|
+
onCommit={(value) => {
|
|
395
|
+
props.onEdit(String(value))
|
|
396
|
+
apply?.commit()
|
|
397
|
+
}}
|
|
398
|
+
>
|
|
399
|
+
{input}
|
|
400
|
+
</RangeBubble>
|
|
401
|
+
)}
|
|
352
402
|
<p className={props.invalid ? css.invalid : css.hint} title={props.hintTitle}>
|
|
353
403
|
{props.invalid ? props.invalidLabel : props.hint}
|
|
354
404
|
</p>
|
|
@@ -376,8 +426,8 @@ const SELECT_CLOSE_MS = 100
|
|
|
376
426
|
* renders the legacy native `<select>` untouched, so element-level skin
|
|
377
427
|
* selectors keep working; under the default appearance it renders a
|
|
378
428
|
* self-drawn `role="listbox"` popup whose open/close is transition-animated.
|
|
379
|
-
*
|
|
380
|
-
*
|
|
429
|
+
* Cards reach it through BooleanField/ChoiceField; editors outside a card
|
|
430
|
+
* (the side-card prefs) bind it directly through onEdit.
|
|
381
431
|
* 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
|
|
382
432
|
*/
|
|
383
433
|
export function SelectField(props: {
|
|
@@ -560,7 +610,56 @@ export function SelectField(props: {
|
|
|
560
610
|
)
|
|
561
611
|
}
|
|
562
612
|
|
|
563
|
-
/**
|
|
613
|
+
/**
|
|
614
|
+
* A visible segmented group for a small set of mutually exclusive values.
|
|
615
|
+
* Every option stays on screen, so inherit/on/off and short enum fields take
|
|
616
|
+
* one click without opening a popup. The pressed option carries the group's
|
|
617
|
+
* sliding highlight and `aria-pressed`; the group takes the field label as its
|
|
618
|
+
* accessible name.
|
|
619
|
+
*/
|
|
620
|
+
export function SegmentField(props: {
|
|
621
|
+
id: string
|
|
622
|
+
label: string
|
|
623
|
+
options: ReadonlyArray<SelectOption>
|
|
624
|
+
value: string
|
|
625
|
+
disabled: boolean
|
|
626
|
+
invalid: boolean
|
|
627
|
+
onEdit: (text: string) => void
|
|
628
|
+
}) {
|
|
629
|
+
return (
|
|
630
|
+
<SegmentGroup
|
|
631
|
+
id={props.id}
|
|
632
|
+
role="group"
|
|
633
|
+
aria-label={props.label}
|
|
634
|
+
aria-invalid={props.invalid || undefined}
|
|
635
|
+
>
|
|
636
|
+
{props.options.map((option, index) => {
|
|
637
|
+
const active = option.value === props.value
|
|
638
|
+
return (
|
|
639
|
+
<button
|
|
640
|
+
key={option.value}
|
|
641
|
+
type="button"
|
|
642
|
+
className={css.segment}
|
|
643
|
+
aria-pressed={active}
|
|
644
|
+
disabled={props.disabled}
|
|
645
|
+
data-active={active ? '' : undefined}
|
|
646
|
+
data-segment-index={index}
|
|
647
|
+
onClick={() => {
|
|
648
|
+
if (!active) props.onEdit(option.value)
|
|
649
|
+
}}
|
|
650
|
+
>
|
|
651
|
+
{option.label}
|
|
652
|
+
</button>
|
|
653
|
+
)
|
|
654
|
+
})}
|
|
655
|
+
</SegmentGroup>
|
|
656
|
+
)
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** How a small single-choice field presents its options. */
|
|
660
|
+
export type FieldPresentation = 'select' | 'segment'
|
|
661
|
+
|
|
662
|
+
/** A boolean field: 继承 / 开 / 关. */
|
|
564
663
|
export function BooleanField(props: FieldProps & {
|
|
565
664
|
/** Copy for the inherit option. */
|
|
566
665
|
inheritLabel: string
|
|
@@ -568,11 +667,16 @@ export function BooleanField(props: FieldProps & {
|
|
|
568
667
|
onLabel: string
|
|
569
668
|
/** Copy for the off option. */
|
|
570
669
|
offLabel: string
|
|
670
|
+
/** Defaults to the visible segments: the three answers always fit on one row. */
|
|
671
|
+
presentation?: FieldPresentation
|
|
571
672
|
}) {
|
|
673
|
+
const segmented = props.presentation !== 'select'
|
|
572
674
|
return (
|
|
573
675
|
<div className={css.field}>
|
|
574
676
|
<div className={css.head}>
|
|
575
|
-
|
|
677
|
+
{segmented
|
|
678
|
+
? <span className={css.label}>{props.label}</span>
|
|
679
|
+
: <label className={css.label} htmlFor={props.id}>{props.label}</label>}
|
|
576
680
|
{props.overridden
|
|
577
681
|
? (
|
|
578
682
|
<span className={css.badges}>
|
|
@@ -589,34 +693,61 @@ export function BooleanField(props: FieldProps & {
|
|
|
589
693
|
)
|
|
590
694
|
: null}
|
|
591
695
|
</div>
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
696
|
+
{segmented
|
|
697
|
+
? (
|
|
698
|
+
<SegmentField
|
|
699
|
+
id={props.id}
|
|
700
|
+
label={props.label}
|
|
701
|
+
options={[
|
|
702
|
+
{ value: '', label: props.inheritLabel },
|
|
703
|
+
{ value: 'true', label: props.onLabel },
|
|
704
|
+
{ value: 'false', label: props.offLabel },
|
|
705
|
+
]}
|
|
706
|
+
value={props.text}
|
|
707
|
+
disabled={props.disabled}
|
|
708
|
+
invalid={props.invalid}
|
|
709
|
+
onEdit={props.onEdit}
|
|
710
|
+
/>
|
|
711
|
+
)
|
|
712
|
+
: (
|
|
713
|
+
<SelectField
|
|
714
|
+
id={props.id}
|
|
715
|
+
options={[
|
|
716
|
+
{ value: '', label: props.inheritLabel },
|
|
717
|
+
{ value: 'true', label: props.onLabel },
|
|
718
|
+
{ value: 'false', label: props.offLabel },
|
|
719
|
+
]}
|
|
720
|
+
value={props.text}
|
|
721
|
+
disabled={props.disabled}
|
|
722
|
+
invalid={props.invalid}
|
|
723
|
+
onEdit={props.onEdit}
|
|
724
|
+
/>
|
|
725
|
+
)}
|
|
604
726
|
<p className={css.hint} title={props.hintTitle}>{props.hint}</p>
|
|
605
727
|
</div>
|
|
606
728
|
)
|
|
607
729
|
}
|
|
608
730
|
|
|
609
|
-
/**
|
|
731
|
+
/** An enumerated field, selecting or segmenting its small choice set. */
|
|
610
732
|
export function ChoiceField(props: FieldProps & {
|
|
611
733
|
/** Copy for the inherit option (draft text is the empty string). */
|
|
612
734
|
inheritLabel: string
|
|
613
735
|
/** Choices rendered in order; `value` is the draft/stored text. */
|
|
614
736
|
choices: ReadonlyArray<{ value: string; label: string }>
|
|
737
|
+
/**
|
|
738
|
+
* Visible segmented options for a short fixed set; defaults to the compact
|
|
739
|
+
* select, which also suits a list whose length follows the deployment.
|
|
740
|
+
*/
|
|
741
|
+
presentation?: FieldPresentation
|
|
615
742
|
}) {
|
|
743
|
+
const segmented = props.presentation === 'segment'
|
|
744
|
+
const options = [{ value: '', label: props.inheritLabel }, ...props.choices]
|
|
616
745
|
return (
|
|
617
746
|
<div className={css.field}>
|
|
618
747
|
<div className={css.head}>
|
|
619
|
-
|
|
748
|
+
{segmented
|
|
749
|
+
? <span className={css.label}>{props.label}</span>
|
|
750
|
+
: <label className={css.label} htmlFor={props.id}>{props.label}</label>}
|
|
620
751
|
{props.overridden
|
|
621
752
|
? (
|
|
622
753
|
<span className={css.badges}>
|
|
@@ -633,14 +764,28 @@ export function ChoiceField(props: FieldProps & {
|
|
|
633
764
|
)
|
|
634
765
|
: null}
|
|
635
766
|
</div>
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
767
|
+
{segmented
|
|
768
|
+
? (
|
|
769
|
+
<SegmentField
|
|
770
|
+
id={props.id}
|
|
771
|
+
label={props.label}
|
|
772
|
+
options={options}
|
|
773
|
+
value={props.text}
|
|
774
|
+
disabled={props.disabled}
|
|
775
|
+
invalid={props.invalid}
|
|
776
|
+
onEdit={props.onEdit}
|
|
777
|
+
/>
|
|
778
|
+
)
|
|
779
|
+
: (
|
|
780
|
+
<SelectField
|
|
781
|
+
id={props.id}
|
|
782
|
+
options={options}
|
|
783
|
+
value={props.text}
|
|
784
|
+
disabled={props.disabled}
|
|
785
|
+
invalid={props.invalid}
|
|
786
|
+
onEdit={props.onEdit}
|
|
787
|
+
/>
|
|
788
|
+
)}
|
|
644
789
|
<p className={props.invalid ? css.invalid : css.hint} title={props.hintTitle}>
|
|
645
790
|
{props.invalid ? props.invalidLabel : props.hint}
|
|
646
791
|
</p>
|
|
@@ -649,11 +794,15 @@ export function ChoiceField(props: FieldProps & {
|
|
|
649
794
|
}
|
|
650
795
|
|
|
651
796
|
/**
|
|
652
|
-
*
|
|
653
|
-
* applies on flip
|
|
797
|
+
* A boolean toggle drawn as a switch track, for a setting that is only on or
|
|
798
|
+
* off and applies on flip. It is a real button with
|
|
654
799
|
* `role="switch"` and `aria-checked`, so keyboard and assistive activation
|
|
655
800
|
* arrive as a click and the state is announced instead of inferred from a
|
|
656
801
|
* checkbox tick.
|
|
802
|
+
*
|
|
803
|
+
* The thumb bounces across only once the reader has pressed this switch: the
|
|
804
|
+
* press writes the mark that arms the bounce, so a page opening, a TAB
|
|
805
|
+
* switching back or a value arriving from elsewhere draws every thumb at rest.
|
|
657
806
|
*/
|
|
658
807
|
export function ToggleSwitch(props: {
|
|
659
808
|
/** Id of the element naming the switch (the card's title). */
|
|
@@ -667,6 +816,7 @@ export function ToggleSwitch(props: {
|
|
|
667
816
|
/** Called with the requested next state. */
|
|
668
817
|
onChange: (next: boolean) => void
|
|
669
818
|
}) {
|
|
819
|
+
const [moved, setMoved] = useState(false)
|
|
670
820
|
return (
|
|
671
821
|
<button
|
|
672
822
|
type="button"
|
|
@@ -676,7 +826,11 @@ export function ToggleSwitch(props: {
|
|
|
676
826
|
aria-labelledby={props.labelledBy}
|
|
677
827
|
aria-label={props.labelledBy === undefined ? props.ariaLabel : undefined}
|
|
678
828
|
disabled={props.disabled}
|
|
679
|
-
|
|
829
|
+
data-moved={moved ? '' : undefined}
|
|
830
|
+
onClick={() => {
|
|
831
|
+
setMoved(true)
|
|
832
|
+
props.onChange(!props.checked)
|
|
833
|
+
}}
|
|
680
834
|
>
|
|
681
835
|
<span className={css.toggleTrack}><span className={css.toggleThumb} /></span>
|
|
682
836
|
</button>
|