@gecko-ui-kit/components 0.0.0-stage → 0.20.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 +712 -2
- package/index.js +198 -0
- package/package.json +42 -4
- package/src/accordion.js +208 -0
- package/src/alert.js +205 -0
- package/src/authform.js +285 -0
- package/src/breadcrumbs.js +204 -0
- package/src/calendar.js +523 -0
- package/src/carousel.js +266 -0
- package/src/combobox.js +421 -0
- package/src/daterange.js +311 -0
- package/src/donut.js +346 -0
- package/src/filedrop.js +378 -0
- package/src/gauge.js +169 -0
- package/src/grid.js +298 -0
- package/src/heatmap.js +332 -0
- package/src/kanban.js +319 -0
- package/src/leaderboard.js +201 -0
- package/src/linechart.js +550 -0
- package/src/multiselect.js +324 -0
- package/src/notifications.js +393 -0
- package/src/otp.js +112 -0
- package/src/pagination.js +242 -0
- package/src/password.js +245 -0
- package/src/rangeslider.js +266 -0
- package/src/rating.js +171 -0
- package/src/signature.js +213 -0
- package/src/skeleton.js +254 -0
- package/src/spinner.js +38 -0
- package/src/stepper.js +211 -0
- package/src/swipe.js +280 -0
- package/src/tagsinput.js +369 -0
- package/src/timeline.js +340 -0
- package/src/timepicker.js +290 -0
- package/src/tree.js +490 -0
- package/src/upload.js +416 -0
- package/src/virtuallist.js +373 -0
- package/src/wizard.js +392 -0
- package/style.css +1761 -0
package/README.md
CHANGED
|
@@ -1,3 +1,713 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gecko-ui-kit/components
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Small HTML builders + the behaviour that brings them to life.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import '@gecko-ui-kit/components/style.css'
|
|
7
|
+
import { btn, seg, sw, tabs, meter, bindAll, animateBits } from '@gecko-ui-kit/components'
|
|
8
|
+
|
|
9
|
+
el.innerHTML = btn('Save', { variant: 'primary', icon: 'check' }) + seg('view', [['list', 'List'], ['grid', 'Grid']], 'list')
|
|
10
|
+
bindAll(el, { seg: (name, value) => console.log(name, value) }) // stretchy thumbs, switches, tabs, hover
|
|
11
|
+
animateBits(el) // meters, rings, steps, count-ups
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Don't want the builders? Copy the HTML from the playground — the CSS works on plain markup.
|
|
15
|
+
|
|
16
|
+
## Slider and colour swatch
|
|
17
|
+
```js
|
|
18
|
+
range({ min: 0, max: 100, step: 1, value: 60 }) // <input type="range" class="range">
|
|
19
|
+
swatch('#5b4cf0') // <input type="color" class="swatch">
|
|
20
|
+
bindAll(root) // keeps the slider's filled track in step
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Data grid
|
|
25
|
+
A table people can search, filter, sort, page through and edit in place.
|
|
26
|
+
```js
|
|
27
|
+
import { grid } from '@gecko-ui-kit/components'
|
|
28
|
+
|
|
29
|
+
const stock = grid(document.querySelector('#stock'), {
|
|
30
|
+
rows: products,
|
|
31
|
+
columns: [
|
|
32
|
+
{ key: 'name', label: 'Product', edit: true, validate: (v) => (v.trim() ? '' : 'Give it a name') },
|
|
33
|
+
{ key: 'cat', label: 'Category', type: 'select', options: [['coffee', 'Coffee'], ['tea', 'Tea']], edit: true, filter: true },
|
|
34
|
+
{ key: 'stock', label: 'In stock', type: 'number', align: 'right', edit: true },
|
|
35
|
+
{ key: 'active', label: 'On sale', type: 'bool', edit: true },
|
|
36
|
+
],
|
|
37
|
+
search: true, pageSize: 8, select: true, remove: true, add: true,
|
|
38
|
+
onChange: (row, key, value, old) => save(row),
|
|
39
|
+
})
|
|
40
|
+
stock.rows() // every row after edits; also .visible(), .selected(), .search(q), .filter(key, v), .sort(key, dir)
|
|
41
|
+
```
|
|
42
|
+
Keys: Enter or F2 edits, Enter saves and moves down, Tab moves right, Esc cancels, arrows move, typing starts editing.
|
|
43
|
+
Load `@gecko-ui-kit/overlays` too and the filter becomes the animated dropdown.
|
|
44
|
+
|
|
45
|
+
## Booking timeline
|
|
46
|
+
Rows of things people book (bikes, rooms, staff) against days. Drag a bar to another day or row, stretch it from
|
|
47
|
+
either end; it snaps to whole days, refuses a clash with a shake, and every change can be undone.
|
|
48
|
+
```js
|
|
49
|
+
import { timeline } from '@gecko-ui-kit/components'
|
|
50
|
+
|
|
51
|
+
const cal = timeline(document.querySelector('#bikes'), {
|
|
52
|
+
rows: bikes.map((b) => ({ id: b.id, label: b.plate, sub: b.model })),
|
|
53
|
+
items: rentals.map((r) => ({ id: r.id, row: r.bikeId, start: r.startAt, end: r.dueAt, label: r.customer,
|
|
54
|
+
status: r.status, // 'booked' | 'out' | 'done' | 'service' ('out' past its end shows late)
|
|
55
|
+
edit: r.status === 'out' ? 'end' : true })), // a bike already out can only be made longer
|
|
56
|
+
days: 14, locale: 'th-TH', title: 'ปฏิทินรถ',
|
|
57
|
+
onChange: (item, before) => save(item), // after a drag or arrow-key move
|
|
58
|
+
onOpen: (item) => showDetails(item), // a tap on a bar
|
|
59
|
+
onAdd: ({ row, start }) => newBooking(row, start), // a tap on an empty day
|
|
60
|
+
})
|
|
61
|
+
cal.go(7); cal.today(); cal.undo(); cal.update(id, { status: 'done' })
|
|
62
|
+
```
|
|
63
|
+
On a phone, hold a bar for a moment to pick it up (a quick swipe still scrolls). Arrow keys move a focused bar,
|
|
64
|
+
Shift+arrows change its length, Up/Down change its row.
|
|
65
|
+
|
|
66
|
+
## Swipe actions
|
|
67
|
+
Slide a list row sideways to show buttons behind it. Past half way the row stays open; a long pull runs the
|
|
68
|
+
edge button straight away. An action can remove the row, and `ctx.undo()` puts it back.
|
|
69
|
+
```js
|
|
70
|
+
import { swipeItem, swipeActions } from '@gecko-ui-kit/components'
|
|
71
|
+
|
|
72
|
+
list.innerHTML = items.map((it) => swipeItem({
|
|
73
|
+
id: it.id,
|
|
74
|
+
body: renderRow(it), // your own row HTML
|
|
75
|
+
start: [{ id: 'done', label: 'Done', icon: 'check', tone: 'good' }], // pull right
|
|
76
|
+
end: [ // pull left; the first sits at the edge
|
|
77
|
+
{ id: 'delete', label: 'Delete', icon: 'trash', tone: 'bad', remove: true },
|
|
78
|
+
{ id: 'later', label: 'Later', icon: 'clock' },
|
|
79
|
+
],
|
|
80
|
+
})).join('')
|
|
81
|
+
|
|
82
|
+
swipeActions(list, {
|
|
83
|
+
onAction: (action, ctx) => { // ctx: { row, id, action, undo }
|
|
84
|
+
if (action === 'delete') toast('Deleted', { undo: () => ctx.undo() })
|
|
85
|
+
},
|
|
86
|
+
}).peek() // a small nudge that hints at the gesture
|
|
87
|
+
```
|
|
88
|
+
Tones: good · bad · warn · accent · neutral. Button width: `--swp-w` (76px). Up-and-down scrolling still works.
|
|
89
|
+
Keyboard: focus a row, ← or → opens it, Escape shuts it.
|
|
90
|
+
|
|
91
|
+
## Date range picker
|
|
92
|
+
A month calendar for one date or a start and an end. A band and a small tag follow the pointer and count the
|
|
93
|
+
days (or nights); the band fills in like ink when the end is picked. Taken days are struck out and a range
|
|
94
|
+
cannot run across them.
|
|
95
|
+
```js
|
|
96
|
+
import { dateRange, formatRange } from '@gecko-ui-kit/components'
|
|
97
|
+
|
|
98
|
+
const dp = dateRange(document.querySelector('#dates'), {
|
|
99
|
+
months: 2, // drops to one when the box is narrow
|
|
100
|
+
min: '2026-12-04', // 'YYYY-MM-DD'; earlier days can't be picked
|
|
101
|
+
disabled: ['2026-12-24', { start: '2026-12-30', end: '2027-01-02' }], // or (date) => isTaken(date)
|
|
102
|
+
count: 'days', // or 'nights' (4–7 Dec = 3 nights)
|
|
103
|
+
presets: [{ label: 'Next 7 days', days: 7 }],
|
|
104
|
+
locale: 'th-TH', // Thai month names and the Buddhist year
|
|
105
|
+
onChange: (v) => { label.textContent = formatRange(v, { locale: 'th-TH' }) }, // v = { start, end, count }
|
|
106
|
+
})
|
|
107
|
+
dp.value; dp.set({ start, end }); dp.clear(); dp.go(+1)
|
|
108
|
+
```
|
|
109
|
+
`mode: 'single'` picks one date. It sits inline: put it in a pop-over or a bottom sheet from `@gecko-ui-kit/overlays`.
|
|
110
|
+
Keyboard: arrows move a day or a week, Page Up / Page Down a month, Enter picks.
|
|
111
|
+
|
|
112
|
+
## Kanban board
|
|
113
|
+
Columns of cards you drag between columns or up and down. A picked-up card hangs from where you hold it and
|
|
114
|
+
swings as you move; a gap opens where it will land and the other cards slide aside.
|
|
115
|
+
```js
|
|
116
|
+
import { kanban } from '@gecko-ui-kit/components'
|
|
117
|
+
|
|
118
|
+
const board = kanban(document.querySelector('#board'), { // give #board a height
|
|
119
|
+
columns: [{ id: 'todo', title: 'To do' }, { id: 'doing', title: 'In progress', limit: 3 }, { id: 'done', title: 'Done' }],
|
|
120
|
+
cards: tasks.map((t) => ({ id: t.id, column: t.status, title: t.title, text: t.note, tags: [t.area] })),
|
|
121
|
+
render: (card) => '…', // optional: your own card
|
|
122
|
+
canDrop: (card, to) => to !== 'done' || card.column === 'doing', // optional rules
|
|
123
|
+
onMove: (card, { from, to, index }) => save(card.id, to, index), // return false to put it back
|
|
124
|
+
onOpen: (card) => openTask(card.id),
|
|
125
|
+
})
|
|
126
|
+
board.move(id, 'done'); board.add(card, 0); board.cards()
|
|
127
|
+
```
|
|
128
|
+
On a phone, hold a card to pick it up (a swipe still scrolls; columns snap one at a time). Keyboard: Space picks
|
|
129
|
+
up, arrows move, Space drops, Escape cancels. Column width: `--kb-col` (280px).
|
|
130
|
+
|
|
131
|
+
## Signature pad
|
|
132
|
+
Sign with a finger, a pen or the mouse. The line gets thinner when you move fast and thicker when you slow down.
|
|
133
|
+
```js
|
|
134
|
+
import { signaturePad } from '@gecko-ui-kit/components'
|
|
135
|
+
|
|
136
|
+
const sig = signaturePad(document.querySelector('#sign'), {
|
|
137
|
+
// color: '#1f3a93', default: the text colour (readable in dark mode)
|
|
138
|
+
// width: [1.2, 3.6], thinnest and thickest line in px
|
|
139
|
+
onChange: (isEmpty) => { sendBtn.disabled = isEmpty },
|
|
140
|
+
})
|
|
141
|
+
sig.toImage({ background: '#fff' }) // trimmed PNG data URL (dark ink unless you pass color)
|
|
142
|
+
sig.toSVG() // an SVG string
|
|
143
|
+
const data = sig.toJSON() // save the strokes…
|
|
144
|
+
sig.fromJSON(data, { animate: true }) // …and show them again, drawn stroke by stroke
|
|
145
|
+
sig.undo(); sig.clear(); sig.replay(); sig.isEmpty
|
|
146
|
+
```
|
|
147
|
+
`readOnly: true, tools: false` shows a saved signature. Shape: `--sig-ratio` (3 / 1); taller is easier on a phone.
|
|
148
|
+
Pass `words` to translate the hint, buttons and screen-reader text.
|
|
149
|
+
|
|
150
|
+
## Photo upload
|
|
151
|
+
Drop photos on it, click to choose or paste. Each one shows its upload progress; drag them to reorder (the first is
|
|
152
|
+
the cover).
|
|
153
|
+
```js
|
|
154
|
+
import { photoUpload } from '@gecko-ui-kit/components'
|
|
155
|
+
|
|
156
|
+
const up = photoUpload(document.querySelector('#photos'), {
|
|
157
|
+
max: 8, maxSize: 10, // photos, MB each
|
|
158
|
+
value: listing.photos, // [{ url, … }] already uploaded
|
|
159
|
+
upload: (file, { progress, signal }) => sendWithProgress('/api/photos', file, progress, signal), // → { url, … }
|
|
160
|
+
resize: { max: 2000, quality: 0.85 }, // optional: make big photos smaller first
|
|
161
|
+
})
|
|
162
|
+
const photos = await up.settled() // the results in order, once uploads have finished
|
|
163
|
+
up.add(files); up.remove(id); up.move(id, 0); up.retry(id); up.open(); up.busy; up.items
|
|
164
|
+
```
|
|
165
|
+
Without `upload` the files are kept and `up.value` gives the `File`s, ready for `FormData`. Removing a photo that is
|
|
166
|
+
still uploading aborts its `signal`. `onReject(file, 'type' | 'size' | 'count')`. Keyboard: arrows move between
|
|
167
|
+
photos, Alt + arrows move one, Delete removes it. Sizes: `--pu-size` (112px), `--pu-ratio` (1), `--pu-gap` (10px).
|
|
168
|
+
|
|
169
|
+
## Multi-select
|
|
170
|
+
Pick several people, tags or options. Typing narrows the list; picked ones become chips.
|
|
171
|
+
```js
|
|
172
|
+
import { multiSelect } from '@gecko-ui-kit/components'
|
|
173
|
+
|
|
174
|
+
const ms = multiSelect(document.querySelector('#who'), {
|
|
175
|
+
options: team.map((p) => ({ value: p.id, label: p.name, sub: p.role, person: p })), // or ['A', 'B'] or { color: 'teal' }
|
|
176
|
+
value: ['pw'],
|
|
177
|
+
max: 3, // optional limit
|
|
178
|
+
creatable: (text) => api.createLabel(text), // optional: offer to create what was typed
|
|
179
|
+
name: 'who', // optional: hidden inputs for a plain <form>
|
|
180
|
+
onChange: (values) => save(values),
|
|
181
|
+
})
|
|
182
|
+
ms.value; ms.add('ab'); ms.remove('pw'); ms.set(['ab']); ms.clear(); ms.setOptions(list)
|
|
183
|
+
```
|
|
184
|
+
Backspace twice removes the last chip; Left walks along the chips. Pass `words` to translate it. List height:
|
|
185
|
+
`--ms-list-h` (280px).
|
|
186
|
+
|
|
187
|
+
## Time picker
|
|
188
|
+
A wheel like a phone's clock, or a grid of time slots.
|
|
189
|
+
```js
|
|
190
|
+
import { timePicker } from '@gecko-ui-kit/components'
|
|
191
|
+
|
|
192
|
+
const tp = timePicker(document.querySelector('#time'), {
|
|
193
|
+
look: 'wheel', // or 'slots'
|
|
194
|
+
value: '09:30', step: 5, // minutes (slots: 30)
|
|
195
|
+
min: '08:00', max: '20:00',
|
|
196
|
+
disabled: ['12:00', '12:30'], // or (time) => true
|
|
197
|
+
hour12: false, // shows 9:30 AM; values stay 'HH:MM'
|
|
198
|
+
onChange: (value) => save(value),
|
|
199
|
+
})
|
|
200
|
+
tp.value; tp.set('13:30'); tp.setDisabled(booked); tp.format() // '09:30' or '9:30 AM'
|
|
201
|
+
```
|
|
202
|
+
Pass `words` for the group names (morning, afternoon, evening) and other text. Wheel size: `--tp-item`, `--tp-rows`;
|
|
203
|
+
slots: `--tp-slot`.
|
|
204
|
+
|
|
205
|
+
## Number stepper
|
|
206
|
+
A number with − and +; the digits roll like an odometer. Hold a button to count fast; click the number to type.
|
|
207
|
+
```js
|
|
208
|
+
import { stepper } from '@gecko-ui-kit/components'
|
|
209
|
+
|
|
210
|
+
const days = stepper(document.querySelector('#days'), {
|
|
211
|
+
value: 3, min: 1, max: 30,
|
|
212
|
+
unit: (n) => (n === 1 ? 'day' : 'days'), // or a string; prefix: '฿' goes before
|
|
213
|
+
size: 'sm', // 'sm' | 'lg'
|
|
214
|
+
onChange: (n) => updateTotal(n),
|
|
215
|
+
})
|
|
216
|
+
days.value; days.set(7); days.stepBy(1); days.setRange({ max: 14 })
|
|
217
|
+
```
|
|
218
|
+
`step: 0.5` shows one decimal; `format` replaces the default grouping; `name` adds a hidden input. Sizes:
|
|
219
|
+
`--st-h`, `--st-fs`.
|
|
220
|
+
|
|
221
|
+
## Rating
|
|
222
|
+
Stars (or hearts) to pick or show a score.
|
|
223
|
+
```js
|
|
224
|
+
import { rating } from '@gecko-ui-kit/components'
|
|
225
|
+
|
|
226
|
+
const stars = rating(document.querySelector('#score'), {
|
|
227
|
+
value: 0, half: true, size: 'lg',
|
|
228
|
+
labels: ['Bad', 'Poor', 'Okay', 'Good', 'Great'],
|
|
229
|
+
name: 'score', // hidden input for plain forms
|
|
230
|
+
onChange: (v) => save(v),
|
|
231
|
+
})
|
|
232
|
+
rating(avgEl, { readOnly: true, value: 4.3 }) // the fifth star filled by a third
|
|
233
|
+
```
|
|
234
|
+
`icon: 'heart'`, `showValue: true`, `clearable: false`. Colours and size: `--rt-on`, `--rt-off`, `--rt-size`.
|
|
235
|
+
|
|
236
|
+
## Carousel
|
|
237
|
+
Swipe, drag or step through slides; the current dot stretches and fills with autoplay.
|
|
238
|
+
```js
|
|
239
|
+
import { carousel } from '@gecko-ui-kit/components'
|
|
240
|
+
|
|
241
|
+
const slider = carousel(document.querySelector('#photos'), {
|
|
242
|
+
slides: photos.map((url) => `<img src="${url}" alt="">`), // or leave out: el's children
|
|
243
|
+
perView: { 0: 1, 600: 2 }, // by the carousel's own width
|
|
244
|
+
peek: 40, focus: true, // show part of the next one; shrink the ones beside
|
|
245
|
+
autoplay: 4000, // pauses on hover, focus and drag; a pause button is added
|
|
246
|
+
onChange: (i) => console.log(i),
|
|
247
|
+
})
|
|
248
|
+
slider.go(2); slider.next(); slider.prev(); slider.index
|
|
249
|
+
```
|
|
250
|
+
`rewind: true` goes from the last slide back to the first; `arrows: false`, `dots: false`.
|
|
251
|
+
|
|
252
|
+
## Tree view
|
|
253
|
+
Nested items that open and close: folders and files, categories, an org chart. The selection highlight
|
|
254
|
+
stretches from row to row; checkboxes tick a whole branch; branches can load their children when opened.
|
|
255
|
+
```js
|
|
256
|
+
import { tree } from '@gecko-ui-kit/components'
|
|
257
|
+
|
|
258
|
+
const files = tree(document.querySelector('#files'), {
|
|
259
|
+
items: [
|
|
260
|
+
{ id: 'src', label: 'src', open: true, children: [
|
|
261
|
+
{ id: 'src/main.js', label: 'main.js' },
|
|
262
|
+
{ id: 'src/theme.css', label: 'theme.css', icon: 'droplet' },
|
|
263
|
+
] },
|
|
264
|
+
{ id: 'api', label: 'api', children: true }, // loaded with load() when first opened
|
|
265
|
+
],
|
|
266
|
+
label: 'Files',
|
|
267
|
+
select: 'single', // 'multiple' | 'none'
|
|
268
|
+
checkable: false, // true: tri-state checkboxes
|
|
269
|
+
load: async (item) => (await fetch(`/files/${item.id}`)).json(),
|
|
270
|
+
onSelect: (ids) => console.log(ids),
|
|
271
|
+
onActivate: (item) => open(item.id), // double-click or Enter on a leaf
|
|
272
|
+
})
|
|
273
|
+
files.filter('main'); files.reveal('src/theme.css'); files.add('src', { id: 'src/new.js', label: 'new.js' })
|
|
274
|
+
files.value; files.checkedLeaves; files.expandAll(); files.collapseAll(); files.remove(id); files.rename(id, label)
|
|
275
|
+
```
|
|
276
|
+
Keyboard follows the ARIA tree pattern: ↑ ↓ Home End, → / ← open, close or step in and out, Enter, Space, `*`, and type to jump.
|
|
277
|
+
`--tv-indent` and `--tv-row` set the step per level and the row height.
|
|
278
|
+
|
|
279
|
+
## Accordion
|
|
280
|
+
Headings that open to show more — one at a time or many, chevron or plus, lines or cards.
|
|
281
|
+
```js
|
|
282
|
+
import { accordion } from '@gecko-ui-kit/components'
|
|
283
|
+
|
|
284
|
+
const acc = accordion(document.querySelector('#faq'), {
|
|
285
|
+
items: [{ id: 'hours', title: 'Opening hours', body: '<p>Every day, 08:00 – 20:00.</p>', open: true },
|
|
286
|
+
{ id: 'park', title: 'Where to park', sub: 'Behind the shop', icon: 'pin', body: '<p>…</p>' }],
|
|
287
|
+
multiple: false, // opening one closes the others
|
|
288
|
+
look: 'cards', // 'lines' | 'cards'
|
|
289
|
+
marker: 'plus', // 'chevron' | 'plus'
|
|
290
|
+
})
|
|
291
|
+
acc.open('park'); acc.value; acc.filter('park', { open: true }) // FAQ search: hides the rest, marks the words
|
|
292
|
+
```
|
|
293
|
+
No `items`? The `<details>` inside the element become the accordion. Side padding: `--acc-pad`.
|
|
294
|
+
|
|
295
|
+
## Notification feed
|
|
296
|
+
Newest first, grouped by day, unread dots, All / Unread tabs, "Mark all as read", row buttons and dismiss.
|
|
297
|
+
```js
|
|
298
|
+
import { notifications } from '@gecko-ui-kit/components'
|
|
299
|
+
|
|
300
|
+
const nf = notifications(document.querySelector('#inbox'), {
|
|
301
|
+
items: [{ id: 1, time: new Date(), person: { name: 'Pim Wong' }, icon: 'chat',
|
|
302
|
+
title: 'commented on “Roadmap”', body: 'Looks good!',
|
|
303
|
+
actions: [{ id: 'like', label: 'Like', done: 'Liked' }] }],
|
|
304
|
+
height: 420, // the list scrolls past this
|
|
305
|
+
onAction: (item, action) => api.answer(item.id, action), // a Promise: the button spins until it settles
|
|
306
|
+
onChange: (unread) => setBadge(unread),
|
|
307
|
+
})
|
|
308
|
+
nf.add(item) // slides in at the top (or waits behind a "1 new" pill if the reader scrolled down)
|
|
309
|
+
nf.readAll(); nf.read(id); nf.remove(id); nf.setFilter('unread'); nf.unread
|
|
310
|
+
```
|
|
311
|
+
`plain: true` for inside a popover; `group: false` for one list; `words` and `locale` for other languages;
|
|
312
|
+
`when(date)` for your own time text. Height: `--nf-h`.
|
|
313
|
+
|
|
314
|
+
## Code field (one-time code / PIN)
|
|
315
|
+
```js
|
|
316
|
+
import { otp, bindOtp, otpState } from '@gecko-ui-kit/components'
|
|
317
|
+
|
|
318
|
+
box.innerHTML = otp({ length: 6, split: true }) // mask: true for a PIN, letters: true for A–Z too
|
|
319
|
+
bindOtp(box, async (code, el) => { // runs when every box is filled
|
|
320
|
+
otpState(el, (await checkCode(code)) ? 'good' : 'bad') // green wave → tick, or red shake → cleared
|
|
321
|
+
})
|
|
322
|
+
```
|
|
323
|
+
Typing moves on, Backspace goes back, paste and the phone's code suggestion fill every box.
|
|
324
|
+
|
|
325
|
+
## Pagination
|
|
326
|
+
Page numbers with previous / next. The highlight on the current page stretches from number to number; when
|
|
327
|
+
the “…” moves, the numbers glide and new ones slide in from the side you are heading. Optional “21–30 of 240”
|
|
328
|
+
line and page-size list. It turns compact on its own at narrow widths.
|
|
329
|
+
```js
|
|
330
|
+
import { pagination } from '@gecko-ui-kit/components'
|
|
331
|
+
|
|
332
|
+
const pager = pagination(document.querySelector('#pager'), {
|
|
333
|
+
total: 240,
|
|
334
|
+
pageSize: 10,
|
|
335
|
+
siblings: 1, // numbers either side of the current page
|
|
336
|
+
boundaries: 1, // numbers always shown at each end
|
|
337
|
+
sizes: [10, 20, 50], // a page-size <select>; null for none
|
|
338
|
+
info: true, // “21–30 of 240”
|
|
339
|
+
look: 'numbers', // or 'simple': arrows + “Page 3 of 24”
|
|
340
|
+
onChange: (page, pageSize) => load(page, pageSize),
|
|
341
|
+
})
|
|
342
|
+
pager.go(3); pager.next(); pager.prev(); pager.setTotal(180); pager.page; pager.pages
|
|
343
|
+
```
|
|
344
|
+
Every word comes from `words` (`label`, `prev`, `next`, `perPage`, `none`, `page(n)`, `pageOf(n, pages)`, `info(from, to, total)`, `num(n)`).
|
|
345
|
+
`--pgn-size` sets the button size. Call `dropdowns(pager.root)` from `@gecko-ui-kit/overlays` for an animated page-size list.
|
|
346
|
+
|
|
347
|
+
## Breadcrumbs
|
|
348
|
+
The path to the current page, each step a way back up. A long path folds its middle steps into “…” (press it
|
|
349
|
+
to open them in place), and more fold on their own when space is tight. `set(items)` moves like a route
|
|
350
|
+
change: shared steps stay, old ones fade out, new ones slide in from the right.
|
|
351
|
+
```js
|
|
352
|
+
import { breadcrumbs } from '@gecko-ui-kit/components'
|
|
353
|
+
|
|
354
|
+
const crumbs = breadcrumbs(document.querySelector('#crumbs'), {
|
|
355
|
+
items: [
|
|
356
|
+
{ label: 'Home', href: '/', icon: 'home' },
|
|
357
|
+
{ label: 'Shop', href: '/shop' },
|
|
358
|
+
{ label: 'Helmets' }, // the last one is the current page
|
|
359
|
+
],
|
|
360
|
+
max: 4, // more steps → the middle ones fold into “…”
|
|
361
|
+
separator: 'chevron', // 'slash' | 'dot'
|
|
362
|
+
onNavigate: (item, index, e) => { e.preventDefault(); router.go(item.href) },
|
|
363
|
+
})
|
|
364
|
+
crumbs.set(newItems); crumbs.expand(); crumbs.items
|
|
365
|
+
```
|
|
366
|
+
A step without `href` is a button. `words: { label, more(n) }`; `--bc-max` sets the longest label before it is cut off.
|
|
367
|
+
|
|
368
|
+
## Range slider
|
|
369
|
+
Two thumbs on one track pick a low and a high value: a price filter, opening hours. Drag a thumb, press the
|
|
370
|
+
track to send the nearest thumb there, or drag the filled middle to move both. Optional histogram behind the
|
|
371
|
+
track (bars inside the range light up), marks under it and two number boxes.
|
|
372
|
+
```js
|
|
373
|
+
import { rangeSlider } from '@gecko-ui-kit/components'
|
|
374
|
+
|
|
375
|
+
const price = rangeSlider(document.querySelector('#price'), {
|
|
376
|
+
min: 0, max: 10000, step: 100,
|
|
377
|
+
value: [1200, 4800],
|
|
378
|
+
minGap: 500, // the thumbs stay this far apart
|
|
379
|
+
format: (v) => '฿' + v.toLocaleString('en-US'),
|
|
380
|
+
label: 'Price per night', // heading with "฿1,200 – ฿4,800" next to it
|
|
381
|
+
histogram: [3, 6, 11, 17, 22], // counts, spread evenly from min to max
|
|
382
|
+
marks: 2500, // or [0, 1000, 5000]
|
|
383
|
+
inputs: true, // two boxes under the track
|
|
384
|
+
name: 'price', // hidden inputs price_min and price_max
|
|
385
|
+
onInput: ([lo, hi]) => showCount(lo, hi), // while dragging
|
|
386
|
+
onChange: ([lo, hi]) => search(lo, hi), // when it is let go
|
|
387
|
+
})
|
|
388
|
+
price.value; price.set([2000, 6000]); price.set([0, 10000], { silent: true })
|
|
389
|
+
```
|
|
390
|
+
Pass `words: { min, max, to, range }` to translate it. Sizes: `--rs-hist` (histogram height), `--rs-knob` (thumb).
|
|
391
|
+
|
|
392
|
+
## Tags input
|
|
393
|
+
Type words (emails, topics, skills) and each one becomes a tag. A comma or Enter makes a tag; pasting
|
|
394
|
+
"a, b, c" makes three. Backspace twice removes the last tag; ← → walk along them. Optional suggestions under
|
|
395
|
+
the field, a limit, no repeats and a check of your own.
|
|
396
|
+
```js
|
|
397
|
+
import { tagsInput } from '@gecko-ui-kit/components'
|
|
398
|
+
|
|
399
|
+
const to = tagsInput(document.querySelector('#to'), {
|
|
400
|
+
value: ['nok@example.com'],
|
|
401
|
+
placeholder: 'Add people by email…',
|
|
402
|
+
separators: [',', ' ', 'Enter', 'Tab'], // characters, or the keys 'Enter' / 'Tab'
|
|
403
|
+
transform: (t) => t.toLowerCase(), // runs before the checks
|
|
404
|
+
validate: (t) => /^\S+@\S+\.\S+$/.test(t) || 'Not an email address',
|
|
405
|
+
max: 5, // a counter shows 1/5
|
|
406
|
+
suggestions: ['team@example.com'], // optional list under the field
|
|
407
|
+
name: 'to', // one hidden input, tags joined by commas
|
|
408
|
+
onChange: (tags) => save(tags),
|
|
409
|
+
})
|
|
410
|
+
to.value; to.add('ops@example.com'); to.remove(0); to.remove('ops@example.com'); to.clear(); to.focus()
|
|
411
|
+
```
|
|
412
|
+
`unique` (on by default) ignores upper/lower case. Pass `words` to translate every text. List height: `--ti-list-h`.
|
|
413
|
+
|
|
414
|
+
## Combobox
|
|
415
|
+
A text field you type into to find one option. The matching letters are marked, the highlight stretches from row to
|
|
416
|
+
row, and the pick settles into the field. Options come from a list or from your server (`source`, with older
|
|
417
|
+
searches cancelled). Full ARIA 1.2 combobox keyboard.
|
|
418
|
+
```js
|
|
419
|
+
import { combobox } from '@gecko-ui-kit/components'
|
|
420
|
+
|
|
421
|
+
const where = combobox(document.querySelector('#country'), {
|
|
422
|
+
label: 'Ship to',
|
|
423
|
+
options: [{ value: 'th', label: 'Thailand', sub: 'Bangkok', icon: 'plane', group: 'Asia' }, /* … */],
|
|
424
|
+
value: 'th',
|
|
425
|
+
clearable: true, allowCustom: false, // allowCustom: Enter keeps the typed text
|
|
426
|
+
name: 'country', // optional: hidden input for a plain <form>
|
|
427
|
+
onChange: (value, option) => save(value),
|
|
428
|
+
})
|
|
429
|
+
// or ask a server: source: async (query, { signal }) => (await fetch(`/api/people?q=${query}`, { signal })).json()
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
## File drop zone
|
|
433
|
+
Drop files on it, click it (a real button) or paste. Each file becomes a row with a type icon or a small preview,
|
|
434
|
+
its size and a progress bar; failed uploads can be retried, and files that are too big, of the wrong type or too
|
|
435
|
+
many get a row that says why. Without an `upload` function the files are only listed.
|
|
436
|
+
```js
|
|
437
|
+
import { fileDrop } from '@gecko-ui-kit/components'
|
|
438
|
+
|
|
439
|
+
const invoices = fileDrop(document.querySelector('#invoices'), {
|
|
440
|
+
accept: '.pdf,image/*',
|
|
441
|
+
maxSize: 2 * 1024 * 1024, // bytes per file
|
|
442
|
+
maxFiles: 10,
|
|
443
|
+
upload: (file, { progress, signal }) => sendWithProgress('/api/invoices', file, progress, signal), // → anything
|
|
444
|
+
onChange: (files) => save(invoices.value), // value: results of finished uploads
|
|
445
|
+
})
|
|
446
|
+
// invoices.files · invoices.retry(id) · invoices.remove(id) · invoices.clear() · await invoices.upload()
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
## Skeleton
|
|
450
|
+
Grey placeholders in the shape of what is loading (`look: 'list' | 'card' | 'text' | 'table' | 'custom'`), with a
|
|
451
|
+
soft light that sweeps across all blocks at once. `reveal()` fades the placeholders row by row while the real rows
|
|
452
|
+
rise in, and the height moves from the skeleton's to the real one. With `look: 'custom'` every element marked
|
|
453
|
+
`data-sk` in your own markup becomes a block of its own size (one bar per line of text).
|
|
454
|
+
```js
|
|
455
|
+
import { skeleton, skeletonHtml } from '@gecko-ui-kit/components'
|
|
456
|
+
|
|
457
|
+
const team = skeleton(document.querySelector('#team'), { look: 'list', rows: 5, label: 'Team' })
|
|
458
|
+
await team.reveal(html) // an HTML string, a Node, or (box) => …
|
|
459
|
+
team.loading(true) // placeholders over the content again, same height
|
|
460
|
+
box.innerHTML = skeletonHtml('table', { rows: 4 }) // the same markup, if you render HTML yourself
|
|
461
|
+
```
|
|
462
|
+
Sets `aria-busy` on the element and says “Loading…” to screen readers (`words: { loading, loaded }`).
|
|
463
|
+
Colours and speed: `--sk-base`, `--sk-hi`, `--sk-speed`, `--sk-gap`, `--sk-card`. No sweep with reduced motion.
|
|
464
|
+
|
|
465
|
+
## Alert / banner
|
|
466
|
+
A message that sits in the page. It grows open while its icon pops in; `update()` changes it in place (colours
|
|
467
|
+
cross-fade, the icon swaps with a pop, the text slides, the height follows); `close()` folds it away.
|
|
468
|
+
```js
|
|
469
|
+
import { alert } from '@gecko-ui-kit/components'
|
|
470
|
+
|
|
471
|
+
const note = alert(document.querySelector('#save-note'), {
|
|
472
|
+
tone: 'info', // 'info' | 'good' | 'warn' | 'bad'
|
|
473
|
+
look: 'soft', // 'soft' | 'outline' | 'solid' | 'banner' (full-width bar)
|
|
474
|
+
title: 'Unsaved changes', body: 'Save to publish them.', // body is HTML (trusted)
|
|
475
|
+
dismissible: true,
|
|
476
|
+
actions: [{ label: 'Save now', primary: true, run: () => save() }], // a Promise makes the button wait
|
|
477
|
+
})
|
|
478
|
+
note.update({ tone: 'good', title: 'Saved', body: 'Your changes are live.', actions: [] })
|
|
479
|
+
note.shake(); await note.close(); note.show()
|
|
480
|
+
```
|
|
481
|
+
`role="status"` for info / good, `role="alert"` for warn / bad. `words: { close }`, `onClose(a)`, `open: false`.
|
|
482
|
+
Colours: `--al-c`, `--al-soft`, `--al-on`.
|
|
483
|
+
|
|
484
|
+
## Wizard
|
|
485
|
+
A long form split into steps. Panels slide the way you go while the box resizes; Next checks the step first
|
|
486
|
+
(a message, a shake, a spinner while a server answers); finishing shows a success panel that draws its tick.
|
|
487
|
+
```js
|
|
488
|
+
import { wizard, field, input } from '@gecko-ui-kit/components'
|
|
489
|
+
|
|
490
|
+
const checkout = wizard(document.querySelector('#checkout'), {
|
|
491
|
+
steps: [
|
|
492
|
+
{ id: 'cart', title: 'Cart', content: cartHtml },
|
|
493
|
+
{ id: 'delivery', title: 'Delivery', content: field('Phone', input({ type: 'tel', a: 'name="phone" required' })) },
|
|
494
|
+
{ id: 'pay', title: 'Payment', content: payChoices,
|
|
495
|
+
validate: async (panel) => (await checkArea(panel)) ? true : 'We don’t deliver there yet.' },
|
|
496
|
+
{ id: 'review', title: 'Review', content: '<div id="review"></div>' },
|
|
497
|
+
],
|
|
498
|
+
header: 'steps', // 'bar' | 'none'
|
|
499
|
+
linear: true, // the steps along the top can’t jump past unfinished ones
|
|
500
|
+
onStep: (i, w) => i === 3 && showReview(w.values),
|
|
501
|
+
onFinish: (values) => sendOrder(values), // a Promise shows a spinner; false keeps the last step open
|
|
502
|
+
})
|
|
503
|
+
checkout.next(); checkout.back(); checkout.go(1); checkout.reset(); checkout.values
|
|
504
|
+
```
|
|
505
|
+
No `validate` → the browser’s own checks on the fields (`required`, `type="email"`, `pattern`…). Set `aria-invalid="true"` on the field at fault and it gets marked, shaken and focused.
|
|
506
|
+
|
|
507
|
+
## Line chart
|
|
508
|
+
Numbers over time, one or more series. Lines draw themselves in, a crosshair snaps to the nearest label
|
|
509
|
+
with a card that follows, legend keys hide a series (the axis rescales smoothly) and `update()` morphs every
|
|
510
|
+
point to its new value. Smooth lines never overshoot; `null` leaves a gap. Keyboard ← → reads each point.
|
|
511
|
+
```js
|
|
512
|
+
import { lineChart } from '@gecko-ui-kit/components'
|
|
513
|
+
|
|
514
|
+
const chart = lineChart(document.querySelector('#revenue'), {
|
|
515
|
+
labels: ['Jan', 'Feb', 'Mar', 'Apr'],
|
|
516
|
+
series: [
|
|
517
|
+
{ name: 'This year', data: [42800, 47100, 45300, null], tone: 'accent' },
|
|
518
|
+
{ name: 'Last year', data: [38200, 36900, 41500, 44100], tone: 'teal' },
|
|
519
|
+
],
|
|
520
|
+
area: true, smooth: true, stacked: false,
|
|
521
|
+
dots: 'hover', // true | false
|
|
522
|
+
format: (v) => '$' + v.toLocaleString('en-US'),
|
|
523
|
+
label: 'Revenue',
|
|
524
|
+
onPoint: (i, info) => {}, // i is -1 when the crosshair hides
|
|
525
|
+
})
|
|
526
|
+
chart.update({ series: [{ name: 'This year', data: [50000, 52000, 49000, 61000] }] })
|
|
527
|
+
// chart.toggle('Last year') · chart.highlight(2) · chart.destroy()
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
## Virtual list
|
|
531
|
+
Thousands of rows with only the visible ones (plus a few either side) in the page; row elements are reused
|
|
532
|
+
as you scroll. Rows have one height or `'auto'` (measured as they show). `selectable` makes it a listbox
|
|
533
|
+
with an active row you move with the keys; `scrollTo` glides to any row.
|
|
534
|
+
```js
|
|
535
|
+
import { virtualList } from '@gecko-ui-kit/components'
|
|
536
|
+
|
|
537
|
+
const list = virtualList(document.querySelector('#contacts'), {
|
|
538
|
+
items: contacts, // or a count: 10000
|
|
539
|
+
rowHeight: 56, // or 'auto' (+ estimate: 64)
|
|
540
|
+
height: 400, // leave out to fill the element
|
|
541
|
+
render: (p) => `<b>${p.name}</b><small>${p.city}</small>`,
|
|
542
|
+
key: (p) => p.id,
|
|
543
|
+
selectable: true,
|
|
544
|
+
label: 'Contacts',
|
|
545
|
+
words: { empty: 'No contacts match' },
|
|
546
|
+
onSelect: (p, i) => {},
|
|
547
|
+
onRange: ({ start, end, rendered, count }) => {},
|
|
548
|
+
})
|
|
549
|
+
list.update(contacts.filter((p) => p.name.includes('Ann'))) // keeps your place when it can
|
|
550
|
+
await list.scrollTo(2500, { align: 'center', smooth: true })
|
|
551
|
+
list.select(2500)
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
## Calendar
|
|
555
|
+
A month with its events: chips on each day, a bar across the days for anything longer, “+2 more” when a day is full.
|
|
556
|
+
Months slide the way you go; with `draggable` an event lifts and lands on another day.
|
|
557
|
+
```js
|
|
558
|
+
import { calendar } from '@gecko-ui-kit/components'
|
|
559
|
+
|
|
560
|
+
const team = calendar(document.querySelector('#team'), {
|
|
561
|
+
events: [
|
|
562
|
+
{ id: 'a', title: 'Design sprint', start: '2026-12-01', end: '2026-12-03', tone: 'teal' },
|
|
563
|
+
{ id: 'b', title: 'Stand-up', start: '2026-12-07', allDay: false, time: '10:00' },
|
|
564
|
+
],
|
|
565
|
+
locale: 'en-GB', weekStart: 1, maxPerDay: 3,
|
|
566
|
+
draggable: true, // touch: press and hold, then drag
|
|
567
|
+
onDay: (date, events) => showDay(date, events),
|
|
568
|
+
onEvent: (event) => openDetails(event.id),
|
|
569
|
+
onMove: (event, start, end) => save(event.id, start, end), // return false to put it back
|
|
570
|
+
})
|
|
571
|
+
team.next(); team.prev(); team.today(); team.go('2027-01-01')
|
|
572
|
+
team.addEvent({ id: 'c', title: 'Demo day', start: '2026-12-18' }); team.removeEvent('a'); team.events
|
|
573
|
+
```
|
|
574
|
+
`size: 'sm'` (or a box narrower than 520px) shows thin colour bars instead of titles. Keyboard follows the ARIA grid pattern; Alt + arrow keys move a focused event.
|
|
575
|
+
|
|
576
|
+
## Password strength
|
|
577
|
+
Attach it to a password field. Four bars fill one after another and change colour together, the level word rolls
|
|
578
|
+
(too weak → weak → okay → strong), each rule ticks itself off with a drawn tick, and a padlock clicks shut when the
|
|
579
|
+
password is strong. `reveal: true` adds a show / hide eye (also on its own as `passwordToggle`).
|
|
580
|
+
```js
|
|
581
|
+
import { passwordMeter, passwordToggle } from '@gecko-ui-kit/components'
|
|
582
|
+
|
|
583
|
+
const pw = passwordMeter(document.querySelector('#new-password'), {
|
|
584
|
+
min: 8, // the default length rule
|
|
585
|
+
minScore: 3, // pw.valid from “okay” up
|
|
586
|
+
reveal: true,
|
|
587
|
+
// rules: [{ id: 'long', test: (v) => v.length >= 12, label: '12 or more characters' }],
|
|
588
|
+
// score: (value, met) => 0–4, words: { tooWeak, weak, okay, strong, … },
|
|
589
|
+
onChange: ({ score, level, valid, rules }) => { save.disabled = !valid },
|
|
590
|
+
})
|
|
591
|
+
pw.score; pw.level; pw.valid; pw.check(); pw.destroy()
|
|
592
|
+
|
|
593
|
+
const eye = passwordToggle(document.querySelector('#password')) // just the eye
|
|
594
|
+
```
|
|
595
|
+
The level word and the rules describe the field (`aria-describedby`); a polite live region reads the level when it changes.
|
|
596
|
+
Colour: `--pwm-c` per `.pwm[data-level]`.
|
|
597
|
+
|
|
598
|
+
## Sign in / sign up
|
|
599
|
+
A sign in / create account card. The switch slides between the two, the name (and confirm) field grows in for sign-up,
|
|
600
|
+
the password has a show / hide eye and, on sign-up, a strength meter (`passwordMeter`); the submit label rolls.
|
|
601
|
+
Each field is checked before sending (red, a message under it, a shake); `onSubmit` may return a Promise (spinner,
|
|
602
|
+
error on reject). It sends nothing by itself.
|
|
603
|
+
```js
|
|
604
|
+
import { authForm } from '@gecko-ui-kit/components'
|
|
605
|
+
|
|
606
|
+
const auth = authForm(document.querySelector('#auth'), {
|
|
607
|
+
mode: 'in', // or 'up'
|
|
608
|
+
fields: { name: true, confirm: false, remember: true, forgot: true },
|
|
609
|
+
meter: true, // or passwordMeter options
|
|
610
|
+
onSubmit: async (values, mode) => {
|
|
611
|
+
const res = await fetch(`/api/${mode === 'up' ? 'sign-up' : 'sign-in'}`, { method: 'POST', body: JSON.stringify(values) })
|
|
612
|
+
if (!res.ok) throw Object.assign(new Error('That password isn’t right.'), { field: 'password' })
|
|
613
|
+
},
|
|
614
|
+
onModeChange: (mode) => {}, onForgot: (email) => {},
|
|
615
|
+
})
|
|
616
|
+
auth.mode; auth.setMode('up'); auth.values; auth.setError('email', 'Taken'); auth.reset(); auth.destroy()
|
|
617
|
+
```
|
|
618
|
+
Every string is in `words` (the meter's in `words.meter`).
|
|
619
|
+
|
|
620
|
+
## Donut chart
|
|
621
|
+
Parts of a whole as a ring. Slices draw in one after another when the chart scrolls into view and the total
|
|
622
|
+
counts up in the middle. Point at a slice or its legend row (or use the arrow keys) to lift it and see its
|
|
623
|
+
value and share; click or Enter keeps it picked. `set()` morphs the slices to the new shares.
|
|
624
|
+
```js
|
|
625
|
+
import { donut } from '@gecko-ui-kit/components'
|
|
626
|
+
|
|
627
|
+
const chart = donut(document.querySelector('#sales'), {
|
|
628
|
+
data: [
|
|
629
|
+
{ label: 'Coffee', value: 2480 },
|
|
630
|
+
{ label: 'Pastries', value: 1320, tone: 'amber' }, // 'accent' | 'good' | 'warn' | 'bad' | 'teal' | 'rose' | … or any CSS colour
|
|
631
|
+
{ label: 'Tea', value: 760 },
|
|
632
|
+
],
|
|
633
|
+
thickness: 26, gap: 3,
|
|
634
|
+
legend: 'right', // 'bottom' | false
|
|
635
|
+
sort: 'desc', // 'asc' | false
|
|
636
|
+
format: (v) => '$' + v.toLocaleString('en-US'),
|
|
637
|
+
label: 'Sales by category',
|
|
638
|
+
onSelect: (i, item) => {}, // i is -1 when nothing is picked
|
|
639
|
+
})
|
|
640
|
+
chart.set([{ label: 'Coffee', value: 2900 }, { label: 'Tea', value: 810 }]) // morphs; Pastries shrinks away
|
|
641
|
+
// chart.select(0) · chart.select('Tea') · chart.data · chart.total · chart.destroy()
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
## Gauge
|
|
645
|
+
One number against a range or a goal, on a half-circle dial. The arc fills, the needle swings to the value
|
|
646
|
+
with a small overshoot and the number counts up; `set()` swings from where it is now. Add a `goal` tick and
|
|
647
|
+
coloured `zones` if you like.
|
|
648
|
+
```js
|
|
649
|
+
import { gauge } from '@gecko-ui-kit/components'
|
|
650
|
+
|
|
651
|
+
const sales = gauge(document.querySelector('#today'), {
|
|
652
|
+
value: 864, min: 0, max: 1500,
|
|
653
|
+
goal: 1200, // a tick on the arc; "Goal reached" once it gets there
|
|
654
|
+
zones: [{ to: 600, tone: 'bad', label: 'Slow' }, { to: 1000, tone: 'warn' }, { to: 1500, tone: 'good' }],
|
|
655
|
+
format: (v) => '$' + Math.round(v).toLocaleString('en-US'),
|
|
656
|
+
label: 'Sales today',
|
|
657
|
+
needle: true, // false: the number sits inside the arc
|
|
658
|
+
})
|
|
659
|
+
sales.set(1248) // swings from 864
|
|
660
|
+
// sales.value · sales.destroy()
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
## Heatmap
|
|
664
|
+
Busy days at a glance: one square per day, weeks across and weekdays down, darker = busier, with month names on
|
|
665
|
+
top and a “Less ▢▢▢▢ More” key. Squares grow in week by week when it scrolls into view, a small card glides from
|
|
666
|
+
square to square on hover or with the arrow keys, and `set()` re-shades everything in a ripple.
|
|
667
|
+
```js
|
|
668
|
+
import { heatmap } from '@gecko-ui-kit/components'
|
|
669
|
+
|
|
670
|
+
const busy = heatmap(document.querySelector('#busy'), {
|
|
671
|
+
data: [{ date: '2026-12-03', value: 14 }, { date: '2026-12-04', value: 21 }], // or (date) => number | null
|
|
672
|
+
weeks: 26, weekStart: 1, levels: 4, // or levels: [1, 10, 20, 30]
|
|
673
|
+
tone: 'teal', locale: 'en-GB',
|
|
674
|
+
words: { label: 'Bookings per day', count: (v, text) => (v == null ? 'No data' : `${text} bookings`) },
|
|
675
|
+
onSelect: (day) => showDay(day.date, day.value), // { date, value, level }
|
|
676
|
+
})
|
|
677
|
+
busy.set(newData); busy.select('2026-12-03'); busy.value; busy.destroy()
|
|
678
|
+
```
|
|
679
|
+
An ARIA grid: ↑ ↓ a day, ← → a week, Home / End, Page Up / Page Down a month, Enter picks.
|
|
680
|
+
|
|
681
|
+
## Leaderboard
|
|
682
|
+
A ranked list with a bar for each value. On `set()` every row glides to its new rank, bars stretch, numbers count
|
|
683
|
+
to their new value, climbers flash and show “▲2”, new rows slide in and rows that drop out fade away. A polite
|
|
684
|
+
status tells screen readers who moved up.
|
|
685
|
+
```js
|
|
686
|
+
import { leaderboard } from '@gecko-ui-kit/components'
|
|
687
|
+
|
|
688
|
+
const best = leaderboard(document.querySelector('#best'), {
|
|
689
|
+
items: [
|
|
690
|
+
{ id: 'mug', label: 'Ceramic mug', sub: 'Kitchen', value: 88 },
|
|
691
|
+
{ id: 'tote', label: 'Canvas tote', sub: 'Bags', value: 64, avatar: { name: 'Pim Wong', ini: 'PW', tone: 'indigo' } },
|
|
692
|
+
],
|
|
693
|
+
max: 5, // rows shown (0 = all)
|
|
694
|
+
format: (v) => '฿' + v.toLocaleString('en-US'),
|
|
695
|
+
bars: true, medals: true,
|
|
696
|
+
})
|
|
697
|
+
best.set(newItems) // matched by id
|
|
698
|
+
best.items // [{ …item, rank }]
|
|
699
|
+
```
|
|
700
|
+
`--lbd-c` sets the bar colour.
|
|
701
|
+
|
|
702
|
+
## Spinner
|
|
703
|
+
An orbit loader: a comet with a glowing head sweeps round a faint ring. Pure CSS (keeps turning while scripts are busy),
|
|
704
|
+
sized by `font-size` (the ring is 1em across). With reduced motion the comet stops and the ring breathes slowly.
|
|
705
|
+
```js
|
|
706
|
+
import { spinner } from '@gecko-ui-kit/components'
|
|
707
|
+
|
|
708
|
+
list.innerHTML = spinner({ size: 36, label: 'Loading bookings…', stack: true })
|
|
709
|
+
button.querySelector('svg').outerHTML = spinner({ size: '1.15em', tone: 'current', decorative: true })
|
|
710
|
+
```
|
|
711
|
+
Options: `size` (28), `tone` (`accent ink muted good warn bad current`), `speed` (s per lap), `track`, `label`, `stack`,
|
|
712
|
+
`words: { loading }` (the hidden text when there is no label), `decorative`, `cls`. CSS: `--orb-c`, `--orb-track`,
|
|
713
|
+
`--orb-w`, `--orb-head`, `--orb-speed`. It has `role="status"`, so the label (or a hidden "Loading…") is read out.
|