zidan-select 0.0.0-stage → 2.0.2
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/LICENSE +21 -0
- package/README.md +581 -2
- package/dist/plugin-core.css +1073 -0
- package/dist/plugin-theme.css +1277 -0
- package/dist/zidan-form.cjs +2 -0
- package/dist/zidan-form.js +3047 -0
- package/dist/zidan-form.mjs +31 -0
- package/docs/build.md +145 -0
- package/docs/comparison.md +76 -0
- package/docs/frameworks.md +234 -0
- package/docs/index.html +76 -0
- package/docs/options.md +193 -0
- package/docs/theming.md +225 -0
- package/docs/validation.html +200 -0
- package/docs/validation.md +215 -0
- package/package.json +69 -4
- package/plugin-core.css +1073 -0
- package/plugin-theme.css +1277 -0
- package/zidan-form.js +3047 -0
- package/zidan-form.mjs +31 -0
package/docs/options.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Options & data attributes
|
|
2
|
+
|
|
3
|
+
Everything is opt-in. A control is enhanced only when it carries a `data-zidan*` attribute,
|
|
4
|
+
is matched by `initZidanSelects()` / `initZidanForms()`, or is passed to `zidanSelect()` /
|
|
5
|
+
`zidanField()`. `zidanField()` itself accepts any supported `<input>`/`<textarea>`, with or
|
|
6
|
+
without a `data-zidan*` attribute, which is how JS-only options are applied.
|
|
7
|
+
|
|
8
|
+
## Field options
|
|
9
|
+
|
|
10
|
+
Applies to `ZidanCheckbox`, `ZidanRadioGroup`, `ZidanFileUpload`, `ZidanTextField`.
|
|
11
|
+
|
|
12
|
+
| JS option | Data attribute | Type | Default | Notes |
|
|
13
|
+
| --- | --- | --- | --- | --- |
|
|
14
|
+
| `variant` | `data-zidan-variant` | string | `default` | Checkbox: `default`, `switch`, `card`. Radio: `stacked`, `inline`, `card`. |
|
|
15
|
+
| `layout` | `data-zidan-layout` | string | `stacked` | `stacked`, `inline`, `compact`, `floating`, `outlined`, `card`. |
|
|
16
|
+
| `theme` | `data-zidan-theme`, `data-zs-theme` | string | `default` | `default`, `modern`, `minimal`, `dark`, `glass`. Resolves element → ancestor → `<html>`. |
|
|
17
|
+
| `framework` | `data-zidan-framework`, `data-zs-framework` | string | `none` | `none`, `bootstrap`, `tailwind`, `bulma`, `foundation`, `vanilla`. |
|
|
18
|
+
| `label` | `data-zidan-label` | string | — | Used when the markup has no `<label>`; a generated label is `<label for>`. |
|
|
19
|
+
| `hint` | `data-zidan-hint` | string | — | Rendered under the control and linked via `aria-describedby`. |
|
|
20
|
+
| `validation` | `data-zidan-validation` | `valid` \| `invalid` | — | Initial state; later states come from validity or `setValidation()`. |
|
|
21
|
+
| `alwaysValidate` | — | boolean | `false` | Mark invalid as soon as native validity fails instead of on blur. |
|
|
22
|
+
| `indeterminate` | `data-zidan-indeterminate` | boolean | `false` | Checkbox starts mixed. |
|
|
23
|
+
| `clearable` | `data-zidan-clear` | boolean | `search` only | Clear button for text inputs and textarea. |
|
|
24
|
+
| `reveal` | `data-zidan-reveal` | boolean | `false` | Password show/hide toggle. |
|
|
25
|
+
| `prefix` | `data-zidan-prefix` | string | — | Static text before the input. |
|
|
26
|
+
| `suffix` | `data-zidan-suffix` | string | — | Static text after the input. |
|
|
27
|
+
| `counter` | `data-zidan-counter` | number | `maxlength` | Counter maximum; wins over the `maxlength` default. |
|
|
28
|
+
| `output` | `data-zidan-output` | selector | — | Range value is mirrored into this element. |
|
|
29
|
+
| `title` | `data-zidan-title` | string | `Choose a file` | Dropzone headline. |
|
|
30
|
+
| `dropHint` | `data-zidan-drop-hint` | string | — | Dropzone subtitle. |
|
|
31
|
+
| `accept` | native `accept` | string | — | Validated on top of the native picker filter and shown in the dropzone hint. |
|
|
32
|
+
| `maxFiles` | `data-zidan-max-files` | number | — | Extra files are trimmed and reported. |
|
|
33
|
+
| `maxSize` | `data-zidan-max-size` | number | — | Bytes per file. |
|
|
34
|
+
| `maxSizeMB` | `data-zidan-max-size-mb` | number | — | Megabytes per file; `2` = 2 MB, decimals allowed. Ignored when `maxSize` is set. |
|
|
35
|
+
| `labels` | — | object | — | Radio group: `{ value: 'Label' }` fallback labels. |
|
|
36
|
+
| `clearLabel` | — | string | `Clear all` / `Clear field` | Button text/aria-label. |
|
|
37
|
+
| `showPasswordLabel` | — | string | `Show` | Password toggle labels. |
|
|
38
|
+
| `hidePasswordLabel` | — | string | `Hide` | Password toggle labels. |
|
|
39
|
+
|
|
40
|
+
### Field callbacks
|
|
41
|
+
|
|
42
|
+
| Callback | Payload |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `onInit` | `{ instance, variant?, type? }` |
|
|
45
|
+
| `onChange` | `{ instance, value }` (text/radio), `{ instance, checked, value }` (checkbox), `{ instance, files }` (file) |
|
|
46
|
+
| `onValidation` | `{ instance, state }` where `state` is `valid`, `invalid` or `null` |
|
|
47
|
+
| `onRemove` | `{ instance, file }` |
|
|
48
|
+
|
|
49
|
+
DOM events with the same information: `zidan:init`, `zidan:change`, `zidan:validation`,
|
|
50
|
+
`zidan:remove`, `zidan:reveal`, `zidan:clear`, `zidan:destroy`, `zidan:error`.
|
|
51
|
+
|
|
52
|
+
## Select options
|
|
53
|
+
|
|
54
|
+
`ZidanSelect` keeps its full 1.x option set.
|
|
55
|
+
|
|
56
|
+
### Core
|
|
57
|
+
|
|
58
|
+
| Option | Data attribute | Default | Description |
|
|
59
|
+
| --- | --- | --- | --- |
|
|
60
|
+
| `mode` | `data-zidan-select`, `data-zidan-mode` | `select` | `select`, `combobox`, `tags`. |
|
|
61
|
+
| `layout` | `data-zidan-layout` | `classic-clean` | Five select layouts (see theming doc). |
|
|
62
|
+
| `themeFramework` | `data-zidan-framework` | `auto` | `auto`, `none`, `vanilla`, `bootstrap`, `tailwind`, `bulma`, `foundation`. |
|
|
63
|
+
| `theme` | `data-zidan-theme` | `default` | Colour preset. |
|
|
64
|
+
| `id` | — | generated | Root id prefix. |
|
|
65
|
+
| `name` | `data-zidan-name` | native name | Name for hidden mirror input in mount mode. |
|
|
66
|
+
| `disabled` | `data-zidan-disabled` | native | Mirrors the native `disabled`. |
|
|
67
|
+
| `required` | — | native | Mirrors native `required`. |
|
|
68
|
+
| `validation` | `data-zidan-validation` | `null` | `valid` \| `invalid`. |
|
|
69
|
+
| `scrollbar` | `data-zidan-scrollbar` | `default` | `default`, `thin`, `fancy`, `hover`, `hidden`. |
|
|
70
|
+
| `customClasses` | — | `{}` | Map of `root/control/input` → class names. |
|
|
71
|
+
|
|
72
|
+
### Data
|
|
73
|
+
|
|
74
|
+
| Option | Data attribute | Description |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `options` | — | Array of strings or `{value,label,disabled,group}`. |
|
|
77
|
+
| `suggestions` | — | Tags suggestions. |
|
|
78
|
+
| `value` | — | Initial value(s). |
|
|
79
|
+
| `label` | `data-zidan-label` | Floating label text. |
|
|
80
|
+
| `placeholder` | `data-zidan-placeholder` | Trigger placeholder. |
|
|
81
|
+
|
|
82
|
+
### Behaviour
|
|
83
|
+
|
|
84
|
+
| Option | Data attribute | Default | Description |
|
|
85
|
+
| --- | --- | --- | --- |
|
|
86
|
+
| `multiple` | `data-zidan-multiple` | from `multiple` | Multi-select. |
|
|
87
|
+
| `searchable` | `data-zidan-searchable` | `true` except plain select | Type-to-filter. |
|
|
88
|
+
| `clearable` | `data-zidan-clearable` | `false` | Clear button. |
|
|
89
|
+
| `closeOnSelect` | — | single: `true` | Close after choosing. |
|
|
90
|
+
| `maxDropdownHeight` | — | `280` | Listbox max height in px. |
|
|
91
|
+
| `noResultsText` | — | `No results found` | Empty search message. |
|
|
92
|
+
| `emptyText` | — | `No options` | Empty source message. |
|
|
93
|
+
| `loadingText` | — | `Searching…` | Async loading message. |
|
|
94
|
+
| `clearText` | — | `Clear selection` | Clear button label. |
|
|
95
|
+
|
|
96
|
+
### Combobox / async
|
|
97
|
+
|
|
98
|
+
| Option | Default | Description |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `fetchOptions(query, signal)` | — | Return a promise of items; an `AbortController` signal is provided. |
|
|
101
|
+
| `debounce` | `250` | Async debounce in ms. |
|
|
102
|
+
| `minChars` | `0` | Characters before fetching. |
|
|
103
|
+
| `allowFreeText` | tags only | Allow values not in the list. |
|
|
104
|
+
| `searchValues` | `true` | Match against values as well as labels. |
|
|
105
|
+
|
|
106
|
+
### Tags
|
|
107
|
+
|
|
108
|
+
| Option | Data attribute | Default |
|
|
109
|
+
| --- | --- | --- |
|
|
110
|
+
| `maxTags` | `data-zidan-max-tags` | `Infinity` |
|
|
111
|
+
| `minTagLength` | `data-zidan-min-tag-length` | `1` |
|
|
112
|
+
| `maxTagLength` | `data-zidan-max-tag-length` | `Infinity` |
|
|
113
|
+
| `caseSensitive` | `data-zidan-case-sensitive` | `false` |
|
|
114
|
+
| `allowFreeText` | `data-zidan-allow-free-text` | `true` |
|
|
115
|
+
| `delimiters` | — | `[',']` |
|
|
116
|
+
| `commitOnTab` / `commitOnBlur` | — | `false` |
|
|
117
|
+
| `valueDelimiter` | — | `,` |
|
|
118
|
+
|
|
119
|
+
### Rendering hooks
|
|
120
|
+
|
|
121
|
+
| Option | Signature |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `filterOption(item, query)` | return boolean |
|
|
124
|
+
| `renderOption(item, index)` | HTML string or element |
|
|
125
|
+
| `renderSelected(value)` | HTML string or element |
|
|
126
|
+
| `renderTag(tag)` | HTML string or element |
|
|
127
|
+
| `validateTag(tag)` | boolean or message string |
|
|
128
|
+
| `formatTag(tag)` | display string |
|
|
129
|
+
|
|
130
|
+
### Select callbacks
|
|
131
|
+
|
|
132
|
+
`onInit`, `onChange`, `onSelect`, `onOpen`, `onClose`, `onTagAdd`, `onTagRemove`, `onError`.
|
|
133
|
+
Every callback receives a single payload object with `instance` and the relevant value(s).
|
|
134
|
+
|
|
135
|
+
### DOM data attributes
|
|
136
|
+
|
|
137
|
+
`data-zidan-select`, `data-zidan-mode`, `data-zidan-layout`, `data-zidan-framework`,
|
|
138
|
+
`data-zidan-theme`, `data-zidan-placeholder`, `data-zidan-label`, `data-zidan-name`,
|
|
139
|
+
`data-zidan-multiple`, `data-zidan-searchable`, `data-zidan-clearable`, `data-zidan-disabled`,
|
|
140
|
+
`data-zidan-allow-free-text`, `data-zidan-max-tags`, `data-zidan-min-tag-length`,
|
|
141
|
+
`data-zidan-max-tag-length`, `data-zidan-case-sensitive`, `data-zidan-validation`,
|
|
142
|
+
`data-zidan-scrollbar`.
|
|
143
|
+
|
|
144
|
+
## Defaults
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
ZidanForm.themes // ['default','modern','minimal','dark','glass']
|
|
148
|
+
ZidanForm.frameworks // ['auto','none','vanilla','bootstrap','tailwind','bulma','foundation']
|
|
149
|
+
ZidanForm.fieldLayouts // ['stacked','inline','card','compact','floating','outlined']
|
|
150
|
+
ZidanSelect.layouts // five select layouts
|
|
151
|
+
ZidanSelect.scrollbars // ['default','thin','fancy','hover','hidden']
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`themes` and `fieldLayouts` are live arrays, so `ZidanForm.themes.push('brand')` registers a
|
|
155
|
+
custom preset that `theme` / `setTheme()` will accept (register before initialising fields).
|
|
156
|
+
|
|
157
|
+
`grid` is not a field layout value: add `class="zs-form-grid"` to the wrapper (and `zs-full`
|
|
158
|
+
to any field that should span the row) rather than putting it on a single field.
|
|
159
|
+
|
|
160
|
+
## Instance methods
|
|
161
|
+
|
|
162
|
+
### Fields
|
|
163
|
+
|
|
164
|
+
| Method | Description |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| `getValue()` | Text/textarea value, checked value, radio value or selected files. |
|
|
167
|
+
| `setValue(v)` | Writes to the native control and re-renders. |
|
|
168
|
+
| `update()` / `refresh()` | Re-read native state (checked, disabled, validity, value). |
|
|
169
|
+
| `setValidation('valid'\|'invalid'\|null)` | Mirrors state to classes and `aria-invalid`. |
|
|
170
|
+
| `getValidation()` | Current validation state. |
|
|
171
|
+
| `setTheme(name)`, `setFramework(name)`, `setLayout(name)` | Scoped restyling. |
|
|
172
|
+
| `destroy()` | Restores the original DOM and removes every listener. |
|
|
173
|
+
|
|
174
|
+
Checkbox adds `setIndeterminate(bool)` and `isChecked()`; file adds `clear()` and
|
|
175
|
+
`getFiles()`.
|
|
176
|
+
|
|
177
|
+
### Select
|
|
178
|
+
|
|
179
|
+
`open()`, `close()`, `toggle()`, `isOpen()`, `getValue()`, `setValue()`, `clear()`,
|
|
180
|
+
`setOptions(items)`, `addTag()`, `removeTag()`, `getTags()`, `enable()`, `disable()`,
|
|
181
|
+
`setLayout()`, `setFramework()`, `setScrollbar()`, `setValidation()`, `refresh()`,
|
|
182
|
+
`on(event, handler)`, `off(event, handler)`, `announce(message)`, `destroy()`.
|
|
183
|
+
|
|
184
|
+
## Events
|
|
185
|
+
|
|
186
|
+
| Event | Detail |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `zidan:init` | `{ instance, kind \| mode }` |
|
|
189
|
+
| `zidan:change` | `{ instance, value }`, `{ checked }`, `{ files }` |
|
|
190
|
+
| `zidan:validation` | `{ instance, state, message? }` |
|
|
191
|
+
| `zidan:remove` | `{ instance, file }` (file upload) |
|
|
192
|
+
| `zidan:destroy` | `{ instance }` |
|
|
193
|
+
| `zidan:error` | `{ error, callback, instance }` |
|
package/docs/theming.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Theming
|
|
2
|
+
|
|
3
|
+
`plugin-core.css` contains structure only: layout, positioning, the 1×1 px native-input
|
|
4
|
+
mechanism and visibility rules. Every colour, border, shadow and skin is in
|
|
5
|
+
`plugin-theme.css`, driven by `--zs-*` custom properties.
|
|
6
|
+
|
|
7
|
+
Load order:
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<link rel="stylesheet" href="plugin-core.css">
|
|
11
|
+
<link rel="stylesheet" href="plugin-theme.css">
|
|
12
|
+
<link rel="stylesheet" href="my-theme.css"> <!-- optional overrides -->
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Resolution order
|
|
16
|
+
|
|
17
|
+
| Level | Wins over |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `style="--zs-primary: …"` | everything |
|
|
20
|
+
| `data-zs-theme` / `data-zs-framework` on the control wrapper | ancestors |
|
|
21
|
+
| Wrapper (`form`, section) attributes | `<html>` |
|
|
22
|
+
| `<html data-zs-theme="dark" data-zs-framework="bootstrap">` | theme defaults |
|
|
23
|
+
|
|
24
|
+
Themes and frameworks resolve independently: you can combine `dark` + `bootstrap`.
|
|
25
|
+
|
|
26
|
+
## Presets
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<form data-zs-theme="dark">
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
| Preset | Character |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `default` | Neutral greys, indigo `#4f6bed`, 10px radius. |
|
|
35
|
+
| `modern` | Softer indigo, 12px radius, layered shadows. |
|
|
36
|
+
| `minimal` | Near-black borders, 4px radius, no shadows. |
|
|
37
|
+
| `dark` | `#161a23` surfaces, `#7c8cff` accent, light text, dark-native pickers. |
|
|
38
|
+
| `glass` | Translucent white, blurred surfaces, works over imagery. |
|
|
39
|
+
|
|
40
|
+
## Tokens
|
|
41
|
+
|
|
42
|
+
### Typography & geometry
|
|
43
|
+
|
|
44
|
+
| Token | Default |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `--zs-font-family` | `inherit` |
|
|
47
|
+
| `--zs-font-size` | `0.9375rem` |
|
|
48
|
+
| `--zs-line-height` | `1.4` |
|
|
49
|
+
| `--zs-label-size` | `0.8125rem` |
|
|
50
|
+
| `--zs-height` | `44px` |
|
|
51
|
+
| `--zs-radius` | `10px` |
|
|
52
|
+
| `--zs-chip-radius` | `8px` |
|
|
53
|
+
| `--zs-border-width` | `1px` |
|
|
54
|
+
| `--zs-padding-x` / `--zs-padding-y` | `12px` / `5px` |
|
|
55
|
+
| `--zs-gap` | `6px` |
|
|
56
|
+
| `--zs-dropdown-radius` / `--zs-dropdown-border-width` | `12px` / `1px` |
|
|
57
|
+
| `--zs-option-radius` | `8px` |
|
|
58
|
+
| `--zs-option-padding-y` / `--zs-option-padding-x` | `9px` / `12px` |
|
|
59
|
+
|
|
60
|
+
### Colour
|
|
61
|
+
|
|
62
|
+
| Token | Default | Used by |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| `--zs-bg` | `#ffffff` | control, input shell, cards |
|
|
65
|
+
| `--zs-text` | `#16181d` | labels, values, options |
|
|
66
|
+
| `--zs-text-muted` | `#6b7280` | hints, counters, clear buttons |
|
|
67
|
+
| `--zs-placeholder` | `#9aa1ac` | placeholders |
|
|
68
|
+
| `--zs-border-color` | `#dfe3e8` | idle borders |
|
|
69
|
+
| `--zs-border-color-hover` | `#c3c9d2` | hover |
|
|
70
|
+
| `--zs-border-color-focus` | `#4f6bed` | focus |
|
|
71
|
+
| `--zs-border-color-invalid` / `--zs-border-color-valid` | `#dc3545` / `#198754` | validation |
|
|
72
|
+
| `--zs-primary` / `--zs-primary-contrast` | `#4f6bed` / `#fff` | checked, focus, accents |
|
|
73
|
+
| `--zs-primary-soft` | `#eef1fd` | card checked, hover wash |
|
|
74
|
+
| `--zs-focus-ring` / `--zs-focus-ring-width` | `rgba(79,107,237,.22)` / `3px` | focus ring |
|
|
75
|
+
| `--zs-chip-bg` / `-text` / `-border` | `#eef1fd` / `#33407a` / `#dfe5fb` | tags |
|
|
76
|
+
| `--zs-dropdown-bg` / `-border` / `-shadow` | white / `#e6e9ee` / layered shadow | listbox |
|
|
77
|
+
| `--zs-option-hover-bg` / `-active-bg` / `-active-text` | greys/indigo | listbox options |
|
|
78
|
+
| `--zs-option-selected-bg` / `-selected-text` | indigo tints | selected options |
|
|
79
|
+
| `--zs-group-text` | `#8b93a1` | listbox groups |
|
|
80
|
+
|
|
81
|
+
### Field tokens
|
|
82
|
+
|
|
83
|
+
| Token | Default |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| `--zs-check-size` | `20px` |
|
|
86
|
+
| `--zs-check-radius` | `6px` |
|
|
87
|
+
| `--zs-check-gap` | `10px` |
|
|
88
|
+
| `--zs-check-bg` / `--zs-check-border` | `#fff` / `#c3c9d2` |
|
|
89
|
+
| `--zs-check-mark` | `#fff` |
|
|
90
|
+
| `--zs-check-checked-bg` / `-checked-border` | `#4f6bed` / `#4f6bed` |
|
|
91
|
+
| `--zs-switch-width` / `-height` | `40px` / `22px` |
|
|
92
|
+
| `--zs-switch-off` / `--zs-switch-knob` | `#d6dae1` / `#fff` |
|
|
93
|
+
| `--zs-radio-size` | `18px` |
|
|
94
|
+
| `--zs-radio-border` / `--zs-radio-gap` | `#c3c9d2` / `10px` |
|
|
95
|
+
| `--zs-file-drop-bg` / `--zs-file-drop-border` | `#f8f9fc` / `#cfd5de` |
|
|
96
|
+
| `--zs-file-thumb-bg` / `-text` | `#eef1fd` / `#4a5590` |
|
|
97
|
+
| `--zs-field-gap` | `6px` |
|
|
98
|
+
|
|
99
|
+
### Scrollbar
|
|
100
|
+
|
|
101
|
+
`--zs-scrollbar-size`, `--zs-scrollbar-thumb`, `--zs-scrollbar-thumb-hover`,
|
|
102
|
+
`--zs-scrollbar-thumb-reveal` (hover variant), `--zs-scrollbar-track`.
|
|
103
|
+
|
|
104
|
+
## Custom theme
|
|
105
|
+
|
|
106
|
+
```css
|
|
107
|
+
.my-brand {
|
|
108
|
+
--zs-primary: #e11d48;
|
|
109
|
+
--zs-primary-soft: #fff1f4;
|
|
110
|
+
--zs-border-color-focus: #e11d48;
|
|
111
|
+
--zs-focus-ring: rgba(225, 29, 72, 0.22);
|
|
112
|
+
--zs-check-checked-bg: #e11d48;
|
|
113
|
+
--zs-check-checked-border: #e11d48;
|
|
114
|
+
--zs-radius: 14px;
|
|
115
|
+
--zs-dropdown-radius: 16px;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```html
|
|
120
|
+
<form class="my-brand">…</form>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
No JS change is needed when the tokens apply to a wrapper class. For a named preset that also
|
|
124
|
+
works with `data-zs-theme="brand"` and `setTheme('brand')`, register the name first:
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
ZidanForm.themes.push('brand'); // register before fields initialise
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<form data-zs-theme="brand">…</form>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```css
|
|
135
|
+
[data-zs-theme="brand"] { /* tokens */ }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`ZidanForm.themes` is the live list the plugin validates against, so a pushed name survives
|
|
139
|
+
initialisation and is written to the field root as `data-zs-theme`. Names that were never
|
|
140
|
+
registered fall back to `default`; pushing after fields exist only affects `setTheme()` calls
|
|
141
|
+
made afterwards.
|
|
142
|
+
|
|
143
|
+
## Automatic dark mode
|
|
144
|
+
|
|
145
|
+
Add the attribute based on `prefers-color-scheme`:
|
|
146
|
+
|
|
147
|
+
```html
|
|
148
|
+
<script>
|
|
149
|
+
if (matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
150
|
+
document.documentElement.setAttribute('data-zs-theme', 'dark');
|
|
151
|
+
}
|
|
152
|
+
</script>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Or scope it to a wrapper and switch at runtime:
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
document.querySelectorAll('.zs-field').forEach(el => el.setAttribute('data-zs-theme', 'dark'));
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`setTheme()` on an instance does the same for one field.
|
|
162
|
+
|
|
163
|
+
## Select layouts
|
|
164
|
+
|
|
165
|
+
| Layout | Notes |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `classic-clean` | 10px radius, standard height, soft dropdown shadow. |
|
|
168
|
+
| `floating-label` | Label starts as placeholder, lifts on focus/value. |
|
|
169
|
+
| `soft-pill` | Pill trigger and chips, tinted surface. |
|
|
170
|
+
| `bordered-brutalist` | 2px black border, zero radius, offset shadow, yellow accent. |
|
|
171
|
+
| `glass-elevated` | Blur, translucency, elevated shadows, solid fallback without `backdrop-filter`. |
|
|
172
|
+
|
|
173
|
+
## Field layouts
|
|
174
|
+
|
|
175
|
+
| Layout | Notes |
|
|
176
|
+
| --- | --- |
|
|
177
|
+
| `stacked` | Label, control, hint vertically. |
|
|
178
|
+
| `inline` | Label and control on one row. |
|
|
179
|
+
| `compact` | 34px control height, smaller label. |
|
|
180
|
+
| `floating` | Label lives inside the shell and lifts when filled/focused. |
|
|
181
|
+
| `outlined` | Like floating, with the label notching the border. |
|
|
182
|
+
| `card` | Adds a padded card surface around the field. |
|
|
183
|
+
|
|
184
|
+
`grid` is not a field layout value — the grid lives on the wrapper:
|
|
185
|
+
|
|
186
|
+
```html
|
|
187
|
+
<div class="zs-form-grid">
|
|
188
|
+
<input data-zidan="input" data-zidan-label="First name">
|
|
189
|
+
<input data-zidan="input" data-zidan-label="Last name">
|
|
190
|
+
<textarea data-zidan="textarea" data-zidan-label="Notes" class="zs-full"></textarea>
|
|
191
|
+
</div>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`--zs-grid-min` / `--zs-grid-gap` control the auto-fit columns.
|
|
195
|
+
|
|
196
|
+
## Framework adapters
|
|
197
|
+
|
|
198
|
+
`data-zs-framework` (or the `framework` option) accepts `none`, `vanilla`, `bootstrap`,
|
|
199
|
+
`tailwind`, `bulma`, `foundation`. Adapters only remap tokens plus a few structural
|
|
200
|
+
compat rules (Bootstrap `input-group`, for example). Nothing depends on the framework's
|
|
201
|
+
JavaScript.
|
|
202
|
+
|
|
203
|
+
```html
|
|
204
|
+
<html data-zs-framework="bootstrap"> <!-- whole page -->
|
|
205
|
+
<form data-zs-framework="tailwind"> <!-- one form -->
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Scrollbar variants
|
|
209
|
+
|
|
210
|
+
```html
|
|
211
|
+
<select data-zidan-select="combobox" data-zidan-scrollbar="fancy">
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
| Value | Chromium / Safari | Firefox |
|
|
215
|
+
| --- | --- | --- |
|
|
216
|
+
| `default` | 8px rounded thumb | thin native gutter, `scrollbar-color` |
|
|
217
|
+
| `thin` | 6px | thin native |
|
|
218
|
+
| `fancy` | gradient thumb on tinted track | flat accent thumb (no gradients possible) |
|
|
219
|
+
| `hover` | invisible until hover/focus, soft 0.3 then 0.45 on the thumb | soft 0.3 on listbox hover only |
|
|
220
|
+
| `hidden` | no visible bar, still scrollable | `scrollbar-width: none` |
|
|
221
|
+
|
|
222
|
+
## Reduced motion & forced colours
|
|
223
|
+
|
|
224
|
+
Both are handled in the stylesheets. Keep animations in custom themes behind
|
|
225
|
+
`@media (prefers-reduced-motion: no-preference)`.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" data-zs-theme="default" data-zs-framework="none">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>ZidanForm × validation libraries</title>
|
|
7
|
+
<link rel="stylesheet" href="../plugin-core.css">
|
|
8
|
+
<link rel="stylesheet" href="../plugin-theme.css">
|
|
9
|
+
<style>
|
|
10
|
+
* { box-sizing: border-box; }
|
|
11
|
+
body {
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 40px 22px 70px;
|
|
14
|
+
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
15
|
+
color: #101324;
|
|
16
|
+
background: #f5f6fb;
|
|
17
|
+
line-height: 1.55;
|
|
18
|
+
}
|
|
19
|
+
main { max-width: 900px; margin: 0 auto; }
|
|
20
|
+
h1 { margin: 0 0 6px; font-size: 1.9rem; letter-spacing: -0.02em; }
|
|
21
|
+
.lead { margin: 0 0 26px; color: #525a70; }
|
|
22
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
|
|
23
|
+
.card {
|
|
24
|
+
background: #fff;
|
|
25
|
+
border: 1px solid #e4e8f1;
|
|
26
|
+
border-radius: 16px;
|
|
27
|
+
padding: 20px;
|
|
28
|
+
box-shadow: 0 1px 2px rgba(16, 19, 36, 0.05);
|
|
29
|
+
}
|
|
30
|
+
.card h2 { margin: 0 0 2px; font-size: 1rem; }
|
|
31
|
+
.card p { margin: 0 0 16px; font-size: 0.8125rem; color: #6b7385; }
|
|
32
|
+
.card form { display: flex; flex-direction: column; gap: 14px; }
|
|
33
|
+
.status { margin-top: 12px; font-size: 0.8125rem; color: #067647; min-height: 20px; }
|
|
34
|
+
.status[data-state="error"] { color: #b42318; }
|
|
35
|
+
.status[data-state="missing"] { color: #b45309; }
|
|
36
|
+
button.submit {
|
|
37
|
+
align-self: flex-start;
|
|
38
|
+
font: inherit;
|
|
39
|
+
font-size: 0.85rem;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
padding: 9px 16px;
|
|
42
|
+
border-radius: 999px;
|
|
43
|
+
border: 0;
|
|
44
|
+
color: #fff;
|
|
45
|
+
background: linear-gradient(140deg, #4f6bed, #6f5cf0);
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
}
|
|
48
|
+
label.error { color: #b42318; font-size: 0.75rem; }
|
|
49
|
+
.just-validate-error-label { color: #b42318; font-size: 0.75rem; margin-top: 4px; }
|
|
50
|
+
.parsley-errors-list { color: #b42318; font-size: 0.75rem; list-style: none; padding: 0; margin: 4px 0 0; }
|
|
51
|
+
.back { display: inline-block; margin-bottom: 18px; font-size: 0.85rem; color: #4f6bed; }
|
|
52
|
+
</style>
|
|
53
|
+
</head>
|
|
54
|
+
<body>
|
|
55
|
+
<main>
|
|
56
|
+
<a class="back" href="index.html">← documentation</a>
|
|
57
|
+
<h1>Validation-library test bench</h1>
|
|
58
|
+
<p class="lead">
|
|
59
|
+
The same plugin markup under four validators. Everything is loaded from a CDN, so this
|
|
60
|
+
page also works as a smoke test: submit each empty form, then fill it in.
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
<div class="grid">
|
|
64
|
+
<section class="card">
|
|
65
|
+
<h2>Native HTML5</h2>
|
|
66
|
+
<p>Constraint validation and <code>aria-invalid</code> mirroring.</p>
|
|
67
|
+
<form id="form-native" novalidate>
|
|
68
|
+
<input name="email" type="email" required data-zidan="input" data-zidan-label="Email">
|
|
69
|
+
<label><input type="checkbox" name="terms" required data-zidan="checkbox" data-zidan-label="Accept terms"> Accept terms</label>
|
|
70
|
+
<button class="submit" type="submit">Submit</button>
|
|
71
|
+
</form>
|
|
72
|
+
<p class="status" id="native-status" role="status"></p>
|
|
73
|
+
</section>
|
|
74
|
+
|
|
75
|
+
<section class="card">
|
|
76
|
+
<h2>jQuery Validation</h2>
|
|
77
|
+
<p><code>ignore: []</code>, plugin-aware error placement.</p>
|
|
78
|
+
<form id="form-jquery">
|
|
79
|
+
<input name="email" id="jq-email" type="email" required data-zidan="input" data-zidan-label="Email">
|
|
80
|
+
<input name="name" id="jq-name" required minlength="3" data-zidan="input" data-zidan-label="Name">
|
|
81
|
+
<button class="submit" type="submit">Submit</button>
|
|
82
|
+
</form>
|
|
83
|
+
<p class="status" id="jquery-status" role="status"></p>
|
|
84
|
+
</section>
|
|
85
|
+
|
|
86
|
+
<section class="card">
|
|
87
|
+
<h2>JustValidate</h2>
|
|
88
|
+
<p>Shared error class and container.</p>
|
|
89
|
+
<form id="form-justvalidate">
|
|
90
|
+
<input name="email" id="jv-email" data-zidan="input" data-zidan-label="Email">
|
|
91
|
+
<input name="name" id="jv-name" data-zidan="input" data-zidan-label="Name">
|
|
92
|
+
<button class="submit" type="submit">Submit</button>
|
|
93
|
+
</form>
|
|
94
|
+
<p class="status" id="justvalidate-status" role="status"></p>
|
|
95
|
+
</section>
|
|
96
|
+
|
|
97
|
+
<section class="card">
|
|
98
|
+
<h2>Parsley</h2>
|
|
99
|
+
<p>Data attributes plus an errors container inside the field.</p>
|
|
100
|
+
<form id="form-parsley">
|
|
101
|
+
<input name="email" id="parsley-email" data-parsley-required data-parsley-type="email"
|
|
102
|
+
data-zidan="input" data-zidan-label="Email">
|
|
103
|
+
<input name="name" id="parsley-name" data-parsley-required data-parsley-minlength="3"
|
|
104
|
+
data-zidan="input" data-zidan-label="Name">
|
|
105
|
+
<button class="submit" type="submit">Submit</button>
|
|
106
|
+
</form>
|
|
107
|
+
<p class="status" id="parsley-status" role="status"></p>
|
|
108
|
+
</section>
|
|
109
|
+
</div>
|
|
110
|
+
</main>
|
|
111
|
+
|
|
112
|
+
<script src="../zidan-form.js"></script>
|
|
113
|
+
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
|
114
|
+
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.20.0/dist/jquery.validate.min.js"></script>
|
|
115
|
+
<script src="https://unpkg.com/just-validate@4.3.0/dist/just-validate.production.min.js"></script>
|
|
116
|
+
<script src="https://cdn.jsdelivr.net/npm/parsleyjs@2.9.2/dist/parsley.min.js"></script>
|
|
117
|
+
<script>
|
|
118
|
+
initZidanForms(document);
|
|
119
|
+
|
|
120
|
+
function report(id, message, state) {
|
|
121
|
+
var node = document.getElementById(id);
|
|
122
|
+
if (!node) return;
|
|
123
|
+
node.textContent = message;
|
|
124
|
+
node.dataset.state = state || '';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* native ------------------------------------------------------------ */
|
|
128
|
+
var nativeForm = document.getElementById('form-native');
|
|
129
|
+
nativeForm.addEventListener('submit', function (event) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
ZidanForm.fields.forEach(function (field) {
|
|
132
|
+
if (nativeForm.contains(field.el)) field.update();
|
|
133
|
+
});
|
|
134
|
+
if (!nativeForm.checkValidity()) {
|
|
135
|
+
nativeForm.querySelector(':invalid').focus();
|
|
136
|
+
report('native-status', 'Blocked: ' + nativeForm.querySelectorAll(':invalid').length + ' invalid field(s).', 'error');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
report('native-status', 'Valid — FormData: ' + new URLSearchParams(new FormData(nativeForm)).toString());
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/* jQuery Validation -------------------------------------------------- */
|
|
143
|
+
if (window.jQuery && jQuery.validator) {
|
|
144
|
+
jQuery('#form-jquery').validate({
|
|
145
|
+
ignore: [],
|
|
146
|
+
errorPlacement: function (error, element) {
|
|
147
|
+
var field = element.closest('.zs-field');
|
|
148
|
+
(field || element.parent()).append(error);
|
|
149
|
+
},
|
|
150
|
+
highlight: function (element) {
|
|
151
|
+
jQuery(element).attr('aria-invalid', 'true');
|
|
152
|
+
jQuery(element).closest('.zs-field').addClass('zs-field--invalid');
|
|
153
|
+
},
|
|
154
|
+
unhighlight: function (element) {
|
|
155
|
+
jQuery(element).removeAttr('aria-invalid');
|
|
156
|
+
jQuery(element).closest('.zs-field').removeClass('zs-field--invalid');
|
|
157
|
+
},
|
|
158
|
+
submitHandler: function (form) {
|
|
159
|
+
report('jquery-status', 'Valid — ' + new URLSearchParams(new FormData(form)).toString());
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
report('jquery-status', 'jQuery Validation could not load from the CDN.', 'missing');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* JustValidate ------------------------------------------------------- */
|
|
167
|
+
if (window.JustValidate) {
|
|
168
|
+
new JustValidate('#form-justvalidate', {
|
|
169
|
+
errorFieldCssClass: 'zs-field--invalid',
|
|
170
|
+
errorLabelStyle: { color: 'var(--zs-border-color-invalid)', fontSize: '0.75rem' }
|
|
171
|
+
})
|
|
172
|
+
.addField('#jv-email', [{ rule: 'required' }, { rule: 'email' }])
|
|
173
|
+
.addField('#jv-name', [{ rule: 'required' }, { rule: 'minLength', value: 3 }])
|
|
174
|
+
.onSuccess(function (event) {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
report('justvalidate-status', 'Valid — ' + new URLSearchParams(new FormData(event.target)).toString());
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
report('justvalidate-status', 'JustValidate could not load from the CDN.', 'missing');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Parsley ------------------------------------------------------------ */
|
|
183
|
+
if (window.jQuery && jQuery.fn.parsley) {
|
|
184
|
+
jQuery('#form-parsley').parsley({
|
|
185
|
+
errorsContainer: function (field) {
|
|
186
|
+
return field.$element.closest('.zs-field');
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
jQuery('#form-parsley').on('form:success', function () {
|
|
190
|
+
report('parsley-status', 'Valid — ' + new URLSearchParams(new FormData(this)).toString());
|
|
191
|
+
});
|
|
192
|
+
jQuery('#form-parsley').on('form:error', function () {
|
|
193
|
+
report('parsley-status', 'Blocked by Parsley.', 'error');
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
report('parsley-status', 'Parsley could not load from the CDN.', 'missing');
|
|
197
|
+
}
|
|
198
|
+
</script>
|
|
199
|
+
</body>
|
|
200
|
+
</html>
|