@directo-ui/astro 1.0.0 → 1.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.
Files changed (67) hide show
  1. package/README.md +14 -0
  2. package/components.css +326 -0
  3. package/index.d.ts +31 -31
  4. package/index.js +31 -31
  5. package/package.json +19 -1
  6. package/src/components/Accordion.astro +8 -8
  7. package/src/components/AccordionItem.astro +14 -14
  8. package/src/components/Alert.astro +42 -42
  9. package/src/components/Avatar.astro +21 -21
  10. package/src/components/Badge.astro +13 -13
  11. package/src/components/BottomSheet.astro +23 -23
  12. package/src/components/Breadcrumb.astro +18 -18
  13. package/src/components/Button.astro +31 -31
  14. package/src/components/Card.astro +25 -25
  15. package/src/components/Checkbox.astro +14 -14
  16. package/src/components/DatePicker.astro +25 -25
  17. package/src/components/Divider.astro +11 -11
  18. package/src/components/Dropdown.astro +71 -71
  19. package/src/components/EmptyState.astro +15 -15
  20. package/src/components/IconButton.astro +18 -18
  21. package/src/components/Modal.astro +34 -34
  22. package/src/components/MultiSelect.astro +108 -0
  23. package/src/components/Pagination.astro +30 -30
  24. package/src/components/Progress.astro +20 -20
  25. package/src/components/RadioGroup.astro +24 -24
  26. package/src/components/Select.astro +29 -29
  27. package/src/components/Skeleton.astro +13 -13
  28. package/src/components/Spinner.astro +17 -17
  29. package/src/components/StatusTag.astro +18 -0
  30. package/src/components/Switch.astro +13 -13
  31. package/src/components/Tabs.astro +60 -60
  32. package/src/components/TextField.astro +24 -24
  33. package/src/components/Textarea.astro +41 -41
  34. package/src/components/Toaster.astro +8 -8
  35. package/src/components/Tooltip.astro +31 -31
  36. package/src/components/WariDateField.astro +56 -0
  37. package/src/components/WariSchedule.astro +48 -0
  38. package/src/components/WariSelect.astro +76 -0
  39. package/src/components/WariServiceMeta.astro +19 -0
  40. package/src/components/WariStatusSelect.astro +20 -0
  41. package/src/components/WariStepper.astro +40 -0
  42. package/src/components/WariSwitchList.astro +33 -0
  43. package/src/components/WariTimeField.astro +50 -0
  44. package/src/components/WariTripAttributes.astro +60 -0
  45. package/src/modal.d.ts +3 -3
  46. package/src/modal.js +39 -39
  47. package/src/pagination.d.ts +2 -2
  48. package/src/pagination.js +16 -16
  49. package/src/toast.d.ts +9 -9
  50. package/src/toast.js +66 -66
  51. package/src/wari/datetime.d.ts +57 -0
  52. package/src/wari/datetime.js +151 -0
  53. package/src/wari/logic.d.ts +8 -0
  54. package/src/wari/logic.js +41 -0
  55. package/src/wari/multiselect.d.ts +2 -0
  56. package/src/wari/multiselect.js +169 -0
  57. package/src/wari/pickers.d.ts +2 -0
  58. package/src/wari/pickers.js +369 -0
  59. package/src/wari/statuses.d.ts +14 -0
  60. package/src/wari/statuses.js +15 -0
  61. package/src/wari/trip-client.d.ts +4 -0
  62. package/src/wari/trip-client.js +222 -0
  63. package/src/wari/trip.d.ts +56 -0
  64. package/src/wari/trip.js +69 -0
  65. package/styles.css +3 -3
  66. package/wari.d.ts +20 -0
  67. package/wari.js +16 -0
@@ -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';
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,24 +1,24 @@
1
- ---
2
- import type { HTMLAttributes } from 'astro/types';
3
-
4
- interface Props extends Omit<HTMLAttributes<'input'>, 'size'> {
5
- label?: string;
6
- supportingText?: string;
7
- error?: boolean;
8
- size?: 'sm' | 'md' | 'lg';
9
- }
10
-
11
- const { label, supportingText, error = false, size = 'md', id, disabled = false, required = false, type = 'text', ...rest } = Astro.props;
12
- const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
13
- const hintId = supportingText ? `${fieldId}-hint` : undefined;
14
- ---
15
- <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
- <div class="ds-input-shell">
18
- {Astro.slots.has('start') && <span class="ds-input-icon" aria-hidden="true"><slot name="start" /></span>}
19
- <input {...rest} id={fieldId} type={type} disabled={disabled} required={required}
20
- aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} />
21
- {Astro.slots.has('end') && <span class="ds-input-icon" aria-hidden="true"><slot name="end" /></span>}
22
- </div>
23
- {supportingText && <small id={hintId}>{supportingText}</small>}
24
- </div>
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+
4
+ interface Props extends Omit<HTMLAttributes<'input'>, 'size'> {
5
+ label?: string;
6
+ supportingText?: string;
7
+ error?: boolean;
8
+ size?: 'sm' | 'md' | 'lg';
9
+ }
10
+
11
+ const { label, supportingText, error = false, size = 'md', id, disabled = false, required = false, type = 'text', ...rest } = Astro.props;
12
+ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
13
+ const hintId = supportingText ? `${fieldId}-hint` : undefined;
14
+ ---
15
+ <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
+ <div class="ds-input-shell">
18
+ {Astro.slots.has('start') && <span class="ds-input-icon" aria-hidden="true"><slot name="start" /></span>}
19
+ <input {...rest} id={fieldId} type={type} disabled={disabled} required={required}
20
+ aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} />
21
+ {Astro.slots.has('end') && <span class="ds-input-icon" aria-hidden="true"><slot name="end" /></span>}
22
+ </div>
23
+ {supportingText && <small id={hintId}>{supportingText}</small>}
24
+ </div>
@@ -1,41 +1,41 @@
1
- ---
2
- import type { HTMLAttributes } from 'astro/types';
3
-
4
- interface Props extends HTMLAttributes<'textarea'> {
5
- label?: string;
6
- supportingText?: string;
7
- error?: boolean;
8
- /** Live character counter (requires maxlength). */
9
- showCount?: boolean;
10
- value?: string;
11
- }
12
-
13
- const { label, supportingText, error = false, showCount = false, id, disabled = false, required = false, rows = 4, maxlength, value = '', ...rest } = Astro.props;
14
- const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
15
- const hintId = supportingText ? `${fieldId}-hint` : undefined;
16
- ---
17
- <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
- <div class="ds-input-shell">
20
- <textarea {...rest} id={fieldId} rows={rows} maxlength={maxlength} disabled={disabled} required={required}
21
- aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} data-ds-count={showCount && maxlength ? '' : undefined}>{value}</textarea>
22
- </div>
23
- {(supportingText || (showCount && maxlength)) && (
24
- <span style="display:flex;justify-content:space-between;gap:12px">
25
- {supportingText ? <small id={hintId}>{supportingText}</small> : <span />}
26
- {showCount && maxlength && <span class="ds-input-counter" data-ds-counter-for={fieldId}>{value.length}/{maxlength}</span>}
27
- </span>
28
- )}
29
- </div>
30
-
31
- <script>
32
- function initCounters() {
33
- document.querySelectorAll<HTMLTextAreaElement>('textarea[data-ds-count]:not([data-ds-ready])').forEach(area => {
34
- area.dataset.dsReady = '';
35
- const counter = document.querySelector(`[data-ds-counter-for="${area.id}"]`);
36
- area.addEventListener('input', () => { if (counter) counter.textContent = `${area.value.length}/${area.maxLength}`; });
37
- });
38
- }
39
- initCounters();
40
- document.addEventListener('astro:page-load', initCounters);
41
- </script>
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+
4
+ interface Props extends HTMLAttributes<'textarea'> {
5
+ label?: string;
6
+ supportingText?: string;
7
+ error?: boolean;
8
+ /** Live character counter (requires maxlength). */
9
+ showCount?: boolean;
10
+ value?: string;
11
+ }
12
+
13
+ const { label, supportingText, error = false, showCount = false, id, disabled = false, required = false, rows = 4, maxlength, value = '', ...rest } = Astro.props;
14
+ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
15
+ const hintId = supportingText ? `${fieldId}-hint` : undefined;
16
+ ---
17
+ <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
+ <div class="ds-input-shell">
20
+ <textarea {...rest} id={fieldId} rows={rows} maxlength={maxlength} disabled={disabled} required={required}
21
+ aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} data-ds-count={showCount && maxlength ? '' : undefined}>{value}</textarea>
22
+ </div>
23
+ {(supportingText || (showCount && maxlength)) && (
24
+ <span style="display:flex;justify-content:space-between;gap:12px">
25
+ {supportingText ? <small id={hintId}>{supportingText}</small> : <span />}
26
+ {showCount && maxlength && <span class="ds-input-counter" data-ds-counter-for={fieldId}>{value.length}/{maxlength}</span>}
27
+ </span>
28
+ )}
29
+ </div>
30
+
31
+ <script>
32
+ function initCounters() {
33
+ document.querySelectorAll<HTMLTextAreaElement>('textarea[data-ds-count]:not([data-ds-ready])').forEach(area => {
34
+ area.dataset.dsReady = '';
35
+ const counter = document.querySelector(`[data-ds-counter-for="${area.id}"]`);
36
+ area.addEventListener('input', () => { if (counter) counter.textContent = `${area.value.length}/${area.maxLength}`; });
37
+ });
38
+ }
39
+ initCounters();
40
+ document.addEventListener('astro:page-load', initCounters);
41
+ </script>
@@ -1,8 +1,8 @@
1
- ---
2
- interface Props {
3
- position?: 'bottom-right' | 'top-right' | 'top-center' | 'bottom-center';
4
- }
5
-
6
- const { position = 'bottom-right' } = Astro.props;
7
- ---
8
- <ol class="ds-toaster" data-position={position} aria-label="Notificaciones" data-ds-toaster></ol>
1
+ ---
2
+ interface Props {
3
+ position?: 'bottom-right' | 'top-right' | 'top-center' | 'bottom-center';
4
+ }
5
+
6
+ const { position = 'bottom-right' } = Astro.props;
7
+ ---
8
+ <ol class="ds-toaster" data-position={position} aria-label="Notificaciones" data-ds-toaster></ol>
@@ -1,31 +1,31 @@
1
- ---
2
- interface Props {
3
- text: string;
4
- position?: 'top' | 'bottom' | 'left' | 'right';
5
- /** Milliseconds before showing. */
6
- delay?: number;
7
- }
8
-
9
- const { text, position = 'top', delay = 250 } = Astro.props;
10
- const id = `ds-tip-${Math.random().toString(36).slice(2, 9)}`;
11
- ---
12
- <span class="ds-tooltip-wrap" style={`--ds-tooltip-delay:${delay}ms`} data-ds-tooltip={id}>
13
- <slot />
14
- <span class="ds-tooltip" role="tooltip" id={id} data-side={position}>{text}</span>
15
- </span>
16
-
17
- <script>
18
- function initTooltips() {
19
- document.querySelectorAll<HTMLElement>('[data-ds-tooltip]:not([data-ds-ready])').forEach(wrap => {
20
- wrap.dataset.dsReady = '';
21
- const trigger = wrap.querySelector('a, button, input, select, textarea, [tabindex]');
22
- if (trigger && !trigger.hasAttribute('aria-describedby')) trigger.setAttribute('aria-describedby', wrap.dataset.dsTooltip ?? '');
23
- wrap.addEventListener('keydown', event => { if (event.key === 'Escape') wrap.dataset.dismissed = 'true'; });
24
- const reset = () => delete wrap.dataset.dismissed;
25
- wrap.addEventListener('mouseleave', reset);
26
- wrap.addEventListener('focusout', reset);
27
- });
28
- }
29
- initTooltips();
30
- document.addEventListener('astro:page-load', initTooltips);
31
- </script>
1
+ ---
2
+ interface Props {
3
+ text: string;
4
+ position?: 'top' | 'bottom' | 'left' | 'right';
5
+ /** Milliseconds before showing. */
6
+ delay?: number;
7
+ }
8
+
9
+ const { text, position = 'top', delay = 250 } = Astro.props;
10
+ const id = `ds-tip-${Math.random().toString(36).slice(2, 9)}`;
11
+ ---
12
+ <span class="ds-tooltip-wrap" style={`--ds-tooltip-delay:${delay}ms`} data-ds-tooltip={id}>
13
+ <slot />
14
+ <span class="ds-tooltip" role="tooltip" id={id} data-side={position}>{text}</span>
15
+ </span>
16
+
17
+ <script>
18
+ function initTooltips() {
19
+ document.querySelectorAll<HTMLElement>('[data-ds-tooltip]:not([data-ds-ready])').forEach(wrap => {
20
+ wrap.dataset.dsReady = '';
21
+ const trigger = wrap.querySelector('a, button, input, select, textarea, [tabindex]');
22
+ if (trigger && !trigger.hasAttribute('aria-describedby')) trigger.setAttribute('aria-describedby', wrap.dataset.dsTooltip ?? '');
23
+ wrap.addEventListener('keydown', event => { if (event.key === 'Escape') wrap.dataset.dismissed = 'true'; });
24
+ const reset = () => delete wrap.dataset.dismissed;
25
+ wrap.addEventListener('mouseleave', reset);
26
+ wrap.addEventListener('focusout', reset);
27
+ });
28
+ }
29
+ initTooltips();
30
+ document.addEventListener('astro:page-load', initTooltips);
31
+ </script>
@@ -0,0 +1,56 @@
1
+ ---
2
+ import { formatDisplayDate, longDateLabel } from '../wari/datetime.js';
3
+
4
+ export interface Props {
5
+ label?: string;
6
+ /** Fecha inicial ISO "YYYY-MM-DD". */
7
+ value?: string;
8
+ min?: string;
9
+ max?: string;
10
+ /** Nombre del campo enviado en el <form> (valor ISO). */
11
+ name?: string;
12
+ id?: string;
13
+ placeholder?: string;
14
+ supportingText?: string;
15
+ error?: boolean;
16
+ required?: boolean;
17
+ disabled?: boolean;
18
+ locale?: string;
19
+ /** 0 = domingo (como en Figma), 1 = lunes. */
20
+ weekStartsOn?: 0 | 1;
21
+ cancelLabel?: string;
22
+ okLabel?: string;
23
+ align?: 'start' | 'end';
24
+ class?: string;
25
+ }
26
+
27
+ const {
28
+ label, value = '', min, max, name, placeholder = 'dd/mm/aa', supportingText, error = false, required = false,
29
+ disabled = false, locale = 'es', weekStartsOn = 0, cancelLabel = 'Cancelar', okLabel = 'Aceptar', align = 'start',
30
+ class: className,
31
+ } = Astro.props;
32
+ const id = Astro.props.id ?? `ds-wdate-${Math.random().toString(36).slice(2, 9)}`;
33
+ ---
34
+ <div class:list={['ds-input', 'ds-wfield', className]} data-ds-wfield="date" data-open="false" data-align={align}
35
+ data-error={String(error)} data-disabled={String(disabled)} data-min={min} data-max={max} data-locale={locale}
36
+ 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
+ <div class="ds-wfield-anchor">
39
+ <div class="ds-input-shell">
40
+ <input id={id} type="text" inputmode="numeric" autocomplete="off" placeholder={placeholder} value={formatDisplayDate(value)}
41
+ disabled={disabled} required={required} aria-invalid={error ? 'true' : undefined} aria-describedby={supportingText ? `${id}-hint` : undefined} />
42
+ <button type="button" class="ds-wfield-trigger" disabled={disabled} aria-haspopup="dialog" aria-expanded="false"
43
+ aria-label={`Elegir fecha${value ? `, ${longDateLabel(value, locale)}` : ''}`}>
44
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3.5" y="5" width="17" height="15.5" rx="2.5"/><path d="M3.5 9.5h17M8 3v4M16 3v4"/><rect x="11" y="13" width="2.4" height="2.4" rx=".6" fill="currentColor" stroke="none"/></svg>
45
+ </button>
46
+ </div>
47
+ </div>
48
+ {supportingText && <small id={`${id}-hint`}>{supportingText}</small>}
49
+ <input type="hidden" name={name} value={value} data-ds-value />
50
+ </div>
51
+
52
+ <script>
53
+ import { initWariFields } from '../wari/pickers.js';
54
+ initWariFields();
55
+ document.addEventListener('astro:page-load', () => initWariFields());
56
+ </script>
@@ -0,0 +1,48 @@
1
+ ---
2
+ import WariDateField from './WariDateField.astro';
3
+ import WariTimeField from './WariTimeField.astro';
4
+
5
+ interface Props {
6
+ title?: string;
7
+ headingLevel?: 2 | 3 | 4;
8
+ /** Fecha inicial ISO "YYYY-MM-DD". */
9
+ date?: string;
10
+ /** Hora inicial "HH:mm" (24 h). */
11
+ time?: string;
12
+ dateLabel?: string;
13
+ timeLabel?: string;
14
+ minDate?: string;
15
+ maxDate?: string;
16
+ dateName?: string;
17
+ timeName?: string;
18
+ required?: boolean;
19
+ disabled?: boolean;
20
+ dateError?: boolean;
21
+ timeError?: boolean;
22
+ dateSupportingText?: string;
23
+ timeSupportingText?: string;
24
+ locale?: string;
25
+ weekStartsOn?: 0 | 1;
26
+ class?: string;
27
+ }
28
+
29
+ const {
30
+ title = 'Horario', headingLevel = 3, date, time, dateLabel = 'Fecha', timeLabel = 'Hora de recojo', minDate, maxDate,
31
+ dateName, timeName, required = true, disabled = false, dateError, timeError, dateSupportingText, timeSupportingText,
32
+ locale, weekStartsOn, class: className,
33
+ } = Astro.props;
34
+ const titleId = `ds-wschedule-${Math.random().toString(36).slice(2, 9)}`;
35
+ const Heading = `h${headingLevel}`;
36
+ ---
37
+ <section class:list={['ds-wschedule', className]} aria-labelledby={titleId}>
38
+ <header class="ds-wschedule-header">
39
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="8.5"/><path d="M12 7.5V12l3 2"/></svg>
40
+ <Heading id={titleId} class="ds-wschedule-title">{title}</Heading>
41
+ </header>
42
+ <div class="ds-wschedule-fields">
43
+ <WariDateField label={dateLabel} value={date} min={minDate} max={maxDate} name={dateName} required={required} disabled={disabled}
44
+ error={dateError} supportingText={dateSupportingText} locale={locale} weekStartsOn={weekStartsOn} />
45
+ <WariTimeField label={timeLabel} value={time} name={timeName} required={required} disabled={disabled} error={timeError}
46
+ supportingText={timeSupportingText} align="end" />
47
+ </div>
48
+ </section>
@@ -0,0 +1,76 @@
1
+ ---
2
+ import WariServiceMeta from './WariServiceMeta.astro';
3
+ import { serviceMeta } from '../wari/trip.js';
4
+ import type { WariService } from '../wari/trip';
5
+
6
+ export interface WariSelectOption {
7
+ value: string;
8
+ label: string;
9
+ disabled?: boolean;
10
+ /** Muestra el detalle de un servicio (capacidad, "Envío", "Desde S/…") a la derecha. */
11
+ service?: WariService;
12
+ }
13
+
14
+ export interface Props {
15
+ label?: string;
16
+ ariaLabel?: string;
17
+ options: WariSelectOption[];
18
+ value?: string;
19
+ placeholder?: string;
20
+ supportingText?: string;
21
+ error?: boolean;
22
+ required?: boolean;
23
+ disabled?: boolean;
24
+ /** Nombre del campo enviado en el <form>. */
25
+ name?: string;
26
+ id?: string;
27
+ /** Modo para el detalle de los servicios. */
28
+ hourly?: boolean;
29
+ delivery?: boolean;
30
+ class?: string;
31
+ }
32
+
33
+ const {
34
+ label, ariaLabel, options, value = '', placeholder = 'Seleccionar', supportingText, error = false, required = false,
35
+ disabled = false, name, hourly = false, delivery = false, class: className,
36
+ } = Astro.props;
37
+ const id = Astro.props.id ?? `ds-wselect-${Math.random().toString(36).slice(2, 9)}`;
38
+ const selected = options.find(option => option.value === value);
39
+ const metaLabel = (option?: WariSelectOption) => (option?.service ? serviceMeta(option.service, { hourly, delivery }).label : undefined);
40
+ const selectedMeta = metaLabel(selected);
41
+ ---
42
+ <div class:list={['ds-input', 'ds-wfield', 'ds-wselect', className]} data-ds-wselect data-open="false" data-error={String(error)}
43
+ 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
+ <div class="ds-wfield-anchor">
46
+ <div class="ds-input-shell" role="combobox" tabindex={disabled ? -1 : 0} aria-haspopup="listbox" aria-expanded="false"
47
+ aria-controls={`${id}-listbox`} aria-labelledby={label ? `${id}-label ${id}-value` : undefined} aria-label={label ? undefined : ariaLabel}
48
+ aria-disabled={disabled ? 'true' : undefined} aria-required={required ? 'true' : undefined} aria-invalid={error ? 'true' : undefined}
49
+ aria-describedby={supportingText ? `${id}-hint` : undefined}>
50
+ <span id={`${id}-value`} class="ds-wselect-value" data-placeholder={String(!selected)}>{selected ? selected.label : placeholder}<span class="ds-wvisually-hidden">{selectedMeta ? `, ${selectedMeta}` : ''}</span></span>
51
+ <span aria-hidden="true" style="display:contents" data-ds-value-meta>{selected?.service && <WariServiceMeta service={selected.service} hourly={hourly} delivery={delivery} />}</span>
52
+ <span class="ds-wselect-caret" aria-hidden="true"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9.5 6 6 6-6"/></svg></span>
53
+ </div>
54
+ <ul id={`${id}-listbox`} class="ds-wselect-list" role="listbox" hidden aria-labelledby={label ? `${id}-label` : undefined} aria-label={label ? undefined : ariaLabel}>
55
+ {options.map((option, index) => {
56
+ const meta = metaLabel(option);
57
+ return (
58
+ <li id={`${id}-option-${index}`} role="option" class="ds-wselect-option" data-value={option.value} data-label={option.label}
59
+ data-meta-label={meta} aria-selected={String(option.value === value)} aria-disabled={option.disabled ? 'true' : undefined}
60
+ aria-label={meta ? `${option.label}, ${meta}` : undefined}>
61
+ <span class="ds-wselect-label">{option.label}</span>
62
+ {option.service && <span aria-hidden="true" style="display:contents"><WariServiceMeta service={option.service} hourly={hourly} delivery={delivery} /></span>}
63
+ </li>
64
+ );
65
+ })}
66
+ </ul>
67
+ </div>
68
+ {supportingText && <small id={`${id}-hint`}>{supportingText}</small>}
69
+ <input type="hidden" name={name} value={value} data-ds-value />
70
+ </div>
71
+
72
+ <script>
73
+ import { initWariTripFields } from '../wari/trip-client.js';
74
+ initWariTripFields();
75
+ document.addEventListener('astro:page-load', () => initWariTripFields());
76
+ </script>
@@ -0,0 +1,19 @@
1
+ ---
2
+ import { serviceMeta } from '../wari/trip.js';
3
+ import type { WariService } from '../wari/trip';
4
+
5
+ interface Props {
6
+ service: WariService;
7
+ hourly?: boolean;
8
+ delivery?: boolean;
9
+ }
10
+
11
+ const { service, hourly = false, delivery = false } = Astro.props;
12
+ const meta = serviceMeta(service, { hourly, delivery });
13
+ const user = '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8" r="4" fill="currentColor"/><path d="M4.5 20.5c1-4 4-6 7.5-6s6.5 2 7.5 6" fill="currentColor"/></svg>';
14
+ const luggage = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><rect x="6" y="7" width="12" height="13" rx="2" fill="currentColor" stroke="none"/><path d="M9.5 7V4.5h5V7M9 22v-2M15 22v-2"/></svg>';
15
+ const bag = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><rect x="2.5" y="8.5" width="19" height="11" rx="2" fill="currentColor" stroke="none"/><path d="M9 8.5V6.5h6v2"/></svg>';
16
+ ---
17
+ <span class="ds-wmeta">{meta.delivery && <span class="ds-wmeta-badge">Envío</span>}{meta.price && <span class="ds-wmeta-item">{meta.price}</span>}{meta.capacity && (
18
+ <Fragment><span class="ds-wmeta-item"><Fragment set:html={user} />{meta.capacity.passengers}</span><span class="ds-wmeta-item"><Fragment set:html={luggage} />{meta.capacity.luggage}</span>{meta.capacity.luggageAlt != null && <span class="ds-wmeta-item">o <Fragment set:html={bag} />{meta.capacity.luggageAlt}</span>}</Fragment>
19
+ )}</span>
@@ -0,0 +1,20 @@
1
+ ---
2
+ import MultiSelect from './MultiSelect.astro';
3
+ import type { Props as MultiSelectProps } from './MultiSelect.astro';
4
+ import { wariStatuses } from '../wari/statuses.js';
5
+
6
+ type WariStatus = (typeof wariStatuses)[number]['value'];
7
+
8
+ interface Props extends Omit<MultiSelectProps, 'options'> {
9
+ /** Estados a mostrar (por defecto todos, en el orden de Wari). */
10
+ statuses?: string[];
11
+ /** Texto a la derecha de cada estado, por ejemplo la cantidad de servicios. */
12
+ descriptions?: Partial<Record<WariStatus | string, string>>;
13
+ }
14
+
15
+ const { statuses, descriptions = {}, label = 'Estado', ...props } = Astro.props;
16
+ const options = wariStatuses
17
+ .filter(item => !statuses || statuses.includes(item.value))
18
+ .map(item => ({ value: item.value, label: item.label, status: item.value, description: descriptions[item.value] }));
19
+ ---
20
+ <MultiSelect {...props} label={label} options={options} />
@@ -0,0 +1,40 @@
1
+ ---
2
+ import { clampCount } from '../wari/trip.js';
3
+
4
+ interface Props {
5
+ label?: string;
6
+ value?: number;
7
+ min?: number;
8
+ max?: number;
9
+ /** Nombre del campo enviado en el <form>. */
10
+ name?: string;
11
+ id?: string;
12
+ disabled?: boolean;
13
+ class?: string;
14
+ }
15
+
16
+ const { label, value = 1, min = 1, max = 99, name, disabled = false, class: className } = Astro.props;
17
+ const id = Astro.props.id ?? `ds-wstepper-${Math.random().toString(36).slice(2, 9)}`;
18
+ const current = clampCount(value, min, max);
19
+ const subject = label ? label.toLowerCase() : 'cantidad';
20
+ ---
21
+ <div class:list={['ds-input', 'ds-wfield', 'ds-wstepper', className]} data-ds-wstepper data-min={min} data-max={max}
22
+ data-disabled={String(disabled)} data-label="lg">
23
+ {label && <label for={id}>{label}</label>}
24
+ <div class="ds-input-shell">
25
+ <button type="button" class="ds-wstepper-button" aria-label={`Disminuir ${subject}`} aria-controls={id} disabled={disabled || current <= min}>
26
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M5 12h14"/></svg>
27
+ </button>
28
+ <input id={id} type="text" inputmode="numeric" role="spinbutton" name={name} value={String(current)} disabled={disabled}
29
+ aria-valuenow={current} aria-valuemin={min} aria-valuemax={max} />
30
+ <button type="button" class="ds-wstepper-button" aria-label={`Aumentar ${subject}`} aria-controls={id} disabled={disabled || current >= max}>
31
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>
32
+ </button>
33
+ </div>
34
+ </div>
35
+
36
+ <script>
37
+ import { initWariTripFields } from '../wari/trip-client.js';
38
+ initWariTripFields();
39
+ document.addEventListener('astro:page-load', () => initWariTripFields());
40
+ </script>
@@ -0,0 +1,33 @@
1
+ ---
2
+ import type { WariOption } from '../wari/trip';
3
+
4
+ interface Props {
5
+ /** Nombre del grupo para lectores de pantalla (no se muestra). */
6
+ legend: string;
7
+ items: WariOption[];
8
+ /** Valores activos al cargar. */
9
+ value?: string[];
10
+ orientation?: 'vertical' | 'horizontal';
11
+ /** Envía cada interruptor activo como name=value. */
12
+ name?: string;
13
+ disabled?: boolean;
14
+ class?: string;
15
+ }
16
+
17
+ const { legend, items, value = [], orientation = 'vertical', name, disabled = false, class: className } = Astro.props;
18
+ ---
19
+ <fieldset class:list={['ds-wswitches', className]} data-ds-wswitches data-orientation={orientation} disabled={disabled}>
20
+ <legend>{legend}</legend>
21
+ {items.map(item => (
22
+ <label class="ds-wswitch">
23
+ <span>{item.label}</span>
24
+ <input type="checkbox" role="switch" name={name} value={item.value} checked={value.includes(item.value)} disabled={item.disabled} />
25
+ </label>
26
+ ))}
27
+ </fieldset>
28
+
29
+ <script>
30
+ import { initWariTripFields } from '../wari/trip-client.js';
31
+ initWariTripFields();
32
+ document.addEventListener('astro:page-load', () => initWariTripFields());
33
+ </script>