@ismailnakkar/ui-behaviours 0.3.0 → 0.5.0
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/README.md +92 -65
- package/package.json +2 -2
- package/src/helpers.js +4 -0
- package/src/index.js +63 -17
- package/src/range-picker.css +16 -24
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @ismailnakkar/ui-behaviours
|
|
2
2
|
|
|
3
|
-
Page behaviours from plain HTML attributes: copy to the clipboard
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Page behaviours from plain HTML attributes: copy to the clipboard and say the result to screen readers, confirm
|
|
4
|
+
a submit, send a form once, send a form on a change, open, close and light-dismiss a native `<dialog>`, walk a form's
|
|
5
|
+
steps one at a time, show what a radio, a checkbox or a select chose, check every row from a header box, and select a
|
|
6
|
+
field's text on a click. They listen on the document, so markup added later works too.
|
|
6
7
|
|
|
7
8
|
A date range picker over [Cally](https://wicky.nillia.ms/cally/) has its own entry, so pages without one never load the
|
|
8
9
|
calendar, and an optional stylesheet themed by custom properties. Nothing else ships styles, and nothing ships wording:
|
|
@@ -35,14 +36,16 @@ Then mark up the page:
|
|
|
35
36
|
|---|---|---|
|
|
36
37
|
| [`data-copy="id"`](#data-copyid) | a button | copies the element with that id |
|
|
37
38
|
| [`data-copy-value`](#data-copyid) | the copied element | the text to copy instead of what it shows |
|
|
39
|
+
| [`data-copy-status="id"`](#data-copy-statusid) | a copy button | says the result in the live region with that id |
|
|
38
40
|
| [`data-confirm="question"`](#data-confirmquestion) | a form or a submit button | asks before submitting |
|
|
39
41
|
| [`data-submit-once`](#data-submit-once) | a form | refuses a second submit |
|
|
42
|
+
| [`data-submit-on-change`](#data-submit-on-change) | a select, a checkbox or a radio in a form | submits the form when it changes |
|
|
40
43
|
| [`data-show-modal="id"`](#data-show-modalid) | a button or a link | opens the dialog with that id as a modal |
|
|
41
44
|
| [`data-close-modal`](#data-close-modal) | a button in a dialog | closes that dialog |
|
|
42
45
|
| [`closedby="any"`](#closedbyany) | a dialog | closes it on a backdrop click |
|
|
43
46
|
| [`data-open-on-load`](#data-open-on-load) | a dialog | opens it on install |
|
|
44
47
|
| [`data-steps`](#data-steps) | a dialog or any box | shows its `data-step` sections one at a time |
|
|
45
|
-
| [`data-show-if="name=value"`](#data-show-ifnamevalue-and-data-clear-onname) | any element in a form | shows it only while the radio `name`
|
|
48
|
+
| [`data-show-if="name=value"`](#data-show-ifnamevalue-and-data-clear-onname) | any element in a form | shows it only while the radio, checkbox or select `name` holds that value |
|
|
46
49
|
| [`data-clear-on="name"`](#data-show-ifnamevalue-and-data-clear-onname) | a field in a form | empties it when another radio `name` is picked |
|
|
47
50
|
| [`data-check-all="name"`](#data-check-allname) | a header checkbox | checks every row named `name` |
|
|
48
51
|
| [`data-autoselect`](#data-autoselect) | an input or a textarea | selects its text on a click |
|
|
@@ -70,6 +73,26 @@ focused too, so the user copies it by hand. A missing source copies nothing.
|
|
|
70
73
|
To refuse a copy (asking for a missing field first), call `event.preventDefault()` in a click listener of your own on
|
|
71
74
|
the button or an element around it: the copy skips a cancelled click.
|
|
72
75
|
|
|
76
|
+
### `data-copy-status="id"`
|
|
77
|
+
|
|
78
|
+
On a copy button: names a live region (`role="status"`) that says the result, as the button's own marks are not read
|
|
79
|
+
out. The region holds the words: its `data-copied-text` for a copy that worked, its `data-copy-failed-text` for a
|
|
80
|
+
refusal; a result it has no words for says nothing.
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<input id="short-url" value="https://example.com/abcd" readonly data-autoselect>
|
|
84
|
+
<button type="button" data-copy="short-url" data-copy-status="short-url-status">
|
|
85
|
+
<span>Copy</span><span>Copied</span>
|
|
86
|
+
</button>
|
|
87
|
+
<p id="short-url-status" role="status" class="sr-only"
|
|
88
|
+
data-copied-text="Link copied" data-copy-failed-text="Copy blocked: copy the selected link by hand"></p>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The click empties the region, so the same words said again are read out again; the words go in once the clipboard
|
|
92
|
+
answers and leave with the button's marks, 1.5 seconds later, unless the page has written something else there since.
|
|
93
|
+
Buttons may share one region, and the page may use it for its own news too. Keep the region in place, never `hidden`:
|
|
94
|
+
a hidden element is out of the accessibility tree, and one that appears as it speaks is not reliably read.
|
|
95
|
+
|
|
73
96
|
### `data-confirm="question"`
|
|
74
97
|
|
|
75
98
|
On a form, or on one of its submit buttons: the browser's `confirm()` asks that question, and only a yes submits. The
|
|
@@ -97,6 +120,20 @@ forms send again.
|
|
|
97
120
|
</form>
|
|
98
121
|
```
|
|
99
122
|
|
|
123
|
+
### `data-submit-on-change`
|
|
124
|
+
|
|
125
|
+
On a select, a checkbox or a radio in a form: a change submits the form with `requestSubmit()`, as its submit button
|
|
126
|
+
would, so the browser checks the fields and `data-confirm` and `data-submit-once` apply. A field in no form sends
|
|
127
|
+
nothing. Mark only choices whose result the label makes plain, such as a sort or a filter.
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<form method="GET" action="/admin/reports">
|
|
131
|
+
<label for="sort">Sort by</label>
|
|
132
|
+
<select id="sort" name="sort" data-submit-on-change>…</select>
|
|
133
|
+
<noscript><button>Sort</button></noscript>
|
|
134
|
+
</form>
|
|
135
|
+
```
|
|
136
|
+
|
|
100
137
|
### `data-show-modal="id"`
|
|
101
138
|
|
|
102
139
|
On a button or a link: a click opens the `<dialog>` with that id with `showModal()`. On a link the `href` is the
|
|
@@ -208,9 +245,16 @@ before the script runs. A stepper added later works, but opens at nothing.
|
|
|
208
245
|
|
|
209
246
|
### `data-show-if="name=value"` and `data-clear-on="name"`
|
|
210
247
|
|
|
211
|
-
In a form, for a choice
|
|
212
|
-
|
|
213
|
-
|
|
248
|
+
In a form, for a choice: an element marked `data-show-if="name=value"` shows while the field named `name` holds that
|
|
249
|
+
value, and hides once it does not.
|
|
250
|
+
|
|
251
|
+
- **A radio**: picking one shows the elements naming its value and hides those naming another.
|
|
252
|
+
- **A checkbox**: ticking the box with that value shows them, unticking it hides them, and another box of the same name
|
|
253
|
+
leaves them alone. A box without a `value` has the value `on`.
|
|
254
|
+
- **A select**: a change shows the elements naming a selected option's value and hides the rest.
|
|
255
|
+
|
|
256
|
+
Picking a radio named `name` also empties the fields marked `data-clear-on="name"`, which belonged to the value picked
|
|
257
|
+
before. A payout destination is one: the account depends on the method.
|
|
214
258
|
|
|
215
259
|
```html
|
|
216
260
|
<form method="POST" action="/withdrawals/destination">
|
|
@@ -225,8 +269,21 @@ belonged to the value picked before. A payout destination is one: the account de
|
|
|
225
269
|
</form>
|
|
226
270
|
```
|
|
227
271
|
|
|
228
|
-
|
|
229
|
-
|
|
272
|
+
```html
|
|
273
|
+
<select name="driver">
|
|
274
|
+
<option value="local" selected>Local disk</option>
|
|
275
|
+
<option value="s3">S3</option>
|
|
276
|
+
</select>
|
|
277
|
+
<fieldset data-show-if="driver=s3" hidden>…</fieldset>
|
|
278
|
+
|
|
279
|
+
<label><input type="checkbox" name="report" value="1"> Report it</label>
|
|
280
|
+
<div data-show-if="report=1" hidden>…</div>
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The server draws the chosen value's elements shown and the others `hidden`, a refused submit's page from the values
|
|
284
|
+
sent back; the script changes them on a change only. It reads within the changed field's form (the page, for a field in
|
|
285
|
+
no form). A hidden element's fields still submit, and a hidden `required` one blocks the submit: leave `required` off
|
|
286
|
+
them and let the server require each for its own value.
|
|
230
287
|
|
|
231
288
|
### `data-check-all="name"`
|
|
232
289
|
|
|
@@ -287,8 +344,11 @@ The package sets attributes and the browser's own states; the app styles them:
|
|
|
287
344
|
and focus goes back to the opener on close. Give each one an `aria-labelledby`.
|
|
288
345
|
- Put the copy state in the button's text (two spans, one hidden), so it never relies on colour alone.
|
|
289
346
|
- A refused copy selects and focuses the field, so the user can copy it with the keyboard.
|
|
290
|
-
- The copy marks change an attribute only,
|
|
291
|
-
`
|
|
347
|
+
- The copy marks change an attribute only, which screen readers do not read out: give the button a
|
|
348
|
+
[`data-copy-status`](#data-copy-statusid) region with the words for both results, so the result is heard.
|
|
349
|
+
- A change that submits moves the page under the user, and on some desktop browsers an arrow key on a closed select
|
|
350
|
+
changes it at once: keep `data-submit-on-change` to a sort or a filter that is cheap to redo, and give the form a
|
|
351
|
+
submit button for a page without script.
|
|
292
352
|
- A stepper moves focus to the new step's heading, so a screen reader starts where the step does: give each a
|
|
293
353
|
`tabindex="-1"`. Hide the progress marks (`aria-hidden="true"`) and put the step's words in a `data-step-label` inside
|
|
294
354
|
an `aria-live="polite"` region.
|
|
@@ -434,10 +494,8 @@ any rule of yours wins; the ones defaulting to another property follow it.
|
|
|
434
494
|
| `--range-picker-text-color` | `#1c2130` | The popover's text, the days, the month and year, the summary's range name, and a custom range's days on the button |
|
|
435
495
|
| `--range-picker-muted-color` | `#687086` | The button's days and the summary |
|
|
436
496
|
| `--range-picker-preset-color` | `--range-picker-muted-color` | The presets |
|
|
437
|
-
| `--range-picker-preset-hover-
|
|
438
|
-
| `--range-picker-preset-hover-background` | `--range-picker-hover-background` | Its ground |
|
|
497
|
+
| `--range-picker-preset-hover-background` | `--range-picker-hover-background` | A preset under the pointer |
|
|
439
498
|
| `--range-picker-arrow-color` | `--range-picker-muted-color` | Cally's previous and next buttons |
|
|
440
|
-
| `--range-picker-arrow-hover-color` | `--range-picker-text-color` | An arrow under the pointer |
|
|
441
499
|
| `--range-picker-weekday-color` | `--range-picker-muted-color` | The weekday names |
|
|
442
500
|
| `--range-picker-background` | `#fff` | The popover, the arrows and the year select |
|
|
443
501
|
| `--range-picker-hover-background` | `#f4f6fb` | A day, an arrow and the year select under the pointer, and the button while the popover is open |
|
|
@@ -457,19 +515,10 @@ any rule of yours wins; the ones defaulting to another property follow it.
|
|
|
457
515
|
| `--range-picker-disabled-end-color` | `--range-picker-text-color` | Its text |
|
|
458
516
|
| `--range-picker-radius` | `0.75rem` | The popover's corners |
|
|
459
517
|
| `--range-picker-control-radius` | `0.5rem` | The presets', the days', the arrows' and the year select's corners |
|
|
460
|
-
| `--range-picker-shadow` | `0 16px 40px -8px rgb(16 24 40 / 0.22)` | The popover's shadow |
|
|
461
|
-
| `--range-picker-font-size` | `0.875rem` | The popover's text size |
|
|
462
518
|
| `--range-picker-padding` | `1.25rem` | The popover's padding: set a smaller one under your phone width |
|
|
463
|
-
| `--range-picker-window-gap` | `0.75rem` | The least room the popover leaves to the window's edges |
|
|
464
|
-
| `--range-picker-offset` | `0.375rem` | The gap between the anchored popover and its button |
|
|
465
|
-
| `--range-picker-anchored-max-height` | `calc(100% - 2 * var(--range-picker-offset))` | The anchored popover's height limit, against the room on the side it opens toward |
|
|
466
|
-
| `--range-picker-position-try-order` | `most-height` | Which side the anchored popover prefers: the roomier one by default; `normal` keeps the order below, then above |
|
|
467
|
-
| `--range-picker-day-size` | `2.5rem` | A day's width and height |
|
|
468
|
-
| `--range-picker-preset-height` | `2.5rem` | A preset's least height |
|
|
469
|
-
| `--range-picker-chip-height` | `--range-picker-preset-height` | A chip's least height, where the presets are chips |
|
|
470
519
|
|
|
471
|
-
The weights and the text sizes are the stylesheet's
|
|
472
|
-
|
|
520
|
+
The weights and the text sizes are the stylesheet's: the popover's text is `0.875rem`, the year select's `1rem`, the
|
|
521
|
+
button's days `0.8125rem` and the weekday names `0.75rem`.
|
|
473
522
|
|
|
474
523
|
The colours are light; a dark page sets its own under its dark selector. The stylesheet uses no `light-dark()`:
|
|
475
524
|
Lightning CSS (in Vite and Tailwind v4) lowers it to variables it sets only where the same stylesheet declares
|
|
@@ -521,9 +570,9 @@ if (!(await copyText(url))) {
|
|
|
521
570
|
|
|
522
571
|
## Events
|
|
523
572
|
|
|
524
|
-
The package fires none of its own. A dialog's native `close` fires when a close button or the backdrop closes it,
|
|
525
|
-
|
|
526
|
-
the capture phase, as the package does.
|
|
573
|
+
The package fires none of its own. A dialog's native `close` fires when a close button or the backdrop closes it, the
|
|
574
|
+
range picker's radios fire the native `change`, and a `data-submit-on-change` field's form the native `submit`. Cally's
|
|
575
|
+
`change` and `rangestart` do not bubble: listen to them in the capture phase, as the package does.
|
|
527
576
|
|
|
528
577
|
## Testing
|
|
529
578
|
|
|
@@ -552,46 +601,24 @@ Run this package's suite with `npm test`.
|
|
|
552
601
|
|
|
553
602
|
## Upgrading
|
|
554
603
|
|
|
604
|
+
### From 0.4
|
|
605
|
+
|
|
606
|
+
- The stylesheet no longer reads `--range-picker-shadow`, `--range-picker-font-size`, `--range-picker-window-gap`,
|
|
607
|
+
`--range-picker-offset`, `--range-picker-anchored-max-height`, `--range-picker-position-try-order`,
|
|
608
|
+
`--range-picker-day-size`, `--range-picker-preset-height`, `--range-picker-chip-height`,
|
|
609
|
+
`--range-picker-preset-hover-color` or `--range-picker-arrow-hover-color`: it draws their old defaults. A page that
|
|
610
|
+
set one gets the default instead.
|
|
611
|
+
|
|
612
|
+
### From 0.3
|
|
613
|
+
|
|
614
|
+
Nothing changes for a page on 0.3: copy buttons without `data-copy-status` and radios work as before, a select or a
|
|
615
|
+
checkbox changes nothing unless a `data-show-if` names its field, and only a field marked `data-submit-on-change`
|
|
616
|
+
submits.
|
|
617
|
+
|
|
555
618
|
### From 0.2
|
|
556
619
|
|
|
557
620
|
Nothing changes for a page on 0.2: the stepper, `data-show-if` and `data-clear-on` read only attributes of their own,
|
|
558
|
-
and the stylesheet loads only when imported.
|
|
559
|
-
|
|
560
|
-
- **The two-factor stepper.** Delete the app's stepper script, its steps module and their tests, then in the dialog:
|
|
561
|
-
- add `data-steps` to the dialog;
|
|
562
|
-
- replace `data-email-code-sent` with `data-open-at-step="2"`, the email step;
|
|
563
|
-
- rename `data-step-turn-on` to `data-step-submit` (`data-step`, `data-step-back` and `data-step-next` stay);
|
|
564
|
-
- on the progress bars, rename `data-progress-step="n"` to `data-step-mark="n"`, draw mark 1 with
|
|
565
|
-
`data-step-state="current"`, and style `[data-step-state="done"]` and `[data-step-state="current"]` in place of the
|
|
566
|
-
`is-done` and `is-current` classes (or `data-state`);
|
|
567
|
-
- on the progress line's spans, rename `data-progress-step="n"` to `data-step-label="n"`;
|
|
568
|
-
- give each field the server refused `aria-invalid="true"`: the stepper reads no error class (`.validation-error`,
|
|
569
|
-
`.invalid-feedback`).
|
|
570
|
-
- **The payout destination form.** Delete the app's destination script, drop `data-destination-form`, add
|
|
571
|
-
`data-clear-on="method"` to the account field, and turn each `data-method-hint="paypal"` into
|
|
572
|
-
`data-show-if="method=paypal"`.
|
|
573
|
-
- **The range picker's look.** Import `range-picker.css` and set the custom properties from the app's palette and
|
|
574
|
-
sizes, with a smaller `--range-picker-padding` under the app's phone width (`1rem` for a popover that had 16px). In
|
|
575
|
-
the markup, `r-range-button` becomes `range-picker-button`, `r-range-panel` `range-picker-panel`, `r-presets`
|
|
576
|
-
`range-picker-presets`, `r-preset` `range-picker-preset`, `r-months` `range-picker-months`, `r-range-foot`
|
|
577
|
-
`range-picker-foot`, `r-range-sum` `range-picker-summary` and `r-pick-end` `range-picker-pick-end`; `r-range`,
|
|
578
|
-
`r-calendar`, `r-range-name` and `r-range-dates` go, as the stylesheet styles `[data-range-picker]`, its
|
|
579
|
-
`calendar-range`, `[data-range-name]` and `[data-range-dates]`. Utility classes that restyle the popover (border,
|
|
580
|
-
background, padding, shadow, text colour) go too; an opening animation stays.
|
|
581
|
-
|
|
582
|
-
Then delete the app's own picker rules, except those that draw the app's controls and icons, which the stylesheet
|
|
583
|
-
leaves to the app. Keep these, under the new class names:
|
|
584
|
-
- the range button's control: its height, padding, border, corners, background, text colour and size, hover and
|
|
585
|
-
transition, its icons' size and colour, and the chevron's `margin-inline-start: auto` (cuty's `.r-range-button`
|
|
586
|
-
and its desktop font size, upfiles' `.r-range-button > i`; exe draws it with utility classes);
|
|
587
|
-
- the arrows' icons in Cally's slots, both nested in `.r-calendar`, so move them out before deleting that block:
|
|
588
|
-
their size (cuty's `[slot] > svg`, as `[data-range-picker] [slot] > svg`) and their mirror on a right-to-left
|
|
589
|
-
page (upfiles' `.r-flip:dir(rtl)`; cuty's `flip-rtl` and exe's `rtl:-scale-x-100` sit outside the picker's
|
|
590
|
-
rules);
|
|
591
|
-
- a preset's icon size (cuty's `.r-preset svg`);
|
|
592
|
-
- the Set button: cuty's `.r-range-foot button` (height, padding, size, weight), and its full width on a phone,
|
|
593
|
-
cuty's `.r-range-foot button { flex: 1 }` and upfiles' `.r-range-foot .btn` (exe's `max-sm:flex-1` is in the
|
|
594
|
-
markup).
|
|
621
|
+
and the stylesheet loads only when imported.
|
|
595
622
|
|
|
596
623
|
### From 0.1
|
|
597
624
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ismailnakkar/ui-behaviours",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Page behaviours from plain HTML attributes (copy, confirm, submit once, native dialogs, steps, show by a radio, check all, autoselect), and a date range picker over Cally with an optional stylesheet.",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Page behaviours from plain HTML attributes (copy with a spoken result, confirm, submit once or on a change, native dialogs, steps, show by a radio, checkbox or select, check all, autoselect), and a date range picker over Cally with an optional stylesheet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clipboard",
|
|
7
7
|
"dialog",
|
package/src/helpers.js
CHANGED
|
@@ -18,3 +18,7 @@ export function closestTo({target}, selector) {
|
|
|
18
18
|
export function isRadio(element) {
|
|
19
19
|
return element instanceof HTMLInputElement && element.type === 'radio';
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
export function isCheckbox(element) {
|
|
23
|
+
return element instanceof HTMLInputElement && element.type === 'checkbox';
|
|
24
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {closestTo, isRadio, once} from './helpers.js';
|
|
1
|
+
import {closestTo, isCheckbox, isRadio, once} from './helpers.js';
|
|
2
2
|
import {installSteps} from './steps.js';
|
|
3
3
|
|
|
4
4
|
const COPY_FLASH_MS = 1500;
|
|
@@ -10,7 +10,7 @@ const SUBMITTING = 'data-submitting';
|
|
|
10
10
|
/** closedby's light-dismiss value, polyfilled where the browser lacks it. */
|
|
11
11
|
const CLOSED_BY_ANY = 'any';
|
|
12
12
|
|
|
13
|
-
/** Between a
|
|
13
|
+
/** Between a field's name and its value in data-show-if: "method=paypal". */
|
|
14
14
|
const SHOW_IF_SEPARATOR = '=';
|
|
15
15
|
|
|
16
16
|
const copyTimers = new WeakMap();
|
|
@@ -24,7 +24,10 @@ export const installUiBehaviours = once(() => {
|
|
|
24
24
|
document.addEventListener('submit', submitOnce);
|
|
25
25
|
window.addEventListener('pageshow', releaseSubmitted);
|
|
26
26
|
document.addEventListener('change', checkAll);
|
|
27
|
-
document.addEventListener('change',
|
|
27
|
+
document.addEventListener('change', showOnChange);
|
|
28
|
+
document.addEventListener('change', clearOnPick);
|
|
29
|
+
// Last: the form goes as the other behaviours leave it.
|
|
30
|
+
document.addEventListener('change', submitOnChange);
|
|
28
31
|
document.addEventListener('click', autoselect);
|
|
29
32
|
document.addEventListener('click', copyOnClick);
|
|
30
33
|
document.addEventListener('click', showModal);
|
|
@@ -94,12 +97,19 @@ function releaseSubmitted({persisted}) {
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
|
|
100
|
+
// requestSubmit(), not submit(): the browser checks the fields, and data-confirm and data-submit-once apply.
|
|
101
|
+
function submitOnChange({target}) {
|
|
102
|
+
if (target instanceof Element && target.hasAttribute('data-submit-on-change')) {
|
|
103
|
+
target.form?.requestSubmit();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
function checkboxesNamed(name) {
|
|
98
|
-
return [...document.getElementsByName(name)].filter((box) => box
|
|
108
|
+
return [...document.getElementsByName(name)].filter((box) => isCheckbox(box) && !box.disabled);
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
function checkAll({target}) {
|
|
102
|
-
if (!(target
|
|
112
|
+
if (!isCheckbox(target)) {
|
|
103
113
|
return;
|
|
104
114
|
}
|
|
105
115
|
|
|
@@ -125,25 +135,42 @@ function checkAll({target}) {
|
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
/**
|
|
128
|
-
* A radio picked shows its form's data-show-if="name=value" elements
|
|
129
|
-
*
|
|
138
|
+
* A radio picked, a box ticked or a select changed shows its form's data-show-if="name=value" elements while it holds
|
|
139
|
+
* that value and hides them once it does not.
|
|
130
140
|
*/
|
|
131
|
-
function
|
|
132
|
-
if (!isRadio(target)) {
|
|
141
|
+
function showOnChange({target}) {
|
|
142
|
+
if (!isRadio(target) && !isCheckbox(target) && !(target instanceof HTMLSelectElement)) {
|
|
133
143
|
return;
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
for (const element of scope.querySelectorAll('[data-show-if]')) {
|
|
146
|
+
for (const element of (target.form ?? document).querySelectorAll('[data-show-if]')) {
|
|
139
147
|
const condition = showIfOf(element);
|
|
140
148
|
|
|
141
|
-
if (condition?.name === target.name) {
|
|
142
|
-
element.hidden = condition.value
|
|
149
|
+
if (condition?.name === target.name && speaksFor(target, condition.value)) {
|
|
150
|
+
element.hidden = !holds(target, condition.value);
|
|
143
151
|
}
|
|
144
152
|
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A box speaks for its own value alone, as other boxes of its name keep theirs; a radio or select for every value. */
|
|
156
|
+
function speaksFor(field, value) {
|
|
157
|
+
return !isCheckbox(field) || field.value === value;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// options, not selectedOptions: happy-dom's list goes stale after its first read, so app tests would see an old pick.
|
|
161
|
+
function holds(field, value) {
|
|
162
|
+
return field instanceof HTMLSelectElement
|
|
163
|
+
? [...field.options].some((option) => option.selected && option.value === value)
|
|
164
|
+
: field.checked && field.value === value;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A radio picked empties its form's fields marked data-clear-on="name", which belong to the value picked before. */
|
|
168
|
+
function clearOnPick({target}) {
|
|
169
|
+
if (!isRadio(target)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
145
172
|
|
|
146
|
-
for (const field of
|
|
173
|
+
for (const field of (target.form ?? document).querySelectorAll('[data-clear-on]')) {
|
|
147
174
|
if (field.dataset.clearOn === target.name) {
|
|
148
175
|
field.value = '';
|
|
149
176
|
}
|
|
@@ -185,25 +212,44 @@ async function copyOnClick(event) {
|
|
|
185
212
|
return;
|
|
186
213
|
}
|
|
187
214
|
|
|
215
|
+
const status = button.dataset.copyStatus ? document.getElementById(button.dataset.copyStatus) : null;
|
|
216
|
+
|
|
217
|
+
// Emptied first, so the same words said again are read out again.
|
|
218
|
+
status?.replaceChildren();
|
|
219
|
+
|
|
188
220
|
const copied = await copyText(copiedTextOf(source));
|
|
189
221
|
|
|
190
|
-
flashCopyResult(button, copied);
|
|
222
|
+
flashCopyResult(button, copied, status);
|
|
191
223
|
|
|
192
224
|
if (!copied) {
|
|
193
225
|
selectForManualCopy(source);
|
|
194
226
|
}
|
|
195
227
|
}
|
|
196
228
|
|
|
197
|
-
function flashCopyResult(button, copied) {
|
|
229
|
+
function flashCopyResult(button, copied, status) {
|
|
230
|
+
const said = status ? sayCopyResult(status, copied) : null;
|
|
231
|
+
|
|
198
232
|
clearTimeout(copyTimers.get(button));
|
|
199
233
|
button.toggleAttribute(COPIED, copied);
|
|
200
234
|
button.toggleAttribute(COPY_FAILED, !copied);
|
|
201
235
|
copyTimers.set(button, setTimeout(() => {
|
|
202
236
|
button.removeAttribute(COPIED);
|
|
203
237
|
button.removeAttribute(COPY_FAILED);
|
|
238
|
+
|
|
239
|
+
// Its own words only: the page may have said something else there since.
|
|
240
|
+
if (status?.textContent === said) {
|
|
241
|
+
status.textContent = '';
|
|
242
|
+
}
|
|
204
243
|
}, COPY_FLASH_MS));
|
|
205
244
|
}
|
|
206
245
|
|
|
246
|
+
/** Writes the live region's words for the result, its data-copied-text or data-copy-failed-text, and returns them. */
|
|
247
|
+
function sayCopyResult(status, copied) {
|
|
248
|
+
status.textContent = (copied ? status.dataset.copiedText : status.dataset.copyFailedText) ?? '';
|
|
249
|
+
|
|
250
|
+
return status.textContent;
|
|
251
|
+
}
|
|
252
|
+
|
|
207
253
|
// select() alone may leave the field unfocused; focused, Ctrl/Cmd+C copies it by hand.
|
|
208
254
|
function selectForManualCopy(source) {
|
|
209
255
|
if (isField(source)) {
|
package/src/range-picker.css
CHANGED
|
@@ -21,14 +21,7 @@
|
|
|
21
21
|
--range-picker-disabled-color: #aeb5c6;
|
|
22
22
|
--range-picker-radius: 0.75rem;
|
|
23
23
|
--range-picker-control-radius: 0.5rem;
|
|
24
|
-
--range-picker-shadow: 0 16px 40px -8px rgb(16 24 40 / 0.22);
|
|
25
|
-
--range-picker-font-size: 0.875rem;
|
|
26
24
|
--range-picker-padding: 1.25rem;
|
|
27
|
-
--range-picker-window-gap: 0.75rem;
|
|
28
|
-
--range-picker-offset: 0.375rem;
|
|
29
|
-
--range-picker-day-size: 2.5rem;
|
|
30
|
-
--range-picker-preset-height: 2.5rem;
|
|
31
|
-
--range-picker-position-try-order: most-height;
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
/* The button: the app draws the control; this lays out its icon, name and days. */
|
|
@@ -88,15 +81,15 @@
|
|
|
88
81
|
[data-range-picker] {
|
|
89
82
|
margin: auto;
|
|
90
83
|
width: max-content;
|
|
91
|
-
max-width: calc(100vw -
|
|
92
|
-
max-height: calc(100dvh -
|
|
84
|
+
max-width: calc(100vw - 1.5rem);
|
|
85
|
+
max-height: calc(100dvh - 1.5rem);
|
|
93
86
|
padding: var(--range-picker-padding);
|
|
94
87
|
border: 1px solid var(--range-picker-border-color);
|
|
95
88
|
border-radius: var(--range-picker-radius);
|
|
96
89
|
background: var(--range-picker-background);
|
|
97
|
-
box-shadow:
|
|
90
|
+
box-shadow: 0 16px 40px -8px rgb(16 24 40 / 0.22);
|
|
98
91
|
color: var(--range-picker-text-color);
|
|
99
|
-
font-size:
|
|
92
|
+
font-size: 0.875rem;
|
|
100
93
|
}
|
|
101
94
|
|
|
102
95
|
.range-picker-panel {
|
|
@@ -118,7 +111,7 @@
|
|
|
118
111
|
display: flex;
|
|
119
112
|
align-items: center;
|
|
120
113
|
gap: 0.625rem;
|
|
121
|
-
min-block-size:
|
|
114
|
+
min-block-size: 2.5rem;
|
|
122
115
|
margin: 0;
|
|
123
116
|
padding-inline: 0.75rem;
|
|
124
117
|
border-radius: var(--range-picker-control-radius);
|
|
@@ -130,7 +123,7 @@
|
|
|
130
123
|
|
|
131
124
|
.range-picker-preset:hover {
|
|
132
125
|
background: var(--range-picker-preset-hover-background, var(--range-picker-hover-background));
|
|
133
|
-
color: var(--range-picker-
|
|
126
|
+
color: var(--range-picker-text-color);
|
|
134
127
|
}
|
|
135
128
|
|
|
136
129
|
.range-picker-preset input {
|
|
@@ -181,7 +174,7 @@
|
|
|
181
174
|
|
|
182
175
|
[data-range-picker] calendar-range::part(button):hover {
|
|
183
176
|
background: var(--range-picker-hover-background);
|
|
184
|
-
color: var(--range-picker-
|
|
177
|
+
color: var(--range-picker-text-color);
|
|
185
178
|
}
|
|
186
179
|
|
|
187
180
|
[data-range-picker] calendar-range::part(button):focus-visible {
|
|
@@ -238,7 +231,7 @@
|
|
|
238
231
|
}
|
|
239
232
|
|
|
240
233
|
[data-range-picker] calendar-month::part(th) {
|
|
241
|
-
inline-size:
|
|
234
|
+
inline-size: 2.5rem;
|
|
242
235
|
block-size: 1.75rem;
|
|
243
236
|
color: var(--range-picker-weekday-color, var(--range-picker-muted-color));
|
|
244
237
|
font-size: 0.75rem;
|
|
@@ -246,8 +239,8 @@
|
|
|
246
239
|
}
|
|
247
240
|
|
|
248
241
|
[data-range-picker] calendar-month::part(day) {
|
|
249
|
-
inline-size:
|
|
250
|
-
block-size:
|
|
242
|
+
inline-size: 2.5rem;
|
|
243
|
+
block-size: 2.5rem;
|
|
251
244
|
border-radius: var(--range-picker-control-radius);
|
|
252
245
|
color: var(--range-picker-text-color);
|
|
253
246
|
}
|
|
@@ -377,7 +370,6 @@
|
|
|
377
370
|
}
|
|
378
371
|
|
|
379
372
|
.range-picker-preset {
|
|
380
|
-
min-block-size: var(--range-picker-chip-height, var(--range-picker-preset-height));
|
|
381
373
|
border: 1px solid var(--range-picker-control-border-color);
|
|
382
374
|
border-radius: 999px;
|
|
383
375
|
}
|
|
@@ -392,15 +384,15 @@
|
|
|
392
384
|
@supports (position-area: bottom) {
|
|
393
385
|
[data-range-picker] {
|
|
394
386
|
inset: auto;
|
|
395
|
-
margin-block:
|
|
396
|
-
margin-inline: 0
|
|
387
|
+
margin-block: 0.375rem;
|
|
388
|
+
margin-inline: 0 0.75rem;
|
|
397
389
|
position-anchor: --range-picker;
|
|
398
390
|
position-area: bottom span-right;
|
|
399
391
|
position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
|
|
400
|
-
/* No taller than the room on the side it opens toward, which is the roomier one
|
|
401
|
-
|
|
402
|
-
max-height:
|
|
403
|
-
position-try-order:
|
|
392
|
+
/* No taller than the room on the side it opens toward, which is the roomier one: a short window scrolls it
|
|
393
|
+
inside, so its Set button stays reachable. */
|
|
394
|
+
max-height: calc(100% - 0.75rem);
|
|
395
|
+
position-try-order: most-height;
|
|
404
396
|
}
|
|
405
397
|
|
|
406
398
|
[data-range-picker]:dir(rtl) {
|