@ismailnakkar/ui-behaviours 0.2.0 → 0.3.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 +285 -41
- package/package.json +9 -3
- package/src/helpers.js +4 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +41 -1
- package/src/range-picker.css +410 -0
- package/src/range-picker.d.css.ts +2 -0
- package/src/range-picker.js +1 -5
- package/src/steps.js +197 -0
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @ismailnakkar/ui-behaviours
|
|
2
2
|
|
|
3
3
|
Page behaviours from plain HTML attributes: copy to the clipboard, confirm a submit, send a form once, open, close and
|
|
4
|
-
light-dismiss a native `<dialog>`,
|
|
5
|
-
on the document, so markup added later works too.
|
|
4
|
+
light-dismiss a native `<dialog>`, walk a form's steps one at a time, show a radio's own hints, check every row from a
|
|
5
|
+
header box, and select a field's text on a click. They listen on the document, so markup added later works too.
|
|
6
6
|
|
|
7
7
|
A date range picker over [Cally](https://wicky.nillia.ms/cally/) has its own entry, so pages without one never load the
|
|
8
|
-
calendar
|
|
9
|
-
app's markup.
|
|
8
|
+
calendar, and an optional stylesheet themed by custom properties. Nothing else ships styles, and nothing ships wording:
|
|
9
|
+
the app styles the states the package sets, and every word comes from the app's markup.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -20,7 +20,8 @@ optional peer dependency (`npm i cally`). Type declarations are included.
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
22
|
Call `installUiBehaviours()` once from the layout's script, on every page, after the page is parsed (a module or a
|
|
23
|
-
deferred script): it also opens the page's `data-open-on-load` dialogs
|
|
23
|
+
deferred script): it also opens the page's `data-open-on-load` dialogs and shows each stepper at the step it opens at. A
|
|
24
|
+
second call does nothing.
|
|
24
25
|
|
|
25
26
|
```js
|
|
26
27
|
import {installUiBehaviours} from '@ismailnakkar/ui-behaviours';
|
|
@@ -40,6 +41,9 @@ Then mark up the page:
|
|
|
40
41
|
| [`data-close-modal`](#data-close-modal) | a button in a dialog | closes that dialog |
|
|
41
42
|
| [`closedby="any"`](#closedbyany) | a dialog | closes it on a backdrop click |
|
|
42
43
|
| [`data-open-on-load`](#data-open-on-load) | a dialog | opens it on install |
|
|
44
|
+
| [`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` has that value |
|
|
46
|
+
| [`data-clear-on="name"`](#data-show-ifnamevalue-and-data-clear-onname) | a field in a form | empties it when another radio `name` is picked |
|
|
43
47
|
| [`data-check-all="name"`](#data-check-allname) | a header checkbox | checks every row named `name` |
|
|
44
48
|
| [`data-autoselect`](#data-autoselect) | an input or a textarea | selects its text on a click |
|
|
45
49
|
|
|
@@ -133,6 +137,97 @@ submit inside it, or a one-time result.
|
|
|
133
137
|
<dialog id="recovery-codes" data-open-on-load>…</dialog>
|
|
134
138
|
```
|
|
135
139
|
|
|
140
|
+
### `data-steps`
|
|
141
|
+
|
|
142
|
+
On a dialog or any other box: a form's fields in steps, one showing at a time, each checked before the next shows, and
|
|
143
|
+
the form sent from the last. Two-factor enrolment is one: scan the code, the mailed code, the app's code, all posted
|
|
144
|
+
by one form.
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<dialog id="two-factor-dialog" aria-labelledby="two-factor-title" data-steps>
|
|
148
|
+
<h2 id="two-factor-title">Turn on two-factor</h2>
|
|
149
|
+
<div aria-hidden="true">
|
|
150
|
+
<i data-step-mark="1" data-step-state="current"></i><i data-step-mark="2"></i><i data-step-mark="3"></i>
|
|
151
|
+
</div>
|
|
152
|
+
<p aria-live="polite">
|
|
153
|
+
<span data-step-label="1">Step 1 of 3</span>
|
|
154
|
+
<span data-step-label="2" hidden>Step 2 of 3</span>
|
|
155
|
+
<span data-step-label="3" hidden>Step 3 of 3</span>
|
|
156
|
+
</p>
|
|
157
|
+
|
|
158
|
+
<form id="two-factor-enable" method="POST" action="/user/two-factor-authentication">
|
|
159
|
+
<section data-step="1">
|
|
160
|
+
<h3 tabindex="-1">Scan the QR code</h3>
|
|
161
|
+
…
|
|
162
|
+
</section>
|
|
163
|
+
<section data-step="2" hidden>
|
|
164
|
+
<h3 tabindex="-1">Confirm your email</h3>
|
|
165
|
+
<input name="email_code" required autocomplete="one-time-code">
|
|
166
|
+
</section>
|
|
167
|
+
<section data-step="3" hidden>
|
|
168
|
+
<h3 tabindex="-1">Enter the code from your app</h3>
|
|
169
|
+
<input name="code" required aria-invalid="true" aria-describedby="code-error" autocomplete="one-time-code">
|
|
170
|
+
<p id="code-error">The code is not valid.</p>
|
|
171
|
+
</section>
|
|
172
|
+
</form>
|
|
173
|
+
|
|
174
|
+
<button type="button" data-step-back hidden>Back</button>
|
|
175
|
+
<button type="button" data-close-modal>Cancel</button>
|
|
176
|
+
<button type="button" data-step-next>Next</button>
|
|
177
|
+
<button type="button" data-step-submit hidden>Turn on</button>
|
|
178
|
+
</dialog>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- **`data-step="n"`** on each step, numbered from 1 in the order they come, all inside one form. Only the step showing
|
|
182
|
+
is not `hidden`. Its fields are the inputs, selects and textareas in it.
|
|
183
|
+
- **`data-step-next`**: checks the step's fields (`reportValidity()`, so the browser says what is missing), then shows
|
|
184
|
+
the next step and focuses its first heading; give the heading `tabindex="-1"`. From the last step it submits, as
|
|
185
|
+
`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
|
|
186
|
+
check; Enter while an input method composes is left alone.
|
|
187
|
+
- **`data-step-back`** shows the step before.
|
|
188
|
+
- **`data-step-submit`**: checks every step's fields; one left empty shows its step and the browser's message, else the
|
|
189
|
+
form is sent (`requestSubmit()`, so `data-confirm` and `data-submit-once` apply).
|
|
190
|
+
- **`data-step-mark="n"`**, a progress mark: gets `data-step-state="done"` behind the step showing and `"current"` for
|
|
191
|
+
it; the marks ahead have none.
|
|
192
|
+
- **`data-step-label="n"`**: shown only while step `n` shows, such as "Step 2 of 3" in a live region.
|
|
193
|
+
|
|
194
|
+
The controls may sit anywhere in the stepper, in or out of the form; one that is a submit button moves the steps without
|
|
195
|
+
sending the form. Back is hidden on the first step, Next on the last, and Submit on every other.
|
|
196
|
+
|
|
197
|
+
On install, a stepper opens (`showModal()` on a dialog) at:
|
|
198
|
+
|
|
199
|
+
1. the earliest step with a refused or an empty field, when a field carries **`aria-invalid="true"`**: the page a
|
|
200
|
+
refused submit came back as. A field the server never hands back, such as a mailed code, is empty again, so its step
|
|
201
|
+
comes first. `aria-invalid="true"` is the one error mark the stepper reads: set it on each field the server refused,
|
|
202
|
+
with its message.
|
|
203
|
+
2. else **`data-open-at-step="n"`** on the stepper, such as the email step on the page after "Email me a code";
|
|
204
|
+
3. else nowhere: a dialog stays shut, and the stepper shows the step the server drew.
|
|
205
|
+
|
|
206
|
+
Draw the first state on the server too (step 1 showing, its mark current, Back and Submit hidden): it is what shows
|
|
207
|
+
before the script runs. A stepper added later works, but opens at nothing.
|
|
208
|
+
|
|
209
|
+
### `data-show-if="name=value"` and `data-clear-on="name"`
|
|
210
|
+
|
|
211
|
+
In a form, for a choice made with radios: picking a radio named `name` shows the form's elements whose `data-show-if`
|
|
212
|
+
names that radio's value and hides those naming another, and empties the fields marked `data-clear-on="name"`, which
|
|
213
|
+
belonged to the value picked before. A payout destination is one: the account depends on the method.
|
|
214
|
+
|
|
215
|
+
```html
|
|
216
|
+
<form method="POST" action="/withdrawals/destination">
|
|
217
|
+
<label><input type="radio" name="method" value="paypal" checked> PayPal</label>
|
|
218
|
+
<label><input type="radio" name="method" value="usdt_polygon"> USDT on Polygon</label>
|
|
219
|
+
|
|
220
|
+
<input name="account" required data-clear-on="method" aria-describedby="account-hint">
|
|
221
|
+
<div id="account-hint" aria-live="polite">
|
|
222
|
+
<p data-show-if="method=paypal">Your PayPal email address.</p>
|
|
223
|
+
<p data-show-if="method=usdt_polygon" hidden>Your USDT address on the Polygon network.</p>
|
|
224
|
+
</div>
|
|
225
|
+
</form>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The server draws the checked radio's elements shown and the others `hidden`; the script changes them on a pick only. It
|
|
229
|
+
reads radios only, within the picked radio's form (the page, for a radio in no form).
|
|
230
|
+
|
|
136
231
|
### `data-check-all="name"`
|
|
137
232
|
|
|
138
233
|
On a header checkbox: checking or unchecking it does the same to every enabled checkbox named `name`. When a row
|
|
@@ -160,6 +255,7 @@ The package sets attributes and the browser's own states; the app styles them:
|
|
|
160
255
|
- `[data-copied]` and `[data-copy-failed]` on a copy button: show its "Copied" or "Copy it by hand" label instead of
|
|
161
256
|
"Copy". The words are the app's, in the button.
|
|
162
257
|
- `[data-submitting]` on a form sent once, to show the wait.
|
|
258
|
+
- `[data-step-state="done"]` and `[data-step-state="current"]` on a stepper's progress marks.
|
|
163
259
|
- `dialog`, `dialog::backdrop`, and `dialog[open]` for an opening transition.
|
|
164
260
|
- `:indeterminate` on a header checkbox, if the app restyles checkboxes.
|
|
165
261
|
|
|
@@ -193,6 +289,11 @@ The package sets attributes and the browser's own states; the app styles them:
|
|
|
193
289
|
- A refused copy selects and focuses the field, so the user can copy it with the keyboard.
|
|
194
290
|
- The copy marks change an attribute only, so screen readers announce nothing. A page that needs it adds a
|
|
195
291
|
`role="status"` line and fills it when `data-copied` appears (a `MutationObserver`).
|
|
292
|
+
- A stepper moves focus to the new step's heading, so a screen reader starts where the step does: give each a
|
|
293
|
+
`tabindex="-1"`. Hide the progress marks (`aria-hidden="true"`) and put the step's words in a `data-step-label` inside
|
|
294
|
+
an `aria-live="polite"` region.
|
|
295
|
+
- Point a field's `aria-describedby` at its `data-show-if` hints' box, in an `aria-live="polite"` region, so a warning
|
|
296
|
+
shown on a pick is read out.
|
|
196
297
|
|
|
197
298
|
## Range picker
|
|
198
299
|
|
|
@@ -214,43 +315,56 @@ opens nothing and the box shows in place, where its radios and fields still subm
|
|
|
214
315
|
|
|
215
316
|
### The markup
|
|
216
317
|
|
|
318
|
+
The classes are the [stylesheet](#styling-the-picker)'s, for an app that uses it.
|
|
319
|
+
|
|
217
320
|
```html
|
|
218
321
|
<form method="get" action="/reports">
|
|
219
|
-
<
|
|
220
|
-
<
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
<div
|
|
227
|
-
<
|
|
228
|
-
|
|
229
|
-
|
|
322
|
+
<div class="field">
|
|
323
|
+
<button type="button" class="range-picker-button" popovertarget="report-range" data-range-state="preset">
|
|
324
|
+
<svg aria-hidden="true">…</svg>
|
|
325
|
+
<span data-range-name>Last 7 days</span>
|
|
326
|
+
<span data-range-dates="compact">14 Nov – 20 Nov</span>
|
|
327
|
+
</button>
|
|
328
|
+
|
|
329
|
+
<div id="report-range" popover data-range-picker data-range-state="preset">
|
|
330
|
+
<div class="range-picker-panel">
|
|
331
|
+
<div class="range-picker-presets" role="radiogroup" aria-label="Range">
|
|
332
|
+
<label class="range-picker-preset"><input type="radio" name="range" value="today" data-range-preset="2026-11-20/2026-11-20"> Today</label>
|
|
333
|
+
<label class="range-picker-preset"><input type="radio" name="range" value="last7" data-range-preset="2026-11-14/2026-11-20" checked> Last 7 days</label>
|
|
334
|
+
<label class="range-picker-preset"><input type="radio" name="range" value="custom" data-range-custom> Custom range</label>
|
|
335
|
+
</div>
|
|
336
|
+
|
|
337
|
+
<calendar-range months="2" page-by="single" value="2026-11-14/2026-11-20" focused-date="2026-11-20"
|
|
338
|
+
min="2025-03-02" max="2026-11-20" today="2026-11-20" locale="en-GB" first-day-of-week="1">
|
|
339
|
+
<svg slot="previous" role="img" aria-label="Previous">…</svg>
|
|
340
|
+
<svg slot="next" role="img" aria-label="Next">…</svg>
|
|
341
|
+
<calendar-select-year slot="heading"><span slot="label">Year</span></calendar-select-year>
|
|
342
|
+
<div class="range-picker-months">
|
|
343
|
+
<calendar-month></calendar-month>
|
|
344
|
+
<calendar-month offset="1"></calendar-month>
|
|
345
|
+
</div>
|
|
346
|
+
</calendar-range>
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
<div class="range-picker-foot">
|
|
350
|
+
<p class="range-picker-summary" aria-live="polite">
|
|
351
|
+
<span class="when-preset"><b data-range-name>Last 7 days</b>, </span>
|
|
352
|
+
<span data-range-dates>14 Nov – 20 Nov 2026</span>
|
|
353
|
+
<span class="when-pending">– <span class="range-picker-pick-end">pick the end day</span></span>
|
|
354
|
+
</p>
|
|
355
|
+
<input type="hidden" name="from" value="2026-11-14" data-range-from>
|
|
356
|
+
<input type="hidden" name="to" value="2026-11-20" data-range-to>
|
|
357
|
+
<button type="button" popovertarget="report-range" popovertargetaction="hide">Set</button>
|
|
358
|
+
</div>
|
|
230
359
|
</div>
|
|
231
|
-
|
|
232
|
-
<calendar-range months="2" page-by="single" value="2026-11-14/2026-11-20" focused-date="2026-11-20"
|
|
233
|
-
min="2025-03-02" max="2026-11-20" today="2026-11-20" locale="en-GB" first-day-of-week="1">
|
|
234
|
-
<svg slot="previous" role="img" aria-label="Previous">…</svg>
|
|
235
|
-
<svg slot="next" role="img" aria-label="Next">…</svg>
|
|
236
|
-
<calendar-select-year slot="heading"><span slot="label">Year</span></calendar-select-year>
|
|
237
|
-
<calendar-month></calendar-month>
|
|
238
|
-
<calendar-month offset="1"></calendar-month>
|
|
239
|
-
</calendar-range>
|
|
240
|
-
|
|
241
|
-
<p aria-live="polite">
|
|
242
|
-
<span class="when-preset"><b data-range-name>Last 7 days</b>, </span>
|
|
243
|
-
<span data-range-dates>14 Nov – 20 Nov 2026</span>
|
|
244
|
-
<span class="when-pending">– pick the end day</span>
|
|
245
|
-
</p>
|
|
246
|
-
|
|
247
|
-
<input type="hidden" name="from" value="2026-11-14" data-range-from>
|
|
248
|
-
<input type="hidden" name="to" value="2026-11-20" data-range-to>
|
|
249
|
-
<button>Show</button>
|
|
250
360
|
</div>
|
|
361
|
+
|
|
362
|
+
<button>Show</button>
|
|
251
363
|
</form>
|
|
252
364
|
```
|
|
253
365
|
|
|
366
|
+
Set only closes the popover, with the picks already in the fields: the form's own submit button runs it.
|
|
367
|
+
|
|
254
368
|
- **`data-range-picker`** marks the box holding the rest, a `popover` here. Its buttons are the elements whose
|
|
255
369
|
`popovertarget` names its id.
|
|
256
370
|
- **`data-range-preset="from/to"`** on a preset's radio gives its days as `YYYY-MM-DD/YYYY-MM-DD`, the format of
|
|
@@ -262,8 +376,8 @@ opens nothing and the box shows in place, where its radios and fields still subm
|
|
|
262
376
|
the buttons keep the range the form sends. Paging the calendar or changing its year or month only moves the view and
|
|
263
377
|
keeps the pick; picking a radio, this one too, drops it.
|
|
264
378
|
- **`data-range-from` and `data-range-to`** on the two hidden fields the form sends, inside the picker.
|
|
265
|
-
- **`<calendar-range>`** is set up
|
|
266
|
-
|
|
379
|
+
- **`<calendar-range>`** is set up by the app: its months, `min`, `max`, `today`, `locale`, `page-by` and slots. The
|
|
380
|
+
package sets only its `value`, `focusedDate` and `tentative`; the stylesheet styles its parts.
|
|
267
381
|
- **`data-range-name`**, in the picker or a button: the checked radio's label text.
|
|
268
382
|
- **`data-range-dates`**, in the picker or a button: each end by `Intl.DateTimeFormat` (day, short month) in the
|
|
269
383
|
calendar's `locale`, else the page's `lang`, joined by a spaced en dash, with the year once when both ends share it
|
|
@@ -278,10 +392,93 @@ later until its first pick.
|
|
|
278
392
|
|
|
279
393
|
### Styling the picker
|
|
280
394
|
|
|
281
|
-
The
|
|
395
|
+
The stylesheet styles the button's layout and open look, the popover, the presets, Cally's parts and the state words.
|
|
396
|
+
Import it once, from the page's script or the app's CSS:
|
|
397
|
+
|
|
398
|
+
```js
|
|
399
|
+
import '@ismailnakkar/ui-behaviours/range-picker.css';
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
```css
|
|
403
|
+
@import '@ismailnakkar/ui-behaviours/range-picker.css' layer(components);
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
It is in no cascade layer, so it beats layered utility classes (Tailwind v4's) on the picker; the second form puts it in
|
|
407
|
+
the app's `components` layer, under its utilities.
|
|
408
|
+
|
|
409
|
+
It styles these, and nothing outside them:
|
|
410
|
+
|
|
411
|
+
| Selector | On |
|
|
412
|
+
|---|---|
|
|
413
|
+
| `.range-picker-button` | the button that opens the picker: the app draws the control (border, height, padding); the stylesheet lays out its icon, name and days, anchors the popover to it, and marks it while the popover is open. Put the popover after it in the same parent. |
|
|
414
|
+
| `[data-range-picker]` | the popover |
|
|
415
|
+
| `.range-picker-panel` | the presets beside the calendar |
|
|
416
|
+
| `.range-picker-presets`, `.range-picker-preset` | the radio group, and each preset's label around its radio |
|
|
417
|
+
| `.range-picker-months` | the calendar's months, inside `<calendar-range>` |
|
|
418
|
+
| `.range-picker-foot`, `.range-picker-summary`, `.range-picker-pick-end` | the row under the calendar, its summary line, and the "pick the end day" words in it |
|
|
419
|
+
| `.when-preset`, `.when-pending` | the words for each `data-range-state` |
|
|
420
|
+
|
|
421
|
+
It draws no icons: the app sizes the button's, the arrows' in Cally's `previous` and `next` slots and any in a preset,
|
|
422
|
+
and mirrors the arrows on a right-to-left page.
|
|
423
|
+
|
|
424
|
+
Under 56rem the presets turn into a row of chips over the calendar. From 64rem, where the browser has anchor
|
|
425
|
+
positioning (Chrome 129, Safari 26), the popover opens under its button toward the line's end, flipped where that runs
|
|
426
|
+
out of room and no taller than the room it opens into, so a short window scrolls it; under 64rem it is centred. A
|
|
427
|
+
second picker on the same page anchors to the last button.
|
|
428
|
+
|
|
429
|
+
Override these custom properties on `:root`, or on one picker and its button. The defaults sit in `:where(:root)`, so
|
|
430
|
+
any rule of yours wins; the ones defaulting to another property follow it.
|
|
431
|
+
|
|
432
|
+
| Property | Default | Styles |
|
|
433
|
+
|---|---|---|
|
|
434
|
+
| `--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
|
+
| `--range-picker-muted-color` | `#687086` | The button's days and the summary |
|
|
436
|
+
| `--range-picker-preset-color` | `--range-picker-muted-color` | The presets |
|
|
437
|
+
| `--range-picker-preset-hover-color` | `--range-picker-text-color` | A preset under the pointer |
|
|
438
|
+
| `--range-picker-preset-hover-background` | `--range-picker-hover-background` | Its ground |
|
|
439
|
+
| `--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
|
+
| `--range-picker-weekday-color` | `--range-picker-muted-color` | The weekday names |
|
|
442
|
+
| `--range-picker-background` | `#fff` | The popover, the arrows and the year select |
|
|
443
|
+
| `--range-picker-hover-background` | `#f4f6fb` | A day, an arrow and the year select under the pointer, and the button while the popover is open |
|
|
444
|
+
| `--range-picker-border-color` | `#e6e8ef` | The popover's border |
|
|
445
|
+
| `--range-picker-rule-color` | `--range-picker-border-color` | The rule beside the presets (under them as chips) and the one over the summary |
|
|
446
|
+
| `--range-picker-control-border-color` | `#cfd4df` | The arrows, the year select and the presets as chips |
|
|
447
|
+
| `--range-picker-accent-color` | `#3d5afe` | The picked preset's text, the range's two ends, today, the "pick the end day" words, focus rings, and the button's border while the popover is open |
|
|
448
|
+
| `--range-picker-accent-hover-color` | `#2f48d4` | The range's ends under the pointer: set it to the accent to keep them as they are |
|
|
449
|
+
| `--range-picker-on-accent-color` | `#fff` | The range's ends' text |
|
|
450
|
+
| `--range-picker-selected-background` | `#eef1ff` | The picked preset |
|
|
451
|
+
| `--range-picker-band-background` | `--range-picker-selected-background` | The days between the ends |
|
|
452
|
+
| `--range-picker-band-color` | `#2f48d4` | Their text |
|
|
453
|
+
| `--range-picker-disabled-color` | `#aeb5c6` | The days out of the calendar's bounds |
|
|
454
|
+
| `--range-picker-disabled-band-background` | `--range-picker-border-color` | Picked days out of the bounds (a preset reaching before the first day) |
|
|
455
|
+
| `--range-picker-disabled-band-color` | `--range-picker-muted-color` | Their text |
|
|
456
|
+
| `--range-picker-disabled-end-background` | `--range-picker-control-border-color` | A range end out of the bounds |
|
|
457
|
+
| `--range-picker-disabled-end-color` | `--range-picker-text-color` | Its text |
|
|
458
|
+
| `--range-picker-radius` | `0.75rem` | The popover's corners |
|
|
459
|
+
| `--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
|
+
| `--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
|
+
|
|
471
|
+
The weights and the text sizes are the stylesheet's, all from `--range-picker-font-size` but the year select (`1rem`),
|
|
472
|
+
the button's days (`0.8125rem`) and the weekday names (`0.75rem`).
|
|
473
|
+
|
|
474
|
+
The colours are light; a dark page sets its own under its dark selector. The stylesheet uses no `light-dark()`:
|
|
475
|
+
Lightning CSS (in Vite and Tailwind v4) lowers it to variables it sets only where the same stylesheet declares
|
|
476
|
+
`color-scheme`.
|
|
477
|
+
|
|
478
|
+
Without the stylesheet, the app shows the words each state calls for itself:
|
|
282
479
|
|
|
283
480
|
```css
|
|
284
|
-
.when-pending,
|
|
481
|
+
[data-range-state] .when-pending,
|
|
285
482
|
[data-range-state="custom"] .when-preset,
|
|
286
483
|
[data-range-state="pending"] .when-preset,
|
|
287
484
|
[data-range-state="custom"] > [data-range-name] {
|
|
@@ -294,7 +491,8 @@ The words for each state are the app's, in the markup; the app shows the ones `d
|
|
|
294
491
|
```
|
|
295
492
|
|
|
296
493
|
While `pending` the checked radio is still the range the form sends. To show Custom range as the one being picked,
|
|
297
|
-
style `[data-range-state="pending"] label:has([data-range-custom])` as checked, and the checked label as not
|
|
494
|
+
style `[data-range-state="pending"] label:has([data-range-custom])` as checked, and the checked label as not, as the
|
|
495
|
+
stylesheet does.
|
|
298
496
|
|
|
299
497
|
### The picker's accessibility
|
|
300
498
|
|
|
@@ -306,9 +504,10 @@ style `[data-range-state="pending"] label:has([data-range-custom])` as checked,
|
|
|
306
504
|
|
|
307
505
|
| Import | Does |
|
|
308
506
|
|---|---|
|
|
309
|
-
| `installUiBehaviours()` | listens on the document for every behaviour above
|
|
507
|
+
| `installUiBehaviours()` | listens on the document for every behaviour above, opens the `data-open-on-load` dialogs and shows each stepper at the step it opens at; later calls do nothing |
|
|
310
508
|
| `copyText(text)` | the copy buttons' clipboard write: resolves to `true` when the clipboard took the text, `false` where `navigator.clipboard` is absent (plain http) or refuses |
|
|
311
509
|
| `installRangePicker()`, from `@ismailnakkar/ui-behaviours/range-picker` | listens on the document for range pickers and writes those already on the page; later calls do nothing |
|
|
510
|
+
| `@ismailnakkar/ui-behaviours/range-picker.css` | the range picker's [stylesheet](#styling-the-picker) |
|
|
312
511
|
|
|
313
512
|
`copyText()` serves a page's own script, copying a link it just made:
|
|
314
513
|
|
|
@@ -345,10 +544,55 @@ customElements.define('calendar-range', class extends HTMLElement {
|
|
|
345
544
|
});
|
|
346
545
|
```
|
|
347
546
|
|
|
547
|
+
A stepper needs nothing more: happy-dom and jsdom check `required` fields and send a form with `requestSubmit()`. To
|
|
548
|
+
test one opening on load, put its markup in place before installing, in a test file of its own or after
|
|
549
|
+
`vi.resetModules()` with a fresh `import()`.
|
|
550
|
+
|
|
348
551
|
Run this package's suite with `npm test`.
|
|
349
552
|
|
|
350
553
|
## Upgrading
|
|
351
554
|
|
|
555
|
+
### From 0.2
|
|
556
|
+
|
|
557
|
+
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. An app replacing its own copies changes these:
|
|
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).
|
|
595
|
+
|
|
352
596
|
### From 0.1
|
|
353
597
|
|
|
354
598
|
- A preset radio gives its days in one attribute, `data-range-preset="from/to"`, in place of `data-from` and `data-to`:
|
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, check all, autoselect), and a date range picker over Cally.",
|
|
3
|
+
"version": "0.3.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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clipboard",
|
|
7
7
|
"dialog",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"date-range",
|
|
10
10
|
"cally",
|
|
11
11
|
"data-attributes",
|
|
12
|
+
"stepper",
|
|
12
13
|
"laravel"
|
|
13
14
|
],
|
|
14
15
|
"homepage": "https://github.com/ismailnakkar/ui-behaviours",
|
|
@@ -35,13 +36,18 @@
|
|
|
35
36
|
"./range-picker": {
|
|
36
37
|
"types": "./src/range-picker.d.ts",
|
|
37
38
|
"default": "./src/range-picker.js"
|
|
39
|
+
},
|
|
40
|
+
"./range-picker.css": {
|
|
41
|
+
"types": "./src/range-picker.d.css.ts",
|
|
42
|
+
"default": "./src/range-picker.css"
|
|
38
43
|
}
|
|
39
44
|
},
|
|
40
45
|
"files": [
|
|
41
46
|
"src"
|
|
42
47
|
],
|
|
43
48
|
"sideEffects": [
|
|
44
|
-
"./src/range-picker.js"
|
|
49
|
+
"./src/range-picker.js",
|
|
50
|
+
"./src/range-picker.css"
|
|
45
51
|
],
|
|
46
52
|
"publishConfig": {
|
|
47
53
|
"access": "public"
|
package/src/helpers.js
CHANGED
|
@@ -14,3 +14,7 @@ export function once(install) {
|
|
|
14
14
|
export function closestTo({target}, selector) {
|
|
15
15
|
return target instanceof Element ? target.closest(selector) : null;
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
export function isRadio(element) {
|
|
19
|
+
return element instanceof HTMLInputElement && element.type === 'radio';
|
|
20
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Listens on the document for every behaviour, opens the data-open-on-load dialogs and shows each data-steps stepper at
|
|
3
|
+
* the step it opens at. Later calls do nothing.
|
|
4
|
+
*/
|
|
2
5
|
export function installUiBehaviours(): void;
|
|
3
6
|
|
|
4
7
|
/** Writes text to the clipboard: false where navigator.clipboard is absent (plain http) or refuses. */
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {closestTo, once} from './helpers.js';
|
|
1
|
+
import {closestTo, isRadio, once} from './helpers.js';
|
|
2
|
+
import {installSteps} from './steps.js';
|
|
2
3
|
|
|
3
4
|
const COPY_FLASH_MS = 1500;
|
|
4
5
|
|
|
@@ -9,6 +10,9 @@ const SUBMITTING = 'data-submitting';
|
|
|
9
10
|
/** closedby's light-dismiss value, polyfilled where the browser lacks it. */
|
|
10
11
|
const CLOSED_BY_ANY = 'any';
|
|
11
12
|
|
|
13
|
+
/** Between a radio's name and its value in data-show-if: "method=paypal". */
|
|
14
|
+
const SHOW_IF_SEPARATOR = '=';
|
|
15
|
+
|
|
12
16
|
const copyTimers = new WeakMap();
|
|
13
17
|
|
|
14
18
|
/** The dialog a press landed on outside its box: a selection dragged out of the body must not close it. */
|
|
@@ -20,6 +24,7 @@ export const installUiBehaviours = once(() => {
|
|
|
20
24
|
document.addEventListener('submit', submitOnce);
|
|
21
25
|
window.addEventListener('pageshow', releaseSubmitted);
|
|
22
26
|
document.addEventListener('change', checkAll);
|
|
27
|
+
document.addEventListener('change', switchOnPick);
|
|
23
28
|
document.addEventListener('click', autoselect);
|
|
24
29
|
document.addEventListener('click', copyOnClick);
|
|
25
30
|
document.addEventListener('click', showModal);
|
|
@@ -27,6 +32,8 @@ export const installUiBehaviours = once(() => {
|
|
|
27
32
|
document.addEventListener('pointerdown', pressBackdrop);
|
|
28
33
|
document.addEventListener('click', closeOnBackdrop);
|
|
29
34
|
|
|
35
|
+
// First: a stepper dialog opened on load shows its step before showModal() moves focus in.
|
|
36
|
+
installSteps();
|
|
30
37
|
openOnLoad();
|
|
31
38
|
});
|
|
32
39
|
|
|
@@ -117,6 +124,39 @@ function checkAll({target}) {
|
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
126
|
|
|
127
|
+
/**
|
|
128
|
+
* A radio picked shows its form's data-show-if="name=value" elements for its own value and hides those for another,
|
|
129
|
+
* and empties the fields marked data-clear-on="name", which belong to the value picked before.
|
|
130
|
+
*/
|
|
131
|
+
function switchOnPick({target}) {
|
|
132
|
+
if (!isRadio(target)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const scope = target.form ?? document;
|
|
137
|
+
|
|
138
|
+
for (const element of scope.querySelectorAll('[data-show-if]')) {
|
|
139
|
+
const condition = showIfOf(element);
|
|
140
|
+
|
|
141
|
+
if (condition?.name === target.name) {
|
|
142
|
+
element.hidden = condition.value !== target.value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
for (const field of scope.querySelectorAll('[data-clear-on]')) {
|
|
147
|
+
if (field.dataset.clearOn === target.name) {
|
|
148
|
+
field.value = '';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function showIfOf(element) {
|
|
154
|
+
const condition = element.dataset.showIf;
|
|
155
|
+
const at = condition.indexOf(SHOW_IF_SEPARATOR);
|
|
156
|
+
|
|
157
|
+
return at > 0 ? {name: condition.slice(0, at), value: condition.slice(at + 1)} : null;
|
|
158
|
+
}
|
|
159
|
+
|
|
120
160
|
// Tabbing in selects a field's text natively; a click only places a caret.
|
|
121
161
|
function autoselect({target}) {
|
|
122
162
|
if (isField(target) && target.matches('[data-autoselect]')) {
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The range picker's look (README, "Styling the picker"): its button, the popover with the presets beside the calendar,
|
|
3
|
+
* and Cally's parts. Every app value is a custom property; the defaults sit in :where(:root), so any rule of the app's
|
|
4
|
+
* wins. The properties left out here default, where they are used, to the one named beside them in the README.
|
|
5
|
+
*
|
|
6
|
+
* Light colours only: Lightning CSS (Vite's, Tailwind v4's) lowers light-dark() to variables it sets only where the
|
|
7
|
+
* same stylesheet declares color-scheme, so a pair here breaks in an app's build. A dark page sets its own.
|
|
8
|
+
*/
|
|
9
|
+
:where(:root) {
|
|
10
|
+
--range-picker-text-color: #1c2130;
|
|
11
|
+
--range-picker-muted-color: #687086;
|
|
12
|
+
--range-picker-background: #fff;
|
|
13
|
+
--range-picker-hover-background: #f4f6fb;
|
|
14
|
+
--range-picker-border-color: #e6e8ef;
|
|
15
|
+
--range-picker-control-border-color: #cfd4df;
|
|
16
|
+
--range-picker-accent-color: #3d5afe;
|
|
17
|
+
--range-picker-accent-hover-color: #2f48d4;
|
|
18
|
+
--range-picker-on-accent-color: #fff;
|
|
19
|
+
--range-picker-selected-background: #eef1ff;
|
|
20
|
+
--range-picker-band-color: #2f48d4;
|
|
21
|
+
--range-picker-disabled-color: #aeb5c6;
|
|
22
|
+
--range-picker-radius: 0.75rem;
|
|
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
|
+
--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
|
+
}
|
|
33
|
+
|
|
34
|
+
/* The button: the app draws the control; this lays out its icon, name and days. */
|
|
35
|
+
.range-picker-button {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: 0.625rem;
|
|
39
|
+
inline-size: 100%;
|
|
40
|
+
text-align: start;
|
|
41
|
+
/* ponytail: one name per page, so a second picker anchors to the last button; anchor-scope if a page needs two. */
|
|
42
|
+
anchor-name: --range-picker;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Its popover is a later sibling: the button's parent holds both. */
|
|
46
|
+
.range-picker-button:has(~ [data-range-picker]:popover-open) {
|
|
47
|
+
border-color: var(--range-picker-accent-color);
|
|
48
|
+
background-color: var(--range-picker-hover-background);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.range-picker-button > [data-range-name] {
|
|
52
|
+
font-weight: 600;
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.range-picker-button > [data-range-dates] {
|
|
57
|
+
min-inline-size: 0;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
color: var(--range-picker-muted-color);
|
|
60
|
+
font-size: 0.8125rem;
|
|
61
|
+
text-overflow: ellipsis;
|
|
62
|
+
white-space: nowrap;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* A custom range's button names its days alone. */
|
|
66
|
+
.range-picker-button[data-range-state="custom"] > [data-range-dates] {
|
|
67
|
+
color: var(--range-picker-text-color);
|
|
68
|
+
font-size: inherit;
|
|
69
|
+
font-weight: 600;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* The words for each data-range-state, in the app's markup. */
|
|
73
|
+
[data-range-state] .when-pending,
|
|
74
|
+
[data-range-state="custom"] .when-preset,
|
|
75
|
+
[data-range-state="pending"] .when-preset,
|
|
76
|
+
[data-range-state="custom"] > [data-range-name] {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
[data-range-state="pending"] .when-pending {
|
|
81
|
+
display: inline;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* The popover, never given a display (that would show it closed): centred, as the browser places one, and under its
|
|
86
|
+
* button on a wide window (below). margin: auto puts back the browser's centring, which a reset zeroes.
|
|
87
|
+
*/
|
|
88
|
+
[data-range-picker] {
|
|
89
|
+
margin: auto;
|
|
90
|
+
width: max-content;
|
|
91
|
+
max-width: calc(100vw - 2 * var(--range-picker-window-gap));
|
|
92
|
+
max-height: calc(100dvh - 2 * var(--range-picker-window-gap));
|
|
93
|
+
padding: var(--range-picker-padding);
|
|
94
|
+
border: 1px solid var(--range-picker-border-color);
|
|
95
|
+
border-radius: var(--range-picker-radius);
|
|
96
|
+
background: var(--range-picker-background);
|
|
97
|
+
box-shadow: var(--range-picker-shadow);
|
|
98
|
+
color: var(--range-picker-text-color);
|
|
99
|
+
font-size: var(--range-picker-font-size);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.range-picker-panel {
|
|
103
|
+
display: grid;
|
|
104
|
+
grid-template-columns: 12rem auto;
|
|
105
|
+
gap: 0 1.5rem;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.range-picker-presets {
|
|
109
|
+
display: grid;
|
|
110
|
+
align-content: start;
|
|
111
|
+
gap: 2px;
|
|
112
|
+
padding-inline-end: 1.25rem;
|
|
113
|
+
border-inline-end: 1px solid var(--range-picker-rule-color, var(--range-picker-border-color));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.range-picker-preset {
|
|
117
|
+
position: relative;
|
|
118
|
+
display: flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
gap: 0.625rem;
|
|
121
|
+
min-block-size: var(--range-picker-preset-height);
|
|
122
|
+
margin: 0;
|
|
123
|
+
padding-inline: 0.75rem;
|
|
124
|
+
border-radius: var(--range-picker-control-radius);
|
|
125
|
+
color: var(--range-picker-preset-color, var(--range-picker-muted-color));
|
|
126
|
+
font-weight: 500;
|
|
127
|
+
white-space: nowrap;
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.range-picker-preset:hover {
|
|
132
|
+
background: var(--range-picker-preset-hover-background, var(--range-picker-hover-background));
|
|
133
|
+
color: var(--range-picker-preset-hover-color, var(--range-picker-text-color));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.range-picker-preset input {
|
|
137
|
+
position: absolute;
|
|
138
|
+
opacity: 0;
|
|
139
|
+
pointer-events: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.range-picker-preset:has(:focus-visible) {
|
|
143
|
+
outline: 2px solid var(--range-picker-accent-color);
|
|
144
|
+
outline-offset: -2px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
* The picked preset; while only the start day is picked, Custom range, which the calendar is making, though the checked
|
|
149
|
+
* radio stays the range the form sends.
|
|
150
|
+
*/
|
|
151
|
+
[data-range-picker]:not([data-range-state="pending"]) .range-picker-preset:has(:checked),
|
|
152
|
+
[data-range-picker][data-range-state="pending"] .range-picker-preset:has([data-range-custom]) {
|
|
153
|
+
background: var(--range-picker-selected-background);
|
|
154
|
+
color: var(--range-picker-accent-color);
|
|
155
|
+
font-weight: 600;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/*
|
|
159
|
+
* Cally's parts, styled from outside: square ends joined by a tinted band, today in bold, and focus an outline only
|
|
160
|
+
* (its accent, which fills a focused day, made transparent).
|
|
161
|
+
*/
|
|
162
|
+
[data-range-picker] calendar-range {
|
|
163
|
+
display: block;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
[data-range-picker] calendar-range::part(container) {
|
|
167
|
+
gap: 0.75rem;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
[data-range-picker] calendar-range::part(button) {
|
|
171
|
+
display: grid;
|
|
172
|
+
place-items: center;
|
|
173
|
+
inline-size: 2.25rem;
|
|
174
|
+
block-size: 2.25rem;
|
|
175
|
+
border: 1px solid var(--range-picker-control-border-color);
|
|
176
|
+
border-radius: var(--range-picker-control-radius);
|
|
177
|
+
background: var(--range-picker-background);
|
|
178
|
+
color: var(--range-picker-arrow-color, var(--range-picker-muted-color));
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
[data-range-picker] calendar-range::part(button):hover {
|
|
183
|
+
background: var(--range-picker-hover-background);
|
|
184
|
+
color: var(--range-picker-arrow-hover-color, var(--range-picker-text-color));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
[data-range-picker] calendar-range::part(button):focus-visible {
|
|
188
|
+
outline: 2px solid var(--range-picker-accent-color);
|
|
189
|
+
outline-offset: 2px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
[data-range-picker] calendar-range::part(disabled) {
|
|
193
|
+
opacity: 0.35;
|
|
194
|
+
cursor: default;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* Read out, not shown: the year select's label slot. */
|
|
198
|
+
[data-range-picker] calendar-select-year::part(label) {
|
|
199
|
+
position: absolute;
|
|
200
|
+
width: 1px;
|
|
201
|
+
height: 1px;
|
|
202
|
+
overflow: hidden;
|
|
203
|
+
clip-path: inset(50%);
|
|
204
|
+
white-space: nowrap;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
[data-range-picker] calendar-select-year::part(select) {
|
|
208
|
+
block-size: 2.25rem;
|
|
209
|
+
padding: 0 0.625rem;
|
|
210
|
+
border: 1px solid var(--range-picker-control-border-color);
|
|
211
|
+
border-radius: var(--range-picker-control-radius);
|
|
212
|
+
background: var(--range-picker-background);
|
|
213
|
+
color: var(--range-picker-text-color);
|
|
214
|
+
font: inherit;
|
|
215
|
+
font-size: 1rem;
|
|
216
|
+
font-weight: 600;
|
|
217
|
+
cursor: pointer;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
[data-range-picker] calendar-select-year::part(select):hover {
|
|
221
|
+
background: var(--range-picker-hover-background);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
[data-range-picker] calendar-select-year::part(select):focus-visible {
|
|
225
|
+
outline: 2px solid var(--range-picker-accent-color);
|
|
226
|
+
outline-offset: 2px;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
[data-range-picker] calendar-month {
|
|
230
|
+
--color-accent: transparent;
|
|
231
|
+
--color-text-on-accent: var(--range-picker-accent-color);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
[data-range-picker] calendar-month::part(heading) {
|
|
235
|
+
margin-bottom: 0.25rem;
|
|
236
|
+
color: var(--range-picker-text-color);
|
|
237
|
+
font-weight: 600;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
[data-range-picker] calendar-month::part(th) {
|
|
241
|
+
inline-size: var(--range-picker-day-size);
|
|
242
|
+
block-size: 1.75rem;
|
|
243
|
+
color: var(--range-picker-weekday-color, var(--range-picker-muted-color));
|
|
244
|
+
font-size: 0.75rem;
|
|
245
|
+
font-weight: 600;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
[data-range-picker] calendar-month::part(day) {
|
|
249
|
+
inline-size: var(--range-picker-day-size);
|
|
250
|
+
block-size: var(--range-picker-day-size);
|
|
251
|
+
border-radius: var(--range-picker-control-radius);
|
|
252
|
+
color: var(--range-picker-text-color);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
[data-range-picker] calendar-month::part(day):hover {
|
|
256
|
+
background: var(--range-picker-hover-background);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
[data-range-picker] calendar-month::part(day):focus-visible {
|
|
260
|
+
outline: 2px solid var(--range-picker-accent-color);
|
|
261
|
+
outline-offset: -2px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
[data-range-picker] calendar-month::part(today) {
|
|
265
|
+
color: var(--range-picker-accent-color);
|
|
266
|
+
font-weight: 700;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
[data-range-picker] calendar-month::part(range-inner) {
|
|
270
|
+
border-radius: 0;
|
|
271
|
+
background: var(--range-picker-band-background, var(--range-picker-selected-background));
|
|
272
|
+
color: var(--range-picker-band-color);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
[data-range-picker] calendar-month::part(range-start) {
|
|
276
|
+
border-start-end-radius: 0;
|
|
277
|
+
border-end-end-radius: 0;
|
|
278
|
+
background: var(--range-picker-accent-color);
|
|
279
|
+
color: var(--range-picker-on-accent-color);
|
|
280
|
+
font-weight: 700;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
[data-range-picker] calendar-month::part(range-end) {
|
|
284
|
+
border-start-start-radius: 0;
|
|
285
|
+
border-end-start-radius: 0;
|
|
286
|
+
background: var(--range-picker-accent-color);
|
|
287
|
+
color: var(--range-picker-on-accent-color);
|
|
288
|
+
font-weight: 700;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
[data-range-picker] calendar-month::part(range-start range-end) {
|
|
292
|
+
border-radius: var(--range-picker-control-radius);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/*
|
|
296
|
+
* A picked day keeps its own ground under the pointer: the day's hover, a pseudo-class heavier than a part, would lay
|
|
297
|
+
* the hover tint under the ends' text. A disabled picked day's rules below still win.
|
|
298
|
+
*/
|
|
299
|
+
[data-range-picker] calendar-month::part(range-inner):hover {
|
|
300
|
+
background: var(--range-picker-band-background, var(--range-picker-selected-background));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
[data-range-picker] calendar-month::part(range-start):hover,
|
|
304
|
+
[data-range-picker] calendar-month::part(range-end):hover {
|
|
305
|
+
background: var(--range-picker-accent-hover-color);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/*
|
|
309
|
+
* Out of the calendar's bounds: Cally disables those days, with no part of their own. Picked days before the first day
|
|
310
|
+
* (a preset wholly before it keeps its own days) are a grey range.
|
|
311
|
+
*/
|
|
312
|
+
[data-range-picker] calendar-month::part(disabled) {
|
|
313
|
+
color: var(--range-picker-disabled-color);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
[data-range-picker] calendar-month::part(range-inner):disabled,
|
|
317
|
+
[data-range-picker] calendar-month::part(range-start):disabled,
|
|
318
|
+
[data-range-picker] calendar-month::part(range-end):disabled {
|
|
319
|
+
opacity: 1;
|
|
320
|
+
background: var(--range-picker-disabled-band-background, var(--range-picker-border-color));
|
|
321
|
+
color: var(--range-picker-disabled-band-color, var(--range-picker-muted-color));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
[data-range-picker] calendar-month::part(range-start):disabled,
|
|
325
|
+
[data-range-picker] calendar-month::part(range-end):disabled {
|
|
326
|
+
background: var(--range-picker-disabled-end-background, var(--range-picker-control-border-color));
|
|
327
|
+
color: var(--range-picker-disabled-end-color, var(--range-picker-text-color));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.range-picker-months {
|
|
331
|
+
display: flex;
|
|
332
|
+
flex-wrap: wrap;
|
|
333
|
+
justify-content: center;
|
|
334
|
+
gap: 1.5rem 2rem;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.range-picker-foot {
|
|
338
|
+
display: flex;
|
|
339
|
+
flex-wrap: wrap;
|
|
340
|
+
align-items: center;
|
|
341
|
+
justify-content: space-between;
|
|
342
|
+
gap: 0.75rem 1.25rem;
|
|
343
|
+
margin-top: 1.125rem;
|
|
344
|
+
padding-top: 1rem;
|
|
345
|
+
border-top: 1px solid var(--range-picker-rule-color, var(--range-picker-border-color));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.range-picker-summary {
|
|
349
|
+
margin: 0;
|
|
350
|
+
color: var(--range-picker-muted-color);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.range-picker-summary [data-range-name] {
|
|
354
|
+
color: var(--range-picker-text-color);
|
|
355
|
+
font-weight: 600;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.range-picker-pick-end {
|
|
359
|
+
color: var(--range-picker-accent-color);
|
|
360
|
+
font-weight: 600;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/* The presets as a row of chips over the calendar, where both don't fit beside it. */
|
|
364
|
+
@media (width < 56rem) {
|
|
365
|
+
.range-picker-panel {
|
|
366
|
+
grid-template-columns: minmax(0, 1fr);
|
|
367
|
+
gap: 1rem;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.range-picker-presets {
|
|
371
|
+
display: flex;
|
|
372
|
+
flex-wrap: wrap;
|
|
373
|
+
gap: 0.375rem;
|
|
374
|
+
padding: 0 0 1rem;
|
|
375
|
+
border: 0;
|
|
376
|
+
border-bottom: 1px solid var(--range-picker-rule-color, var(--range-picker-border-color));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
.range-picker-preset {
|
|
380
|
+
min-block-size: var(--range-picker-chip-height, var(--range-picker-preset-height));
|
|
381
|
+
border: 1px solid var(--range-picker-control-border-color);
|
|
382
|
+
border-radius: 999px;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/*
|
|
387
|
+
* Under its button on a wide window, opening toward the line's end, or flipped where that runs out of room. The gap at
|
|
388
|
+
* its far end keeps it off the window's edge: flip-inline swaps the inline margins with the side it opens toward, and
|
|
389
|
+
* where no placement fits the browser shifts the margin box, gap and all, back into the window.
|
|
390
|
+
*/
|
|
391
|
+
@media (width >= 64rem) {
|
|
392
|
+
@supports (position-area: bottom) {
|
|
393
|
+
[data-range-picker] {
|
|
394
|
+
inset: auto;
|
|
395
|
+
margin-block: var(--range-picker-offset);
|
|
396
|
+
margin-inline: 0 var(--range-picker-window-gap);
|
|
397
|
+
position-anchor: --range-picker;
|
|
398
|
+
position-area: bottom span-right;
|
|
399
|
+
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 by default: a short window
|
|
401
|
+
scrolls it inside, so its Set button stays reachable. */
|
|
402
|
+
max-height: var(--range-picker-anchored-max-height, calc(100% - 2 * var(--range-picker-offset)));
|
|
403
|
+
position-try-order: var(--range-picker-position-try-order);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
[data-range-picker]:dir(rtl) {
|
|
407
|
+
position-area: bottom span-left;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
package/src/range-picker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'cally';
|
|
2
|
-
import {closestTo, once} from './helpers.js';
|
|
2
|
+
import {closestTo, isRadio, once} from './helpers.js';
|
|
3
3
|
|
|
4
4
|
const PICKER = '[data-range-picker]';
|
|
5
5
|
const CALENDAR = 'calendar-range';
|
|
@@ -38,10 +38,6 @@ function isCalendar(element) {
|
|
|
38
38
|
return element.localName === CALENDAR;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function isRadio(element) {
|
|
42
|
-
return element instanceof HTMLInputElement && element.type === 'radio';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
41
|
function pickRange(event) {
|
|
46
42
|
const picker = closestTo(event, PICKER);
|
|
47
43
|
|
package/src/steps.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {closestTo} from './helpers.js';
|
|
2
|
+
|
|
3
|
+
const STEPPER = '[data-steps]';
|
|
4
|
+
const STEP = '[data-step]';
|
|
5
|
+
const FIELDS = 'input, select, textarea';
|
|
6
|
+
const HEADING = 'h1, h2, h3, h4, h5, h6';
|
|
7
|
+
const BACK = '[data-step-back]';
|
|
8
|
+
const NEXT = '[data-step-next]';
|
|
9
|
+
const SUBMIT = '[data-step-submit]';
|
|
10
|
+
const MARK_STATE = 'data-step-state';
|
|
11
|
+
|
|
12
|
+
/** Steps are numbered from 1, in the order they come. */
|
|
13
|
+
const FIRST_STEP = 1;
|
|
14
|
+
|
|
15
|
+
/** The values of data-step-state on a progress mark: the steps behind are done, the one showing is current. */
|
|
16
|
+
const MarkState = Object.freeze({done: 'done', current: 'current'});
|
|
17
|
+
|
|
18
|
+
/** Listens for the steppers' buttons and Enter, and shows each stepper on the page at the step it opens at. */
|
|
19
|
+
export function installSteps() {
|
|
20
|
+
document.addEventListener('click', stepOnClick);
|
|
21
|
+
document.addEventListener('keydown', stepOnEnter);
|
|
22
|
+
|
|
23
|
+
for (const stepper of document.querySelectorAll(STEPPER)) {
|
|
24
|
+
openStepper(stepper);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// preventDefault(): a control that is a submit button moves the steps without sending the form.
|
|
29
|
+
function stepOnClick(event) {
|
|
30
|
+
const control = closestTo(event, `${BACK}, ${NEXT}, ${SUBMIT}`);
|
|
31
|
+
const stepper = control?.closest(STEPPER);
|
|
32
|
+
|
|
33
|
+
if (!stepper || event.defaultPrevented) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
|
|
39
|
+
if (control.matches(BACK)) {
|
|
40
|
+
back(stepper);
|
|
41
|
+
} else if (control.matches(NEXT)) {
|
|
42
|
+
advance(stepper);
|
|
43
|
+
} else {
|
|
44
|
+
submit(stepper);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Enter in a field moves on, as Next does: the form's own submit would skip the steps' checks.
|
|
49
|
+
function stepOnEnter(event) {
|
|
50
|
+
const field = event.target;
|
|
51
|
+
const stepper = field instanceof HTMLInputElement ? field.closest(STEP)?.closest(STEPPER) : null;
|
|
52
|
+
|
|
53
|
+
if (event.key !== 'Enter' || event.isComposing || event.defaultPrevented || !stepper) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
advance(stepper);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 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 data-open-at-step, or
|
|
64
|
+
* shut at the step it shows.
|
|
65
|
+
*/
|
|
66
|
+
function openStepper(stepper) {
|
|
67
|
+
const opening = openingStepOf(stepper);
|
|
68
|
+
|
|
69
|
+
show(stepper, opening ?? currentStepOf(stepper));
|
|
70
|
+
|
|
71
|
+
if (opening !== null && stepper instanceof HTMLDialogElement && !stepper.open) {
|
|
72
|
+
stepper.showModal();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function openingStepOf(stepper) {
|
|
77
|
+
const fields = fieldsOf(stepper);
|
|
78
|
+
|
|
79
|
+
if (fields.some(isRefused)) {
|
|
80
|
+
return stepOf(fields.find((field) => isRefused(field) || !field.checkValidity()));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const asked = Number(stepper.dataset.openAtStep);
|
|
84
|
+
|
|
85
|
+
return sectionOf(stepper, asked) ? asked : null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A field the server refused: aria-invalid="true" beside its message. */
|
|
89
|
+
function isRefused(field) {
|
|
90
|
+
return field.getAttribute('aria-invalid') === 'true';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function back(stepper) {
|
|
94
|
+
const step = currentStepOf(stepper);
|
|
95
|
+
|
|
96
|
+
if (step > FIRST_STEP) {
|
|
97
|
+
moveTo(stepper, step - 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Moves on once the step's fields pass, or submits from the last step. */
|
|
102
|
+
function advance(stepper) {
|
|
103
|
+
const step = currentStepOf(stepper);
|
|
104
|
+
|
|
105
|
+
if (isLast(stepper, step)) {
|
|
106
|
+
submit(stepper);
|
|
107
|
+
} else if (fieldsOf(sectionOf(stepper, step)).every((field) => field.reportValidity())) {
|
|
108
|
+
moveTo(stepper, step + 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// An empty field on another step would block the submit with nothing on screen to say why: show its step instead.
|
|
113
|
+
function submit(stepper) {
|
|
114
|
+
const invalid = fieldsOf(stepper).find((field) => !field.checkValidity());
|
|
115
|
+
|
|
116
|
+
if (invalid) {
|
|
117
|
+
show(stepper, stepOf(invalid));
|
|
118
|
+
invalid.reportValidity();
|
|
119
|
+
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
stepper.querySelector(STEP)?.closest('form')?.requestSubmit();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// To the new step's heading, so a screen reader starts where the step does.
|
|
127
|
+
function moveTo(stepper, step) {
|
|
128
|
+
show(stepper, step);
|
|
129
|
+
sectionOf(stepper, step)?.querySelector(HEADING)?.focus();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function show(stepper, step) {
|
|
133
|
+
for (const section of stepsOf(stepper)) {
|
|
134
|
+
section.hidden = stepOf(section) !== step;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (const mark of stepper.querySelectorAll('[data-step-mark]')) {
|
|
138
|
+
const state = markStateOf(Number(mark.dataset.stepMark), step);
|
|
139
|
+
|
|
140
|
+
if (state === null) {
|
|
141
|
+
mark.removeAttribute(MARK_STATE);
|
|
142
|
+
} else {
|
|
143
|
+
mark.setAttribute(MARK_STATE, state);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (const label of stepper.querySelectorAll('[data-step-label]')) {
|
|
148
|
+
label.hidden = Number(label.dataset.stepLabel) !== step;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
hideAll(stepper, BACK, step === FIRST_STEP);
|
|
152
|
+
hideAll(stepper, NEXT, isLast(stepper, step));
|
|
153
|
+
hideAll(stepper, SUBMIT, !isLast(stepper, step));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function markStateOf(mark, step) {
|
|
157
|
+
if (mark < step) {
|
|
158
|
+
return MarkState.done;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return mark === step ? MarkState.current : null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function hideAll(stepper, selector, hidden) {
|
|
165
|
+
for (const element of stepper.querySelectorAll(selector)) {
|
|
166
|
+
element.hidden = hidden;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function stepsOf(stepper) {
|
|
171
|
+
return [...stepper.querySelectorAll(STEP)];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function sectionOf(stepper, step) {
|
|
175
|
+
return stepsOf(stepper).find((section) => stepOf(section) === step);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The step a section or a field belongs to. */
|
|
179
|
+
function stepOf(element) {
|
|
180
|
+
return Number(element.closest(STEP).dataset.step);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The step showing; the first when none does. */
|
|
184
|
+
function currentStepOf(stepper) {
|
|
185
|
+
const showing = stepsOf(stepper).find((section) => !section.hidden);
|
|
186
|
+
|
|
187
|
+
return showing ? stepOf(showing) : FIRST_STEP;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function isLast(stepper, step) {
|
|
191
|
+
return step >= stepsOf(stepper).length;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The fields of a step, or of every step in a stepper. */
|
|
195
|
+
function fieldsOf(element) {
|
|
196
|
+
return [...element.querySelectorAll(FIELDS)].filter((field) => field.closest(STEP));
|
|
197
|
+
}
|