zidan-select 2.0.1 → 2.1.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 CHANGED
@@ -19,6 +19,14 @@ two separate stylesheets.
19
19
  - **5 select layouts** `classic-clean · floating-label · soft-pill · bordered-brutalist · glass-elevated`.
20
20
  - **Field layouts** `stacked · inline · compact · floating · outlined · card`.
21
21
  - **Framework adapters** standalone, Bootstrap 5, Tailwind CSS, Bulma, Foundation.
22
+ - **Input add-ons (2.1)** — opt-in icons for any input type, a − / + number stepper in three
23
+ modes, phone formatting (national / international / E.164, caret-safe), rich range skins
24
+ with ticks/bubble/formatters, weekend/date rules and a full upload pipeline.
25
+ - **More skins** — checkbox `default · switch · card · button · minimal`; five switch styles
26
+ (`ios · material · square · labeled · icon`); radio `stacked · inline · card · button · tile`
27
+ with click-to-deselect; file `dropzone · button · avatar · gallery · compact`.
28
+ - **Upload API** — `simulateUpload`, custom `upload()` handler, XHR `uploadUrl`, progress,
29
+ cancel, retry, `getUploadState()`, per-file `renderFile` hook.
22
30
  - WAI-ARIA labels, focus management, keyboard support throughout, `prefers-reduced-motion`.
23
31
 
24
32
  ---
@@ -69,7 +77,8 @@ limitations and migration notes: **[`docs/comparison.md`](docs/comparison.md)**.
69
77
  10. [React, Next.js, Vue, Angular](#react-nextjs-vue-angular)
70
78
  11. [Build & publish](#build--publish)
71
79
  12. [Browser support](#browser-support)
72
- 13. [Migrating from 1.x](#migrating-from-1x)
80
+ 13. [What's new in 2.1](#whats-new-in-21)
81
+ 14. [Migrating from 1.x](#migrating-from-1x)
73
82
 
74
83
  ---
75
84
 
@@ -196,6 +205,38 @@ Windows/macOS keyboard behaviour, grouping, search and all select features live
196
205
  The mixed state paints a bar and clears as soon as the user clicks, exactly like a native
197
206
  checkbox.
198
207
 
208
+ ### Checkbox, switch & radio — extra skins
209
+
210
+ ```html
211
+ <!-- filter-style pill and dense minimal row -->
212
+ <label><input type="checkbox" data-zidan="checkbox" data-zidan-variant="button" data-zidan-label="Email"> Email</label>
213
+ <label><input type="checkbox" data-zidan="checkbox" data-zidan-variant="minimal" data-zidan-label="Compact row"> Compact row</label>
214
+
215
+ <!-- five switch skins -->
216
+ <label><input type="checkbox" data-zidan="checkbox" data-zidan-variant="switch"
217
+ data-zidan-switch-style="ios" data-zidan-label="iOS"> iOS</label>
218
+ <label><input type="checkbox" data-zidan="checkbox" data-zidan-variant="switch"
219
+ data-zidan-switch-style="labeled"
220
+ data-zidan-on-label="YES" data-zidan-off-label="NO"> Labeled</label>
221
+
222
+ <!-- pill radios and description tiles, click-to-clear -->
223
+ <fieldset data-zidan="radio-group" data-zidan-variant="button">
224
+ <legend>View</legend>
225
+ <label><input type="radio" name="view" value="day" checked> Day</label>
226
+ <label><input type="radio" name="view" value="week"> Week</label>
227
+ </fieldset>
228
+ <fieldset data-zidan="radio-group" data-zidan-variant="tile" data-zidan-deselectable="true">
229
+ <legend>Workspace</legend>
230
+ <label><input type="radio" name="workspace" value="design"
231
+ data-zidan-description="Boards, docs and feedback."> Design</label>
232
+ <label><input type="radio" name="workspace" value="build"
233
+ data-zidan-description="Repos, pipelines and previews."> Build</label>
234
+ </fieldset>
235
+ ```
236
+
237
+ `data-zidan-description` adds a second line to card/tile/button/minimal labels.
238
+ `data-zidan-deselectable="true"` lets a click on the checked radio clear the group.
239
+
199
240
  ### Radio groups
200
241
 
201
242
  ```html
@@ -206,23 +247,47 @@ checkbox.
206
247
  </fieldset>
207
248
  ```
208
249
 
209
- Variants: `stacked`, `inline`, `card`. Radios share a native `name`, so arrow keys, Home/End
210
- and Space keep browser semantics; the wrapper adds `role="radiogroup"` when missing.
250
+ Variants: `stacked`, `inline`, `card`, `button`, `tile`. Radios share a native `name`, so arrow
251
+ keys, Home/End and Space keep browser semantics; the wrapper adds `role="radiogroup"` when missing.
211
252
 
212
- ### File upload
253
+ ### File upload — variants, progress and the upload API
213
254
 
214
255
  ```html
215
- <input type="file" name="docs" multiple accept="image/*,.pdf"
216
- data-zidan="file"
217
- data-zidan-max-files="3"
218
- data-zidan-max-size="1048576"
256
+ <!-- drop target -->
257
+ <input type="file" name="docs" multiple accept="image/*,.pdf" data-zidan="file"
258
+ data-zidan-max-files="3" data-zidan-max-size="1048576"
219
259
  data-zidan-title="Drop documents here">
260
+
261
+ <!-- other designs -->
262
+ <input type="file" data-zidan="file" data-zidan-file-variant="button" data-zidan-upload-icon="document">
263
+ <input type="file" accept="image/*" data-zidan="file" data-zidan-file-variant="avatar">
264
+ <input type="file" multiple accept="image/*" data-zidan="file" data-zidan-file-variant="gallery">
265
+ <input type="file" data-zidan="file" data-zidan-file-variant="compact"
266
+ data-zidan-show-file-meta="false">
267
+
268
+ <!-- simulated progress (no network) -->
269
+ <input type="file" multiple data-zidan="file" data-zidan-simulate-upload="true"
270
+ data-zidan-simulate-duration="1800">
220
271
  ```
221
272
 
273
+ - Variants: `dropzone`, `button`, `avatar`, `gallery`, `compact`.
222
274
  - Native `input.files` is the source of truth; removing a file rebuilds it with `DataTransfer`.
223
- - Drag & drop, click to pick, thumbnails for images, extension badges otherwise.
224
275
  - `maxFiles`, `maxSize` (bytes) / `maxSizeMB`, `accept` are validated with a live status message.
225
- - `required` works: an empty file input fails native validation as usual.
276
+ - Real uploads: set `data-zidan-upload-url` (XHR multipart) or pass `upload(context)` in JS.
277
+ - Progress, cancel, retry, `getUploadState()`, `renderFile(item, info)` and `zidan:upload-*`
278
+ events are all available; files stay put during `simulateUpload`.
279
+
280
+ ```js
281
+ zidanField('#files', {
282
+ upload(context) {
283
+ // context: { file, field, formData, signal, onProgress, complete, fail }
284
+ fetch('/upload', { method: 'POST', body: context.formData, signal: context.signal })
285
+ .then(res => res.ok ? res.json() : Promise.reject(res.status))
286
+ .then(context.complete)
287
+ .catch(context.fail);
288
+ }
289
+ });
290
+ ```
226
291
 
227
292
  ### Text inputs & textarea
228
293
 
@@ -236,12 +301,91 @@ and Space keep browser semantics; the wrapper adds `role="radiogroup"` when miss
236
301
  data-zidan-counter="140" data-zidan-clear></textarea>
237
302
 
238
303
  <input type="text" data-zidan="input" data-zidan-layout="floating" data-zidan-label="Company">
239
- <input type="range" data-zidan="input" data-zidan-label="Budget" data-zidan-output="#budget-out">
240
304
  ```
241
305
 
242
306
  Supported types: `text`, `email`, `password`, `number`, `tel`, `url`, `search`, `date`,
243
307
  `time`, `datetime-local`, `month`, `week`, `range`, `color`, plus `<textarea>`.
244
- Range inputs can mirror their value into any element with `data-zidan-output`.
308
+
309
+ ### Input icons
310
+
311
+ ```html
312
+ <!-- automatic icon for the input type -->
313
+ <input type="email" data-zidan="input" data-zidan-auto-icon="true" data-zidan-clear>
314
+
315
+ <!-- choose an icon and the side; clickable ones emit zidan:icon-click -->
316
+ <input type="url" data-zidan="input" data-zidan-icon="link"
317
+ data-zidan-icon-position="right" data-zidan-icon-clickable="true"
318
+ data-zidan-icon-label="Open website">
319
+ ```
320
+
321
+ ```js
322
+ ZidanForm.registerIcon('sparkle', '<path d="M12 3l1.9 5.3L19 10l-5.1 1.7L12 17Z"/>');
323
+ ```
324
+
325
+ Works for `text`, `email`, `password`, `number`, `tel`, `url`, `search`, all date/time types
326
+ and `range`. `data-zidan-validation-icon="true"` adds check/alert glyphs.
327
+
328
+ ### Number stepper
329
+
330
+ ```html
331
+ <input type="number" min="0" max="10" value="3" data-zidan="input"
332
+ data-zidan-stepper="stacked">
333
+ <input type="number" min="0" max="99" data-zidan="input" data-zidan-stepper="split">
334
+ <input type="number" step="0.5" data-zidan="input" data-zidan-stepper="inline"
335
+ data-zidan-stepper-position="left" data-zidan-stepper-long-press="true">
336
+ ```
337
+
338
+ Modes: `stacked`, `split`, `inline`. Press and hold repeats (configurable delay/interval);
339
+ min, max and step are respected. Methods: `stepUp()`, `stepDown()`, `setStepper()`.
340
+
341
+ ### Phone formatting
342
+
343
+ ```html
344
+ <input type="tel" data-zidan="input" data-zidan-phone="true"
345
+ data-zidan-phone-country="GB" data-zidan-phone-format="international">
346
+ <input type="tel" data-zidan="input" data-zidan-phone="true"
347
+ data-zidan-phone-country="US" data-zidan-phone-format="national"
348
+ data-zidan-phone-country-select="false">
349
+ ```
350
+
351
+ Three styles per country: `national`, `international`, `e164`. The optional country `<select>`
352
+ changes both the dial code and the mask; typing re-formats around the caret. Static helpers:
353
+ `ZidanForm.formatPhone(value, 'US', 'e164')` and `ZidanForm.detectPhoneCountry(value)`.
354
+
355
+ ### Range inputs
356
+
357
+ ```html
358
+ <input type="range" min="0" max="1000" step="50" value="400"
359
+ data-zidan="input" data-zidan-range-variant="minimal"
360
+ data-zidan-range-bubble="true" data-zidan-range-minmax="false"
361
+ data-zidan-output="#budget-out">
362
+ ```
363
+
364
+ ```js
365
+ zidanField('#price', {
366
+ rangeTicks: [0, 250, 500, 750, 1000],
367
+ rangeTickLabels: true,
368
+ rangeLabels: { 0: 'Free', 1000: 'Top' },
369
+ rangeFormat: value => '€' + Number(value).toLocaleString('en-US')
370
+ });
371
+ ```
372
+
373
+ Variants: `default`, `gradient`, `stepped`, `minimal`. Bubble, min/max scale, ticks and labels
374
+ can each be toggled; `rangeFormat` accepts a template (`{value}`, `{min}`, `{max}`) or a function.
375
+
376
+ ### Date & time pickers
377
+
378
+ ```html
379
+ <input type="date" data-zidan="input" data-zidan-icon="calendar"
380
+ data-zidan-icon-position="right" data-zidan-disable-weekends="true">
381
+
382
+ <input type="datetime-local" data-zidan="input" data-zidan-picker-button="true"
383
+ data-zidan-picker-icon="calendar">
384
+ ```
385
+
386
+ `data-zidan-disable-weekends` and `data-zidan-disabled-dates` (ISO list or JS function) are
387
+ written into native validity, so `checkValidity()` blocks them. Change the picker icon and side
388
+ per field; clickable icons call `input.showPicker()` when available.
245
389
 
246
390
  ---
247
391
 
@@ -251,7 +395,7 @@ Range inputs can mirror their value into any element with `data-zidan-output`.
251
395
 
252
396
  | Option | Data attribute | Type | Default | Description |
253
397
  | --- | --- | --- | --- | --- |
254
- | `variant` | `data-zidan-variant` | string | `default` | Checkbox `default/switch/card`; radio `stacked/inline/card`. |
398
+ | `variant` | `data-zidan-variant` | string | `default` | Checkbox `default/switch/card/button/minimal`; radio `stacked/inline/card/button/tile`; file `dropzone/button/avatar/gallery/compact`; range `default/gradient/stepped/minimal`. |
255
399
  | `layout` | `data-zidan-layout` | string | `stacked` | `stacked`, `inline`, `compact`, `floating`, `outlined`, `card`. |
256
400
  | `theme` | `data-zidan-theme` | string | `default` | `default`, `modern`, `minimal`, `dark`, `glass`. |
257
401
  | `framework` | `data-zidan-framework` | string | `none` | `none`, `bootstrap`, `tailwind`, `bulma`, `foundation`. |
@@ -264,8 +408,26 @@ Range inputs can mirror their value into any element with `data-zidan-output`.
264
408
  | `prefix` / `suffix` | `data-zidan-prefix` / `-suffix` | string | — | Static adornments. |
265
409
  | `counter` | `data-zidan-counter` | number | `maxlength` | Character limit for the counter; overrides `maxlength`. |
266
410
  | `output` | `data-zidan-output` | selector | — | Range value is mirrored into this element. |
411
+ | `autoIcon` / `icon` | `data-zidan-auto-icon` / `data-zidan-icon` | boolean / string | `false` / — | Type-based or custom input icon (any registered name). |
412
+ | `iconPosition` / `iconClickable` | `data-zidan-icon-position` / `-icon-clickable` | `left`\|`right` / boolean | `left` / `false` | Side and behaviour of the icon. |
413
+ | `validationIcon` | `data-zidan-validation-icon` | boolean | `false` | Check/alert glyphs tied to validation state. |
414
+ | `stepper` | `data-zidan-stepper` | boolean \| `stacked`\|`split`\|`inline` | `false` | Number − / + controls. |
415
+ | `stepperPosition` / `stepperLongPress` | `data-zidan-stepper-position` / `-long-press` | `left`\|`right` / boolean | `right` / `true` | Inline side and hold-to-repeat. |
416
+ | `stepperDelay` / `stepperInterval` | `data-zidan-stepper-delay` / `-interval` | number | `420` / `90` | Repeat timing in ms. |
417
+ | `phone` / `phoneCountry` / `phoneFormat` | `data-zidan-phone` / `-phone-country` / `-phone-format` | boolean / ISO-2 / `national`\|`international`\|`e164` | — / `US` / `national` | Phone formatting and validation. |
418
+ | `phoneCountrySelect` / `phoneCountries` | `data-zidan-phone-country-select` / `-phone-countries` | boolean / list | `true` / common set | Country selector. |
419
+ | `rangeVariant` / `rangeBubble` / `rangeMinMax` | `data-zidan-range-variant` / `-range-bubble` / `-range-minmax` | string / boolean / boolean | `default` / `true` / `true` | Range skin and chrome. |
420
+ | `rangeTicks` / `rangeTickLabels` / `rangeLabels` / `rangeFormat` | `data-zidan-range-ticks` / `-range-tick-labels` / — / `-range-format` | number\|array / boolean / object / string\|function | `0` / `false` / — / — | Ticks, labels and value formatter. |
421
+ | `pickerButton` / `pickerIcon` | `data-zidan-picker-button` / `-picker-icon` | boolean / string | `false` / per type | Date/time picker button and icon. |
422
+ | `disableWeekends` / `disabledDates` | `data-zidan-disable-weekends` / `-disabled-dates` | boolean / list\|function | `false` / — | Date rules written into native validity. |
267
423
  | `title` | `data-zidan-title` | string | `Choose a file` | File dropzone title. |
268
424
  | `dropHint` | `data-zidan-drop-hint` | string | — | File dropzone subtitle. |
425
+ | `fileVariant` / `uploadIcon` | `data-zidan-file-variant` / `-upload-icon` | string | `dropzone` / `upload` | Upload design and icon. |
426
+ | `upload` / `uploadHandler` / `uploadUrl` | `data-zidan-upload-url` | function / string | — | Custom uploader or XHR endpoint. |
427
+ | `uploadField` / `uploadData` / `uploadHeaders` | `data-zidan-upload-field` | string / object\|function / object\|function | `file` / — / — | FormData and request extras. |
428
+ | `simulateUpload` / `simulateDuration` / `autoUpload` | `data-zidan-simulate-upload` / `-simulate-duration` / `-auto-upload` | boolean / number / boolean | `false` / `900` / `true` | Visual upload mode and timing. |
429
+ | `showFileMeta` / `showPreview` / `replaceTitle` | `data-zidan-show-file-meta` / `-preview` | boolean / boolean / string | `true` / `true` / `Change image` | Per-file rows and avatar preview. |
430
+ | `renderFile` | — | function | — | `(itemEl, { file, index, state, field })` hook. |
269
431
  | `maxFiles` | `data-zidan-max-files` | number | — | File count limit. |
270
432
  | `maxSize` | `data-zidan-max-size` | number | — | Bytes per file. |
271
433
  | `maxSizeMB` | `data-zidan-max-size-mb` | number | — | Per-file limit in megabytes; `2` = 2 MB, decimals allowed. Ignored when `maxSize` is set. |
@@ -313,15 +475,32 @@ Per-select instance: `open()`, `close()`, `toggle()`, `isOpen()`, `getValue()`,
313
475
  Per-field instance: `getValue()`, `setValue(v)`, `update()`, `refresh()`,
314
476
  `setValidation(state)`, `getValidation()`, `setTheme()`, `setFramework()`, `setLayout()`,
315
477
  `destroy()`, plus `setIndeterminate()`/`isChecked()` (checkbox), `setValue()` (radio group),
316
- and `clear()` (file).
478
+ `stepUp()`/`stepDown()`/`setStepper()` (number), `getPhoneCountry()`/`setPhoneCountry()`/
479
+ `setPhoneFormat()`/`formatPhone()` (phone), `openPicker()`/`showPicker()` (date/time),
480
+ and `getFiles()`/`getUploadState()`/`addFiles()`/`replaceFiles()`/`removeFile()`/`clear()`/
481
+ `setVariant()`/`setUploader()`/`uploadAll()`/`uploadFile()`/`cancelUpload()`/`cancelAll()`/
482
+ `retryUpload()` (file).
317
483
 
318
- Events bubble from the wrapper as `zidan:change`, `zidan:validation`, `zidan:init`,
319
- `zidan:destroy`, `zidan:error`:
484
+ Events bubble from the wrapper:
485
+
486
+ | Event | Detail |
487
+ | --- | --- |
488
+ | `zidan:change` | `{ instance, kind, value }`, `{ checked }` or `{ files }` |
489
+ | `zidan:validation` | `{ instance, state, message? }` |
490
+ | `zidan:step` | `{ instance, value, direction }` (number stepper) |
491
+ | `zidan:phone-country` / `zidan:phone-format` | `{ country }` / `{ format }` |
492
+ | `zidan:icon-click` | `{ instance, icon, position }` |
493
+ | `zidan:picker` | `{ instance, type }` |
494
+ | `zidan:upload-start` / `-progress` / `-success` / `-error` / `-cancel` | file state, name, progress/result/message |
495
+ | `zidan:remove` / `zidan:clear` / `zidan:init` / `zidan:destroy` / `zidan:error` | lifecycle |
320
496
 
321
497
  ```js
322
498
  document.addEventListener('zidan:change', event => {
323
499
  console.log(event.detail.kind, event.detail.value || event.detail.checked);
324
500
  });
501
+ document.addEventListener('zidan:upload-progress', event => {
502
+ console.log(event.detail.name, event.detail.progress + '%');
503
+ });
325
504
  ```
326
505
 
327
506
  ---
@@ -563,9 +742,34 @@ Full checklist, folder tree and release automation notes: [`docs/build.md`](docs
563
742
 
564
743
  ---
565
744
 
745
+ ## What's new in 2.1
746
+
747
+ - **Input icons** — `data-zidan-auto-icon`, `data-zidan-icon`, left/right placement,
748
+ clickable icons and `ZidanForm.registerIcon()` for custom artwork.
749
+ - **Number stepper** — stacked, split and inline − / + controls with hold-to-repeat,
750
+ min/max/step support and `stepUp()` / `stepDown()`.
751
+ - **Phone formatting** — country selector plus `national`, `international` and `e164` masks,
752
+ caret-safe while typing, with `setPhoneCountry()` / `setPhoneFormat()`.
753
+ - **Range skins** — `gradient`, `stepped`, `minimal`; bubble, min/max scale, tick arrays,
754
+ labels and string/function formatters.
755
+ - **More skins** — checkbox `button` / `minimal`; switch `ios/material/square/labeled/icon`
756
+ with YES/NO labels; radio `button` / `tile` with descriptions and deselect.
757
+ - **File variants & uploads** — `dropzone/button/avatar/gallery/compact`, progress, cancel,
758
+ retry, simulated uploads, XHR or custom `upload()` handlers, `getUploadState()`,
759
+ `renderFile` and `zidan:upload-*` events.
760
+ - **Date rules** — weekend and blocked-date rules now write into native validity, so
761
+ `form.checkValidity()` and third-party validators see them.
762
+ - **Docs & demo** — new option tables in [`docs/options.md`](docs/options.md), token list in
763
+ [`docs/theming.md`](docs/theming.md), validation rules in
764
+ [`docs/validation.md`](docs/validation.md), and a live event console on the demo page.
765
+
766
+ The 2.0 API is unchanged; every addition is opt-in.
767
+
768
+ ---
769
+
566
770
  ## Migrating from 1.x
567
771
 
568
- | 1.x | 2.0 |
772
+ | 1.x | 2.x |
569
773
  | --- | --- |
570
774
  | `ZidanSelect.js` | `zidan-form.js` (same select engine inside; `window.ZidanSelect` kept as alias) |
571
775
  | `ZidanSelect.mjs` | `zidan-form.mjs` |