@alvaromarinho/ui-core 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alvaro Marinho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,295 @@
1
- # Temporary Holding Version
1
+ # @alvaromarinho/ui-core
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
+ Framework-free helpers on top of native HTML (`<dialog>`, popover, `<details>`), plus a neutral stylesheet. No dependencies. Each piece has its own entry point, so a project only ships what it imports.
4
+
5
+ | Entry | What it gives |
6
+ |---|---|
7
+ | `@alvaromarinho/ui-core/toast` | `toast.send`, `dismiss`, `dismissAll`, `configureToast`, `toastDuration` |
8
+ | `@alvaromarinho/ui-core/dialog` | `lightDismiss`, `lockScroll` |
9
+ | `@alvaromarinho/ui-core/table` | `createTable` |
10
+ | `@alvaromarinho/ui-core/pagination` | `pages`, `pageCount`, `pageRange` |
11
+ | `@alvaromarinho/ui-core/calendar-grid` | `createCalendarGrid` and date-string helpers |
12
+ | `@alvaromarinho/ui-core/calendar` | `createCalendar`: month grid with events |
13
+ | `@alvaromarinho/ui-core/date-picker` | `createDatePicker`, `parseValue`, `formatValue`, `isValue` |
14
+ | `@alvaromarinho/ui-core/input-mask` | `createMask`, `createNumberInput`, `formatMask`, `unmask`, `isMaskComplete`, `formatNumber` |
15
+ | `@alvaromarinho/ui-core/combobox` | `createCombobox`, `includesText` |
16
+ | `@alvaromarinho/ui-core/ui-core.css` | Structure for dialog, drawer, sheet, menu, toggletip, `<details>`, toast, table, pagination, calendar grid, calendar with events, date picker and combobox |
17
+
18
+ Skin: `@alvaromarinho/ui-bootstrap` maps the `--am-*` tokens to Bootstrap variables. Without a skin, the pieces use neutral system colors.
19
+
20
+ Support: browsers with Baseline Widely features; iOS 17.0 and later. Newer features (`@starting-style`, anchor positioning) are progressive: without them, the function stays the same.
21
+
22
+ ## Toast
23
+
24
+ ```ts
25
+ import { toast } from '@alvaromarinho/ui-core/toast';
26
+
27
+ toast.send('Salvo', 'Planta cadastrada.', 'success');
28
+ const closed = toast.send('Falhou', 'Tente de novo.', 'danger');
29
+ toast.dismiss(closed);
30
+ await closed; // resolves when the toast closes
31
+ ```
32
+
33
+ - `send(title, message = null, style = 'primary', duration?)`. Styles: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark`.
34
+ - Duration by style: `warning` 7 s, `danger` 10 s, the rest 4 s. `Infinity` keeps it open.
35
+ - Title and message are text (`textContent`), never markup.
36
+ - `danger` is `role="alert"`; the rest `role="status"`.
37
+ - Pauses while the pointer is over it or the focus is inside it.
38
+ - Up to 5 visible at once (`configureToast({ max })`); the rest wait in a queue.
39
+ - The region (`<section class="am-toast-region" aria-label="Notifications" popover="manual">`) is created on the first `send`. Labels (default `Notifications` and `Close`): `configureToast({ regionLabel: 'Notificações', closeLabel: 'Fechar' })`.
40
+ - An unknown style falls back to `primary`. Raising `max` shows queued toasts at once.
41
+ - Only exit transitions are awaited (up to 500 ms): an infinite animation on a toast does not hold the queue.
42
+ - **In front of modals:** while a modal `<dialog>` is open, the region moves into the top one (outside it, the page is inert and the toast could not be clicked) and moves back when it closes. The dialog needs nothing for this. Do not give a dialog a permanent `transform`, `filter` or `contain`: it would become the containing block of the fixed region.
43
+
44
+ ## Dialog
45
+
46
+ Each screen owns its `<dialog>` and calls `showModal()`. The helpers add what the browser does not do everywhere.
47
+
48
+ ```ts
49
+ import { lightDismiss, lockScroll } from '@alvaromarinho/ui-core/dialog';
50
+
51
+ const off = lightDismiss(dialog); // once, after the dialog exists
52
+ dialog.showModal();
53
+ const release = lockScroll(dialog); // on every open
54
+ // on destroy: off(); release();
55
+ ```
56
+
57
+ - `lightDismiss(dialog)`: closes when a press starts and ends outside the box (the backdrop). Fallback for `closedby="any"`. Fires `cancel` first (`requestClose()` where available), so `preventDefault()` there keeps it open. Returns the function that removes the listeners.
58
+ - `lockScroll(dialog)`: locks the page scroll until the dialog closes, keeping the scrollbar width. Nested dialogs share the lock. Calling it again for the same dialog returns the same release function; a `close` that arrives after a reopen in the same task is ignored. A dialog removed from the page while open fires no `close`: call the returned function on destroy.
59
+
60
+ ## Table
61
+
62
+ ```ts
63
+ import { createTable } from '@alvaromarinho/ui-core/table';
64
+
65
+ const table = createTable(tableElement, {
66
+ columns: [
67
+ { label: 'Name', field: 'name', sortable: true },
68
+ { label: 'Water', field: 'water', align: 'end', format: v => `${v} days` },
69
+ { label: '', render: row => editButton(row), click: row => edit(row) },
70
+ ],
71
+ labels: { empty: 'No plants', loading: 'Loading…' },
72
+ onSort: sort => load(sort), // the table never reorders rows
73
+ });
74
+ table.update({ loading: true });
75
+ table.update({ rows, loading: false, sort });
76
+ table.destroy();
77
+ ```
78
+
79
+ ```html
80
+ <div class="am-table-wrap am-table-cards">
81
+ <table class="table"><caption>Plants</caption></table>
82
+ </div>
83
+ ```
84
+
85
+ - Column: `label`, `field`, `format(value, row) → string`, `render(row) → Node | string | null`, `sortable` (needs `field`), `align` (`start`, `center`, `end`), `width` (on the `th`), `classes` (on the `th` and every `td`), `click(row, event)`.
86
+ - Content is text: a string from `format` or `render` never becomes markup. Build buttons, links and badges as elements in `render`. Empty values show `labels.missing` (`—`).
87
+ - `click` fires only when the click comes from a `button` or `a` inside the cell, so the keyboard works without extra code.
88
+ - Sorting: a sortable header is a `<button>` in the `th`; clicks cycle ascending, descending, none, set `aria-sort` on that `th` and call `onSort({ field, direction } | null)`. `update({ sort })` sets it from outside without rebuilding the header, so focus stays on the button.
89
+ - `update({ rows?, loading?, sort? })`: rows are replaced; while `loading`, the table gets `aria-busy="true"` and the current rows fade (their nodes stay, so focus and input state survive). With no rows, one cell spanning all columns shows `labels.empty` or `labels.loading`. New rows keep keyboard focus: the control with the same name in the same row and column gets it back, or the table itself when that row is gone.
90
+ - Only its own `thead` and `tbody` are created (after `caption` and `colgroup`); a `tfoot` or another `tbody` of the project stays. `destroy()` removes them.
91
+ - Card mode (opt-in): `.am-table-cards` on the `.am-table-wrap` turns each row into a card below 36rem of the **wrapper** width, with the column label before each value (from `data-label`, kept out of the accessible name). The wrapper is required: size containment does not apply to table boxes. The table, its header cells and cells stay in the accessibility tree (Chromium and WebKit). Sorting is not offered in card mode.
92
+
93
+ ## Pagination
94
+
95
+ ```ts
96
+ import { pageCount, pageRange, pages } from '@alvaromarinho/ui-core/pagination';
97
+
98
+ pages(10, 20); // [1, '…', 8, 9, 10, 11, 12, '…', 20]
99
+ pageCount(25, 10); // 3
100
+ pageRange(3, 10, 25); // { start: 21, end: 25 }, for "Showing 21–25 of 25"
101
+ ```
102
+
103
+ - `pages(current, total, span = 5)`: the first, the last and `span` pages around the current one; a gap that would hide a single page shows the page.
104
+ - The markup is the project's: `<nav class="am-pagination" aria-label="…">` with buttons or links, `aria-current="page"` on the current one, `disabled` on previous or next at the edges and `aria-label` on icon-only buttons. The stylesheet gives every control a 24 px target (44 px with a coarse pointer).
105
+
106
+ ## Calendar grid
107
+
108
+ ```ts
109
+ import { createCalendarGrid } from '@alvaromarinho/ui-core/calendar-grid';
110
+
111
+ const grid = createCalendarGrid(element, {
112
+ value: '2026-11-10',
113
+ min: '2026-01-01',
114
+ locale: 'pt-BR',
115
+ labels: { previous: 'Mês anterior', next: 'Próximo mês' },
116
+ onSelect: date => save(date), // '2026-11-12'
117
+ onMonthChange: month => load(month), // '2026-12'
118
+ });
119
+ grid.update({ value: '2026-12-01', max: '2026-12-31' });
120
+ grid.focus();
121
+ grid.destroy();
122
+ ```
123
+
124
+ - Dates are `YYYY-MM-DD` strings in and out; no `Date` in local time on the way, so there is no time zone shift. `today` defaults to the device's date.
125
+ - ARIA grid pattern: one day in the tab order; arrows move a day or a week, Home/End go to the start and end of the week, PageUp/PageDown change the month (with Shift, the year), Enter or Space selects. The left and right arrows swap in RTL, read from the `dir` attribute (`:dir(rtl)`), not from `direction` set only in CSS.
126
+ - Today has `aria-current="date"`, the selected day `aria-selected="true"`, days of the months around it `data-am-outside`, and days outside `min`/`max` `aria-disabled="true"` (they keep the focus but do not select). The month buttons use `aria-disabled` at the bounds too, so the focus never drops.
127
+ - The first day of the week comes from the locale (`Intl.Locale` week info, else CLDR data for the region); `firstDay` (1 = Monday … 7 = Sunday) overrides it.
128
+ - `renderDay(date)` adds content after the day number (`Node`, or a string as text); `describeDay(date)` adds text to the day's accessible name, which hides that content.
129
+ - Pure helpers for the same strings: `isDate`, `today`, `addDays`, `addMonths` (31/01 + 1 month = last day of February), `weekday`, `firstDayOfWeek`, `monthWeeks`, `moveDate`, `clampDate`, `resolveLocale`, `toUtcDate` (a `Date` at 00:00 UTC, for `Intl.DateTimeFormat` with `timeZone: 'UTC'`) and `isRtl(element)`.
130
+
131
+ ## Calendar with events
132
+
133
+ ```html
134
+ <div id="agenda"></div>
135
+ ```
136
+
137
+ ```ts
138
+ import { createCalendar } from '@alvaromarinho/ui-core/calendar';
139
+
140
+ const calendar = createCalendar<Visit>(document.querySelector('#agenda'), {
141
+ locale: 'pt-BR',
142
+ labels: { previous: 'Mês anterior', next: 'Próximo mês', count: n => (n === 1 ? '1 evento' : `${n} eventos`), empty: 'Nenhum evento', allDay: 'Dia todo' },
143
+ onMonthChange: ({ first, last }) => load(first, last),
144
+ onEventClick: visit => openVisit(visit), // the object given in events
145
+ });
146
+ load(calendar.range().first, calendar.range().last);
147
+
148
+ function load(first: string, last: string): void {
149
+ api.visits(first, last).subscribe(events => calendar.update({ events }));
150
+ }
151
+ ```
152
+
153
+ - Event: `{ start, end?, title, color?, description? }` plus any field of yours (`createCalendar<T>`). `start`/`end` are `YYYY-MM-DD` (all day) or `YYYY-MM-DDTHH:mm`, read as written, with no time zone; an event shows on every day from `start` to `end`.
154
+ - The cells only show the events: titles up to `maxPerDay` (default 3) and `+N`, or one dot per event when the container is narrower than 36rem. Nothing in a cell takes the focus, so the grid keeps one tab stop and its keyboard (see the month grid); the count goes in the day's accessible name (`labels.count`).
155
+ - The selected day (`value`, default today) is listed below the grid as buttons with time, title and description; `onEventClick` gets the event. No tooltip: the list works on touch and with a screen reader.
156
+ - `onMonthChange({ month, first, last })` gives the days on screen, with those of the months around it, to fetch the events; `range()` gives them for the first fetch. `update({ events, value, month, today })` redraws and keeps the focus.
157
+ - The color goes in `--am-event-color`; titles are text.
158
+
159
+ ## Date picker
160
+
161
+ ```html
162
+ <label for="start">Start</label>
163
+ <div class="input-group">
164
+ <input id="start" class="form-control" autocomplete="off" inputmode="numeric" placeholder="dd/mm/aaaa">
165
+ <button id="start-pick" type="button" class="btn btn-outline-secondary"><i class="bi bi-calendar" aria-hidden="true"></i></button>
166
+ </div>
167
+ ```
168
+
169
+ ```ts
170
+ import { createDatePicker } from '@alvaromarinho/ui-core/date-picker';
171
+
172
+ const picker = createDatePicker({
173
+ input: document.querySelector('#start'),
174
+ button: document.querySelector('#start-pick'),
175
+ popoverAfter: document.querySelector('#start-pick').closest('.input-group'),
176
+ value: '2026-11-03',
177
+ max: '2026-12-31',
178
+ locale: 'pt-BR',
179
+ labels: { open: 'Escolher data', previous: 'Mês anterior', next: 'Próximo mês', invalid: 'Data inválida' },
180
+ onChange: (value, { invalid }) => save(value, invalid), // '2026-11-04', or '' with invalid: true while the text is not a date
181
+ });
182
+ picker.update({ min: '2026-11-01' });
183
+ ```
184
+
185
+ - Modes: `date` (`YYYY-MM-DD`, month grid), `month` (`YYYY-MM`, twelve months) and `year` (`YYYY`, twelve years), years 0001 to 9999 (year 0 is 1 BC in `Intl`). Values are strings in and out; no time zone on the way. Dates are Gregorian and the field uses digits 0–9 in any locale (`th-TH`, `ar-EG`, `ja-JP-u-ca-japanese`); typing accepts the locale's own digits, Arabic-Indic, Persian and full-width digits too. A full date as `min`/`max` of a month or year picker is cut to the mode.
186
+ - The field shows the value in the locale's numeric format and accepts typing in the locale's order with any separator, or digits alone (8, 6 or 4), as the iPhone numeric keypad has no separator. The year needs 4 digits. Text that is not a value gives `onChange('', { invalid: true })`, `invalid()` true and a native validation message (`labels.invalid`); a framework that sets `novalidate` (Angular) reads `invalid` instead, to tell "invalid date" from "required". A valid date outside `min`/`max` is kept, for the form to validate. `update({ value })` while the field has the focus rewrites its text on `change` or `blur` (an `update` with the same value keeps the invalid state while the person types); `form.reset()` resets the value and the hidden input; invalid text stays on `change`, so the person sees what to fix.
187
+ - The popover opens from the button only (`popovertarget`), never on focus: on a phone the keyboard would cover it. It is created next to the button, or after `popoverAfter`, so it works inside a modal `<dialog>`. Inside Bootstrap's `.input-group`, pass the group as `popoverAfter`: as the group's last child the popover would take the button's corner radius and get the group's `-1px` margin. Anchored below the button with anchor positioning, at its full width (flipped to the side or above when there is no room, centered on the button when neither side fits); centered on the screen without anchor positioning. Esc and a click outside close it; picking a value closes it and returns the focus to the button (in the field, a phone would open the keyboard). `destroy()` closes it, returns the focus to the button and clears the validation message.
188
+ - Without `input`, the button shows the value (`novembro de 2026`), for a filter with no field: `createDatePicker({ mode: 'month', button, onChange })`.
189
+ - `name` adds an `<input type="hidden">` with the value, for a native form. In a framework, bind the value through `onChange` and `update({ value })`.
190
+ - `parseValue(text, mode, locale)` returns the value, `''` for empty text or `null`; `formatValue(value, mode, locale)` gives the text for the field.
191
+
192
+ ## Input mask
193
+
194
+ ```html
195
+ <label for="cpf">CPF</label>
196
+ <input id="cpf" class="form-control" autocomplete="off">
197
+ <label for="price">Price</label>
198
+ <input id="price" class="form-control" autocomplete="off">
199
+ ```
200
+
201
+ ```ts
202
+ import { createMask, createNumberInput, formatMask, formatNumber } from '@alvaromarinho/ui-core/input-mask';
203
+
204
+ const cpf = createMask(document.querySelector('#cpf'), {
205
+ pattern: '000.000.000-00',
206
+ onChange: (value, { complete }) => save(value, complete), // '12345678909', complete: true
207
+ });
208
+ const price = createNumberInput(document.querySelector('#price'), {
209
+ currency: 'BRL',
210
+ locale: 'pt-BR',
211
+ onChange: value => save(value), // 1234.56, or null when empty
212
+ });
213
+ cpf.update({ value: '98765432100' });
214
+ formatMask('11987654321', '(00) 0000-0000||(00) 00000-0000'); // '(11) 98765-4321', for a table cell or a text
215
+ formatNumber(1234.5, { currency: 'BRL', locale: 'pt-BR' }); // 'R$ 1.234,50'
216
+ ```
217
+
218
+ - Pattern tokens: `0` digit, `9` optional digit, `A` letter or digit; anything else is a literal. `||` separates alternatives, tried in order: the first that takes every character wins (phone with 8 or 9 digits). Only what the pattern takes counts: a letter in a numeric pattern is dropped and does not pick another alternative. A typed literal skips the optional digits before it, so `099.099.099.099` takes `10.0.0.1`. A literal with letters or digits (`+55 (00) 00000-0000`) stays out of the value.
219
+ - Common patterns: CPF `000.000.000-00`, phone `(00) 0000-0000||(00) 00000-0000` (with `autocomplete="tel-national"`: plain `tel` autofills `+55 11 …`, which the pattern reads as another number), CEP `00000-000`, plate `AAA-AAAA` with `uppercase: true` (old and Mercosul), IPv4 `099.099.099.099` with `keepMask: true`. A date is a job for the date picker, not a mask.
220
+ - The value has the characters in slots only; `keepMask: true` keeps the literals. `complete` tells when every required slot is filled, for the form to validate. Without `value`, the field's own text is the start. `onChange` runs when the value or `complete` changes, also on `update({ pattern })`, on a form reset and on `update({ value })` when `complete` changes or the value differs from what was passed (characters dropped, masked text); `update` with the current value does nothing, so echoing `onChange` back into `update` is safe.
221
+ - The caret stays next to the same character on edits in the middle and on paste (formatted or raw text). Backspace or Delete next to a literal removes the nearest character instead of the literal; Backspace after a separator typed at the end removes just the separator. Text composed with an IME is formatted when the composition ends. `inputmode` follows the pattern (`numeric`, or `text` with `A`) and comes back on `destroy()`.
222
+ - `createNumberInput` types from the right, as on a card machine (`1`, `12`, `123` give `0,01`, `0,12`, `1,23`), formatted with `Intl.NumberFormat`: `currency` (ISO code), `decimals` (default: the currency's, or 2), `prefix`/`suffix` for units, `locale`. Digits are 0–9 in any locale. The value is a number, `null` when empty; erasing down to zero empties the field. Digits of `prefix` and `suffix` (`m2`) are not part of the value. Paste replaces the value and reads the locale's decimal separator (`12,5` is 12.50 in `pt-BR`, `1.500` is 1500). `allowNegative: true` lets `-` toggle the sign and sets `inputmode="text"` (the iOS numeric and decimal keyboards have no minus). 15 digits at most, the precision of a JavaScript number: a 16th typed digit is refused. Without `value`, the field's text is the start (`1234.5` or `1.234,50`); a form reset goes back to it. `value` and `update({ value })` are rounded to `decimals`, made positive without `allowNegative` and become `null` past 15 digits; `onChange` tells when that changed what was passed, even before `createNumberInput` returns.
223
+ - In a framework, bind through `onChange` and `update`, not the field's text: the text holds the mask.
224
+
225
+ ## Combobox
226
+
227
+ ```html
228
+ <label for="city">City</label>
229
+ <div class="am-combobox">
230
+ <input id="city">
231
+ </div>
232
+ ```
233
+
234
+ ```ts
235
+ import { createCombobox, includesText } from '@alvaromarinho/ui-core/combobox';
236
+
237
+ const city = createCombobox(document.querySelector('#city'), {
238
+ items: cities,
239
+ label: city => city.name,
240
+ value: city => city.id,
241
+ group: city => city.state,
242
+ search: (city, term) => includesText(city.name, term) || includesText(city.state, term),
243
+ name: 'city', // hidden input for a native form
244
+ onChange: (items, values) => save(values[0] ?? null),
245
+ });
246
+ city.update({ values: ['bsb'] });
247
+
248
+ const users = createCombobox(document.querySelector('#users'), {
249
+ multiple: true,
250
+ minLength: 3,
251
+ load: (term, signal) => fetch(`/api/users?q=${encodeURIComponent(term)}`, { signal }).then(response => response.json()),
252
+ label: user => user.name,
253
+ value: user => user.id,
254
+ chip: user => user.initials, // shorter text in the chip
255
+ render: user => optionWithPhoto(user), // Node or string (a string is text)
256
+ });
257
+ ```
258
+
259
+ - ARIA combobox with a listbox: the focus stays in the input and `aria-activedescendant` points to the active option. ↓/↑ open and move, Enter chooses (and does not submit the form while the list is open), Esc closes only the list (also inside a modal `<dialog>`), Tab closes. Keys during IME composition are left to the IME; the list filters when the composition ends.
260
+ - Markup: the project writes the `.am-combobox` around the `<input>` (no `name` on the input, or the label would be submitted); `createCombobox` throws without it. The library adds the chips, the clear button, the hidden inputs and the list, in a popover anchored to `.am-combobox` (centered without anchor positioning). The wrapper looks like a field (`ui-bootstrap`: like `.form-control`); do not put `.form-control` on it.
261
+ - `items` filters locally (`search`; default: the label contains the term, ignoring case and accents, with `includesText`). `load(term, signal)` runs after `delay` (300 ms) and `minLength` characters; a new term aborts the previous request and an old answer is ignored; errors show `labels.error` in the list's status line.
262
+ - `multiple`: chips with a remove button, Backspace in the empty input removes the last; choosing a chosen option removes it. `closeOnSelect` (default true), `clearable` (default true; in single choice, erasing the text and leaving clears too).
263
+ - `create(term)` offers the typed term when no option has the same label (ignoring case and accents); a pending creation ignores a second Enter.
264
+ - `selected` (items) or `values` (strings) choose; values not in the list wait for `update({ items })` (the list may arrive later) and are already sent in the hidden inputs (not while the input is disabled). `update` with the same values is silent; `onChange(items, values)` runs on each choice, on a form reset (back to the first choice) and when `update` had to drop a value (more than one in single choice). `onOpenChange(open)` follows the list.
265
+ - Labels default to English: `labels: { empty, loading, error, createError, minLength(n), create(term), clear, remove(label) }`. A failed `create` shows `labels.createError` until the next search.
266
+ - Validation is the project's: `required` on the input works in single choice (the text is the chosen label), not with `multiple` (the input stays empty next to the chips); check `values().length`.
267
+ - In a framework, bind through `onChange` and `update`, not the input's text.
268
+
269
+ ## CSS
270
+
271
+ ```css
272
+ @import '@alvaromarinho/ui-core/ui-core.css';
273
+ ```
274
+
275
+ | Class | Use |
276
+ |---|---|
277
+ | `.am-dialog` (`-header`, `-title`, `-body`, `-footer`) | Centered modal |
278
+ | `.am-drawer` (`data-am-side="start\|end"`) | Side drawer, full height, safe areas |
279
+ | `.am-sheet` | Bottom sheet |
280
+ | `.am-menu`, `.am-tip` | Popover menu and toggletip anchored to the invoker (`popovertarget`); centered without anchor positioning |
281
+ | `details.am-details` | Rotating arrow on the `summary` |
282
+ | `.am-table-wrap` (`.am-table-cards`) | Container for `createTable`, horizontal scroll, optional card mode |
283
+ | `nav.am-pagination` | Targets and current page for pagination |
284
+ | `.am-events` | Calendar with events of `createCalendar`: day cells with event marks (dots when narrow) and the day's list |
285
+ | `.am-datepicker` | Popover of `createDatePicker`, anchored to the button with fallback |
286
+ | `.am-combobox`, `.am-combobox-popup` | Field around the combobox input (chips, clear button) and its list in a popover anchored to it; centered without anchor positioning |
287
+ | `.am-calendar` | Month grid built by `createCalendarGrid`: 36 px days (44 px with a coarse pointer), today, selected, outside and disabled states |
288
+
289
+ Drawer next to a fixed column on wider screens: render the content twice (a `<nav>` column shown from the breakpoint and the `.am-drawer` for small screens; in Angular, one `ng-template` used in both). A closed `<dialog>` shown as a column keeps the `dialog` role in the accessibility tree, so the library does not offer that.
290
+
291
+ Selectors weigh one class (the component's); states and children sit in `:where()`. They beat the element rules of a CSS reset (Bootstrap's reboot) and lose to any project rule with a class loaded later. Tokens (all optional): `--am-bg`, `--am-fg`, `--am-border-color`, `--am-border-width`, `--am-radius`, `--am-radius-lg`, `--am-shadow`, `--am-shadow-lg`, `--am-space`, `--am-dialog-width`, `--am-drawer-width`, `--am-menu-gap`, `--am-toast-width`, `--am-toast-z`, `--am-toast-bg`, `--am-toast-fg`, `--am-toast-border`, `--am-toast-icon-color`, `--am-primary`, `--am-success`, `--am-danger`, `--am-warning`, `--am-info`, `--am-primary-fg`, `--am-muted`, `--am-hover`, `--am-focus`, `--am-field-padding`, `--am-field-border-color`, `--am-disabled-bg`.
292
+
293
+ ## Credits
294
+
295
+ Toast icons: paths from [Bootstrap Icons](https://icons.getbootstrap.com) 1.13, MIT license.
@@ -0,0 +1,83 @@
1
+ /** ISO weekday: 1 = Monday … 7 = Sunday. */
2
+ export type Weekday = 1 | 2 | 3 | 4 | 5 | 6 | 7;
3
+ export interface CalendarGridLabels {
4
+ previous: string;
5
+ next: string;
6
+ }
7
+ export interface CalendarGridOptions {
8
+ /** Selected date, `YYYY-MM-DD`. */
9
+ value?: string | null;
10
+ /** Month shown first, `YYYY-MM`. Default: the month of `value`, else of `today`. */
11
+ month?: string | null;
12
+ min?: string | null;
13
+ max?: string | null;
14
+ /** `YYYY-MM-DD`. Default: today in the device's time zone. */
15
+ today?: string;
16
+ /** BCP 47 tag for names and the first day of the week. Default: `<html lang>`, else the browser's. */
17
+ locale?: string;
18
+ /** Overrides the first day of the week taken from the locale. */
19
+ firstDay?: Weekday;
20
+ labels?: Partial<CalendarGridLabels>;
21
+ /** Extra content for a day, after its number (events, marks). A string becomes text. */
22
+ renderDay?: (date: string) => Node | string | null;
23
+ /** Text added to the day's accessible name (`3 de novembro de 2026, 2 eventos`), as the name hides the cell content. */
24
+ describeDay?: (date: string) => string | null;
25
+ onSelect?: (date: string) => void;
26
+ onMonthChange?: (month: string) => void;
27
+ }
28
+ export interface CalendarGridState {
29
+ value?: string | null;
30
+ month?: string | null;
31
+ min?: string | null;
32
+ max?: string | null;
33
+ today?: string;
34
+ }
35
+ export interface CalendarGridHandle {
36
+ update(state: CalendarGridState): void;
37
+ /** Moves the focus to the active day (the selected one, else today, else the first of the month). */
38
+ focus(): void;
39
+ /** Month on screen, `YYYY-MM`. */
40
+ month(): string;
41
+ destroy(): void;
42
+ }
43
+ /** True for a real calendar date written `YYYY-MM-DD`. */
44
+ export declare function isDate(value: unknown): value is string;
45
+ /** Today in the device's time zone, `YYYY-MM-DD`. */
46
+ export declare function today(): string;
47
+ export declare function addDays(date: string, days: number): string;
48
+ /** Same day `months` later; a day past the end of the target month becomes its last day (31/01 + 1 = 28 or 29/02). */
49
+ export declare function addMonths(date: string, months: number): string;
50
+ /** ISO weekday of a date: 1 = Monday … 7 = Sunday. */
51
+ export declare function weekday(date: string): Weekday;
52
+ /**
53
+ * First day of the week for a locale (`pt-BR` → 7, `fr-FR` → 1, `ar-EG` → 6).
54
+ * Uses Intl.Locale week info where the engine has it, else CLDR data for the region.
55
+ */
56
+ export declare function firstDayOfWeek(locale?: string): Weekday;
57
+ /** Weeks shown for a month (`YYYY-MM`): full weeks from `firstDay`, with the days of the months around it. */
58
+ export declare function monthWeeks(month: string, firstDay?: Weekday): string[][];
59
+ /**
60
+ * Date the grid keyboard moves to from `date`, or `null` for any other key.
61
+ * Arrows: a day or a week. Home/End: start and end of the week. PageUp/PageDown: a month; with Shift, a year.
62
+ * Pass `rtl` to swap the left and right arrows.
63
+ */
64
+ export declare function moveDate(date: string, key: string, options?: {
65
+ firstDay?: Weekday;
66
+ shift?: boolean;
67
+ rtl?: boolean;
68
+ }): string | null;
69
+ /** True when `element` is laid out right to left (`:dir(rtl)`, else the closest `dir` attribute). */
70
+ export declare function isRtl(element: Element): boolean;
71
+ /** A `Date` at 00:00 UTC of `date`, for `Intl.DateTimeFormat` with `timeZone: 'UTC'`. */
72
+ export declare function toUtcDate(date: string): Date;
73
+ /** `date` moved inside `[min, max]`; a missing or invalid bound is open. */
74
+ export declare function clampDate(date: string, min?: string | null, max?: string | null): string;
75
+ /** Canonical form of `locale`, else of `<html lang>` or the browser's; `en` when malformed. */
76
+ export declare function resolveLocale(locale?: string | null): string;
77
+ /**
78
+ * Month grid in `container`, in the ARIA grid pattern: one day in the tab order, arrows, Home/End and
79
+ * PageUp/PageDown move between days, Enter or Space selects. Dates go in and out as `YYYY-MM-DD` strings.
80
+ * Clicking or pressing Enter on a day selects it and calls `onSelect`; days outside `min`/`max` are
81
+ * `aria-disabled` and do not select.
82
+ */
83
+ export declare function createCalendarGrid(container: HTMLElement, options?: CalendarGridOptions): CalendarGridHandle;