selectamelo 0.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/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/index.cjs +636 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.global.js +634 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +609 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zycon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# Selectamelo
|
|
4
|
+
|
|
5
|
+
`selectamelo` is a **vanilla JavaScript** component that enhances a standard
|
|
6
|
+
HTML `<select>` element (single or multiple) into a modern, accessible and dynamic select.
|
|
7
|
+
|
|
8
|
+
It does **not** use jQuery, does **not** depend on UI frameworks, and keeps the original
|
|
9
|
+
`<select>` in the DOM to preserve native form submission and backend compatibility.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Single and multiple select
|
|
16
|
+
- Built-in search
|
|
17
|
+
- Clear button (X)
|
|
18
|
+
- Multiple select with removable chips
|
|
19
|
+
- Full keyboard navigation (↑ ↓ Enter Esc Tab Backspace)
|
|
20
|
+
- Dynamic option management
|
|
21
|
+
- Native HTML `disabled`
|
|
22
|
+
- Simulated `readonly` (non-editable but still submitted)
|
|
23
|
+
- Custom events (`zselect:*`)
|
|
24
|
+
- 100% Vanilla JS
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
### NPM
|
|
31
|
+
```bash
|
|
32
|
+
npm install selectamelo
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Build (package development only)
|
|
36
|
+
```bash
|
|
37
|
+
npm run build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Basic usage
|
|
43
|
+
|
|
44
|
+
### HTML
|
|
45
|
+
```html
|
|
46
|
+
<select id="role">
|
|
47
|
+
<option value=""></option>
|
|
48
|
+
<option value="admin">Admin</option>
|
|
49
|
+
<option value="editor">Editor</option>
|
|
50
|
+
</select>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### JavaScript (ESM)
|
|
54
|
+
```js
|
|
55
|
+
import { ZSelectCore } from "selectamelo";
|
|
56
|
+
|
|
57
|
+
const select = document.querySelector("#role");
|
|
58
|
+
|
|
59
|
+
ZSelectCore.create(select, {
|
|
60
|
+
placeholder: "Select a role"
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Options
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
type ZSelectCoreOptions = {
|
|
70
|
+
searchable?: boolean; // default true
|
|
71
|
+
placeholder?: string; // default ""
|
|
72
|
+
allowClear?: boolean; // default true
|
|
73
|
+
hideSearch?: boolean; // default false
|
|
74
|
+
|
|
75
|
+
disabled?: boolean; // disables the select (NOT submitted)
|
|
76
|
+
readonly?: boolean; // locks UI but value is submitted
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### disabled vs readonly
|
|
81
|
+
|
|
82
|
+
| State | Interaction | Submit |
|
|
83
|
+
|----------|-------------|--------|
|
|
84
|
+
| disabled | ❌ | ❌ |
|
|
85
|
+
| readonly | ❌ | ✅ |
|
|
86
|
+
|
|
87
|
+
HTML-driven options are also supported:
|
|
88
|
+
```html
|
|
89
|
+
<select
|
|
90
|
+
data-allow-clear="true"
|
|
91
|
+
data-hide-search="true"
|
|
92
|
+
data-searchable="false"
|
|
93
|
+
data-readonly="true"
|
|
94
|
+
></select>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Instance API
|
|
100
|
+
|
|
101
|
+
### Create / Get
|
|
102
|
+
```js
|
|
103
|
+
const inst = ZSelectCore.create(select);
|
|
104
|
+
const same = ZSelectCore.get(select);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### Value
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
inst.getValue(); // string | string[]
|
|
113
|
+
inst.setValue("admin"); // single
|
|
114
|
+
inst.setValue(["1","2"]); // multiple
|
|
115
|
+
inst.setValue(null); // reset
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### Open / Close
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
inst.open();
|
|
124
|
+
inst.close();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### State
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
inst.setDisabled(true);
|
|
133
|
+
inst.setDisabled(false);
|
|
134
|
+
|
|
135
|
+
inst.setReadonly(true);
|
|
136
|
+
inst.setReadonly(false);
|
|
137
|
+
|
|
138
|
+
inst.isDisabled(); // boolean
|
|
139
|
+
inst.isReadonly(); // boolean
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
### Loading
|
|
145
|
+
|
|
146
|
+
Temporarily blocks UI interaction.
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
inst.setLoading(true);
|
|
150
|
+
inst.setLoading(false);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Dynamic option management
|
|
156
|
+
|
|
157
|
+
### Clear options
|
|
158
|
+
```js
|
|
159
|
+
inst.clearOptions(true); // keep placeholder
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
### Set a full option list
|
|
165
|
+
```js
|
|
166
|
+
inst.setOptions(
|
|
167
|
+
[
|
|
168
|
+
{ value: "1", label: "Rome" },
|
|
169
|
+
{ value: "2", label: "Tivoli", disabled: true }
|
|
170
|
+
],
|
|
171
|
+
true
|
|
172
|
+
);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### Add an option
|
|
178
|
+
```js
|
|
179
|
+
inst.addOption({ value: "3", label: "Latina" });
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Add and select
|
|
183
|
+
```js
|
|
184
|
+
inst.addOption({ value: "3", label: "Latina" }, true);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### Remove an option
|
|
190
|
+
```js
|
|
191
|
+
inst.removeOption("2");
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### Update an option
|
|
197
|
+
```js
|
|
198
|
+
inst.updateOption("1", { label: "Rome (RM)" });
|
|
199
|
+
inst.updateOption("2", { disabled: false });
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### Upsert (create or update)
|
|
205
|
+
```js
|
|
206
|
+
inst.upsertOption({ value: "9", label: "Frosinone" });
|
|
207
|
+
inst.upsertOption({ value: "9", label: "Frosinone (FR)" });
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Custom events
|
|
213
|
+
|
|
214
|
+
Events are emitted **on the original `<select>` element**.
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
select.addEventListener("zselect:change", e => {
|
|
218
|
+
console.log(e.detail.value);
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Available events
|
|
223
|
+
|
|
224
|
+
| Event | Description |
|
|
225
|
+
|------------------|-------------|
|
|
226
|
+
| `zselect:open` | Dropdown opened |
|
|
227
|
+
| `zselect:close` | Dropdown closed |
|
|
228
|
+
| `zselect:search` | Search input (`detail.q`) |
|
|
229
|
+
| `zselect:clear` | Value cleared |
|
|
230
|
+
| `zselect:change` | Value changed |
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Common pattern: dependent selects
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
province.addEventListener("change", () => {
|
|
238
|
+
cityInst.setOptions(
|
|
239
|
+
[...province.selectedOptions].map(o => ({
|
|
240
|
+
value: o.value,
|
|
241
|
+
label: o.textContent.trim()
|
|
242
|
+
}))
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Philosophy
|
|
250
|
+
|
|
251
|
+
- No dependencies
|
|
252
|
+
- No frameworks
|
|
253
|
+
- DOM as the source of truth
|
|
254
|
+
- Core-only and framework-agnostic
|
|
255
|
+
- Optional adapters/wrappers
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT © Zycon
|