@gecko-ui-kit/react 0.0.0-stage → 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/README.md CHANGED
@@ -1,3 +1,1824 @@
1
- # Temporary Holding Version
1
+ # @gecko-ui-kit/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Every [Gecko UI Kit](https://woraphondev.github.io/UI-Package/playground/) piece as a React component: buttons, forms,
4
+ pickers, data display, charts, text and scroll motion, overlays and the app shell. Made for Next.js (App Router):
5
+ every component renders on the server and wakes up in the browser, and comes with TypeScript types.
6
+
7
+ ```bash
8
+ npm install gsap @gecko-ui-kit/react
9
+ ```
10
+ It brings the other Gecko packages with it. `react` and `react-dom` 18 or newer come from your app.
11
+
12
+ ## Set up (Next.js)
13
+
14
+ Load the CSS once, in the root layout, in this order:
15
+
16
+ ```tsx
17
+ // app/layout.tsx
18
+ import '@gecko-ui-kit/tokens/style.css' // variables + small reset (first)
19
+ import '@gecko-ui-kit/motion/motion.css'
20
+ import '@gecko-ui-kit/components/style.css'
21
+ import '@gecko-ui-kit/overlays/style.css'
22
+ import '@gecko-ui-kit/shell/style.css' // only if you use the app shell
23
+ import './globals.css' // your own styles last
24
+ ```
25
+
26
+ Then use the components anywhere, in server or client components:
27
+
28
+ ```tsx
29
+ // app/bikes/page.tsx
30
+ import { Card, Tag, Button } from '@gecko-ui-kit/react'
31
+
32
+ export default function Bikes() {
33
+ return (
34
+ <Card title="Honda Click 125" sub="Plate 1กข 1234" right={<Tag tone="good">Available</Tag>}>
35
+ <Button variant="primary" icon="calendar">Book</Button>
36
+ </Card>
37
+ )
38
+ }
39
+ ```
40
+
41
+ Pieces you control with state need a client component, as usual in Next.js:
42
+
43
+ ```tsx
44
+ 'use client'
45
+ import { useState } from 'react'
46
+ import { Segmented, DateRange, toast } from '@gecko-ui-kit/react'
47
+
48
+ export function BookingFilters() {
49
+ const [view, setView] = useState('list')
50
+ return <>
51
+ <Segmented value={view} onChange={setView} options={[['list', 'List', 'list'], ['calendar', 'Calendar', 'calendar']]} />
52
+ <DateRange onChange={(range) => toast(`From ${range.start}`)} />
53
+ </>
54
+ }
55
+ ```
56
+
57
+ Works the same in Vite, Remix or any React 18+ app: just import the CSS in your entry file.
58
+
59
+ ## How the components behave
60
+
61
+ - **Same look as the vanilla kit.** Each component draws the same HTML (same classes) as its vanilla piece, or runs the
62
+ vanilla piece inside an element React leaves alone, so the CSS, motion and accessibility are identical.
63
+ - **Value props.** A piece with a value takes `value` + `onChange` (controlled) or `defaultValue` (uncontrolled).
64
+ A new `value` updates the piece in place (it animates to it); it does not rebuild it.
65
+ - **Callbacks are always fresh.** Pass inline arrow functions freely: they never cause a rebuild, and the piece always
66
+ calls the latest one.
67
+ - **Your content is React.** Titles, card bodies, modal and drawer bodies, popover and tooltip content, slides, steps,
68
+ kanban cards… take React nodes. Nothing asks you for HTML strings, except a few `render(value) → string` callbacks
69
+ for many small cells (data grid), which say so in their types.
70
+ - **Refs.** Markup pieces give the DOM element. Pieces that the vanilla code builds (DataGrid, Calendar, Rating…) give
71
+ their handle (`ref.current.set(4)`, `ref.current.el`), the same methods as the vanilla API.
72
+ - **Server rendering.** Markup pieces render fully on the server. Pieces the vanilla code builds render an empty slot on
73
+ the server and appear when the page wakes up. Nothing reads `window` or `localStorage` while rendering.
74
+ - **Reduced motion** is honoured everywhere, as in the vanilla kit.
75
+ - **Texts** shown by a piece come from a `words` prop (English by default), e.g. `words={{ loading: 'กำลังโหลด…' }}`.
76
+ - **Any motion helper** without its own component can run on your own element with `useMotion`:
77
+ `const ref = useMotion(rise, [])` then `<ul ref={ref}>…</ul>`.
78
+
79
+ ## Components
80
+
81
+ - [Basics](#basics): `Button`, `IconButton`, `Spinner`, `Tag`, `Badge`, `Avatar`, `AvatarGroup`, `Cell`, `Card`, `Kpi`, `Empty`, `Table`, `Meter`, `Ring`, `Steps`, `Bars`, `Field`, `Input`, `Textarea`
82
+ - [Controls](#controls): `Switch`, `Segmented`, `Checkbox`, `Tabs`, `Chips`, `Range`, `Swatch`, `SearchBox`, `Select`, `Otp`
83
+ - [Forms](#forms): `MultiSelect`, `Combobox`, `TagsInput`, `RangeSlider`, `Stepper`, `Rating`, `RadioCards`, `SubscribeForm`, `PasswordMeter`, `PasswordToggle`, `AuthForm`, `SignaturePad`, `PhotoUpload`, `FileDrop`, `PricingToggle`, `DateRange`, `TimePicker`, `Wizard`, `useValidation`
84
+ - [Data display](#data-display): `Accordion`, `Carousel`, `BeforeAfter`, `Tree`, `DataGrid`, `VirtualList`, `Timeline`, `Calendar`, `SwipeItem`, `SwipeActions`, `Kanban`, `Notifications`, `Activity`, `Pagination`, `Breadcrumbs`, `Skeleton`, `Alert`
85
+ - [Action buttons](#action-buttons): `LikeButton`, `BellSwitch`, `PayButton`, `SpeedDial`, `Typing`
86
+ - [Charts](#charts): `LineChart`, `Donut`, `Gauge`, `Leaderboard`, `Heatmap`
87
+ - [Text & scroll motion](#text--scroll-motion): `TextReveal`, `Typewriter`, `Rotator`, `Shine`, `Highlighter`, `ScrollReveal`, `BlurIn`, `ScrollProgress`, `Odometer`, `CountUp`
88
+ - [Motion wrappers](#motion-wrappers): `Rise`, `Magnetic`, `Lift`, `Tilt`, `Spotlight`, `Marquee`, `useMotion`
89
+ - [Interactive effects](#interactive-effects): `Indicator`, `PageSwap`, `useFeedback`, `useFlash`, `useTick`, `ConfettiButton`, `useConfetti`, `Sortable`, `ThemeToggle`, `useTheme`, `SendButton`, `DeleteButton`, `DownloadButton`, `HoldButton`, `ExpandSearch`, `LiquidTabs`, `Burger`
90
+ - [Overlays](#overlays): `Modal`, `Drawer`, `confirm`, `useConfirm`, `Popover`, `Menu`, `ContextMenu`, `Tooltip`, `toast`, `CookieBanner`, `LoadingBar`, `useLoadingBar`, `CommandPalette`, `Tour`, `Lightbox`, `LightboxGallery`
91
+ - [App shell](#app-shell): `AppShell`, `Sidebar`, `Topbar`, `PageHeader`, `MobileTabbar`
92
+
93
+ ## Basics
94
+
95
+ ### Button
96
+ A button with a look (variant), a size and an optional icon; `busy` locks it and shows a spinner while it works.
97
+ ```tsx
98
+ <Button variant="primary" icon="check" busy={saving} busyText="Saving…" onClick={saveBooking}>Save booking</Button>
99
+ ```
100
+ - `variant`: `primary` `dark` `ghost` `danger` · `size`: `sm` `lg`
101
+ - `icon`, `iconRight`: an icon name or any node · `block`: full width · `magnetic`: leans toward the mouse
102
+ - `busy`, `busyText`: working state (disabled, `aria-busy`, spinner) · every `<button>` prop works
103
+
104
+ ### IconButton
105
+ A square button that shows only an icon; the label is read by screen readers.
106
+ ```tsx
107
+ <IconButton icon="bell" label="Notifications" onClick={openInbox} />
108
+ <IconButton icon="heart" label="Favourite bike" pressed={fav} onChange={setFav} size="sm" />
109
+ ```
110
+ - `icon`, `label` (aria-label), `size: 'sm'`
111
+ - `pressed` / `defaultPressed` + `onChange(pressed)`: an on/off button (`aria-pressed`, pops when pressed)
112
+
113
+ ### Spinner
114
+ The orbit loader: a comet circling a faint ring; with reduced motion it breathes instead.
115
+ ```tsx
116
+ {loading ? <Spinner size={36} label="Loading bookings…" stack /> : <BookingList />}
117
+ ```
118
+ - `size` (px or CSS length, the ring is 1em), `tone` (`accent` `ink` `muted` `good` `warn` `bad` `current`), `speed` (s per lap)
119
+ - `label`, `stack` (label under the ring), `track`, `decorative` (hidden from screen readers), `words: { loading }`
120
+
121
+ ### Tag
122
+ A small coloured status label.
123
+ ```tsx
124
+ <Tag tone={booking.paid ? 'good' : 'warn'}>{booking.paid ? 'Paid' : 'Unpaid'}</Tag>
125
+ ```
126
+ - `tone`: `good` `warn` `bad` `accent` `plain` · `dot` (default true) · `icon` instead of the dot
127
+
128
+ ### Badge
129
+ A small round count.
130
+ ```tsx
131
+ <Button variant="ghost">Inbox <Badge tone="accent">{unread}</Badge></Button>
132
+ ```
133
+ - `tone: 'accent'` · children: the number
134
+
135
+ ### Avatar
136
+ A round avatar with initials in one of eight colours; without a name it is an empty "open slot".
137
+ ```tsx
138
+ <Avatar name="Pim Wong" tone="teal" size="lg" online />
139
+ <Avatar /> {/* nobody assigned yet */}
140
+ ```
141
+ - `name` (tooltip, initials), `ini`, `tone` (`indigo` `teal` `rose` `amber` `violet` `green` `slate` `sky`)
142
+ - `size`: `sm` `lg` · `online`: green dot
143
+
144
+ ### AvatarGroup
145
+ Small overlapping avatars, then "+N".
146
+ ```tsx
147
+ <AvatarGroup people={task.assignees} max={4} />
148
+ ```
149
+ - `people`: `{ id?, name, ini?, tone? }[]` · `max` (default 4)
150
+
151
+ ### Cell
152
+ An avatar with a name and a small line under it, for lists and table cells.
153
+ ```tsx
154
+ <Cell name={rider.name} tone="rose" sub={rider.phone} />
155
+ ```
156
+ - `name`, `ini`, `tone`, `online` · `sub`: any node
157
+
158
+ ### Card
159
+ A white panel with an optional head (title, small line, things on the right); `lift` rises on hover.
160
+ ```tsx
161
+ <Card title="Today" sub={`${bookings.length} bookings`} right={<Button size="sm" variant="ghost">See all</Button>} lift>
162
+ <BookingList items={bookings} />
163
+ </Card>
164
+ ```
165
+ - `title`, `sub`, `right`: any nodes (the head shows when `title` is set) · `flush`: no padding · `lift`
166
+ - `CardHead` draws just the head row (`title`, `sub`, `right`)
167
+
168
+ ### Kpi
169
+ A number tile: a caption, a big value and a small line.
170
+ ```tsx
171
+ <div className="kpis">
172
+ <Kpi label="Bikes out" value={12} sub="of 20" />
173
+ <Kpi label="Revenue" value="฿48,250" sub="This month" tone="good" />
174
+ </div>
175
+ ```
176
+ - `label`, `value`, `sub`: any nodes · `tone`: `accent` `good` `bad`
177
+
178
+ ### Empty
179
+ What to show when a list has nothing in it.
180
+ ```tsx
181
+ <Empty icon="search" title={`No bikes match “${q}”`} body="Check the spelling or try a shorter word."
182
+ action={<Button size="sm" icon="close" onClick={() => setQ('')}>Clear search</Button>} />
183
+ ```
184
+ - `icon`, `title`, `body`, `action`: nodes
185
+
186
+ ### Table
187
+ A table styled by `.table`, inside `.table-wrap` so it scrolls sideways on phones. Give it columns and rows, or write the `<thead>`/`<tbody>` yourself.
188
+ ```tsx
189
+ <Card title="Bookings" flush>
190
+ <Table rows={bookings} rowKey="id" slideRows columns={[
191
+ { key: 'rider', title: 'Rider', render: (b) => <Cell name={b.rider} sub={b.phone} /> },
192
+ { key: 'status', title: 'Status', render: (b) => <Tag tone={b.paid ? 'good' : 'warn'}>{b.paid ? 'Paid' : 'Unpaid'}</Tag> },
193
+ { key: 'days', title: 'Days', align: 'right' },
194
+ ]} />
195
+ </Card>
196
+ ```
197
+ - `columns`: `{ key, title, align: 'right', render(row) }[]` · `rows` · `rowKey` (field or function) · `foot`: `<tr>`s for a `<tfoot>`
198
+ - `slideRows`: rows slide in when they first appear · `wrap` (default true)
199
+
200
+ ### Meter
201
+ A thin bar that fills from zero, and glides when the value changes.
202
+ ```tsx
203
+ <Meter value={task.done / task.total} tone={late ? 'warn' : undefined} />
204
+ ```
205
+ - `value`: 0 to 1 · `tone`: `good` `warn` `bad` · `delay`
206
+
207
+ ### Ring
208
+ A round progress ring with a label in the middle; it sweeps on from the last value.
209
+ ```tsx
210
+ <Ring value={0.72} size={80} stroke={8} label="72%" />
211
+ ```
212
+ - `value`: 0 to 1 · `size` (56), `stroke` (6) · `label`: any node
213
+
214
+ ### Steps
215
+ A row of numbered steps: done ones get a tick, the bar fills up to the current one, the new dot pops.
216
+ ```tsx
217
+ <Steps labels={['Bike', 'Dates', 'Extras', 'Pay']} now={step} />
218
+ ```
219
+ - `labels`: nodes · `now`: the current step from 0
220
+
221
+ ### Bars
222
+ A small column chart: bars grow up from the baseline, then morph when the values change.
223
+ ```tsx
224
+ <Bars values={perDay} labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri']} showValues height={160} />
225
+ ```
226
+ - `values`, `max` (default: the biggest), `labels`, `showValues`, `format(value)`
227
+ - `highlightTop` (default true), `height` (210), `label` for screen readers
228
+
229
+ ### Field
230
+ A label above a control and a small hint under it.
231
+ ```tsx
232
+ <Field label="Phone" hint="We text the pick-up code here." invalid={!!error}>
233
+ <Input type="tel" value={phone} onChange={(e) => setPhone(e.target.value)} />
234
+ </Field>
235
+ ```
236
+ - `label`, `hint`: nodes · `invalid`: red border and hint
237
+
238
+ ### Input
239
+ A text input with the kit's look; every `<input>` prop works.
240
+ ```tsx
241
+ <Input type="email" placeholder="you@shop.com" size="sm" />
242
+ ```
243
+ - `size: 'sm'` · all `<input>` props
244
+
245
+ ### Textarea
246
+ A text area with the same look; `autoGrow` makes it taller with each line, up to a limit.
247
+ ```tsx
248
+ <Field label="Note for the mechanic"><Textarea rows={1} autoGrow={6} value={note} onChange={(e) => setNote(e.target.value)} /></Field>
249
+ ```
250
+ - `autoGrow`: `true` (6 lines) or a number of lines · `size: 'sm'` · all `<textarea>` props
251
+
252
+ ## Controls
253
+
254
+ Each control works controlled (`value` / `checked` + `onChange`) or uncontrolled (`defaultValue` / `defaultChecked`).
255
+
256
+ ### Switch
257
+ An on/off switch; the knob springs across.
258
+ ```tsx
259
+ <Switch checked={settings.sms} onChange={(on) => save({ sms: on })} label="SMS reminders" />
260
+ ```
261
+ - `checked` / `defaultChecked`, `onChange(checked, event)`, `label` (aria-label)
262
+
263
+ ### Segmented
264
+ A row of options where exactly one is picked; the thumb stretches to the new choice.
265
+ ```tsx
266
+ <Segmented options={[['list', 'List', 'list'], ['board', 'Board', 'cards']]} value={view} onChange={setView} />
267
+ ```
268
+ - `options`: `[value, label, icon?]`, `{ value, label, icon, disabled }` or strings · `value` / `defaultValue` · `onChange(value)` · `size: 'sm'`
269
+
270
+ ### Checkbox
271
+ A tick box that pops when ticked.
272
+ ```tsx
273
+ <Checkbox checked={task.done} onChange={(done) => updateTask(task.id, { done })} label={task.title} />
274
+ ```
275
+ - `checked` / `defaultChecked`, `onChange(checked, event)`, `label` (aria-label)
276
+
277
+ ### Tabs
278
+ Tab buttons with a line that stretches to the selected one; a count shows as a badge.
279
+ ```tsx
280
+ <Tabs items={[['all', 'All tasks'], ['mine', 'Mine', myCount], ['done', 'Done']]} value={tab} onChange={setTab} />
281
+ ```
282
+ - `items`: `[value, label, count?]`, `{ value, label, count, disabled }` or strings · `value` / `defaultValue` · `onChange(value)` · `name`
283
+
284
+ ### Chips
285
+ Pill buttons for filters: one picked, or several with `multi`.
286
+ ```tsx
287
+ <Chips options={[['all', 'All'], ['scooter', 'Scooters', 'moto'], ['ebike', 'E-bikes', 'bike']]} value={kind} onChange={setKind} />
288
+ <Chips multi options={['morning', 'day', 'late']} value={shifts} onChange={setShifts} />
289
+ ```
290
+ - `options` (like Segmented) · `multi` · `value` / `defaultValue` (an array with `multi`) · `onChange(value | values)`
291
+
292
+ ### Range
293
+ A slider with a filled track (it fills up from zero when first shown) and a springy thumb.
294
+ ```tsx
295
+ <Field label="Days" hint={`${days} days`}><Range min={1} max={14} value={days} onChange={setDays} /></Field>
296
+ ```
297
+ - `min`, `max`, `step` · `value` / `defaultValue` (number) · `onChange(value, event)`
298
+
299
+ ### Swatch
300
+ A colour picker drawn as a round swatch; it pops when a colour is picked.
301
+ ```tsx
302
+ <Swatch value={label.colour} onChange={(c) => setLabel({ ...label, colour: c })} aria-label="Label colour" />
303
+ ```
304
+ - `value` / `defaultValue` (`'#rrggbb'`) · `onChange(value, event)`
305
+
306
+ ### SearchBox
307
+ A text field with a magnifying glass; Enter searches, an empty box shakes.
308
+ ```tsx
309
+ <SearchBox placeholder="Search bikes…" value={q} onChange={setQ} onSearch={(text) => router.push(`/bikes?q=${encodeURIComponent(text)}`)} />
310
+ ```
311
+ - `placeholder` (also the aria-label) · `value` / `defaultValue` · `onChange(value)` · `onSearch(text)` · `size: 'sm'`
312
+ - `className` / `style` go on the box, other props on the `<input>`; `ref` is the `<input>`
313
+
314
+ ### Select
315
+ The animated dropdown: a real `<select>` (forms and `FormData` keep working) shown as a button whose list pops out, with a highlight that follows the mouse and the arrow keys.
316
+ ```tsx
317
+ <Field label="Assign to">
318
+ <Select name="owner" value={owner} onChange={setOwner} options={[
319
+ { group: 'Design', options: [['pim', 'Pim Wong'], ['ann', 'Ann Ko']] },
320
+ { group: 'Engineering', options: [['tom', 'Tom Lee'], ['max', 'Max Ru']] },
321
+ ]} />
322
+ </Field>
323
+ ```
324
+ - `options`: `[value, label, icon?]`, `{ value, label, icon, disabled }`, strings, or `{ group, options }` (labels are text, icons are icon names)
325
+ - `value` / `defaultValue` (default: the first option) · `onChange(value, event)` · `size: 'sm'` · `disabled`, `name`, …
326
+ - `ref` is the `<select>`; `dropdown(ref.current)` from `@gecko-ui-kit/overlays` gives `{ open, close, sync }`
327
+
328
+ ### Otp
329
+ A code field with one box per character: typing moves on, Backspace goes back, paste or the phone's code autofill fills every box. Return the answer from `onComplete` to play it.
330
+ ```tsx
331
+ <Otp length={6} split autoFocus onComplete={async (code) => (await api.verifyPhone(code)).ok} />
332
+ ```
333
+ - `length` (6), `split`, `mask` (PIN dots), `letters` (A–Z too), `label`, `name`
334
+ - `onComplete(code, el)`: return / resolve `true` (green wave, then a tick) or `false` (shake, then clear) · `gather`, `clear`
335
+ - `value` / `defaultValue`, `onChange(code)` · `disabled` · `ref` is the `.otp` element (`otpState` / `otpClear` work on it)
336
+
337
+ ## Forms
338
+
339
+ Every piece with a value works two ways: pass `value` + `onChange` to control it, or `defaultValue` to let it keep its own.
340
+ A new `value` is applied in place (the piece animates to it, nothing is rebuilt, and `onChange` is not called).
341
+ `ref` gives the piece's handle (its methods, plus `el`). Changing an option that has no in-place method builds the piece again.
342
+
343
+ ### MultiSelect
344
+ Pick several people, labels or options; each pick flies up into the field as a chip.
345
+ ```tsx
346
+ const [who, setWho] = useState<string[]>(['ploy']);
347
+ <MultiSelect
348
+ options={[{ value: 'ploy', label: 'Ploy', person: true }, { value: 'tom', label: 'Tom', person: true }]}
349
+ value={who} onChange={setWho} max={3} placeholder="Assign to…" />
350
+ ```
351
+ - `options` (strings or `{ value, label, sub, group, person, color, icon, disabled }`), `value` / `defaultValue`
352
+ - `max`, `creatable`, `closeOnSelect`, `name`, `disabled`, `words`
353
+ - `onChange(values, options, ms)`, `onCreate(option, ms)`; ref: `set`, `add`, `remove`, `clear`, `open`, `setOptions`
354
+
355
+ ### Combobox
356
+ A text field you type into to find one option; it can ask your server instead of a fixed list.
357
+ ```tsx
358
+ <Combobox label="Pick-up branch" options={branches} value={branch} onChange={(v) => setBranch(v)} />
359
+ <Combobox label="Customer" source={(q, { signal }) => fetch(`/api/customers?q=${q}`, { signal }).then((r) => r.json())} />
360
+ ```
361
+ - `options` or `source(query, { signal })`, `value` / `defaultValue`
362
+ - `clearable`, `allowCustom`, `minChars`, `debounce`, `maxResults`, `name`, `label`, `disabled`, `words`
363
+ - `onChange(value, option, cb)`, `onInput(text, cb)`
364
+
365
+ ### TagsInput
366
+ Type words and each one becomes a tag; a comma or Enter makes a tag, pasting a list makes many.
367
+ ```tsx
368
+ <TagsInput value={labels} onChange={setLabels} suggestions={['bug', 'design', 'mobile']} max={5} />
369
+ ```
370
+ - `value` / `defaultValue`, `suggestions`, `max`, `unique`, `separators`
371
+ - `validate(text) → true | 'message'`, `transform(text)`, `name`, `disabled`, `words`
372
+ - `onChange(tags, ti)`; ref: `add`, `remove`, `clear`, `set`
373
+
374
+ ### RangeSlider
375
+ Two thumbs for a low and a high value, with an optional histogram behind the track.
376
+ ```tsx
377
+ <RangeSlider label="Price per day" min={0} max={2000} step={50} value={price} onChange={setPrice}
378
+ format={(v) => `฿${v.toLocaleString()}`} histogram={[2, 5, 9, 4, 1]} />
379
+ ```
380
+ - `min`, `max`, `step`, `value` / `defaultValue` (`[low, high]`), `minGap`
381
+ - `format`, `parse`, `marks`, `histogram`, `inputs`, `name`, `label`, `disabled`, `words`
382
+ - `onInput(value, rs)` while dragging, `onChange(value, rs)` when it settles
383
+
384
+ ### Stepper
385
+ − and + around a number whose digits roll like an odometer.
386
+ ```tsx
387
+ <Stepper value={days} onChange={setDays} min={1} max={30} unit={(n) => (n === 1 ? 'day' : 'days')} />
388
+ ```
389
+ - `value` / `defaultValue`, `min`, `max` (applied in place), `step`
390
+ - `unit`, `prefix`, `format`, `locale`, `size`, `name`, `disabled`, `words`
391
+ - `onChange(value, st)`; ref: `set`, `stepBy`, `setRange`
392
+
393
+ ### Rating
394
+ Stars (or hearts) to give a score, or to show one read-only.
395
+ ```tsx
396
+ <Rating value={score} onChange={setScore} labels={['Bad', 'Poor', 'Okay', 'Good', 'Great']} />
397
+ <Rating defaultValue={4.6} readOnly size="sm" />
398
+ ```
399
+ - `value` / `defaultValue`, `max`, `half`, `readOnly` (applied in place), `clearable`
400
+ - `icon`, `size`, `labels`, `showValue`, `name`, `disabled`, `words`
401
+ - `onChange(value, r)`; ref: `set`, `setReadOnly`
402
+
403
+ ### RadioCards
404
+ Choices drawn as cards (real radio buttons underneath), exactly one picked.
405
+ ```tsx
406
+ <RadioCards label="Choose a bike" value={bike} onChange={setBike} options={[
407
+ { value: 'scoot', title: 'Scooter 125', desc: 'Easy in town', price: '฿350 / day', icon: 'moto' },
408
+ { value: 'big', title: 'Scooter 160', desc: 'For two', price: '฿550 / day', badge: 'Popular' },
409
+ ]} />
410
+ ```
411
+ - `options` (`{ value, title, desc, price, icon, badge, disabled }`), `value` / `defaultValue`
412
+ - `label`, `hideLabel`, `layout` (`list` | `grid`), `min`, `name`, `required`, `disabled`, `words`
413
+ - `onChange(value, option, plan)`
414
+
415
+ ### SubscribeForm
416
+ One email field and a button; the button grows into the thank-you message.
417
+ ```tsx
418
+ <SubscribeForm icon="mail" words={{ button: 'Join the waitlist' }}
419
+ onSubmit={async (email) => { const r = await fetch('/api/waitlist', { method: 'POST', body: email }); if (!r.ok) throw new Error('Try again later.'); }} />
420
+ ```
421
+ - `defaultValue`, `name`, `icon`, `layout` (`row` | `stack`), `validate(email)`, `resetAfter`, `words`
422
+ - `onSubmit(email, sub)` — resolve (a string replaces the thanks text) or reject to show the error; ref: `setError`, `reset`, `state`
423
+
424
+ ### PasswordMeter
425
+ A password field with the strength meter after it: bars, a checklist that ticks off and a padlock.
426
+ ```tsx
427
+ const [pw, setPw] = useState('');
428
+ <div className="field">
429
+ <label htmlFor="team-pw">Password for the team account</label>
430
+ <PasswordMeter id="team-pw" value={pw} onValueChange={setPw} reveal min={10} onChange={(s) => setCanSave(s.valid)} />
431
+ </div>
432
+ ```
433
+ - The meter: `rules` (`{ id, test, label }`), `min`, `minScore`, `score`, `reveal`, `list`, `lock`, `words`, `onChange({ score, level, valid, rules }, pw)`
434
+ - The text: `value` / `defaultValue` + `onValueChange(text, event)`; every other prop (`id`, `name`, `placeholder`…) goes on the `<input>`
435
+ - ref: `score`, `level`, `valid`, `rules`, `check()`, `reveal(on)`
436
+
437
+ ### PasswordToggle
438
+ A password field with a show / hide eye inside it (drawn by React, so it renders fully on the server).
439
+ ```tsx
440
+ <PasswordToggle name="password" autoComplete="current-password" onToggle={(shown) => track(shown)} />
441
+ ```
442
+ - `shown` / `defaultShown`, `onToggle(shown)`, `words: { show, hide }`
443
+ - Every other prop goes on the `<input>`; ref is the `<input>`
444
+
445
+ ### AuthForm
446
+ One card for signing in and creating an account, with checks, a strength meter and a busy button.
447
+ ```tsx
448
+ <AuthForm fields={{ confirm: true }} onForgot={(email) => sendResetLink(email)}
449
+ onSubmit={async (values, mode) => {
450
+ const r = await fetch(`/api/${mode === 'up' ? 'sign-up' : 'sign-in'}`, { method: 'POST', body: JSON.stringify(values) });
451
+ if (r.status === 401) throw Object.assign(new Error('That password isn’t right.'), { field: 'password' });
452
+ }} />
453
+ ```
454
+ - `mode` / `defaultMode` (`in` | `up`), `fields`, `meter`, `min`, `values` (filled in when it mounts), `validate`, `words`
455
+ - `onSubmit(values, mode, f)`, `onModeChange(mode, f)`, `onForgot(email, f)`; ref: `setMode`, `setError`, `reset`, `values`
456
+
457
+ ### SignaturePad
458
+ Sign with a finger, pen or mouse; the ink is thinner when you move fast.
459
+ ```tsx
460
+ const sig = useRef<Mounted<SignaturePadHandle>>(null);
461
+ <SignaturePad ref={sig} onChange={(empty) => setSigned(!empty)} words={{ hint: 'Sign here' }} />
462
+ <Button onClick={() => saveAgreement(sig.current!.toJSON(), sig.current!.toImage({ background: '#fff' }))}>Sign and send</Button>
463
+ <SignaturePad readOnly tools={false} defaultValue={agreement.strokes} />
464
+ ```
465
+ - `color`, `width`, `pressure`, `guide`, `tools`, `readOnly`, `defaultValue` (saved `toJSON()` data), `words`
466
+ - `onChange(isEmpty, sig)`, `onEnd(sig)`; ref: `undo`, `clear`, `replay`, `toJSON`, `fromJSON`, `toImage`, `toSVG`
467
+ - Changing `readOnly` or another option keeps what was signed
468
+
469
+ ### PhotoUpload
470
+ Drop, pick or paste photos; each tile uploads with a ring and can be dragged to reorder (the first is the cover).
471
+ ```tsx
472
+ <PhotoUpload max={8} defaultValue={bike.photos}
473
+ upload={(file, { progress, signal }) => uploadPhoto(file, { onProgress: progress, signal })}
474
+ onChange={(items) => setPhotos(items)} />
475
+ ```
476
+ - `accept`, `max`, `maxSize` (MB), `value` / `defaultValue` (already uploaded: `[{ url }]`), `upload`, `concurrent`, `resize`
477
+ - `cover`, `sortable`, `readOnly`, `capture`, `words`
478
+ - `onChange(items, up)`, `onReject`, `onUploaded`, `onError`; ref: `value`, `settled()`, `add`, `remove`, `move`, `open`
479
+
480
+ ### FileDrop
481
+ A drop zone that lists each file with its own progress bar, tick or error.
482
+ ```tsx
483
+ <FileDrop accept=".pdf,image/*" maxSize={10 * 1024 * 1024} upload={(file, { progress, signal }) => sendReceipt(file, progress, signal)}
484
+ onChange={(files) => setReceipts(files)} />
485
+ ```
486
+ - `accept`, `multiple`, `maxSize` (bytes), `maxFiles`, `upload`, `auto`, `concurrent`, `compact`, `words`
487
+ - `onChange(files, fd)`, `onError(problem, fd)`; ref: `files`, `value`, `add`, `retry`, `cancel`, `clear`, `browse`, `upload()`
488
+
489
+ ### PricingToggle
490
+ Plan cards with a monthly / yearly switch; every price rolls to its new number.
491
+ ```tsx
492
+ <PricingToggle value={period} onChange={setPeriod} locale="th-TH" format={{ style: 'currency', currency: 'THB', maximumFractionDigits: 0 }}
493
+ plans={[{ id: 'shop', name: 'Shop', price: { month: 390, year: 290 }, features: ['20 bikes'], action: 'Choose Shop', featured: true }]}
494
+ onSelect={(plan, period) => router.push(`/checkout?plan=${plan.id}&period=${period}`)} />
495
+ ```
496
+ - `plans`, `periods`, `value` / `defaultValue`, `format`, `locale`, `motion` (`roll` | `count`), `strike`, `words`
497
+ - `onChange(periodId, prices)`, `onSelect(plan, periodId, prices)`
498
+ - Plan texts are plain strings (the piece draws them)
499
+
500
+ ### DateRange
501
+ A month calendar to pick a start and an end (or one date), counting the days or nights.
502
+ ```tsx
503
+ <DateRange value={dates} onChange={(r) => setDates(r)} count="days" min={today} disabled={bookedDays} months={2} />
504
+ ```
505
+ - `mode` (`range` | `single`), `value` / `defaultValue` (`{ start, end }` or one date; `'YYYY-MM-DD'` or `Date`)
506
+ - `months`, `min`, `max`, `disabled`, `count`, `minDays`, `maxDays`, `blockSpan`, `presets`, `locale`, `weekStart`, `words`
507
+ - `onChange({ start, end, count }, dp)` (end is null until it is picked), `onInvalid(reason, dp)`
508
+
509
+ ### TimePicker
510
+ A wheel or a grid of time slots.
511
+ ```tsx
512
+ <TimePicker look="slots" min="09:00" max="18:00" value={pickUp} onChange={setPickUp} disabled={takenSlots} />
513
+ ```
514
+ - `look` (`wheel` | `slots`), `value` / `defaultValue` (`'HH:MM'`), `step`, `min`, `max`, `disabled` (applied in place), `hour12`, `words`
515
+ - `onChange(value, tp)`; ref: `set`, `setDisabled`, `format`
516
+
517
+ ### Wizard
518
+ A long form split into steps that slide sideways; each step's content is your own React.
519
+ ```tsx
520
+ <Wizard words={{ finish: 'Book' }} onFinish={(values) => book(values)} steps={[
521
+ { id: 'bike', title: 'Bike', content: <BikePicker /> },
522
+ { id: 'rider', title: 'Rider', content: <><label className="field"><span>Phone</span><input className="input" name="phone" required /></label></> },
523
+ { id: 'pay', title: 'Payment', content: <PaymentStep />, validate: () => (paid ? true : 'Choose how to pay.') },
524
+ ]} />
525
+ ```
526
+ - `steps` (`{ id, title, sub, content, optional, validate(panel, wz) }`), `index` (controlled) or `start`
527
+ - `linear`, `header` (`steps` | `bar` | `none`), `level`, `label`, `words`
528
+ - `onStep(index, wz)`, `onFinish(values, wz)`; ref: `next()`, `back()`, `go(i)`, `reset()`, `values`
529
+ - Without `validate`, the browser's own checks run on the step's fields (`required`, `type="email"`…)
530
+
531
+ ### useValidation
532
+ The red-field pattern from the Validation page (`.field.is-bad`, the reason in `.field__hint`, a small shake) as a hook.
533
+ It is a pattern, not a piece: you draw the fields, the hook keeps the messages.
534
+ ```tsx
535
+ const v = useValidation({
536
+ name: (x) => (x.trim() ? '' : 'Please type your name.'),
537
+ email: (x) => (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x) ? '' : 'That email looks incomplete.'),
538
+ });
539
+ <label className={cx('field', v.errors.email && 'is-bad')}>
540
+ <span>Email</span>
541
+ <input className="input" type="email" {...v.field('email')} />
542
+ <small className="field__hint">{v.errors.email || 'We send one email when we launch.'}</small>
543
+ </label>
544
+ <Button variant="primary" onClick={() => v.validate() && join(v.values())}>Join the waitlist</Button>
545
+ ```
546
+ - A rule gets `(value, values)` and returns `''` (fine) or the message
547
+ - `v.field(name)` → `name`, `ref`, `onInput`, `aria-invalid` for the input; `v.validate()` marks and shakes the bad fields, true when all are fine
548
+ - `v.errors`, `v.check(name)`, `v.setError(name, message)` (e.g. a server answer), `v.reset()`, `v.values()`
549
+ - Options: `{ live: true }` re-checks a red field on every key, `{ shake: true }`
550
+
551
+ ## Data display
552
+
553
+ These components wrap the vanilla data pieces. The vanilla code builds and animates each piece inside one
554
+ element, and React draws your own content (panels, slides, cards, rows, messages) into it. Data that changes
555
+ (rows, events, cards, items) is applied in place, so the piece's own motion plays: a new card grows in and a
556
+ removed booking folds away. Pass a `ref` to get the piece's handle (its methods, plus `el`).
557
+
558
+ ### Accordion
559
+ A list of headings that open to show more. The panel grows open and the chevron turns.
560
+
561
+ ```tsx
562
+ <Accordion
563
+ defaultValue={['deposit']}
564
+ items={[
565
+ { id: 'helmet', title: 'Is a helmet included?', content: <p>Yes, two helmets come with every bike.</p> },
566
+ { id: 'deposit', title: 'Deposit', sub: 'Returned at drop-off', content: <DepositInfo bike={bike} /> },
567
+ ]}
568
+ />
569
+ ```
570
+ - `items`: `{ id, title, sub, icon, badge, content, open, disabled }`. `content` and `title` can be any React content.
571
+ - `value` / `defaultValue`: the open ids. `onChange(openIds)` · `onToggle(id, open)`.
572
+ - `multiple`, `collapsible`, `look: 'lines' | 'cards'`, `marker: 'chevron' | 'plus'`, `level`.
573
+
574
+ ### Carousel
575
+ Slides you swipe, drag or step through. The current dot stretches into a pill.
576
+
577
+ ```tsx
578
+ <Carousel perView={{ 0: 1, 640: 2, 960: 3 }} peek={40} label="Bikes">
579
+ {bikes.map((b) => <BikeCard key={b.id} bike={b} />)}
580
+ </Carousel>
581
+ ```
582
+ - Each child is one slide. `value` / `defaultValue`: the slide index. `onChange(index)`.
583
+ - `perView`, `gap`, `peek`, `focus`, `rewind`, `autoplay` (ms), `arrows`, `dots`, `label`, `words`.
584
+
585
+ ### BeforeAfter
586
+ Two pictures on top of each other, with a divider you drag to wipe between them.
587
+
588
+ ```tsx
589
+ <BeforeAfter
590
+ before={<img src="/repairs/42-before.jpg" alt="Scratched side panel" />}
591
+ after={<img src="/repairs/42-after.jpg" alt="Repaired side panel" />}
592
+ hint
593
+ />
594
+ ```
595
+ - `before`, `after`: React content. `value` / `defaultValue`: 0–100 (default 50). `onChange(value)` while it moves.
596
+ - `hover`, `hint`, `labels`, `ratio` ('4/3'), `step`, `words`.
597
+
598
+ ### Tree
599
+ Nested items that open and close, like folders, with keyboard support and optional checkboxes.
600
+
601
+ ```tsx
602
+ <Tree
603
+ label="Fleet"
604
+ items={[{ id: 'scooters', label: 'Scooters', open: true, children: [{ id: 'click', label: 'Honda Click' }] }]}
605
+ value={picked}
606
+ onSelect={(ids) => setPicked(ids)}
607
+ />
608
+ ```
609
+ - `items`: `{ id, label, icon, badge, children, open, disabled }` (`children: true` loads with `load(item)`).
610
+ - `value` / `defaultValue`: selected ids. `checked`: ticked ids (with `checkable`). Both change in place.
611
+ - `select: 'single' | 'multiple' | 'none'`, `lines`, `icons`. `onSelect(ids, item)` · `onCheck(ids)` · `onToggle(id, open)` · `onActivate(item)`.
612
+
613
+ ### DataGrid
614
+ A table people can search, filter, sort, page through and edit in place. Rows glide when the order changes.
615
+
616
+ ```tsx
617
+ <DataGrid
618
+ columns={[
619
+ { key: 'plate', label: 'Plate' },
620
+ { key: 'model', label: 'Model', type: 'select', options: ['Click', 'NMAX'], filter: true },
621
+ { key: 'rate', label: 'Rate / day', type: 'number', align: 'right', edit: true },
622
+ ]}
623
+ rows={bikes}
624
+ onChange={(row, key, value) => saveBike(row.id, { [key]: value })}
625
+ />
626
+ ```
627
+ - `rows` changes are applied in place with `setRows()`. Nothing happens when they already match what is on screen.
628
+ - `search`, `pageSize`, `select`, `add`, `remove`, `density`, `stripes`. `onChange(row, key, value, old)` · `onAdd(row)` · `onRemove(rows)`.
629
+ - `columns[].render(value, row)` returns trusted HTML. Escape app text yourself, or use `format` for plain text.
630
+
631
+ ### VirtualList
632
+ Thousands of rows, but only the ones you can see are in the page.
633
+
634
+ ```tsx
635
+ <VirtualList
636
+ items={customers}
637
+ rowHeight={56}
638
+ height={480}
639
+ selectable
640
+ renderItem={(c) => <CustomerRow customer={c} />}
641
+ onSelect={(c) => openCustomer(c.id)}
642
+ />
643
+ ```
644
+ - `renderItem(item, index)` draws a row with React. You can also use `render(item, index)`, which returns trusted HTML or a Node.
645
+ - `items` changes are applied in place with `update()`. `value` / `defaultValue`: the key of the picked row.
646
+ - `rowHeight` (px or `'auto'`), `estimate`, `height`, `overscan`, `key(item)`, `label`. `onSelect(item, index)` · `onRange(range)`.
647
+
648
+ ### Timeline
649
+ A booking timeline: rows of things you rent against days. Drag a bar to move it, or stretch it from either end.
650
+
651
+ ```tsx
652
+ <Timeline
653
+ title="Bookings"
654
+ rows={bikes.map((b) => ({ id: b.id, label: b.name, sub: b.plate }))}
655
+ items={bookings}
656
+ days={14}
657
+ onChange={(booking) => saveBooking(booking)}
658
+ />
659
+ ```
660
+ - `items`: `{ id, row, start, end, label, status, color, edit }`. Changes are applied in place (bars glide and grow).
661
+ - `from`, `days`, `locale`, `edit`, `overlap`, `minDays`, `now`, `late`, `sub(item, days)`. `onChange(item, before)` · `onOpen(item)` · `onAdd({ row, start })` · `onClash(item, other)`.
662
+
663
+ ### Calendar
664
+ A month calendar with events as small chips. It slides from month to month, and you can drag events to other days.
665
+
666
+ ```tsx
667
+ <Calendar
668
+ events={bookings.map((b) => ({ id: b.id, title: b.bike, start: b.from, end: b.to, tone: 'good' }))}
669
+ value={day}
670
+ onDay={(date) => setDay(date)}
671
+ draggable
672
+ onMove={(ev, start, end) => moveBooking(ev.id, start, end)}
673
+ />
674
+ ```
675
+ - `value` / `defaultValue`: the picked day. `month`: the month on show. `events`: applied with `setEvents()`. All three change in place.
676
+ - `weekStart`, `locale` (`'th'` gives Thai with the Buddhist year), `maxPerDay`, `selectable`, `draggable`, `size`.
677
+ - `onMonth(date)` · `onDay(date, events)` · `onEvent(event)` · `onMove(event, start, end)` (return false to put it back).
678
+
679
+ ### SwipeItem and SwipeActions
680
+ List rows you slide sideways to show buttons behind them (archive, delete…). A long swipe runs the edge button.
681
+
682
+ ```tsx
683
+ <SwipeActions className="card card--flush" onAction={(action, ctx) => {
684
+ if (action === 'cancel') toast('Booking cancelled', { undo: () => ctx.undo() });
685
+ }}>
686
+ {bookings.map((b) => (
687
+ <SwipeItem key={b.id} id={b.id}
688
+ end={[{ id: 'cancel', label: 'Cancel', icon: 'trash', tone: 'bad', remove: true }, { id: 'call', label: 'Call', icon: 'phone' }]}>
689
+ <BookingRow booking={b} />
690
+ </SwipeItem>
691
+ ))}
692
+ </SwipeActions>
693
+ ```
694
+ - `SwipeItem`: `id`, `start` (pull right), `end` (pull left), `look: 'both' | 'icons' | 'labels'`, `label`. Children are the row.
695
+ - `SwipeActions`: `full`, `fullAt`, `single`, `haptic`. `onAction(action, ctx)`: ctx is `{ row, id, action, undo() }`. `onOpen(row, side)` · `onClose(row)`.
696
+ - A row with `remove: true` slides off and is hidden. Remove it from your list when you are done, or call `ctx.undo()` to bring it back.
697
+
698
+ ### Kanban
699
+ Columns of cards you drag between columns or up and down. A picked-up card hangs from where you hold it.
700
+
701
+ ```tsx
702
+ <Kanban
703
+ columns={[{ id: 'todo', title: 'To do' }, { id: 'doing', title: 'Doing', limit: 3 }, { id: 'done', title: 'Done' }]}
704
+ cards={tasks}
705
+ renderCard={(t) => <TaskCard task={t} />}
706
+ onMove={(card, { to, index }) => moveTask(card.id, to, index)}
707
+ />
708
+ ```
709
+ - `renderCard(card)` draws each card with React. Leave it out to get the built-in card (`tags`, `title`, `text`).
710
+ - `cards` changes are applied in place: new cards grow in, removed ones fold away, moved ones slide.
711
+ - `strictLimit`, `canDrop(card, column)`. `onMove(card, { from, to, index })` (return false to put it back) · `onOpen(card)` · `onAdd(column)`.
712
+
713
+ ### Notifications
714
+ A notification feed, newest first and grouped by day. New ones slide in at the top, and unread dots fade when read.
715
+
716
+ ```tsx
717
+ <Notifications
718
+ items={notes}
719
+ onOpen={(n) => markRead(n.id)}
720
+ onAction={async (n, action) => { await api.answer(n.id, action); return action === 'accept' ? 'Accepted' : 'Declined'; }}
721
+ />
722
+ ```
723
+ - `items`: `{ id, time, title, body, person, icon, tone, read, actions, href }`. Changes are applied in place.
724
+ - `filter: 'all' | 'unread'`, `group`, `header`, `tabs`, `markAll`, `dismissible`, `height`, `plain`, `locale`.
725
+ - `onOpen(item)` · `onAction(item, actionId)` · `onDismiss(item)` · `onChange(unreadCount)`.
726
+
727
+ ### Activity
728
+ An activity timeline: who did what, and when. The line draws down, and new events push in at the top.
729
+
730
+ ```tsx
731
+ <Activity
732
+ locale="th"
733
+ items={[{ id: 'a1', who: { name: 'Pim' }, what: 'returned the Honda Click', time: returnedAt, icon: 'check', tone: 'good' }]}
734
+ />
735
+ ```
736
+ - `items`: `{ id, time, who, what, title, detail, icon, tone }`. New ones at the top are added with the push-down motion.
737
+ - `marks: 'auto' | 'icon' | 'avatar' | 'dot'`, `latest`, `max`, `intro`, `locale`, `format(date)`, `refresh`.
738
+
739
+ ### Pagination
740
+ Page numbers with previous and next arrows. The highlight stretches from number to number.
741
+
742
+ ```tsx
743
+ <Pagination total={240} pageSize={size} value={page} onChange={(p, s) => { setPage(p); setSize(s); }} />
744
+ ```
745
+ - `value` / `defaultValue`: the page (from 1). `total` changes are applied in place. `onChange(page, pageSize)`.
746
+ - `pageSize`, `sizes`, `siblings`, `boundaries`, `info`, `look: 'numbers' | 'simple'`, `compact`, `words`.
747
+
748
+ ### Breadcrumbs
749
+ The path to the current page. A long path folds its middle steps into “…”.
750
+
751
+ ```tsx
752
+ <Breadcrumbs
753
+ items={[{ label: 'Fleet', href: '/fleet' }, { label: 'Scooters', href: '/fleet/scooters' }, { label: 'Honda Click' }]}
754
+ onNavigate={(item, i, e) => { if (item.href) { e.preventDefault(); router.push(item.href); } }}
755
+ />
756
+ ```
757
+ - `items`: `{ label, href, icon, id }`. A new path is set like a route change: shared steps stay, new ones slide in.
758
+ - `max`, `separator: 'chevron' | 'slash' | 'dot'`, `size`. `onNavigate(item, index, event)`.
759
+
760
+ ### Skeleton
761
+ Grey placeholders in the shape of what is loading. When loading ends, the real rows rise into their place.
762
+
763
+ ```tsx
764
+ <Skeleton look="list" rows={4} loading={!riders} label="Riders">
765
+ {riders && <RiderList riders={riders} />}
766
+ </Skeleton>
767
+ ```
768
+ - Children are the real content. When `loading` turns false the content is revealed. Set it back to true to show the placeholders again.
769
+ - `look: 'list' | 'card' | 'text' | 'table' | 'custom'`, `rows`, `avatar`, `media`, `lines`, `cols`, `shimmer`, `label`.
770
+
771
+ ### Alert
772
+ A message in the page: saved, couldn't save, a warning. Tone and text changes cross-fade and slide.
773
+
774
+ ```tsx
775
+ <Alert tone="bad" title="Couldn't save the booking" dismissible open={showError} onClose={() => setShowError(false)}
776
+ actions={[{ label: 'Try again', primary: true, run: () => saveBooking() }]}>
777
+ The Honda Click is already booked on <b>4–6 Dec</b>.
778
+ </Alert>
779
+ ```
780
+ - Children are the message. `tone`, `title`, `icon` and `actions` change in place.
781
+ - `open: false` folds it away, and `true` grows it back. `onClose()` runs after ✕ or Esc closes it.
782
+ - `look: 'soft' | 'outline' | 'solid' | 'banner'`, `dismissible`, `words`.
783
+
784
+ ## Action buttons
785
+
786
+ ### LikeButton
787
+
788
+ A like, star or bookmark button that pops (or fills) when it turns on, with a count that rolls up and down.
789
+
790
+ ```tsx
791
+ 'use client';
792
+ import { LikeButton } from '@gecko-ui-kit/react';
793
+
794
+ export function SaveBike({ bike }: { bike: { id: string; saved: boolean; saves: number } }) {
795
+ return (
796
+ <LikeButton
797
+ kind="bookmark"
798
+ defaultPressed={bike.saved}
799
+ count={bike.saves}
800
+ // return the request: if it fails, the button goes back and shakes
801
+ onChange={(on) => fetch(`/api/bikes/${bike.id}/save`, { method: on ? 'PUT' : 'DELETE' })
802
+ .then((r) => { if (!r.ok) throw new Error(String(r.status)); })}
803
+ />
804
+ );
805
+ }
806
+ ```
807
+
808
+ - `kind`: `'heart'` (default), `'star'` or `'bookmark'`.
809
+ - `pressed` (controlled) or `defaultPressed`. Controlled: set it from `onChange`, and set it back yourself if your request fails.
810
+ - `count`: a number shows a rolling count; a new value (for example from the server) rolls to it.
811
+ - `label` / `onLabel`, `iconOnly`, `size` (`'sm'` `''` `'lg'`), `tone`, `format(n)`, `words`.
812
+ - `onChange(pressed, count, handle)`: return a promise; if it fails, the button goes back with a shake.
813
+ - `ref` → `{ pressed, count, set(on), toggle(), setCount(n), el }`.
814
+
815
+ ### BellSwitch
816
+
817
+ A notification switch: turning it on rings the bell, turning it off draws a slash across it. `BellButton` is the same component.
818
+
819
+ ```tsx
820
+ const [alerts, setAlerts] = useState(true);
821
+ const bell = useRef<Mounted<BellHandle>>(null);
822
+ useEffect(() => onNewBooking(() => bell.current?.ring()), []);
823
+
824
+ <BellSwitch ref={bell} label="Booking alerts" on={alerts}
825
+ onChange={(on) => { setAlerts(on); return saveSetting('booking-alerts', on); }} />
826
+ ```
827
+
828
+ - `on` (controlled) or `defaultOn`.
829
+ - `label` (any React node; a string with `iconOnly`), `iconOnly`, `tone`, `words: { label, on, off }`.
830
+ - `onChange(on, handle)`: return a promise; if it fails, it switches back with a shake.
831
+ - `ref` → `{ on, set(on), toggle(), ring(), el }`: `ring()` when something new comes in.
832
+
833
+ ### PayButton
834
+
835
+ A checkout button: a card swipes through, "Processing", then "Paid" with a tick, or red "Try again" when the payment fails.
836
+
837
+ ```tsx
838
+ <PayButton
839
+ label={<>Pay <b>฿{total}</b></>}
840
+ block
841
+ onPay={async () => {
842
+ const r = await fetch('/api/checkout', { method: 'POST', body: JSON.stringify(cart) });
843
+ if (!r.ok) throw new Error('Card declined');
844
+ return r.json(); // resolves = paid
845
+ }}
846
+ onDone={(receipt) => router.push(`/bookings/${(receipt as { id: string }).id}`)}
847
+ onFail={(error) => setCardError(String(error))}
848
+ />
849
+ ```
850
+
851
+ - `onPay(handle)`: resolve = paid; throw, reject or return `false` = failed.
852
+ - `onDone(result, handle)`, `onFail(error, handle)`.
853
+ - `label` (any React node), `variant` (`'dark'` default, `'primary'`), `size` (`'lg'` default), `block`, `icon` (`'card'`, `''` for none).
854
+ - `card` (the swipe, default on), `minBusy` (1.4 s), `back` (3 s; `0` stays "Paid"), `words`.
855
+ - `ref` → `{ state, pay(), reset(), el }`.
856
+
857
+ ### SpeedDial
858
+
859
+ A round + button that fans out a few labelled quick actions.
860
+
861
+ ```tsx
862
+ <SpeedDial
863
+ fixed
864
+ actions={[
865
+ { id: 'booking', label: 'New booking', icon: 'calendar' },
866
+ { id: 'bike', label: 'Add a bike', icon: 'plus' },
867
+ { id: 'note', label: 'Write a note', icon: 'edit' },
868
+ ]}
869
+ onSelect={(a) => router.push(`/new/${a.id}`)}
870
+ />
871
+ ```
872
+
873
+ - `actions`: `{ id, label, icon }` (icon name or `<svg>` string); a new list is swapped in place.
874
+ - `direction` (`'up'` / `'down'`), `side` (`'right'` / `'left'`), `labels`, `fixed`, `icon`, `words: { label, actions }`.
875
+ - `onSelect(action, handle)`, `onToggle(open, handle)`.
876
+ - `ref` → `{ isOpen, open(), close(), toggle(), setActions(list), el }`.
877
+
878
+ ### Typing
879
+
880
+ Three bouncing dots in a chat bubble, with "Pim is typing…".
881
+
882
+ ```tsx
883
+ <Typing visible={typingNames.length > 0} names={typingNames} />
884
+ ```
885
+
886
+ - `visible`: shows or hides it in place (the row opens and closes, `collapse`).
887
+ - `names`: `'Pim'` or `['Pim', 'Mali']`; changes in place.
888
+ - `text`, `bubble`, `size` (`'sm'` `''` `'lg'`), `tone` (`'muted'` `'accent'` `'ink'`), `collapse`, `words: { anon, one, two, many }`.
889
+ - `ref` → `{ visible, text, show(), hide(), set(names), el }`.
890
+
891
+ ## Charts
892
+
893
+ New data never draws these charts again from zero: lines morph, slices change size, the needle swings and rows
894
+ glide to their new places. Pass new arrays as props; that is all.
895
+
896
+ ### LineChart
897
+
898
+ A line or area chart of one or more series over the same labels, with a crosshair, a tooltip and legend keys.
899
+
900
+ ```tsx
901
+ <LineChart
902
+ label="Rental income by month"
903
+ labels={['Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}
904
+ series={[
905
+ { name: 'Walk-in', data: walkIn },
906
+ { name: 'Booked online', data: online, tone: 'teal' },
907
+ ]}
908
+ height={240}
909
+ format={(v) => `฿${v.toLocaleString()}`}
910
+ />
911
+ ```
912
+
913
+ - `labels`, `series: [{ name, data, tone, hidden }]` (`null` in data leaves a gap): new ones morph in place.
914
+ - `area`, `smooth`, `stacked`, `height`, `yMin`, `yMax`, `ticks`, `grid`, `dots` (`'hover'` / `true` / `false`), `tooltip`, `legend`.
915
+ - `format(v)`, `axisFormat(v)`, `label`, `words`, `onPoint(index, info, handle)`.
916
+ - `ref` → `{ labels, series, update(), highlight(i), toggle(name, on?), el }`.
917
+
918
+ ### Donut
919
+
920
+ Parts of a whole as a ring of slices, with the total in the middle.
921
+
922
+ ```tsx
923
+ <Donut
924
+ label="Bikes out today"
925
+ data={[
926
+ { label: 'Scooters', value: 48 },
927
+ { label: 'E-bikes', value: 20, tone: 'teal' },
928
+ { label: 'City bikes', value: 12 },
929
+ ]}
930
+ centre="Bikes"
931
+ onSelect={(i, item) => setFilter(item?.label ?? null)}
932
+ />
933
+ ```
934
+
935
+ - `data: [{ label, value, tone }]`: new data morphs the slices (matched by label).
936
+ - `size`, `thickness`, `gap`, `legend` (`'right'` / `'bottom'` / `false`), `sort`, `format(v)`, `centre`, `label`, `words`.
937
+ - `onSelect(index, item, handle)` (index -1 when cleared).
938
+ - `ref` → `{ data, total, selected, set(data), select(index | label | -1), el }`.
939
+
940
+ ### Gauge
941
+
942
+ One number on a half-circle dial, like today's bookings against a daily goal.
943
+
944
+ ```tsx
945
+ <Gauge
946
+ value={todaySales}
947
+ max={12000}
948
+ goal={10000}
949
+ label="Today's rentals"
950
+ format={(v) => `฿${v.toLocaleString()}`}
951
+ zones={[{ to: 4000, tone: 'bad' }, { to: 8000, tone: 'warn' }, { to: 12000, tone: 'good' }]}
952
+ />
953
+ ```
954
+
955
+ - `value`: a new value swings the needle from where it is now.
956
+ - `min`, `max`, `goal`, `zones: [{ to, tone, label }]`, `tone`, `format(v)`, `label`, `size`, `needle`, `ends`, `words`.
957
+ - `ref` → `{ value, set(v), el }`.
958
+
959
+ ### Leaderboard
960
+
961
+ A ranked list with a bar under each row; when the numbers change the rows glide to their new ranks.
962
+
963
+ ```tsx
964
+ <Leaderboard
965
+ label="Tasks done this week"
966
+ max={5}
967
+ items={team.map((p) => ({ id: p.id, label: p.name, sub: p.role, value: p.done, avatar: { name: p.name } }))}
968
+ />
969
+ ```
970
+
971
+ - `items: [{ id, label, value, sub, avatar }]`: new items glide, bars stretch and numbers count.
972
+ - `max` (rows shown, 0 = all), `format(v)`, `bars`, `medals`, `label`, `words`.
973
+ - `ref` → `{ items, set(items), el }`.
974
+
975
+ ### Heatmap
976
+
977
+ A calendar of small squares, one per day, darker on busier days.
978
+
979
+ ```tsx
980
+ const [day, setDay] = useState<Date | null>(null);
981
+
982
+ <Heatmap
983
+ data={bookings.map((b) => ({ date: b.day, value: b.count }))} // 'YYYY-MM-DD' or Date
984
+ weeks={26}
985
+ value={day}
986
+ onSelect={(d) => setDay(d.date)}
987
+ format={(v) => `${v} bookings`}
988
+ />
989
+ ```
990
+
991
+ - `data: [{ date, value }]`: new data re-shades every square in a ripple. (A function `(date) => number` is read once at the start.)
992
+ - `value` picks a day in place (`defaultValue` only at the start); `onSelect(day, handle)` with `day = { date, value, level }`.
993
+ - `end` (default today), `weeks`, `weekStart`, `levels`, `tone`, `format(v)`, `locale`, `words`.
994
+ - The scroll area reaches 4px past its box (room for the focus ring): give its container a little padding.
995
+ - `ref` → `{ value, set(data), select(date | null), el }`.
996
+
997
+ ## Text & scroll motion
998
+
999
+ Text that moves: letters that roll up, typed words, a word that keeps changing, a band of light, marker strokes,
1000
+ blocks that arrive on scroll, rolling numbers. Each component draws its first state on the server (so the text is
1001
+ in the HTML), then the motion takes over in the browser. Changing a prop (new text, new words, a new value)
1002
+ updates the piece in place. Every motion respects reduced motion.
1003
+
1004
+ ### TextReveal
1005
+
1006
+ A headline whose letters roll up out of a mask, one after another (`title()`); a new text plays again in place.
1007
+
1008
+ ```tsx
1009
+ <TextReveal as="h1" stagger={0.022} tilt={6}>{`Bikes for every trip, ${city}`}</TextReveal>
1010
+ ```
1011
+
1012
+ - `children` — the text (a string). Changing it plays the reveal again (`retitle()`).
1013
+ - `delay`, `stagger` (0.022), `tilt` (6°), `duration` (0.85).
1014
+ - `as` — the element (`'span'` by default: use `'h1'`, `'h2'`…). ref → the element.
1015
+
1016
+ ### Typewriter
1017
+
1018
+ Text typed letter by letter behind a caret; several phrases are deleted and typed in turn. Screen readers hear the whole list once.
1019
+
1020
+ ```tsx
1021
+ <h2>We rent <Typewriter phrases={['scooters', 'city bikes', 'e-bikes']} caret="bar" /></h2>
1022
+ <Typewriter as="p" loop={false} speed={0.03}>Your bike is booked for Friday at 9 am.</Typewriter>
1023
+ ```
1024
+
1025
+ - `phrases` — the list (or one phrase as children). A new list deletes the current phrase and types the new ones.
1026
+ - `speed` (0.06 s a letter), `jitter`, `eraseSpeed`, `erase` (`'backspace'` | `'select'`), `hold`, `gap`, `delay`, `loop`.
1027
+ - `caret` (`'bar'` | `'block'` | `'underscore'` | `false`), `locale`, `label`, `whenVisible`, `paused`.
1028
+ - `onPhrase(i, text)`. ref → `{ phrase, play(), pause(), restart(), set(list), el }`.
1029
+
1030
+ ### Rotator
1031
+
1032
+ One word in a sentence keeps changing; its slot glides to the new width so the sentence moves over smoothly.
1033
+
1034
+ ```tsx
1035
+ <h2>Rent a <Rotator words={['scooter', 'city bike', 'e-bike']} effect="roll" pill /> by the hour</h2>
1036
+ ```
1037
+
1038
+ - `words` — the list. A new list starts again from the first word.
1039
+ - `effect` (`'roll'` | `'drop'` | `'slide'` | `'blur'` | `'letters'`), `every` (2.2 s), `duration`, `ease`, `stagger`.
1040
+ - `pill` — a soft highlight box behind the word. `index` — show this word; `auto={false}` to drive it yourself; `paused`.
1041
+ - `onChange(i, word)`. ref → `{ index, next(), go(i), play(), pause(), set(words), el }`.
1042
+
1043
+ ### Shine
1044
+
1045
+ A slanted band of light sweeps across the letters, like light on a shiny sign. The text stays real text.
1046
+
1047
+ ```tsx
1048
+ <Shine as="h2" look="gradient" trigger="loop">Summer rides, 20% off</Shine>
1049
+ <Shine look="ink" trigger="hover" tabIndex={0}>Loading your bookings…</Shine>
1050
+ ```
1051
+
1052
+ - `look` (`'gradient'` | `'ink'` | `'color'`), `trigger` (`'loop'` | `'view'` | `'hover'`).
1053
+ - `duration` (1.4), `repeatDelay` (1.8), `delay`, `ease`, `angle` (110°), `width` (12), `color`.
1054
+ - CSS only, no React needed: `<span className="shine shine--ink shine--loop">…</span>`.
1055
+
1056
+ ### Highlighter
1057
+
1058
+ A marker stroke draws behind the words in `<mark>`, one after another, when the paragraph scrolls into view.
1059
+
1060
+ ```tsx
1061
+ <Highlighter tone="amber">
1062
+ Every rental comes with <mark>a free helmet</mark> and <mark>a lock</mark>.
1063
+ </Highlighter>
1064
+ ```
1065
+
1066
+ - `look` (`'marker'` | `'underline'`), `tone` (`accent amber green rose sky violet`) or `color`.
1067
+ - `trigger` (`'view'` | `'now'` | `'manual'`), `threshold` (0.6), `once`, `duration`, `stagger`, `delay`, `ease`, `selector`.
1068
+ - `active` — with `trigger="manual"`: `true` draws the strokes, `false` clears them.
1069
+
1070
+ ### ScrollReveal
1071
+
1072
+ Blocks (or their words) wait out of sight and arrive as they scroll into view: fade, rise, slide, zoom or blur.
1073
+
1074
+ ```tsx
1075
+ <ScrollReveal effect="rise"><BookingSummary booking={b} /></ScrollReveal>
1076
+
1077
+ <ScrollReveal items=":scope > article" effect="slide" x={-40}>
1078
+ {steps.map((s) => <article key={s.id}><h4>{s.title}</h4><p>{s.text}</p></article>)}
1079
+ </ScrollReveal>
1080
+
1081
+ <ScrollReveal as="p" words effect="blur">Pick a bike, choose your days and ride.</ScrollReveal>
1082
+ ```
1083
+
1084
+ - Without `items` the element itself is revealed (and hidden in the server HTML until then, no flash).
1085
+ `items` — a selector inside: each match is revealed, top to bottom; items added later are revealed too.
1086
+ - `effect`, `words`, `y`, `x`, `scale`, `blur`, `duration`, `stagger`, `wordStagger`, `delay`, `ease`.
1087
+ - `once` (false = play every time), `threshold` (0.2), `rootMargin`, `root` (the scrolling box: element, ref or selector).
1088
+ - `onEnter(el)`, `onLeave(el)`. ref → the element.
1089
+
1090
+ ### BlurIn
1091
+
1092
+ The words of a paragraph come into focus one after another, right away (for a hero already on screen).
1093
+
1094
+ ```tsx
1095
+ <BlurIn as="p" blur={12} stagger={0.05}>Slow mornings, fresh coffee and a bike waiting at the door.</BlurIn>
1096
+ ```
1097
+
1098
+ - `blur` (10 px), `y` (25), `duration` (0.7), `stagger` (0.04), `delay`, `ease`. A new text plays again.
1099
+
1100
+ ### ScrollProgress
1101
+
1102
+ A thin line that fills as the page (or a scrolling box) is read.
1103
+
1104
+ ```tsx
1105
+ <ScrollProgress style={{ position: 'sticky', top: 0 }} />
1106
+ <ScrollProgress root={panelRef} onChange={(p) => setRead(Math.round(p * 100))} />
1107
+ ```
1108
+
1109
+ - `root` — the scrolling box (default the page). `onChange(progress)` with 0…1.
1110
+ - Colour and height: `--scroll-progress-c`, `--scroll-progress-h`.
1111
+
1112
+ ### Odometer
1113
+
1114
+ A number that rolls digit by digit like a car's meter; only the digits that change spin.
1115
+
1116
+ ```tsx
1117
+ <Odometer value={yearly ? 1990 : 2490} format={{ style: 'currency', currency: 'THB', minimumFractionDigits: 0, maximumFractionDigits: 0 }} locale="th-TH" />
1118
+ ```
1119
+
1120
+ - `value` — a number (or a ready-made string). A new value rolls in place.
1121
+ - `format` (Intl options or `(v) => text`), `locale`, `duration` (0.9), `stagger` (0.06), `direction` (`'auto'` | `'up'` | `'down'`), `ease`.
1122
+ - `from` — roll in from this value on mount.
1123
+
1124
+ ### CountUp
1125
+
1126
+ A number that counts up on mount, and from the number on screen to the new one when it changes.
1127
+
1128
+ ```tsx
1129
+ <div className="kpi"><small>Revenue today</small><b><CountUp value={stats.revenue} prefix="฿" tick /></b></div>
1130
+ <CountUp value={4.8} decimals={1} suffix=" / 5" />
1131
+ ```
1132
+
1133
+ - `value`, `from` (0), `duration` (1.2), `delay`.
1134
+ - `prefix`, `suffix`, `decimals`, `locale` ('en-US'), or your own `format(v)`.
1135
+ - `tick` — tint the number green going up, red going down.
1136
+
1137
+ ## Motion wrappers
1138
+
1139
+ Motions that wrap elements you already have: entrances for lists and grids, hover effects, a 3D tilt, a spotlight
1140
+ across cards and an endless marquee. Hover effects only run with a mouse or trackpad, and nothing moves with reduced
1141
+ motion. Everything is cleaned up when the component unmounts.
1142
+
1143
+ ### Rise
1144
+
1145
+ Lists and grids arrive one item after another; items added later arrive the same way.
1146
+
1147
+ ```tsx
1148
+ <Rise className="bike-grid" stagger={0.06}>
1149
+ {bikes.map((b) => <BikeCard key={b.id} bike={b} />)}
1150
+ </Rise>
1151
+
1152
+ <Rise kind="slide" x={-24}>{tasks.map((t) => <TaskRow key={t.id} task={t} />)}</Rise>
1153
+ <Rise kind="deal" tilt={4}>{shifts.map((s) => <ShiftCard key={s.id} shift={s} />)}</Rise>
1154
+ {open && <Rise kind="reveal"><p>Works mornings this week.</p></Rise>}
1155
+ ```
1156
+
1157
+ - `kind` — `'rise'` (fade in and float up), `'slide'` (from a side), `'deal'` (tilted cards), `'reveal'` (a small fade-down of the element itself).
1158
+ - `y`, `x`, `stagger`, `delay`, `duration`, `tilt`. `items` — a selector inside instead of the direct children.
1159
+ - `animateNew` (true) — children added later arrive too. To play everything again, change the `key`.
1160
+
1161
+ ### Magnetic
1162
+
1163
+ The element leans toward the pointer while it hovers and springs back when it leaves.
1164
+
1165
+ ```tsx
1166
+ <Magnetic strength={0.3}><Button variant="primary" iconRight="arrowR">Book a bike</Button></Magnetic>
1167
+ <Magnetic as="a" href="/bikes" className="btn" magnet={1.5}>See all bikes</Magnetic>
1168
+ ```
1169
+
1170
+ - `strength` (0.2), `strengthY` (0.28), `magnet` — a multiplier for this element.
1171
+ - `<Button magnetic>` does the same for a single button.
1172
+
1173
+ ### Lift
1174
+
1175
+ The element rises a few pixels while the pointer is over it: “you can click this”.
1176
+
1177
+ ```tsx
1178
+ <Lift as="article" y={-6} className="card project-card">…</Lift>
1179
+ ```
1180
+
1181
+ - `y` — px it moves (-4). Pair it with a deeper shadow in your CSS (`:hover { box-shadow: var(--shadow-2) }`).
1182
+
1183
+ ### Tilt
1184
+
1185
+ The card leans toward the pointer in 3D with a soft glare; layers marked `data-depth` float above it.
1186
+
1187
+ ```tsx
1188
+ <Tilt as="article" className="card" max={12} glare>
1189
+ <img data-depth="30" src="/bikes/e-bike.png" alt="" />
1190
+ <h3 data-depth="14">City e-bike</h3>
1191
+ </Tilt>
1192
+ ```
1193
+
1194
+ - `max` (12°), `scale` (1.03), `perspective` (900), `glare` (true), `parallax` (0.25), `follow` (0.35), `spring` (1).
1195
+ - Keep `overflow` visible on the card, or the layers flatten.
1196
+
1197
+ ### Spotlight
1198
+
1199
+ A soft light follows the pointer across a group of cards and lights up their edges; keyboard focus pulls it too.
1200
+
1201
+ ```tsx
1202
+ <Spotlight className="plans" size={300}>
1203
+ {plans.map((p) => <div key={p.id} className="card">{p.name} · {p.price}</div>)}
1204
+ </Spotlight>
1205
+ ```
1206
+
1207
+ - `size` (240 px), `follow` (0.2 s), `border` (true), `fill` (true), `focus` (true), `items` (default: the children).
1208
+ - Colour: `--spot-c`; edge: `--spot-ring`.
1209
+
1210
+ ### Marquee
1211
+
1212
+ An endless sideways strip of logos or items; hover or focus slows it to a stop.
1213
+
1214
+ ```tsx
1215
+ const pause = useRef<HTMLButtonElement>(null);
1216
+
1217
+ <Marquee aria-label="Shops that ride with us" speed={50} gap={48} button={pause}>
1218
+ {partners.map((p) => <img key={p.id} src={p.logo} alt={p.name} height={28} />)}
1219
+ </Marquee>
1220
+ <button ref={pause} className="btn btn--sm">⏸</button>
1221
+ ```
1222
+
1223
+ - Each child becomes one item (`<li>` in a `<ul>`; `listAs` to change).
1224
+ - `speed` (50 px/s), `direction`, `gap`, `fade` change in place; `pauseOnHover` (true), `paused`.
1225
+ - `button` — a pause / play button (element, ref or selector); `words` — its labels.
1226
+ - ref → `{ play(), pause(), toggle(), paused, refresh(), el }`.
1227
+
1228
+ ### useMotion — any other helper
1229
+
1230
+ Helpers without a component of their own (`flash`, `tick`, `pop`, `shake`, `wiggle`, `swap`, `count`, `retitle`,
1231
+ `indicator`…) run on an element you render with `useMotion` from the core. It runs after mount, again when the
1232
+ options (or deps) change, and stops the tween or handle on unmount.
1233
+
1234
+ ```tsx
1235
+ import { useMotion } from '@gecko-ui-kit/react';
1236
+ import { rise, shake, tilt } from '@gecko-ui-kit/motion';
1237
+
1238
+ // a function of the element; the deps array plays it again
1239
+ const list = useMotion((el) => rise(el.querySelectorAll('.row'), { stagger: 0.04 }), [rows.length]);
1240
+ <div ref={list}>{rows.map((r) => <div key={r.id} className="row">{r.name}</div>)}</div>
1241
+
1242
+ // play it when something happens
1243
+ const err = useMotion((el) => (error ? shake(el) : undefined), [error]);
1244
+ <p ref={err} className="field-error">{error}</p>
1245
+
1246
+ // a helper that takes (el, options): options are compared by content
1247
+ const card = useMotion(tilt, { max: 8, glare: false });
1248
+ <article ref={card} className="card">…</article>
1249
+ ```
1250
+
1251
+ ## Interactive effects
1252
+
1253
+ ### Indicator
1254
+ A highlight that stretches toward the newly active item, then snaps into place (sidebar pills, tab lines, segmented thumbs).
1255
+
1256
+ ```tsx
1257
+ import { Indicator } from '@gecko-ui-kit/react';
1258
+
1259
+ const [page, setPage] = useState('bikes');
1260
+ <Indicator as="nav" active={page} radius={99} className="menu">
1261
+ {['bikes', 'bookings', 'returns'].map((p) => (
1262
+ <button key={p} aria-current={page === p ? 'page' : undefined} onClick={() => setPage(p)}>{p}</button>
1263
+ ))}
1264
+ </Indicator>
1265
+ ```
1266
+ - `active`: anything that changes when the active item changes; the pill goes to the child with `aria-current`, `aria-selected="true"`, `aria-pressed="true"` or `.is-active` (`selector` to change it).
1267
+ - `radius` (13; 99 = round ends), `line` (an underline), `lead` / `trail` / `cross` (seconds per edge).
1268
+ - `pillClassName` / `pillStyle` style the pill (default: the accent colour). `as` picks the element.
1269
+ - Hook form for your own markup: `const pill = useIndicator(page, { radius: 99 })`, then `<span ref={pill} className="menu__pill" />` as a child of the menu.
1270
+
1271
+ ### PageSwap
1272
+ A page transition: when `swapKey` changes, the old page steps back and fades, then the new one slides in from the side you are heading to.
1273
+
1274
+ ```tsx
1275
+ 'use client';
1276
+ import { usePathname } from 'next/navigation';
1277
+ import { PageSwap } from '@gecko-ui-kit/react';
1278
+
1279
+ export default function Template({ children }: { children: React.ReactNode }) {
1280
+ const path = usePathname();
1281
+ return <PageSwap swapKey={path} dir={1}>{children}</PageSwap>;
1282
+ }
1283
+ ```
1284
+ - `swapKey`: the page's identity (route, tab id). `dir`: `1` forward, `-1` back.
1285
+ - `leave` (blocks that drop out: `.card, .kpi, .lane, [data-swap]`), `head` (header parts that lift away).
1286
+ - `timing`: `{ out, in, shift, enter }` for this swap only. `onSwap(view)` runs when the new page is in.
1287
+
1288
+ ### useFeedback · useFlash · useTick
1289
+ Tiny answers to what the user just did: a pop for a press, a shake for "no", a wiggle for a new alert, a flash or tint when a value changes.
1290
+
1291
+ ```tsx
1292
+ import { useFeedback, useFlash, useTick } from '@gecko-ui-kit/react';
1293
+
1294
+ const fb = useFeedback<HTMLFormElement>();
1295
+ const totalRef = useFlash(days * 250); // bounces when the price changes
1296
+ const daysRef = useTick(days); // green when it goes up, red when down
1297
+
1298
+ <form ref={fb.ref} onSubmit={(e) => { e.preventDefault(); if (!phone) fb.shake(); }}>
1299
+ <button type="button" onClick={(e) => { fb.pop(e); setDays(days + 1); }}>+1 day</button>
1300
+ <b ref={daysRef}>{days}</b> days · <b ref={totalRef}>฿{days * 250}</b>
1301
+ </form>
1302
+ ```
1303
+ - `fb.pop()`, `fb.shake()`, `fb.wiggle()`, `fb.flash()`, `fb.tick(up)`: run on `fb.ref`, or on an element / ref / event you pass (`onClick={fb.pop}` pops the clicked button).
1304
+ - Tweens are stopped when the component unmounts. With reduced motion only the colour changes stay.
1305
+
1306
+ ### ConfettiButton · useConfetti
1307
+ A burst of paper that shoots up from a button and flutters down over the page (a few sparkles with reduced motion).
1308
+
1309
+ ```tsx
1310
+ import { ConfettiButton, useConfetti } from '@gecko-ui-kit/react';
1311
+
1312
+ <ConfettiButton variant="primary" icon="sparkle" count={150} onClick={finishProject}>Mark as done</ConfettiButton>
1313
+
1314
+ const fire = useConfetti({ spread: 120 });
1315
+ async function pay(e: React.MouseEvent) { await charge(); fire(e); } // from the clicked button
1316
+ ```
1317
+ - Options: `count` (120), `spread` (100°), `angle` (90 = up), `velocity`, `colors`, `shapes`, `gravity`, `duration` (3 s), `zIndex`, `reduced` (`'sparkle'` | `'none'`).
1318
+ - `ConfettiButton` takes every `Button` prop too; `onDone` runs when the last piece has landed. Call `event.preventDefault()` in `onClick` to skip the burst.
1319
+ - `confetti(origin, options)` is the vanilla function itself; bursts from `useConfetti` stop when the component unmounts.
1320
+
1321
+ ### Sortable
1322
+ A list you reorder by dragging (mouse at once, touch after a long press): the card lifts and tilts, the others slide aside, and it lands with a squash. React keeps the order.
1323
+
1324
+ ```tsx
1325
+ import { Sortable } from '@gecko-ui-kit/react';
1326
+
1327
+ const [lanes, setLanes] = useState({ todo: tasksTodo, doing: [], done: [] });
1328
+ <div className="board">
1329
+ {Object.entries(lanes).map(([id, tasks]) => (
1330
+ <Sortable key={id} group="board" className="lane" items={tasks} getKey={(t) => t.id}
1331
+ onReorder={(next) => setLanes((l) => ({ ...l, [id]: next }))}
1332
+ renderItem={(t) => <div className="kcard">{t.title}</div>}>
1333
+ <h3>{id}</h3>
1334
+ </Sortable>
1335
+ ))}
1336
+ </div>
1337
+ ```
1338
+ - `items` + `onReorder(next, { item, from, to, fromList, toList })` (controlled) or `defaultItems`.
1339
+ - `getKey` (a stable key), `renderItem(item, index)`, `onItemClick(item)` (pressed without moving).
1340
+ - `group`: lists with the same group pass items to each other (kanban lanes); `children` are drawn inside the drop zone, before the items.
1341
+ - `lift` (`{ scale, rotation }` in your hand), `squash`, `rotate`, `handle` (a selector to drag from), `as` / `itemAs` / `itemClassName`.
1342
+ - Buttons, inputs and links inside a card do not start a drag. Give cards `cursor: grab; user-select: none` in your CSS.
1343
+
1344
+ ### ThemeToggle · useTheme
1345
+ A round moon / sun button that switches light ↔ dark with a circular reveal growing from the button, and a hook for your own controls.
1346
+
1347
+ ```tsx
1348
+ import { ThemeToggle, useTheme } from '@gecko-ui-kit/react';
1349
+
1350
+ <ThemeToggle onChange={(t) => saveUserPref(t)} />
1351
+
1352
+ const [theme, setTheme] = useTheme();
1353
+ <button onClick={(e) => setTheme(theme === 'dark' ? 'light' : 'dark', e)}>Night mode</button>
1354
+ ```
1355
+ - `storageKey` (`'gecko:theme'`; `''` = don't save), `duration` (450 ms), `easing`, `label` (`'Switch theme'`).
1356
+ - `useTheme()` returns `'light'` on the server and the real theme in the browser (no mismatch); it also applies a saved choice if `<html>` has none.
1357
+ - To avoid a flash on load in Next.js, set it before React starts: `<html suppressHydrationWarning>` and in `<head>`
1358
+ `<script dangerouslySetInnerHTML={{ __html: "try{var t=localStorage.getItem('gecko:theme');if(t)document.documentElement.dataset.theme=t}catch(e){}" }} />`.
1359
+
1360
+ ### SendButton
1361
+ A send button whose plane winds back and flies off with a dotted trail; the button turns green and "Sent" rolls in with a tick.
1362
+
1363
+ ```tsx
1364
+ import { SendButton } from '@gecko-ui-kit/react';
1365
+
1366
+ <SendButton variant="primary" path="loop" onClick={sendReminder}>Send reminder</SendButton>
1367
+
1368
+ // play it when the server says OK:
1369
+ <SendButton variant="primary" type="submit" sent={status === 'sent'}>Send</SendButton>
1370
+ ```
1371
+ - A click plays it (unless `onClick` calls `preventDefault()`) and it comes back after `back` seconds (2.4; 0 = stays).
1372
+ - `sent` (controlled): `true` flies it off, `false` brings it back.
1373
+ - `done` ('Sent'), `path` (`'up'` | `'straight'` | `'loop'`), `trail`, `duration`, `onDone(button)`; plus `variant`, `size`, `icon` and any button prop.
1374
+
1375
+ ### DeleteButton
1376
+ A delete button whose bin opens its lid and eats its own label letter by letter, chews, and shows "Deleted".
1377
+
1378
+ ```tsx
1379
+ import { DeleteButton } from '@gecko-ui-kit/react';
1380
+
1381
+ <DeleteButton variant="danger" size="sm" back={0} onDone={() => removeBooking(id)}>Delete</DeleteButton>
1382
+ ```
1383
+ - The label is text (`children`, 'Delete'). A click plays it (unless `onClick` calls `preventDefault()`); `deleted` makes it controlled.
1384
+ - `done` ('Deleted'), `order` (`'first'` | `'last'` letter jumps first), `chew`, `back` (2.4 s; 0 = stays), `onDone(button)`.
1385
+
1386
+ ### DownloadButton
1387
+ A download button whose own outline is the progress bar; it glows, fills and draws a tick when done.
1388
+
1389
+ ```tsx
1390
+ import { DownloadButton } from '@gecko-ui-kit/react';
1391
+
1392
+ const [p, setP] = useState<number | null | undefined>();
1393
+ const [state, setState] = useState<'done' | 'failed'>();
1394
+ <DownloadButton variant="primary" progress={p} state={state} onClick={() => startDownload(setP, setState)}>
1395
+ Invoice PDF
1396
+ </DownloadButton>
1397
+ ```
1398
+ - `progress`: 0–1 fills the outline, `null` = size unknown (a segment chases round), `undefined` = not started.
1399
+ - `state`: `'loading'` (default once `progress` is set), `'done'`, `'failed'` (red + shake), `'idle'` (back to start).
1400
+ - `label(p)` (the text while loading, default '40%'), `wait` ('Preparing…'), `done` ('Done'), `fail` ('Try again'), `back` (seconds after done before it resets), `width` (outline px).
1401
+
1402
+ ### HoldButton
1403
+ For actions that must not happen by accident: press and hold, colour floods the button, and only a full hold confirms.
1404
+
1405
+ ```tsx
1406
+ import { HoldButton } from '@gecko-ui-kit/react';
1407
+
1408
+ <HoldButton tone="bad" icon="trash" hint="Hold to delete" done="Deleted" onConfirm={() => deleteBike(bike.id)}>
1409
+ Delete bike
1410
+ </HoldButton>
1411
+ <HoldButton look="ring" tone="warn" icon="lock" onConfirm={signOutEverywhere}>Sign out everywhere</HoldButton>
1412
+ ```
1413
+ - `onConfirm(button, handle)` instead of `onClick`; `onCancel(button, handle, progress)` when let go too early.
1414
+ - `duration` (1.2 s), `look` (`'fill'` | `'ring'`: a circle round a round icon button; the label becomes its accessible name), `tone` (`'bad'` | `'accent'` | `'good'` | `'warn'`).
1415
+ - `hint` ('Hold to confirm'), `done` ('Done'), `back` (seconds before it resets; 0 = stays), `haptic`, `confirmed` (controlled).
1416
+
1417
+ ### ExpandSearch
1418
+ A round magnifier that stretches into a search field, types its hint in and draws a close ×; Escape clears, then closes.
1419
+
1420
+ ```tsx
1421
+ import { ExpandSearch } from '@gecko-ui-kit/react';
1422
+
1423
+ const [q, setQ] = useState('');
1424
+ <ExpandSearch placeholder="Search bikes…" width={280} shortcut="/" value={q} onChange={setQ} onSearch={(text) => router.push(`/bikes?q=${encodeURIComponent(text)}`)} />
1425
+ ```
1426
+ - `value` / `defaultValue` + `onChange(text)`; `onSearch(text)` on Enter or a click on the magnifier.
1427
+ - `open` / `defaultOpen` + `onOpen` / `onClose`. `width` (260, or any CSS width), `typing`, `autoClose`, `shortcut` (a key that opens it from anywhere, e.g. `'/'`).
1428
+ - `look` (`'outline'` | `'quiet'`), `size` (`'md'` | `'sm'`), `label` ('Search'), `closeLabel`, `name` ('q').
1429
+
1430
+ ### LiquidTabs
1431
+ A tab bar where the bar and a bubble over the active tab move like one liquid; the active icon rides up into the bubble.
1432
+
1433
+ ```tsx
1434
+ import Link from 'next/link';
1435
+ import { LiquidTabs } from '@gecko-ui-kit/react';
1436
+
1437
+ <LiquidTabs label="Main" linkAs={Link} value={active} onChange={setActive} items={[
1438
+ { label: 'Home', icon: 'home', href: '/' },
1439
+ { label: 'Bikes', icon: 'box', href: '/bikes' },
1440
+ { label: 'Trips', icon: 'calendar', href: '/trips' },
1441
+ ]} />
1442
+ ```
1443
+ - `items`: `{ label, icon, href? }` (an `href` makes it a link; `linkAs={Link}` for Next.js).
1444
+ - `value` / `defaultValue`: the active index; `onChange(index, tabElement)` on click or arrow keys.
1445
+ - `mode` (`'dip'` | `'glide'`), `splash`, `labels` (false = icons only), `goo` (false = plain shapes), `label` (the nav's name).
1446
+
1447
+ ### Burger
1448
+ A menu button whose three lines turn into an ✕ and back; React owns `open`.
1449
+
1450
+ ```tsx
1451
+ import { Burger } from '@gecko-ui-kit/react';
1452
+
1453
+ const [open, setOpen] = useState(false);
1454
+ <Burger open={open} onToggle={setOpen} controls="main-menu" words={{ open: 'เปิดเมนู', close: 'ปิดเมนู' }} />
1455
+ <nav id="main-menu" hidden={!open}>…</nav>
1456
+ ```
1457
+ - `open` / `defaultOpen` + `onToggle(open, button)` (a click, or Escape when `escape` is on).
1458
+ - `words` (`{ open: 'Open menu', close: 'Close menu' }`), `duration` (0.45 s), `controls` (the menu's id), `size`, `iconClassName` (size the lines with `--burger-w`, `--burger-h`, `--burger-t`).
1459
+
1460
+ ## Overlays
1461
+
1462
+ Things that pop up over the page. The vanilla `@gecko-ui-kit/overlays` code still opens, places, animates and
1463
+ stacks them; your React content is drawn inside. Esc closes the newest one (installed once, the first time one opens).
1464
+
1465
+ ### Modal
1466
+
1467
+ A dialog in the middle of the screen that zooms out of the button that opened it (a bottom sheet on phones).
1468
+
1469
+ ```tsx
1470
+ const [open, setOpen] = useState(false);
1471
+ const editBtn = useRef<HTMLButtonElement>(null);
1472
+
1473
+ <Button ref={editBtn} icon="edit" onClick={() => setOpen(true)}>Edit bike</Button>
1474
+ <Modal open={open} onClose={() => setOpen(false)} anchor={editBtn} title="Edit bike" sub="Honda Click · กข 1234"
1475
+ footer={<><Button onClick={() => setOpen(false)}>Cancel</Button><Button variant="primary" onClick={save}>Save</Button></>}>
1476
+ <BikeForm bike={bike} />
1477
+ </Modal>
1478
+ ```
1479
+
1480
+ - `open` / `onClose()` — closing from inside (✕, scrim, Esc) calls `onClose`; set `open` to false there.
1481
+ - `title`, `sub` — text or React nodes; they may change while it is open.
1482
+ - `size` — `''`, `'sm'` or `'lg'`. `anchor` — element or ref it zooms out of. `footer` — buttons at the bottom.
1483
+
1484
+ ### Drawer
1485
+
1486
+ A panel that slides in from the side (a bottom sheet on phones); its content drifts up as it lands.
1487
+
1488
+ ```tsx
1489
+ <Drawer open={!!rider} onClose={() => setRider(null)} title={rider?.name} sub={`Rider since ${rider?.since}`}
1490
+ head={<span className="av av--teal">{rider?.initials}</span>} footer={<Button variant="primary">Message</Button>}>
1491
+ <RiderBookings id={rider?.id} />
1492
+ </Drawer>
1493
+ ```
1494
+
1495
+ - `open` / `onClose()`, `title`, `sub`, `footer` — as in Modal.
1496
+ - `head` — something before the title (an avatar). `side` — `'right'` (default) or `'left'`.
1497
+ - Opening a drawer closes any other drawer (its `onClose` runs).
1498
+
1499
+ ### confirm / useConfirm
1500
+
1501
+ An “are you sure?” dialog you `await`: `true` for OK, `false` for Cancel, ✕, scrim or Esc.
1502
+
1503
+ ```tsx
1504
+ const confirm = useConfirm();
1505
+
1506
+ async function cancelBooking(b: Booking) {
1507
+ if (!(await confirm({ title: `Cancel booking #${b.id}?`, body: 'The rider gets a full refund.', ok: 'Cancel booking', danger: true }))) return;
1508
+ await api.cancel(b.id);
1509
+ toast('Booking cancelled', { tone: 'good' });
1510
+ }
1511
+ ```
1512
+
1513
+ - `title`, `body`, `ok`, `cancel` — plain text (safe for your data). `danger` — red OK button. `anchor` — zooms out of it.
1514
+ - `confirm()` works anywhere; `useConfirm()` also closes a dialog that is still open when the component unmounts.
1515
+
1516
+ ### Popover
1517
+
1518
+ A small panel that pops out of its trigger (the one child), with its origin pointing back at it.
1519
+
1520
+ ```tsx
1521
+ <Popover align="end" label="Share" className="pop--wide"
1522
+ content={(close) => <ShareBooking id={booking.id} onCopied={() => { close(); toast('Link copied', { icon: 'copy' }); }} />}>
1523
+ <Button icon="send">Share</Button>
1524
+ </Popover>
1525
+ ```
1526
+
1527
+ - `content` — React nodes, or `(close) => nodes`.
1528
+ - Clicking the trigger toggles it; a click outside, Esc or a resize closes it.
1529
+ - `open` + `onOpenChange(open)` to control it, or `defaultOpen`. `align` — `'start' | 'center' | 'end'`. `className`, `label`.
1530
+ - `ref` → `{ open(), close(), isOpen, el }`.
1531
+
1532
+ ### Menu
1533
+
1534
+ A popover with a ready-made list of actions that slide in; ↑ ↓ move between them.
1535
+
1536
+ ```tsx
1537
+ <Menu align="end" items={[
1538
+ { section: 'Booking' },
1539
+ { icon: 'edit', label: 'Edit', kbd: 'E', run: () => edit(b) },
1540
+ { icon: 'copy', label: 'Duplicate', run: () => duplicate(b) },
1541
+ '-',
1542
+ { icon: 'trash', label: 'Cancel booking', danger: true, run: () => cancelBooking(b) },
1543
+ ]}>
1544
+ <Button icon="more" aria-label="More" />
1545
+ </Menu>
1546
+ ```
1547
+
1548
+ - `items` — `{ label, icon, kbd, danger, run(trigger) }`, `{ section: 'Heading' }`, or `'-'` for a line.
1549
+ - `onSelect(item, index)` — after any action (after its `run`). `align`, `className`, `label`. `ref` → `{ open(), close(), isOpen }`.
1550
+
1551
+ ### ContextMenu
1552
+
1553
+ The menu you get with a right-click, a long-press on touch screens or Shift+F10. It grows from the pointer and has submenus and ticks.
1554
+
1555
+ ```tsx
1556
+ <ContextMenu as="tbody" selector="tr[data-id]"
1557
+ items={(event, row) => [
1558
+ { section: `Booking #${row.dataset.id}` },
1559
+ { icon: 'edit', label: 'Edit', kbd: 'E', run: () => edit(row.dataset.id) },
1560
+ { label: 'Move to', items: bikes.map((bike) => ({ label: bike.name, run: () => move(row.dataset.id, bike.id) })) },
1561
+ { label: 'Paid', checked: isPaid(row.dataset.id), run: (_el, item) => setPaid(row.dataset.id, item.checked) },
1562
+ '-',
1563
+ { icon: 'trash', label: 'Cancel', danger: true, run: () => cancelBooking(row.dataset.id) },
1564
+ ]}>
1565
+ {bookings.map((b) => <tr key={b.id} data-id={b.id}>…</tr>)}
1566
+ </ContextMenu>
1567
+ ```
1568
+
1569
+ - `items` — a list, or `(event, el) => list` on every open (return `[]` to get the browser's own menu).
1570
+ Rows: `{ label, icon, kbd, hint, disabled, danger, checked, items, run(el, item) }`, `{ section }`, `'-'`.
1571
+ - `checked` rows flip on a copy (never your data): `run` / `onSelect` get the new value in `item.checked`.
1572
+ - `selector`, `longPress` (ms, 0 = off), `nativeOnShift`, `icons`, `shortcuts`, `words: { label }`, `onSelect(item, el)`, `onOpen`, `onClose`.
1573
+ - `as` — the wrapper element (default `div`). `ref` → `{ open(x, y, el?), close(), isOpen, menu, el }`.
1574
+
1575
+ ### Tooltip
1576
+
1577
+ A small label that fades in under (or beside) an element on hover or keyboard focus. Hidden on phones.
1578
+
1579
+ ```tsx
1580
+ <Tooltip text="Edit booking"><Button icon="edit" aria-label="Edit booking" /></Tooltip>
1581
+ <Tooltip text={<>Somchai K.<br />Mechanic</>} side="right"><span className="av av--teal" tabIndex={0}>SK</span></Tooltip>
1582
+ ```
1583
+
1584
+ - `text` — a string (a `\n` makes a second line) or React nodes. `side` — `'below'` (default) or `'right'`.
1585
+ - `disabled` — turn it off for now. Inside an element with `data-tips-right` it opens to the right.
1586
+ - For plain HTML elements you can still use `data-tip="…"` with `initTips()` from `@gecko-ui-kit/overlays`.
1587
+
1588
+ ### toast
1589
+
1590
+ A short message that pops up at the bottom and goes away by itself. A plain function: call it from anywhere.
1591
+
1592
+ ```tsx
1593
+ toast('Booking saved', { tone: 'good' });
1594
+ toast('Bike moved to the workshop', { icon: 'tool', undo: () => moveBack(bike) });
1595
+ const close = toast('Uploading photos…', { duration: 60000 }); // close() when done
1596
+ ```
1597
+
1598
+ - `tone` — `''`, `'good'`, `'warn'` or `'bad'`. `icon` — an icon name. `duration` — ms (default 4200).
1599
+ - `undo` — adds an Undo button; `undoLabel`, `undoneText`. The text is shown as plain text (safe for your data).
1600
+
1601
+ ### CookieBanner
1602
+
1603
+ Asks once which cookies a visitor allows, remembers the answer and stays away until you raise `version`.
1604
+
1605
+ ```tsx
1606
+ const cookies = useRef<CookieBannerHandle>(null);
1607
+
1608
+ <CookieBanner ref={cookies} policy="/privacy" position="end"
1609
+ onChange={(choices) => { if (choices.analytics) loadAnalytics(); }} />
1610
+ <footer><button onClick={() => cookies.current?.open({ settings: true })}>Cookie settings</button></footer>
1611
+ ```
1612
+
1613
+ - `categories` — `{ id, label, text, required }[]` (default: necessary, analytics, marketing). Optional ones start off.
1614
+ - `storageKey` (default `'gecko:consent'`, `''` = never saved), `version`, `show` (`'auto'` or `false`), `position` (`'bottom' | 'start' | 'end'`), `mount`, `policy`, `words`.
1615
+ - `onChange(choices, { action, at })`. `ref` → `{ choices, allowed(id), open({ settings }), close(), reset(), visible, el }`.
1616
+
1617
+ ### LoadingBar / useLoadingBar
1618
+
1619
+ The thin line along the top of the page while something loads. Quick loads never show it.
1620
+
1621
+ ```tsx
1622
+ // with a state
1623
+ const [isPending, startTransition] = useTransition();
1624
+ <LoadingBar active={isPending} />
1625
+
1626
+ // or by hand
1627
+ const bar = useLoadingBar({ color: 'var(--good)' });
1628
+ async function save() { bar.start(); try { await api.save(booking); bar.done(); } catch { bar.fail(); } }
1629
+ ```
1630
+
1631
+ - `<LoadingBar active>` starts when `active` turns true and finishes when it turns false.
1632
+ - `useLoadingBar(options)` → `{ start(), done(all?), fail(), set(0..1), inc(n), value, loads, active, el }`, the same object for the component's life.
1633
+ - Options: `mount` (element, ref or selector; default the window), `height`, `color`, `trickle`, `delay`, `label`, `words`.
1634
+
1635
+ ### CommandPalette
1636
+
1637
+ The ⌘K search window: type, move with the arrow keys, Enter picks, Esc closes.
1638
+
1639
+ ```tsx
1640
+ <CommandPalette open={open} onClose={() => setOpen(false)} placeholder="Search bikes and riders…"
1641
+ search={(q) => [
1642
+ { label: 'Bikes', items: bikes.filter((b) => b.name.toLowerCase().includes(q)).map((b) => ({ title: b.name, sub: b.plate, icon: 'bike', run: () => router.push(`/bikes/${b.id}`) })) },
1643
+ { label: 'Riders', items: riders.filter((r) => r.name.toLowerCase().includes(q)).map((r) => ({ title: r.name, sub: r.phone, icon: 'user', run: () => openRider(r) })) },
1644
+ ]} />
1645
+ ```
1646
+
1647
+ - `search(q)` → groups `{ label, items: [{ title, sub, icon, run }] }`; `q` is trimmed and lowercased.
1648
+ - `open` / `onClose()`, `onSelect(item)`, `placeholder`, `emptyTitle`, `emptyBody`.
1649
+ - Inside `<AppShell>`, ⌘K already opens a palette with your pages; add groups with its `search` prop.
1650
+
1651
+ ### Tour
1652
+
1653
+ A walk-through: the page dims except a spotlight around each stop, and a bubble explains it. ← → move, Esc ends.
1654
+
1655
+ ```tsx
1656
+ const searchRef = useRef<HTMLButtonElement>(null);
1657
+
1658
+ <Tour open={touring} onEnd={(finished) => { setTouring(false); if (finished) markTourSeen(); }} steps={[
1659
+ { title: 'Welcome to MotoRent', text: 'A one-minute look around.' },
1660
+ { target: searchRef, title: 'Find a bike', text: 'Search by name or plate number.' },
1661
+ { target: '#calendar', title: 'Bookings', content: <p>Drag a booking to <b>move</b> it to another bike.</p> },
1662
+ ]} />
1663
+ ```
1664
+
1665
+ - `steps` — `{ target, title, text, content, placement, padding, radius }`. `target`: a ref, element or selector
1666
+ (missing → skipped; none → bubble in the middle). `content`: React nodes instead of `text`.
1667
+ - `open`, `start`, `onStep(index, step)`, `onEnd(finished)` (setting `open` to false ends it quietly).
1668
+ - `placement`, `padding`, `radius`, `backdrop`, `scroll`, `words`. `ref` → `{ start(i), next(), prev(), go(i), stop(), index, active }`.
1669
+
1670
+ ### Lightbox
1671
+
1672
+ Full-screen photos that grow out of their thumbnail and shrink back into it. Swipe, zoom, drag down to close.
1673
+
1674
+ ```tsx
1675
+ const thumbs = useRef<(HTMLImageElement | null)[]>([]);
1676
+ const [shown, setShown] = useState(-1);
1677
+
1678
+ {bike.photos.map((p, i) => <img key={p.id} ref={(el) => { thumbs.current[i] = el; }} src={p.thumb} alt={p.alt} onClick={() => setShown(i)} />)}
1679
+ <Lightbox open={shown >= 0} index={Math.max(0, shown)} onChange={setShown} onClose={() => setShown(-1)}
1680
+ items={bike.photos.map((p, i) => ({ src: p.big, alt: p.alt, caption: p.caption, from: thumbs.current[i] }))} />
1681
+ ```
1682
+
1683
+ - `items` — image addresses or `{ src, alt, caption, w, h, from }` (`from`: the thumbnail element, ref or selector).
1684
+ - `open`, `index` (changing it while open moves there), `onChange(index)`, `onClose(index)`, `zoom`, `maxZoom`, `words`.
1685
+
1686
+ ### LightboxGallery
1687
+
1688
+ The no-state version: wrap links to big images and clicking one opens its whole group.
1689
+
1690
+ ```tsx
1691
+ <LightboxGallery className="photos">
1692
+ {bike.photos.map((p) => <a key={p.id} href={p.big} data-lightbox="bike" data-caption={p.caption}><img src={p.thumb} alt={p.alt} /></a>)}
1693
+ </LightboxGallery>
1694
+ ```
1695
+
1696
+ - Elements with the same `data-lightbox` value form one gallery; image from `href`, `data-src` or the inner `<img>`.
1697
+ - `selector`, `zoom`, `maxZoom`, `words`, `onChange`, `onClose`, `as`.
1698
+
1699
+ ## App shell
1700
+
1701
+ The app frame — sidebar, topbar, page header, phone tab bar — for a Next.js app. These components draw the same
1702
+ markup as `createShell()` (so they render on the server), but the router is Next's: you pass the current path and
1703
+ `onNavigate`, and your pages are ordinary React children.
1704
+
1705
+ ### AppShell
1706
+
1707
+ The whole frame around your pages: Sidebar, Topbar, the page in `<main class="view">`, the phone tab bar, the ⌘K
1708
+ palette, keyboard shortcuts and the opening animation. When the path changes, the new page slides in from the
1709
+ direction of travel.
1710
+
1711
+ ```tsx
1712
+ // app/(app)/layout.tsx
1713
+ 'use client';
1714
+ import Link from 'next/link';
1715
+ import { usePathname, useRouter } from 'next/navigation';
1716
+ import { AppShell } from '@gecko-ui-kit/react';
1717
+
1718
+ const nav = [
1719
+ { label: 'Shop', items: [
1720
+ { id: 'today', label: 'Today', icon: 'today', href: '/' },
1721
+ { id: 'bikes', label: 'Bikes', icon: 'layers', subs: [['fleet', 'Fleet'], ['repairs', 'Repairs']] }, // /bikes/fleet, /bikes/repairs
1722
+ { id: 'bookings', label: 'Bookings', icon: 'rota', count: () => pending.length },
1723
+ ] },
1724
+ { label: 'People', items: [{ id: 'riders', label: 'Riders', icon: 'people' }] },
1725
+ ];
1726
+
1727
+ export default function Layout({ children }: { children: React.ReactNode }) {
1728
+ const router = useRouter();
1729
+ return (
1730
+ <AppShell brand={{ name: 'MotoRent', sub: 'Chiang Mai' }} nav={nav} end={[{ id: 'settings', label: 'Settings', icon: 'settings' }]}
1731
+ user={{ name: 'Pim Wong', role: 'Manager', menu: [{ icon: 'user', label: 'Profile', run: () => router.push('/profile') }] }}
1732
+ path={usePathname()} onNavigate={(href) => router.push(href)} link={Link} storageKey="motorent"
1733
+ top={{ search: { placeholder: 'Search bikes…' }, bell: { count: unread, onClick: openInbox }, primary: { label: 'New booking', run: newBooking } }}
1734
+ search={(q) => [{ label: 'Bikes', items: findBikes(q).map((b) => ({ title: b.name, sub: b.plate, icon: 'layers', run: () => router.push(`/bikes/${b.id}`) })) }]}>
1735
+ {children}
1736
+ </AppShell>
1737
+ );
1738
+ }
1739
+ ```
1740
+
1741
+ - `nav` (groups of `{ id, label, icon, href, count, subs, blurb, tabs }`), `end` (items pinned to the bottom), `brand`, `user`.
1742
+ An item's address is `href`, else `/${id}` (`base` adds a prefix); a sub-page's is `/${id}/${subId}`.
1743
+ - `path` — the current path (`usePathname()`); `onNavigate(href)` — called by every link, menu, the palette and keys; `link` — e.g. Next's `Link`.
1744
+ - `top` — `{ search: { placeholder, onOpen } | false, theme, bell: { count, onClick }, primary: { label, icon, run }, extra }`. `crumbsRoot`.
1745
+ - `tabbar` (ids for the phone tab bar), `tabs`, `intro`, `shortcuts`, `keys: [{ key, label, run }]`, `search(q)`, `storageKey`, `railBreakpoint`, `mobile`, `words`.
1746
+ - `useShell()` inside it → `{ route, path, navigate, palette(), shortcuts(), intro(), setRail(b), isRail() }`.
1747
+ - Put `shellBootScript({ storageKey })` in an inline `<script>` in your `<head>` so the saved theme and rail are set before the first paint
1748
+ (and add `suppressHydrationWarning` to `<html>`). Set the page title with Next's `metadata`.
1749
+
1750
+ ### Sidebar
1751
+
1752
+ The main menu: a pill stretches to the current item, the open section unfolds its sub-pages, counts flash when
1753
+ they change, and it collapses to a rail of icons with a flyout on hover. On phones it is a drawer.
1754
+
1755
+ ```tsx
1756
+ <Sidebar brand={{ name: 'Friday', sub: 'Projects', icon: 'logo' }} nav={nav} end={end} user={me}
1757
+ path={pathname} onNavigate={(href) => router.push(href)} storageKey="friday" />
1758
+ ```
1759
+
1760
+ - Same `nav`, `end`, `path`, `base`, `home`, `onNavigate`, `link`, `words` as AppShell; `brand`, `user`, `storageKey`, `railBreakpoint`, `mobile`.
1761
+ - Clicking the open item folds its sub-pages instead of navigating. The `[` key and the panel button switch the rail (inside AppShell).
1762
+ - `ref` → `{ setRail(rail), isRail(), el }`.
1763
+
1764
+ ### Topbar
1765
+
1766
+ The bar above the page: breadcrumbs from the route, a search button, your own buttons, a theme switch that
1767
+ spreads from the button, a bell whose badge pops when the number goes up, and one main action.
1768
+
1769
+ ```tsx
1770
+ <Topbar nav={nav} path={pathname} onNavigate={router.push} crumbsRoot="Friday"
1771
+ search={{ placeholder: 'Search projects…', onOpen: () => setSearching(true) }}
1772
+ bell={{ count: unread, onClick: (button) => openInbox(button) }}
1773
+ primary={{ label: 'New project', icon: 'plus', run: () => setCreating(true) }}>
1774
+ <TimerButton />
1775
+ </Topbar>
1776
+ ```
1777
+
1778
+ - `crumbsRoot`, `search` (`false` hides it), `theme` (`false` hides it), `bell: { count, onClick(button) }`, `primary: { label, icon, tip, run(button) }`.
1779
+ - `children` go before the theme switch. The menu button (phones) opens the Sidebar drawer.
1780
+
1781
+ ### PageHeader
1782
+
1783
+ The top of a page: an eyebrow, a big title whose letters roll up (again when it changes), a line of text,
1784
+ buttons on the right, and tabs with an underline that stretches to the chosen tab.
1785
+
1786
+ ```tsx
1787
+ // app/(app)/bikes/repairs/page.tsx — inside AppShell the Bikes sub-pages become link tabs by themselves
1788
+ <PageHeader eyebrow="Workshop" title="Repairs" sub="Bikes in the workshop this week."
1789
+ actions={<Button variant="primary" icon="plus">Book a repair</Button>} counts={{ repairs: waiting.length }} />
1790
+
1791
+ // your own tabs (buttons)
1792
+ <PageHeader title="Project Apollo" tabs={[['board', 'Board'], ['list', 'List'], ['files', 'Files', 4]]} value={view} onTabChange={setView} />
1793
+ ```
1794
+
1795
+ - `title` (text), `eyebrow`, `sub`, `actions` (React nodes).
1796
+ - `tabs` — `[{ id, label, count, href }]` or `[id, label, count?, href?]`; with `href` they are links, without they are buttons (`value` + `onTabChange(id)`).
1797
+ Inside AppShell, leave it out to get the current item's sub-pages; `tabs={false}` hides them. `counts: { tabId: n }` adds badges.
1798
+ - Letters are split by grapheme, so Thai vowels and tone marks stay on their letter.
1799
+
1800
+ ### MobileTabbar
1801
+
1802
+ On phones (760px and below) a tab bar at the bottom with your main sections; a soft highlight stretches to the
1803
+ current one and “More” lists the rest. Hidden on wider screens.
1804
+
1805
+ ```tsx
1806
+ <MobileTabbar nav={nav} end={end} path={pathname} onNavigate={router.push} tabbar={['today', 'bikes', 'bookings', 'riders']} />
1807
+ ```
1808
+
1809
+ - `tabbar` — ids that get a tab (default: the first four items). The rest go under “More” (`words.more`).
1810
+
1811
+ ## Helpers
1812
+
1813
+ - `useMotion(fn, options | deps)`: run any `@gecko-ui-kit/motion` helper on an element you render; it is cleaned up
1814
+ on unmount.
1815
+ - `useControllable(value, defaultValue, onChange)`: the controlled / uncontrolled pattern the components use.
1816
+ - `mounted(name, mountFn, spec)` and `enhancer(name, motionFn, spec)`: turn your own vanilla-style piece into a
1817
+ component the same way this package does (see `src/core.js`).
1818
+ - `<Icon name="bike" />`: any icon from `@gecko-ui-kit/icons`.
1819
+
1820
+ ## Tests
1821
+
1822
+ `npm run check:react` in the repo draws every component on the server, hydrates it in a browser inside React
1823
+ StrictMode on a desktop (light) and a phone (dark, reduced motion), clicks and types through it, unmounts it and checks
1824
+ nothing is left behind. It runs on every push.