@ismailnakkar/ui-behaviours 0.4.0 → 0.6.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 +40 -107
- package/package.json +1 -1
- package/src/range-picker.css +16 -24
- package/src/steps.js +37 -28
package/README.md
CHANGED
|
@@ -184,24 +184,20 @@ by one form.
|
|
|
184
184
|
<dialog id="two-factor-dialog" aria-labelledby="two-factor-title" data-steps>
|
|
185
185
|
<h2 id="two-factor-title">Turn on two-factor</h2>
|
|
186
186
|
<div aria-hidden="true">
|
|
187
|
-
<i data-step-mark
|
|
187
|
+
<i data-step-mark data-step-state="current"></i><i data-step-mark></i><i data-step-mark></i>
|
|
188
188
|
</div>
|
|
189
|
-
<p aria-live="polite">
|
|
190
|
-
<span data-step-label="1">Step 1 of 3</span>
|
|
191
|
-
<span data-step-label="2" hidden>Step 2 of 3</span>
|
|
192
|
-
<span data-step-label="3" hidden>Step 3 of 3</span>
|
|
193
|
-
</p>
|
|
189
|
+
<p aria-live="polite" data-step-progress="Step :step of :steps"></p>
|
|
194
190
|
|
|
195
191
|
<form id="two-factor-enable" method="POST" action="/user/two-factor-authentication">
|
|
196
|
-
<section data-step="
|
|
192
|
+
<section data-step="scan">
|
|
197
193
|
<h3 tabindex="-1">Scan the QR code</h3>
|
|
198
194
|
…
|
|
199
195
|
</section>
|
|
200
|
-
<section data-step="
|
|
196
|
+
<section data-step="email" hidden>
|
|
201
197
|
<h3 tabindex="-1">Confirm your email</h3>
|
|
202
198
|
<input name="email_code" required autocomplete="one-time-code">
|
|
203
199
|
</section>
|
|
204
|
-
<section data-step="
|
|
200
|
+
<section data-step="app" hidden>
|
|
205
201
|
<h3 tabindex="-1">Enter the code from your app</h3>
|
|
206
202
|
<input name="code" required aria-invalid="true" aria-describedby="code-error" autocomplete="one-time-code">
|
|
207
203
|
<p id="code-error">The code is not valid.</p>
|
|
@@ -215,8 +211,9 @@ by one form.
|
|
|
215
211
|
</dialog>
|
|
216
212
|
```
|
|
217
213
|
|
|
218
|
-
- **`data-step
|
|
219
|
-
is
|
|
214
|
+
- **`data-step`** on each step, all inside one form: the steps go in the order they come, so none is numbered. Its
|
|
215
|
+
value is a name, needed only for `data-open-at-step` to point at; `data-step` alone is fine. Only the step showing is
|
|
216
|
+
not `hidden`. Its fields are the inputs, selects and textareas in it.
|
|
220
217
|
- **`data-step-next`**: checks the step's fields (`reportValidity()`, so the browser says what is missing), then shows
|
|
221
218
|
the next step and focuses its first heading; give the heading `tabindex="-1"`. From the last step it submits, as
|
|
222
219
|
`data-step-submit` does. Enter in an input of a step does the same, so the form's own submit never skips a step's
|
|
@@ -224,9 +221,12 @@ by one form.
|
|
|
224
221
|
- **`data-step-back`** shows the step before.
|
|
225
222
|
- **`data-step-submit`**: checks every step's fields; one left empty shows its step and the browser's message, else the
|
|
226
223
|
form is sent (`requestSubmit()`, so `data-confirm` and `data-submit-once` apply).
|
|
227
|
-
- **`data-step-mark
|
|
228
|
-
it; the marks ahead have none.
|
|
229
|
-
- **`data-step-
|
|
224
|
+
- **`data-step-mark`**, a progress mark, one per step in the same order: gets `data-step-state="done"` behind the step
|
|
225
|
+
showing and `"current"` for it; the marks ahead have none.
|
|
226
|
+
- **`data-step-progress="…"`**: the stepper writes this wording as the element's text, with `:step` as the showing
|
|
227
|
+
step's place from 1 and `:steps` as the count, such as "Step 2 of 3" in a live region. Laravel's `__()` given no
|
|
228
|
+
replacements leaves both placeholders in, so `data-step-progress="{{ __('enrolment.progress') }}"` works in every
|
|
229
|
+
locale.
|
|
230
230
|
|
|
231
231
|
The controls may sit anywhere in the stepper, in or out of the form; one that is a submit button moves the steps without
|
|
232
232
|
sending the form. Back is hidden on the first step, Next on the last, and Submit on every other.
|
|
@@ -237,11 +237,12 @@ On install, a stepper opens (`showModal()` on a dialog) at:
|
|
|
237
237
|
refused submit came back as. A field the server never hands back, such as a mailed code, is empty again, so its step
|
|
238
238
|
comes first. `aria-invalid="true"` is the one error mark the stepper reads: set it on each field the server refused,
|
|
239
239
|
with its message.
|
|
240
|
-
2. else **`data-open-at-step="
|
|
240
|
+
2. else **`data-open-at-step="name"`** on the stepper, the step whose `data-step` has that name, such as the email
|
|
241
|
+
step on the page after "Email me a code";
|
|
241
242
|
3. else nowhere: a dialog stays shut, and the stepper shows the step the server drew.
|
|
242
243
|
|
|
243
|
-
Draw the first state on the server too (step
|
|
244
|
-
before the script runs. A stepper added later works, but opens at nothing.
|
|
244
|
+
Draw the first state on the server too (the first step showing, its mark current, Back and Submit hidden): it is what
|
|
245
|
+
shows before the script runs. The `data-step-progress` text is written on install. A stepper added later works, but opens at nothing.
|
|
245
246
|
|
|
246
247
|
### `data-show-if="name=value"` and `data-clear-on="name"`
|
|
247
248
|
|
|
@@ -494,10 +495,8 @@ any rule of yours wins; the ones defaulting to another property follow it.
|
|
|
494
495
|
| `--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 |
|
|
495
496
|
| `--range-picker-muted-color` | `#687086` | The button's days and the summary |
|
|
496
497
|
| `--range-picker-preset-color` | `--range-picker-muted-color` | The presets |
|
|
497
|
-
| `--range-picker-preset-hover-
|
|
498
|
-
| `--range-picker-preset-hover-background` | `--range-picker-hover-background` | Its ground |
|
|
498
|
+
| `--range-picker-preset-hover-background` | `--range-picker-hover-background` | A preset under the pointer |
|
|
499
499
|
| `--range-picker-arrow-color` | `--range-picker-muted-color` | Cally's previous and next buttons |
|
|
500
|
-
| `--range-picker-arrow-hover-color` | `--range-picker-text-color` | An arrow under the pointer |
|
|
501
500
|
| `--range-picker-weekday-color` | `--range-picker-muted-color` | The weekday names |
|
|
502
501
|
| `--range-picker-background` | `#fff` | The popover, the arrows and the year select |
|
|
503
502
|
| `--range-picker-hover-background` | `#f4f6fb` | A day, an arrow and the year select under the pointer, and the button while the popover is open |
|
|
@@ -517,19 +516,10 @@ any rule of yours wins; the ones defaulting to another property follow it.
|
|
|
517
516
|
| `--range-picker-disabled-end-color` | `--range-picker-text-color` | Its text |
|
|
518
517
|
| `--range-picker-radius` | `0.75rem` | The popover's corners |
|
|
519
518
|
| `--range-picker-control-radius` | `0.5rem` | The presets', the days', the arrows' and the year select's corners |
|
|
520
|
-
| `--range-picker-shadow` | `0 16px 40px -8px rgb(16 24 40 / 0.22)` | The popover's shadow |
|
|
521
|
-
| `--range-picker-font-size` | `0.875rem` | The popover's text size |
|
|
522
519
|
| `--range-picker-padding` | `1.25rem` | The popover's padding: set a smaller one under your phone width |
|
|
523
|
-
| `--range-picker-window-gap` | `0.75rem` | The least room the popover leaves to the window's edges |
|
|
524
|
-
| `--range-picker-offset` | `0.375rem` | The gap between the anchored popover and its button |
|
|
525
|
-
| `--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 |
|
|
526
|
-
| `--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 |
|
|
527
|
-
| `--range-picker-day-size` | `2.5rem` | A day's width and height |
|
|
528
|
-
| `--range-picker-preset-height` | `2.5rem` | A preset's least height |
|
|
529
|
-
| `--range-picker-chip-height` | `--range-picker-preset-height` | A chip's least height, where the presets are chips |
|
|
530
520
|
|
|
531
|
-
The weights and the text sizes are the stylesheet's
|
|
532
|
-
|
|
521
|
+
The weights and the text sizes are the stylesheet's: the popover's text is `0.875rem`, the year select's `1rem`, the
|
|
522
|
+
button's days `0.8125rem` and the weekday names `0.75rem`.
|
|
533
523
|
|
|
534
524
|
The colours are light; a dark page sets its own under its dark selector. The stylesheet uses no `light-dark()`:
|
|
535
525
|
Lightning CSS (in Vite and Tailwind v4) lowers it to variables it sets only where the same stylesheet declares
|
|
@@ -612,90 +602,33 @@ Run this package's suite with `npm test`.
|
|
|
612
602
|
|
|
613
603
|
## Upgrading
|
|
614
604
|
|
|
605
|
+
### From 0.5
|
|
606
|
+
|
|
607
|
+
Steppers go by order and name, never by number:
|
|
608
|
+
|
|
609
|
+
- `data-step="1"`, `"2"`, … become `data-step`, or `data-step="name"` for a step that `data-open-at-step` points at.
|
|
610
|
+
- `data-open-at-step` takes that name: `data-open-at-step="2"` opens nothing now.
|
|
611
|
+
- `data-step-mark="n"` becomes `data-step-mark`, one per step in the same order.
|
|
612
|
+
- `data-step-label="n"` is gone: one `data-step-progress="Step :step of :steps"` element replaces the labels.
|
|
613
|
+
|
|
614
|
+
### From 0.4
|
|
615
|
+
|
|
616
|
+
- The stylesheet no longer reads `--range-picker-shadow`, `--range-picker-font-size`, `--range-picker-window-gap`,
|
|
617
|
+
`--range-picker-offset`, `--range-picker-anchored-max-height`, `--range-picker-position-try-order`,
|
|
618
|
+
`--range-picker-day-size`, `--range-picker-preset-height`, `--range-picker-chip-height`,
|
|
619
|
+
`--range-picker-preset-hover-color` or `--range-picker-arrow-hover-color`: it draws their old defaults. A page that
|
|
620
|
+
set one gets the default instead.
|
|
621
|
+
|
|
615
622
|
### From 0.3
|
|
616
623
|
|
|
617
624
|
Nothing changes for a page on 0.3: copy buttons without `data-copy-status` and radios work as before, a select or a
|
|
618
625
|
checkbox changes nothing unless a `data-show-if` names its field, and only a field marked `data-submit-on-change`
|
|
619
|
-
submits.
|
|
620
|
-
|
|
621
|
-
- **cuty, the Full Page Script copy** (`resources/js/members/tools/fps.js`, `members/tools/fps.blade.php`). Delete the
|
|
622
|
-
`MutationObserver` at the end of `fps.js` with its `COPIED` and `status` constants, give the Copy button
|
|
623
|
-
`data-copy-status="fps-copy-status"`, and give the `.copy-status` span that id; its `data-copied-text` stays. Add a
|
|
624
|
-
`data-copy-failed-text` to say a refusal too.
|
|
625
|
-
- **exe, both shorten forms' copy** (`resources/js/site/shorten.ts` and `shorten.test.ts`, the home page's form in
|
|
626
|
-
`public/home.blade.php` and the nav dialog's in `layouts/member.blade.php`: one `bind()` serves every
|
|
627
|
-
`form[data-shorten]`). In each form, give the `data-shorten-copy` button `data-copy` naming the form's link
|
|
628
|
-
(`shorten-link`, `shorten-dialog-link`) and `data-copy-status` naming its `data-shorten-status` paragraph, give that
|
|
629
|
-
paragraph the id (`shorten-status`, `shorten-dialog-status`), rename its `data-copied` to `data-copied-text`, and add
|
|
630
|
-
a `data-copy-failed-text` holding the `general.shorten.copy-blocked` words.
|
|
631
|
-
- Restyle each form from the button's own marks, as `x-ui.copy-button` does: the button becomes a `group`,
|
|
632
|
-
`group-data-[copy-state=done]:` becomes `data-copied:` on it (hover repeats included) and `group-data-copied:` on
|
|
633
|
-
its labels, `=failed` the same with `data-copy-failed`, and the copy-blocked line shows with
|
|
634
|
-
`group-has-[[data-copy-failed]]:block`.
|
|
635
|
-
- Delete the copy state machine from `shorten.ts`: the `CopyState` and `Timer` types, `copyState` and its calls, the
|
|
636
|
-
`copied` timer, `copyLink()` and the copy listener. Drop the `failed` hook and the `data-shorten-copy-failed`
|
|
637
|
-
attribute of both copy-blocked lines in the same change: `hooks()` binds nothing while a hook it asks for is
|
|
638
|
-
missing. `copy` and `copyUrl` stay: `showResult()` focuses the one and fills the other.
|
|
639
|
-
- In `shorten.test.ts`, drop `data-shorten-copy-failed` and `data-copied` from the markup, delete "selects the link
|
|
640
|
-
when the clipboard refuses" (this package's tests select a refused copy), and keep "clears a Copied state when a
|
|
641
|
-
new link arrives" as "shows a new link and says it is ready": its submit and answer, without the copy click and the
|
|
642
|
-
`copyState` assertions.
|
|
643
|
-
- Both marks then last 1.5 seconds, as on exe's other copy buttons. Today a copy shows for 2 seconds, a refusal and
|
|
644
|
-
its copy-blocked line stay until the next copy or submit, and a new link clears either at once.
|
|
645
|
-
- **upfiles, the admin's conditional fields** (`resources/js/admin/conditional-fields.js`, its
|
|
646
|
-
`tests/js/conditional-fields.test.mjs`, the `initConditionalFields()` call in `resources/js/admin/index.js`). Delete
|
|
647
|
-
the three, and turn each `data-cond-field="x" data-cond-value="v"` into `data-show-if="x=v"`
|
|
648
|
-
(`admin/delete.blade.php`, `components/storages/form.blade.php`). The storages form now draws its first state on the
|
|
649
|
-
server: each role hint and driver section `hidden` unless it is the role or driver its select shows (`old()`, else the
|
|
650
|
-
storage's, else the default role or the first driver), as the CSAM origin field already is.
|
|
651
|
-
- **upfiles, the auto-submitting select** (`resources/js/lib/form-affordances.js`, called from
|
|
652
|
-
`resources/js/admin/index.js` and `resources/js/member/index.js`). Delete it and its two calls, and rename
|
|
653
|
-
`data-autosubmit` to `data-submit-on-change` (`admin/moderation/index.blade.php`); both bundles already call
|
|
654
|
-
`installUiBehaviours()`. Rename it in the two `assertDontSee('data-autosubmit', false)` of
|
|
655
|
-
`tests/Feature/StatisticsDashboardsTest.php` too, or they pass whatever the month pickers carry.
|
|
656
|
-
- **centratag, the dashboard's select** (`resources/js/dashboard.ts`). Add `@ismailnakkar/ui-behaviours` and replace the
|
|
657
|
-
file's change listener with `installUiBehaviours()`; `data-submit-on-change` in `tags/show.blade.php` stays as it is.
|
|
626
|
+
submits.
|
|
658
627
|
|
|
659
628
|
### From 0.2
|
|
660
629
|
|
|
661
630
|
Nothing changes for a page on 0.2: the stepper, `data-show-if` and `data-clear-on` read only attributes of their own,
|
|
662
|
-
and the stylesheet loads only when imported.
|
|
663
|
-
|
|
664
|
-
- **The two-factor stepper.** Delete the app's stepper script, its steps module and their tests, then in the dialog:
|
|
665
|
-
- add `data-steps` to the dialog;
|
|
666
|
-
- replace `data-email-code-sent` with `data-open-at-step="2"`, the email step;
|
|
667
|
-
- rename `data-step-turn-on` to `data-step-submit` (`data-step`, `data-step-back` and `data-step-next` stay);
|
|
668
|
-
- on the progress bars, rename `data-progress-step="n"` to `data-step-mark="n"`, draw mark 1 with
|
|
669
|
-
`data-step-state="current"`, and style `[data-step-state="done"]` and `[data-step-state="current"]` in place of the
|
|
670
|
-
`is-done` and `is-current` classes (or `data-state`);
|
|
671
|
-
- on the progress line's spans, rename `data-progress-step="n"` to `data-step-label="n"`;
|
|
672
|
-
- give each field the server refused `aria-invalid="true"`: the stepper reads no error class (`.validation-error`,
|
|
673
|
-
`.invalid-feedback`).
|
|
674
|
-
- **The payout destination form.** Delete the app's destination script, drop `data-destination-form`, add
|
|
675
|
-
`data-clear-on="method"` to the account field, and turn each `data-method-hint="paypal"` into
|
|
676
|
-
`data-show-if="method=paypal"`.
|
|
677
|
-
- **The range picker's look.** Import `range-picker.css` and set the custom properties from the app's palette and
|
|
678
|
-
sizes, with a smaller `--range-picker-padding` under the app's phone width (`1rem` for a popover that had 16px). In
|
|
679
|
-
the markup, `r-range-button` becomes `range-picker-button`, `r-range-panel` `range-picker-panel`, `r-presets`
|
|
680
|
-
`range-picker-presets`, `r-preset` `range-picker-preset`, `r-months` `range-picker-months`, `r-range-foot`
|
|
681
|
-
`range-picker-foot`, `r-range-sum` `range-picker-summary` and `r-pick-end` `range-picker-pick-end`; `r-range`,
|
|
682
|
-
`r-calendar`, `r-range-name` and `r-range-dates` go, as the stylesheet styles `[data-range-picker]`, its
|
|
683
|
-
`calendar-range`, `[data-range-name]` and `[data-range-dates]`. Utility classes that restyle the popover (border,
|
|
684
|
-
background, padding, shadow, text colour) go too; an opening animation stays.
|
|
685
|
-
|
|
686
|
-
Then delete the app's own picker rules, except those that draw the app's controls and icons, which the stylesheet
|
|
687
|
-
leaves to the app. Keep these, under the new class names:
|
|
688
|
-
- the range button's control: its height, padding, border, corners, background, text colour and size, hover and
|
|
689
|
-
transition, its icons' size and colour, and the chevron's `margin-inline-start: auto` (cuty's `.r-range-button`
|
|
690
|
-
and its desktop font size, upfiles' `.r-range-button > i`; exe draws it with utility classes);
|
|
691
|
-
- the arrows' icons in Cally's slots, both nested in `.r-calendar`, so move them out before deleting that block:
|
|
692
|
-
their size (cuty's `[slot] > svg`, as `[data-range-picker] [slot] > svg`) and their mirror on a right-to-left
|
|
693
|
-
page (upfiles' `.r-flip:dir(rtl)`; cuty's `flip-rtl` and exe's `rtl:-scale-x-100` sit outside the picker's
|
|
694
|
-
rules);
|
|
695
|
-
- a preset's icon size (cuty's `.r-preset svg`);
|
|
696
|
-
- the Set button: cuty's `.r-range-foot button` (height, padding, size, weight), and its full width on a phone,
|
|
697
|
-
cuty's `.r-range-foot button { flex: 1 }` and upfiles' `.r-range-foot .btn` (exe's `max-sm:flex-1` is in the
|
|
698
|
-
markup).
|
|
631
|
+
and the stylesheet loads only when imported.
|
|
699
632
|
|
|
700
633
|
### From 0.1
|
|
701
634
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ismailnakkar/ui-behaviours",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
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",
|
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) {
|
package/src/steps.js
CHANGED
|
@@ -2,6 +2,8 @@ import {closestTo} from './helpers.js';
|
|
|
2
2
|
|
|
3
3
|
const STEPPER = '[data-steps]';
|
|
4
4
|
const STEP = '[data-step]';
|
|
5
|
+
const MARK = '[data-step-mark]';
|
|
6
|
+
const PROGRESS = '[data-step-progress]';
|
|
5
7
|
const FIELDS = 'input, select, textarea';
|
|
6
8
|
const HEADING = 'h1, h2, h3, h4, h5, h6';
|
|
7
9
|
const BACK = '[data-step-back]';
|
|
@@ -9,8 +11,11 @@ const NEXT = '[data-step-next]';
|
|
|
9
11
|
const SUBMIT = '[data-step-submit]';
|
|
10
12
|
const MARK_STATE = 'data-step-state';
|
|
11
13
|
|
|
12
|
-
/** Steps
|
|
13
|
-
const FIRST_STEP =
|
|
14
|
+
/** Steps go by their place in the markup: the first is 0 here, and 1 in data-step-progress's wording. */
|
|
15
|
+
const FIRST_STEP = 0;
|
|
16
|
+
|
|
17
|
+
/** data-step-progress's placeholders, as Laravel's __() leaves them when given none: the showing step's place and the count. */
|
|
18
|
+
const PROGRESS_PLACEHOLDER = /:(steps|step)\b/g;
|
|
14
19
|
|
|
15
20
|
/** The values of data-step-state on a progress mark: the steps behind are done, the one showing is current. */
|
|
16
21
|
const MarkState = Object.freeze({done: 'done', current: 'current'});
|
|
@@ -60,8 +65,8 @@ function stepOnEnter(event) {
|
|
|
60
65
|
|
|
61
66
|
/**
|
|
62
67
|
* A refused submit comes back with its errors in the stepper: it opens at the earliest step with a refused or an empty
|
|
63
|
-
* field, as a field the server never hands back (a mailed code) is empty again. Otherwise at
|
|
64
|
-
* shut at the step it shows.
|
|
68
|
+
* field, as a field the server never hands back (a mailed code) is empty again. Otherwise at the step
|
|
69
|
+
* data-open-at-step names, or shut at the step it shows.
|
|
65
70
|
*/
|
|
66
71
|
function openStepper(stepper) {
|
|
67
72
|
const opening = openingStepOf(stepper);
|
|
@@ -77,12 +82,14 @@ function openingStepOf(stepper) {
|
|
|
77
82
|
const fields = fieldsOf(stepper);
|
|
78
83
|
|
|
79
84
|
if (fields.some(isRefused)) {
|
|
80
|
-
return stepOf(fields.find((field) => isRefused(field) || !field.checkValidity()));
|
|
85
|
+
return stepOf(stepper, fields.find((field) => isRefused(field) || !field.checkValidity()));
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
// Unnamed steps carry an empty data-step, which an empty data-open-at-step must not pick.
|
|
89
|
+
const name = stepper.dataset.openAtStep;
|
|
90
|
+
const named = name ? stepsOf(stepper).findIndex((section) => section.dataset.step === name) : -1;
|
|
84
91
|
|
|
85
|
-
return
|
|
92
|
+
return named === -1 ? null : named;
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
/** A field the server refused: aria-invalid="true" beside its message. */
|
|
@@ -104,7 +111,7 @@ function advance(stepper) {
|
|
|
104
111
|
|
|
105
112
|
if (isLast(stepper, step)) {
|
|
106
113
|
submit(stepper);
|
|
107
|
-
} else if (fieldsOf(
|
|
114
|
+
} else if (fieldsOf(stepsOf(stepper)[step]).every((field) => field.reportValidity())) {
|
|
108
115
|
moveTo(stepper, step + 1);
|
|
109
116
|
}
|
|
110
117
|
}
|
|
@@ -114,7 +121,7 @@ function submit(stepper) {
|
|
|
114
121
|
const invalid = fieldsOf(stepper).find((field) => !field.checkValidity());
|
|
115
122
|
|
|
116
123
|
if (invalid) {
|
|
117
|
-
show(stepper, stepOf(invalid));
|
|
124
|
+
show(stepper, stepOf(stepper, invalid));
|
|
118
125
|
invalid.reportValidity();
|
|
119
126
|
|
|
120
127
|
return;
|
|
@@ -126,26 +133,32 @@ function submit(stepper) {
|
|
|
126
133
|
// To the new step's heading, so a screen reader starts where the step does.
|
|
127
134
|
function moveTo(stepper, step) {
|
|
128
135
|
show(stepper, step);
|
|
129
|
-
|
|
136
|
+
stepsOf(stepper)[step]?.querySelector(HEADING)?.focus();
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
function show(stepper, step) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
const steps = stepsOf(stepper);
|
|
141
|
+
|
|
142
|
+
steps.forEach((section, place) => {
|
|
143
|
+
section.hidden = place !== step;
|
|
144
|
+
});
|
|
136
145
|
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
// Marks pair with the steps by place: the first mark is the first step's.
|
|
147
|
+
stepper.querySelectorAll(MARK).forEach((mark, place) => {
|
|
148
|
+
const state = markStateOf(place, step);
|
|
139
149
|
|
|
140
150
|
if (state === null) {
|
|
141
151
|
mark.removeAttribute(MARK_STATE);
|
|
142
152
|
} else {
|
|
143
153
|
mark.setAttribute(MARK_STATE, state);
|
|
144
154
|
}
|
|
145
|
-
}
|
|
155
|
+
});
|
|
146
156
|
|
|
147
|
-
for (const
|
|
148
|
-
|
|
157
|
+
for (const progress of stepper.querySelectorAll(PROGRESS)) {
|
|
158
|
+
progress.textContent = progress.dataset.stepProgress.replace(
|
|
159
|
+
PROGRESS_PLACEHOLDER,
|
|
160
|
+
(_placeholder, name) => String(name === 'steps' ? steps.length : step + 1),
|
|
161
|
+
);
|
|
149
162
|
}
|
|
150
163
|
|
|
151
164
|
hideAll(stepper, BACK, step === FIRST_STEP);
|
|
@@ -171,24 +184,20 @@ function stepsOf(stepper) {
|
|
|
171
184
|
return [...stepper.querySelectorAll(STEP)];
|
|
172
185
|
}
|
|
173
186
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
/** The step a section or a field belongs to. */
|
|
179
|
-
function stepOf(element) {
|
|
180
|
-
return Number(element.closest(STEP).dataset.step);
|
|
187
|
+
/** The place of the step a field belongs to. */
|
|
188
|
+
function stepOf(stepper, field) {
|
|
189
|
+
return stepsOf(stepper).indexOf(field.closest(STEP));
|
|
181
190
|
}
|
|
182
191
|
|
|
183
192
|
/** The step showing; the first when none does. */
|
|
184
193
|
function currentStepOf(stepper) {
|
|
185
|
-
const showing = stepsOf(stepper).
|
|
194
|
+
const showing = stepsOf(stepper).findIndex((section) => !section.hidden);
|
|
186
195
|
|
|
187
|
-
return showing ?
|
|
196
|
+
return showing === -1 ? FIRST_STEP : showing;
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
function isLast(stepper, step) {
|
|
191
|
-
return step >= stepsOf(stepper).length;
|
|
200
|
+
return step >= stepsOf(stepper).length - 1;
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
/** The fields of a step, or of every step in a stepper. */
|