@directo-ui/astro 1.3.0 → 1.4.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.
Files changed (39) hide show
  1. package/components.css +97 -4
  2. package/index.d.ts +45 -39
  3. package/index.js +45 -39
  4. package/package.json +1 -1
  5. package/src/close-icon.d.ts +2 -0
  6. package/src/close-icon.js +9 -0
  7. package/src/components/Alert.astro +2 -1
  8. package/src/components/Autocomplete.astro +2 -1
  9. package/src/components/Badge.astro +28 -13
  10. package/src/components/BottomSheet.astro +2 -1
  11. package/src/components/CellText.astro +17 -0
  12. package/src/components/Chip.astro +21 -0
  13. package/src/components/ChipGroup.astro +30 -0
  14. package/src/components/CloseButton.astro +18 -0
  15. package/src/components/DataTable.astro +40 -8
  16. package/src/components/DatePicker.astro +2 -1
  17. package/src/components/DateRangePicker.astro +5 -3
  18. package/src/components/Drawer.astro +2 -1
  19. package/src/components/Dropdown.astro +3 -2
  20. package/src/components/FieldLabel.astro +14 -0
  21. package/src/components/FileUpload.astro +2 -1
  22. package/src/components/FilterBar.astro +6 -4
  23. package/src/components/Modal.astro +4 -2
  24. package/src/components/MultiSelect.astro +2 -1
  25. package/src/components/Select.astro +2 -1
  26. package/src/components/StatusTag.astro +4 -2
  27. package/src/components/Tabs.astro +60 -60
  28. package/src/components/TextField.astro +2 -1
  29. package/src/components/Textarea.astro +2 -1
  30. package/src/components/WariDateField.astro +2 -1
  31. package/src/components/WariDriverInbox.astro +74 -0
  32. package/src/components/WariSelect.astro +2 -1
  33. package/src/components/WariTimeField.astro +2 -1
  34. package/src/toast.d.ts +2 -0
  35. package/src/toast.js +18 -7
  36. package/src/wari/inbox.d.ts +13 -0
  37. package/src/wari/inbox.js +28 -0
  38. package/wari.d.ts +3 -0
  39. package/wari.js +2 -0
@@ -1,10 +1,24 @@
1
1
  ---
2
- type Row = Record<string, string | number | undefined>;
2
+ import CellText from './CellText.astro';
3
+ import StatusTag from './StatusTag.astro';
4
+
5
+ type Row = Record<string, string | number | boolean | undefined>;
6
+ interface Column {
7
+ key: string; label: string; sortable?: boolean; align?: 'start' | 'center' | 'end';
8
+ /** Row key of a second, smaller line (district, user, time…): the cell becomes a CellText. */
9
+ secondaryKey?: string;
10
+ /** Paints the second line purple for these rows (night times). */
11
+ accent?: (row: Row) => boolean;
12
+ /** Strikes the main line for these rows (cancelled services). */
13
+ strike?: (row: Row) => boolean;
14
+ /** Row key of a status code: the cell becomes a StatusTag with a dot and the cell value as text. */
15
+ statusKey?: string;
16
+ }
3
17
  type Direction = 'ascending' | 'descending';
4
18
 
5
19
  interface Props {
6
20
  caption: string;
7
- columns: readonly { key: string; label: string; sortable?: boolean; align?: 'start' | 'center' | 'end' }[];
21
+ columns: readonly Column[];
8
22
  rows: readonly Row[];
9
23
  loading?: boolean;
10
24
  loadingMessage?: string;
@@ -21,6 +35,14 @@ interface Props {
21
35
  clickableRows?: boolean;
22
36
  density?: 'comfortable' | 'compact';
23
37
  stickyHeader?: boolean;
38
+ /** soft: light blue header and 60px rows without lines (Wari tables). */
39
+ variant?: 'default' | 'soft';
40
+ /** Rows shown at half opacity, for example cancelled services. */
41
+ rowMuted?: (row: Row) => boolean;
42
+ /** Totals bar under the table. */
43
+ summary?: readonly { label: string; value: string | number }[];
44
+ /** Maximum height of the scroll area (number = px). */
45
+ maxHeight?: number | string;
24
46
  id?: string;
25
47
  class?: string;
26
48
  }
@@ -28,8 +50,9 @@ interface Props {
28
50
  const {
29
51
  caption, columns, rows, loading = false, loadingMessage = 'Cargando registros…', emptyMessage = 'No hay resultados.',
30
52
  actionLabel = 'Ver detalle', actionHref, rowKey = 'id', defaultSort, manualSort = false, clickableRows = false,
31
- density = 'comfortable', stickyHeader = false, id, class: className,
53
+ density = 'comfortable', stickyHeader = false, variant = 'default', rowMuted, summary = [], maxHeight, id, class: className,
32
54
  } = Astro.props;
55
+ const maxHeightValue = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight;
33
56
  const collator = new Intl.Collator('es', { numeric: true, sensitivity: 'base' });
34
57
  const sortColumn = defaultSort && columns.find(column => column.key === defaultSort.key && column.sortable);
35
58
  const shownRows = sortColumn && !manualSort ? [...rows].sort((left, right) => {
@@ -42,7 +65,9 @@ const directionOf = (key: string) => sortColumn?.key === key ? defaultSort!.dire
42
65
  const arrow = (key: string) => directionOf(key) === 'ascending' ? '↑' : directionOf(key) === 'descending' ? '↓' : '↕';
43
66
  ---
44
67
  <directo-sortable-table id={id} class:list={['ds-data-table', className]} data-density={density}
45
- data-sticky-header={stickyHeader ? '' : undefined} data-manual-sort={manualSort ? '' : undefined}>
68
+ data-variant={variant === 'default' ? undefined : variant} data-max-height={maxHeight === undefined ? undefined : ''}
69
+ style={maxHeightValue ? `--ds-table-max-height:${maxHeightValue}` : undefined}
70
+ data-sticky-header={stickyHeader || maxHeight !== undefined ? '' : undefined} data-manual-sort={manualSort ? '' : undefined}>
46
71
  <div class="ds-data-scroll" role="region" aria-label={caption} tabindex="0">
47
72
  <table aria-busy={loading}>
48
73
  <caption>{caption}</caption>
@@ -55,14 +80,21 @@ const arrow = (key: string) => directionOf(key) === 'ascending' ? '↑' : direct
55
80
  <tbody>
56
81
  {loading || !rows.length
57
82
  ? <tr><td colspan={Math.max(1, columns.length + Number(!!actionHref))}><span role="status">{loading ? loadingMessage : emptyMessage}</span></td></tr>
58
- : shownRows.map((row, index) => <tr data-row data-index={index} data-key={row[rowKey] === undefined ? undefined : String(row[rowKey])}
83
+ : shownRows.map((row, index) => <tr data-row data-muted={rowMuted?.(row) ? '' : undefined} data-index={index} data-key={row[rowKey] === undefined ? undefined : String(row[rowKey])}
59
84
  tabindex={clickableRows ? 0 : undefined} data-clickable={clickableRows ? '' : undefined}>
60
- {columns.map(column => <td data-align={column.align} data-number={typeof row[column.key] === 'number' ? '' : undefined}>{row[column.key]}</td>)}
85
+ {columns.map(column => <td data-align={column.align} data-number={typeof row[column.key] === 'number' ? '' : undefined}>
86
+ {column.statusKey ? <StatusTag status={String(row[column.statusKey] ?? '')} dot>{row[column.key]}</StatusTag>
87
+ : column.secondaryKey || column.accent || column.strike
88
+ ? <CellText secondary={row[column.secondaryKey ?? ''] === undefined ? undefined : String(row[column.secondaryKey ?? ''])}
89
+ tone={column.accent?.(row) ? 'accent' : 'default'} strike={column.strike?.(row)}>{row[column.key]}</CellText>
90
+ : row[column.key]}
91
+ </td>)}
61
92
  {actionHref && <td><a href={actionHref(row)}>{actionLabel}</a></td>}
62
93
  </tr>)}
63
94
  </tbody>
64
95
  </table>
65
96
  </div>
97
+ {summary.length > 0 && <div class="ds-data-table-summary">{summary.map(item => <span>{item.label} {item.value}</span>)}</div>}
66
98
  <slot name="pagination" />
67
99
  </directo-sortable-table>
68
100
 
@@ -124,8 +156,8 @@ const arrow = (key: string) => directionOf(key) === 'ascending' ? '↑' : direct
124
156
  rows.sort((left, right) => {
125
157
  const a = left.cells[column];
126
158
  const b = right.cells[column];
127
- const x = a.textContent ?? '';
128
- const y = b.textContent ?? '';
159
+ const x = (a.querySelector('.ds-cell-text-primary') ?? a).textContent?.trim() ?? '';
160
+ const y = (b.querySelector('.ds-cell-text-primary') ?? b).textContent?.trim() ?? '';
129
161
  const order = a.hasAttribute('data-number') && b.hasAttribute('data-number') ? Number(x) - Number(y) : collator.compare(x, y);
130
162
  return direction === 'ascending' ? order : -order;
131
163
  });
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import type { HTMLAttributes } from 'astro/types';
3
4
 
4
5
  interface Props extends Omit<HTMLAttributes<'input'>, 'type'> {
@@ -16,7 +17,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
16
17
  const hintId = supportingText ? `${fieldId}-hint` : undefined;
17
18
  ---
18
19
  <div class="ds-input" data-error={String(error)} data-disabled={String(Boolean(disabled))}>
19
- {label && <label for={fieldId}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
20
+ {label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
20
21
  <div class="ds-input-shell">
21
22
  <input {...rest} id={fieldId} type="date" disabled={disabled} required={required}
22
23
  aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} />
@@ -1,4 +1,6 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
3
+ import Chip from './Chip.astro';
2
4
  import TextField from './TextField.astro';
3
5
 
4
6
  interface Props {
@@ -32,10 +34,10 @@ const message = error ?? (start && end && end < start ? orderMessage : '');
32
34
  <directo-date-range data-message={orderMessage}>
33
35
  <fieldset id={id} class:list={['ds-date-range', className]} data-min={min} data-max={max} disabled={disabled}
34
36
  data-error={error} aria-describedby={`${id}-error`}>
35
- <legend>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</legend>
37
+ <FieldLabel as="legend" required={required}>{label}</FieldLabel>
36
38
  {presets.length > 0 && <div class="ds-date-range-presets">
37
- {presets.map(preset => <button type="button" class="ds-filter-chip" data-start={preset.range.start} data-end={preset.range.end}
38
- aria-pressed={String(preset.range.start === start && preset.range.end === end)}>{preset.label}</button>)}
39
+ {presets.map(preset => <Chip data-start={preset.range.start} data-end={preset.range.end}
40
+ pressed={preset.range.start === start && preset.range.end === end}>{preset.label}</Chip>)}
39
41
  </div>}
40
42
  <div class="ds-date-range-fields">
41
43
  <TextField id={`${id}-start`} label={startLabel} type="date" name={startName} value={start} min={min} max={startMax}
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import CloseButton from './CloseButton.astro';
2
3
  interface Props {
3
4
  id: string;
4
5
  title: string;
@@ -27,7 +28,7 @@ const {
27
28
  <h2 id={`${id}-title`}>{title}</h2>
28
29
  {description && <p class="ds-drawer-description" id={`${id}-description`}>{description}</p>}
29
30
  </div>
30
- <button type="button" class="ds-sheet-close" aria-label={closeLabel} data-ds-close>×</button>
31
+ <CloseButton class="ds-sheet-close" size="lg" label={closeLabel} data-ds-close />
31
32
  </header>
32
33
  <div class="ds-drawer-body"><slot /></div>
33
34
  {Astro.slots.has('footer') && <footer class="ds-drawer-footer"><slot name="footer" /></footer>}
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import Button from './Button.astro';
2
3
  export interface MenuItem { id: string; label: string; href?: string; disabled?: boolean; danger?: boolean; divider?: boolean; shortcut?: string }
3
4
  interface Props {
4
5
  label: string;
@@ -11,9 +12,9 @@ const { label, items, variant = 'secondary', align = 'start' } = Astro.props;
11
12
  const id = `ds-menu-${Math.random().toString(36).slice(2, 9)}`;
12
13
  ---
13
14
  <div class="ds-menu" data-align={align} data-ds-menu>
14
- <button type="button" class="ds-button" data-variant={variant} data-size="md" aria-haspopup="menu" aria-expanded="false" aria-controls={id}>
15
+ <Button variant={variant} aria-haspopup="menu" aria-expanded="false" aria-controls={id}>
15
16
  {label}<span aria-hidden="true" style="font-size:10px">▼</span>
16
- </button>
17
+ </Button>
17
18
  <div class="ds-dropdown" role="menu" id={id} aria-label={label} hidden>
18
19
  {items.map(item => item.divider
19
20
  ? <div class="ds-dropdown-separator" role="separator" />
@@ -0,0 +1,14 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+
4
+ interface Props extends HTMLAttributes<'label'> {
5
+ /** Adds the red asterisk (hidden from screen readers: the field itself is marked required). */
6
+ required?: boolean;
7
+ /** Use legend inside a fieldset. */
8
+ as?: 'label' | 'legend';
9
+ }
10
+
11
+ /* Atom: label of every form field with the required mark. */
12
+ const { required = false, as: Tag = 'label', ...rest } = Astro.props;
13
+ ---
14
+ <Tag {...rest}><slot />{required && <span class="ds-input-required" aria-hidden="true">*</span>}</Tag>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  interface Props {
3
4
  id: string;
4
5
  label: string;
@@ -24,7 +25,7 @@ const describedBy = [supportingText ? `${id}-hint` : '', `${id}-error`].filter(B
24
25
  ---
25
26
  <directo-file-picker class:list={['ds-file-upload', className]} data-max-bytes={maxBytes} data-max-files={maxFiles}
26
27
  data-dropzone={dropzone ? '' : undefined} data-disabled={disabled ? '' : undefined} data-required={required ? '' : undefined}>
27
- <label for={id}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>
28
+ <FieldLabel for={id} required={required}>{label}</FieldLabel>
28
29
  {supportingText && <small id={`${id}-hint`}>{supportingText}</small>}
29
30
  <input id={id} type="file" name={name} accept={accept} multiple={multiple} required={required} disabled={disabled}
30
31
  aria-describedby={describedBy} />
@@ -1,4 +1,6 @@
1
1
  ---
2
+ import Button from './Button.astro';
3
+ import Chip from './Chip.astro';
2
4
  interface ActiveFilter {
3
5
  label: string;
4
6
  /** Link that removes the filter (server-rendered pages). */
@@ -39,10 +41,10 @@ const formProps = action === undefined ? { role: 'group' } : { role: 'search', m
39
41
  {(activeFilters.length > 0 || resultCount !== undefined) && <div class="ds-filter-active">
40
42
  {resultCount !== undefined && <span class="ds-filter-count" role="status">{resultCount} {resultCount === 1 ? resultSingular : resultPlural}</span>}
41
43
  {activeFilters.map(filter => filter.removeHref !== undefined
42
- ? <a class="ds-filter-chip" href={filter.removeHref} aria-label={`Quitar filtro: ${filter.label}`}>{filter.label} <span aria-hidden="true">×</span></a>
43
- : <button class="ds-filter-chip" type="button" data-filter-id={filter.id} aria-label={`Quitar filtro: ${filter.label}`}>{filter.label} <span aria-hidden="true">×</span></button>)}
44
- {activeFilters.length > 0 && clearHref && <a href={clearHref} class="ds-button" data-variant="text" data-size="sm">{clearLabel}</a>}
45
- {activeFilters.length > 0 && !clearHref && clearable && <button type="button" class="ds-button" data-variant="text" data-size="sm" data-filters-clear>{clearLabel}</button>}
44
+ ? <Chip href={filter.removeHref} removable aria-label={`Quitar filtro: ${filter.label}`}>{filter.label}</Chip>
45
+ : <Chip removable data-filter-id={filter.id} aria-label={`Quitar filtro: ${filter.label}`}>{filter.label}</Chip>)}
46
+ {activeFilters.length > 0 && clearHref && <Button href={clearHref} variant="text" size="sm">{clearLabel}</Button>}
47
+ {activeFilters.length > 0 && !clearHref && clearable && <Button variant="text" size="sm" data-filters-clear>{clearLabel}</Button>}
46
48
  </div>}
47
49
  </Tag>
48
50
  </directo-filter-bar>
@@ -1,4 +1,6 @@
1
1
  ---
2
+ import Button from './Button.astro';
3
+ import CloseButton from './CloseButton.astro';
2
4
  interface Props {
3
5
  /** Used by triggers: <Button data-ds-open="my-id">. */
4
6
  id: string;
@@ -22,9 +24,9 @@ const { id, title, description, size = 'md', closeLabel = 'Cerrar', open = false
22
24
  <div class="ds-modal-body"><slot /></div>
23
25
  <div class="ds-modal-footer">
24
26
  <slot name="footer" />
25
- {closeLabel && <button type="button" class="ds-button" data-variant="secondary" data-size="md" data-ds-close>{closeLabel}</button>}
27
+ {closeLabel && <Button variant="secondary" data-ds-close>{closeLabel}</Button>}
26
28
  </div>
27
- <button type="button" class="ds-modal-close" aria-label="Cerrar diálogo" data-ds-close>×</button>
29
+ <CloseButton class="ds-modal-close" label="Cerrar diálogo" data-ds-close />
28
30
  </dialog>
29
31
 
30
32
  <script>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import StatusTag from './StatusTag.astro';
3
4
  import { selectionState, selectionSummary } from '../wari/logic.js';
4
5
 
@@ -55,7 +56,7 @@ const allSelected = state === 'all' && Boolean(allLabel);
55
56
  data-error={String(error)} data-disabled={String(disabled)} data-size={size}
56
57
  data-max-tags={maxTags} data-summary={String(summary)} data-supporting-text={supportingText}
57
58
  data-name={name} data-placeholder={placeholder} data-search-placeholder={searchPlaceholder}>
58
- {label && <label id={`${id}-label`} for={id}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
59
+ {label && <FieldLabel id={`${id}-label`} for={id} required={required}>{label}</FieldLabel>}
59
60
  <div class="ds-multiselect-anchor">
60
61
  <div class="ds-input-shell">
61
62
  <div class="ds-multiselect-values" aria-hidden="true" hidden={selected.length === 0}>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import type { HTMLAttributes } from 'astro/types';
3
4
 
4
5
  export interface Option { value: string; label: string; disabled?: boolean }
@@ -17,7 +18,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
17
18
  const hintId = supportingText ? `${fieldId}-hint` : undefined;
18
19
  ---
19
20
  <div class="ds-input" data-error={String(error)} data-disabled={String(Boolean(disabled))} data-size={size}>
20
- {label && <label for={fieldId}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
21
+ {label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
21
22
  <div class="ds-input-shell ds-select-native">
22
23
  <select {...rest} id={fieldId} disabled={disabled} required={required} aria-invalid={error ? 'true' : undefined} aria-describedby={hintId}>
23
24
  {placeholder && <option value="" disabled selected={!value}>{placeholder}</option>}
@@ -5,14 +5,16 @@ interface Props {
5
5
  /** Estado de Wari ("libre", "aceptado"…) o "todos". Sin contenido, muestra su nombre. */
6
6
  status?: string;
7
7
  size?: 'sm' | 'md';
8
+ /** Small dot of the same color before the text (Figma tables). */
9
+ dot?: boolean;
8
10
  /** Colores propios para un estado que no está en la lista. */
9
11
  color?: { background: string; foreground: string };
10
12
  class?: string;
11
13
  [attribute: `data-${string}`]: unknown;
12
14
  }
13
15
 
14
- const { status, size = 'md', color, class: className, ...rest } = Astro.props;
16
+ const { status, size = 'md', dot = false, color, class: className, ...rest } = Astro.props;
15
17
  const style = color ? `--ds-status-bg:${color.background};--ds-status-fg:${color.foreground}` : undefined;
16
18
  const fallback = status && status !== 'todos' ? wariStatusLabel(status) : 'Todos';
17
19
  ---
18
- <span class:list={['ds-status', className]} data-status={status} data-size={size} style={style} {...rest}><span><slot>{fallback}</slot></span></span>
20
+ <span class:list={['ds-status', className]} data-status={status} data-size={size} data-dot={dot ? '' : undefined} style={style} {...rest}><span><slot>{fallback}</slot></span></span>
@@ -1,60 +1,60 @@
1
- ---
2
- export interface TabItem { value: string; label: string; disabled?: boolean }
3
- interface Props {
4
- /** Each item renders the slot with the same name as its value. */
5
- items: TabItem[];
6
- value?: string;
7
- label?: string;
8
- variant?: 'default' | 'pills' | 'enclosed';
9
- }
10
-
11
- const { items, value, label, variant = 'default' } = Astro.props;
12
- const active = value ?? items.find(item => !item.disabled)?.value;
13
- const base = `ds-tabs-${Math.random().toString(36).slice(2, 9)}`;
14
- const panels = await Promise.all(items.map(item => Astro.slots.render(item.value)));
15
- ---
16
- <div class="ds-tabs" data-ds-tabs>
17
- <div class="ds-tabs-list" role="tablist" aria-label={label} data-variant={variant}>
18
- {items.map(item => (
19
- <button type="button" class="ds-tab" role="tab" id={`${base}-${item.value}-tab`} aria-controls={`${base}-${item.value}-panel`}
20
- aria-selected={String(item.value === active)} tabindex={item.value === active ? 0 : -1} disabled={item.disabled}
21
- data-value={item.value}>{item.label}</button>
22
- ))}
23
- </div>
24
- {items.map((item, index) => (
25
- <div class="ds-tab-panel" role="tabpanel" tabindex="0" id={`${base}-${item.value}-panel`}
26
- aria-labelledby={`${base}-${item.value}-tab`} hidden={item.value !== active} set:html={panels[index]} />
27
- ))}
28
- </div>
29
-
30
- <script>
31
- function initTabs() {
32
- document.querySelectorAll<HTMLElement>('[data-ds-tabs]:not([data-ds-ready])').forEach(root => {
33
- root.dataset.dsReady = '';
34
- const tabs = [...root.querySelectorAll<HTMLButtonElement>(':scope > .ds-tabs-list > [role="tab"]')];
35
- const select = (tab: HTMLButtonElement, focus = false) => {
36
- for (const item of tabs) {
37
- const selected = item === tab;
38
- item.setAttribute('aria-selected', String(selected));
39
- item.tabIndex = selected ? 0 : -1;
40
- const panel = document.getElementById(item.getAttribute('aria-controls') ?? '');
41
- if (panel) panel.hidden = !selected;
42
- }
43
- if (focus) tab.focus();
44
- root.dispatchEvent(new CustomEvent('ds-change', { detail: tab.dataset.value, bubbles: true }));
45
- };
46
- tabs.forEach(tab => tab.addEventListener('click', () => select(tab)));
47
- root.querySelector(':scope > .ds-tabs-list')?.addEventListener('keydown', event => {
48
- const key = (event as KeyboardEvent).key;
49
- const enabled = tabs.filter(tab => !tab.disabled);
50
- const index = enabled.indexOf(document.activeElement as HTMLButtonElement);
51
- const next = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: enabled.length - 1 }[key];
52
- if (next === undefined || !enabled.length) return;
53
- event.preventDefault();
54
- select(enabled[(next + enabled.length) % enabled.length], true);
55
- });
56
- });
57
- }
58
- initTabs();
59
- document.addEventListener('astro:page-load', initTabs);
60
- </script>
1
+ ---
2
+ export interface TabItem { value: string; label: string; disabled?: boolean }
3
+ interface Props {
4
+ /** Each item renders the slot with the same name as its value. */
5
+ items: TabItem[];
6
+ value?: string;
7
+ label?: string;
8
+ variant?: 'default' | 'pills' | 'enclosed' | 'segmented';
9
+ }
10
+
11
+ const { items, value, label, variant = 'default' } = Astro.props;
12
+ const active = value ?? items.find(item => !item.disabled)?.value;
13
+ const base = `ds-tabs-${Math.random().toString(36).slice(2, 9)}`;
14
+ const panels = await Promise.all(items.map(item => Astro.slots.render(item.value)));
15
+ ---
16
+ <div class="ds-tabs" data-ds-tabs>
17
+ <div class="ds-tabs-list" role="tablist" aria-label={label} data-variant={variant}>
18
+ {items.map(item => (
19
+ <button type="button" class="ds-tab" role="tab" id={`${base}-${item.value}-tab`} aria-controls={`${base}-${item.value}-panel`}
20
+ aria-selected={String(item.value === active)} tabindex={item.value === active ? 0 : -1} disabled={item.disabled}
21
+ data-value={item.value}>{item.label}</button>
22
+ ))}
23
+ </div>
24
+ {items.map((item, index) => (
25
+ <div class="ds-tab-panel" role="tabpanel" tabindex="0" id={`${base}-${item.value}-panel`}
26
+ aria-labelledby={`${base}-${item.value}-tab`} hidden={item.value !== active} set:html={panels[index]} />
27
+ ))}
28
+ </div>
29
+
30
+ <script>
31
+ function initTabs() {
32
+ document.querySelectorAll<HTMLElement>('[data-ds-tabs]:not([data-ds-ready])').forEach(root => {
33
+ root.dataset.dsReady = '';
34
+ const tabs = [...root.querySelectorAll<HTMLButtonElement>(':scope > .ds-tabs-list > [role="tab"]')];
35
+ const select = (tab: HTMLButtonElement, focus = false) => {
36
+ for (const item of tabs) {
37
+ const selected = item === tab;
38
+ item.setAttribute('aria-selected', String(selected));
39
+ item.tabIndex = selected ? 0 : -1;
40
+ const panel = document.getElementById(item.getAttribute('aria-controls') ?? '');
41
+ if (panel) panel.hidden = !selected;
42
+ }
43
+ if (focus) tab.focus();
44
+ root.dispatchEvent(new CustomEvent('ds-change', { detail: tab.dataset.value, bubbles: true }));
45
+ };
46
+ tabs.forEach(tab => tab.addEventListener('click', () => select(tab)));
47
+ root.querySelector(':scope > .ds-tabs-list')?.addEventListener('keydown', event => {
48
+ const key = (event as KeyboardEvent).key;
49
+ const enabled = tabs.filter(tab => !tab.disabled);
50
+ const index = enabled.indexOf(document.activeElement as HTMLButtonElement);
51
+ const next = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: enabled.length - 1 }[key];
52
+ if (next === undefined || !enabled.length) return;
53
+ event.preventDefault();
54
+ select(enabled[(next + enabled.length) % enabled.length], true);
55
+ });
56
+ });
57
+ }
58
+ initTabs();
59
+ document.addEventListener('astro:page-load', initTabs);
60
+ </script>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import type { HTMLAttributes } from 'astro/types';
3
4
 
4
5
  interface Props extends Omit<HTMLAttributes<'input'>, 'size'> {
@@ -13,7 +14,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
13
14
  const hintId = supportingText ? `${fieldId}-hint` : undefined;
14
15
  ---
15
16
  <div class="ds-input" data-error={String(error)} data-disabled={String(Boolean(disabled))} data-size={size}>
16
- {label && <label for={fieldId}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
17
+ {label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
17
18
  <div class="ds-input-shell">
18
19
  {Astro.slots.has('start') && <span class="ds-input-icon" aria-hidden="true"><slot name="start" /></span>}
19
20
  <input {...rest} id={fieldId} type={type} disabled={disabled} required={required}
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import type { HTMLAttributes } from 'astro/types';
3
4
 
4
5
  interface Props extends HTMLAttributes<'textarea'> {
@@ -15,7 +16,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
15
16
  const hintId = supportingText ? `${fieldId}-hint` : undefined;
16
17
  ---
17
18
  <div class="ds-input" data-multiline="true" data-error={String(error)} data-disabled={String(Boolean(disabled))}>
18
- {label && <label for={fieldId}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
19
+ {label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
19
20
  <div class="ds-input-shell">
20
21
  <textarea {...rest} id={fieldId} rows={rows} maxlength={maxlength} disabled={disabled} required={required}
21
22
  aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} data-ds-count={showCount && maxlength ? '' : undefined}>{value}</textarea>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import { formatDisplayDate, longDateLabel } from '../wari/datetime.js';
3
4
 
4
5
  export interface Props {
@@ -34,7 +35,7 @@ const id = Astro.props.id ?? `ds-wdate-${Math.random().toString(36).slice(2, 9)}
34
35
  <div class:list={['ds-input', 'ds-wfield', className]} data-ds-wfield="date" data-open="false" data-align={align}
35
36
  data-error={String(error)} data-disabled={String(disabled)} data-min={min} data-max={max} data-locale={locale}
36
37
  data-week-start={weekStartsOn} data-cancel-label={cancelLabel} data-ok-label={okLabel}>
37
- {label && <label for={id}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
38
+ {label && <FieldLabel for={id} required={required}>{label}</FieldLabel>}
38
39
  <div class="ds-wfield-anchor">
39
40
  <div class="ds-input-shell">
40
41
  <input id={id} type="text" inputmode="numeric" autocomplete="off" placeholder={placeholder} value={formatDisplayDate(value)}
@@ -0,0 +1,74 @@
1
+ ---
2
+ import Button from './Button.astro';
3
+ import ChipGroup from './ChipGroup.astro';
4
+ import Tabs from './Tabs.astro';
5
+ import { expandIconPath, funnelIconPath, wariInboxFilters, wariInboxTabs } from '../wari/inbox.js';
6
+ import type { WariInboxOption } from '../wari/inbox.js';
7
+
8
+ interface Props {
9
+ label?: string;
10
+ tabs?: readonly WariInboxOption[];
11
+ /** Tab shown first. */
12
+ tab?: string;
13
+ /** Filter chips of each tab, by tab value. */
14
+ filters?: Readonly<Record<string, readonly WariInboxOption[]>>;
15
+ /** Shows "Filtros avanzados" (emits ds-advanced-filters). */
16
+ advancedFilters?: boolean;
17
+ /** Shows "Ver lista completa" (emits ds-view-all). */
18
+ viewAll?: boolean;
19
+ advancedFiltersLabel?: string;
20
+ viewAllLabel?: string;
21
+ class?: string;
22
+ }
23
+
24
+ /*
25
+ * Wari "Bandeja interna del conductor": Tabs (segmented) + ChipGroup + Button around the content of each tab.
26
+ * Put each tab's table in a slot named like the tab: slot="historial", slot="mensajes"…
27
+ */
28
+ const {
29
+ label = 'Bandeja interna del conductor', tabs = wariInboxTabs, tab, filters = wariInboxFilters, advancedFilters = true, viewAll = true,
30
+ advancedFiltersLabel = 'Filtros avanzados', viewAllLabel = 'Ver lista completa', class: className,
31
+ } = Astro.props;
32
+ const panels = await Promise.all(tabs.map(item => Astro.slots.render(item.value)));
33
+ ---
34
+ <section class:list={['ds-winbox', className]} aria-label={label} data-ds-winbox>
35
+ <Tabs items={[...tabs]} value={tab} variant="segmented" label={label}>
36
+ {tabs.map((item, index) => <Fragment slot={item.value}>
37
+ <div class="ds-winbox-toolbar">
38
+ {(filters[item.value]?.length ?? 0) > 0 && <ChipGroup label={`Filtrar ${item.label.toLowerCase()}`} variant="brand"
39
+ options={filters[item.value]} data-tab={item.value} />}
40
+ {(advancedFilters || viewAll) && <div class="ds-winbox-actions">
41
+ <slot name="actions" />
42
+ {advancedFilters && <Button variant="secondary" data-winbox-action="advanced-filters" data-tab={item.value}>
43
+ <span class="ds-button-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d={funnelIconPath} /></svg></span>{advancedFiltersLabel}
44
+ </Button>}
45
+ {viewAll && <Button data-winbox-action="view-all" data-tab={item.value}>
46
+ <span class="ds-button-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor"
47
+ stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d={expandIconPath} /></svg></span>{viewAllLabel}
48
+ </Button>}
49
+ </div>}
50
+ </div>
51
+ <Fragment set:html={panels[index]} />
52
+ </Fragment>)}
53
+ </Tabs>
54
+ </section>
55
+
56
+ <script>
57
+ // Events on the section: ds-tab-change (tab), ds-filter-change ({ filter, tab }), ds-advanced-filters and ds-view-all (tab).
58
+ document.addEventListener('ds-change', event => {
59
+ const target = event.target instanceof HTMLElement ? event.target : null;
60
+ const inbox = target?.closest('[data-ds-winbox]');
61
+ if (!target || !inbox) return;
62
+ const detail = (event as CustomEvent<string>).detail;
63
+ if (target.matches('[data-ds-tabs]') && target.parentElement === inbox) {
64
+ inbox.dispatchEvent(new CustomEvent('ds-tab-change', { bubbles: true, detail }));
65
+ } else if (target.matches('[data-ds-chip-group][data-tab]')) {
66
+ inbox.dispatchEvent(new CustomEvent('ds-filter-change', { bubbles: true, detail: { filter: detail, tab: target.dataset.tab } }));
67
+ }
68
+ });
69
+ document.addEventListener('click', event => {
70
+ const button = event.target instanceof Element ? event.target.closest<HTMLElement>('[data-ds-winbox] [data-winbox-action]') : null;
71
+ if (!button) return;
72
+ button.closest('[data-ds-winbox]')?.dispatchEvent(new CustomEvent(`ds-${button.dataset.winboxAction}`, { bubbles: true, detail: button.dataset.tab }));
73
+ });
74
+ </script>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import WariServiceMeta from './WariServiceMeta.astro';
3
4
  import { serviceMeta } from '../wari/trip.js';
4
5
  import type { WariService } from '../wari/trip';
@@ -41,7 +42,7 @@ const selectedMeta = metaLabel(selected);
41
42
  ---
42
43
  <div class:list={['ds-input', 'ds-wfield', 'ds-wselect', className]} data-ds-wselect data-open="false" data-error={String(error)}
43
44
  data-disabled={String(disabled)} data-label="lg" data-placeholder={placeholder}>
44
- {label && <label id={`${id}-label`}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
45
+ {label && <FieldLabel id={`${id}-label`} required={required}>{label}</FieldLabel>}
45
46
  <div class="ds-wfield-anchor">
46
47
  <div class="ds-input-shell" role="combobox" tabindex={disabled ? -1 : 0} aria-haspopup="listbox" aria-expanded="false"
47
48
  aria-controls={`${id}-listbox`} aria-labelledby={label ? `${id}-label ${id}-value` : undefined} aria-label={label ? undefined : ariaLabel}
@@ -1,4 +1,5 @@
1
1
  ---
2
+ import FieldLabel from './FieldLabel.astro';
2
3
  import { formatDisplayTime } from '../wari/datetime.js';
3
4
 
4
5
  export interface Props {
@@ -28,7 +29,7 @@ const id = Astro.props.id ?? `ds-wtime-${Math.random().toString(36).slice(2, 9)}
28
29
  ---
29
30
  <div class:list={['ds-input', 'ds-wfield', className]} data-ds-wfield="time" data-open="false" data-align={align}
30
31
  data-error={String(error)} data-disabled={String(disabled)} data-title={title} data-cancel-label={cancelLabel} data-ok-label={okLabel}>
31
- {label && <label for={id}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
32
+ {label && <FieldLabel for={id} required={required}>{label}</FieldLabel>}
32
33
  <div class="ds-wfield-anchor">
33
34
  <div class="ds-input-shell">
34
35
  <input id={id} type="text" autocomplete="off" placeholder={placeholder} value={formatDisplayTime(value)}
package/src/toast.d.ts CHANGED
@@ -4,6 +4,8 @@ export interface ToastOptions {
4
4
  variant?: 'info' | 'success' | 'warning' | 'error';
5
5
  /** Milliseconds before auto-dismiss; 0 keeps it until closed. Default 5000. */
6
6
  duration?: number;
7
+ /** Text button inside the notification; it closes after onClick runs. */
8
+ action?: { label: string; onClick: () => void };
7
9
  }
8
10
  export declare function toast(options: ToastOptions): HTMLLIElement;
9
11
  export declare function dismissToast(item: HTMLElement): void;