@directo-ui/astro 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/components.css +475 -2
- package/index.d.ts +10 -0
- package/index.js +9 -0
- package/package.json +15 -7
- package/src/components/Autocomplete.astro +106 -0
- package/src/components/DataTable.astro +136 -0
- package/src/components/DateRangePicker.astro +105 -0
- package/src/components/Drawer.astro +40 -0
- package/src/components/FileUpload.astro +152 -0
- package/src/components/FilterBar.astro +66 -0
- package/src/components/Sidebar.astro +64 -0
- package/src/components/Timeline.astro +25 -0
- package/src/components/WariClientDetails.astro +87 -0
- package/src/components/WariClientSearch.astro +88 -0
- package/src/components/WariPassengerField.astro +84 -0
- package/src/components/WariRoute.astro +49 -0
- package/src/components/WariStepper.astro +9 -4
- package/src/components/WariSwitchList.astro +86 -8
- package/src/components/WariTripAttributes.astro +1 -1
- package/src/files.d.ts +27 -0
- package/src/files.js +52 -0
- package/src/modal.d.ts +3 -3
- package/src/modal.js +50 -39
- package/src/wari/motion.d.ts +14 -0
- package/src/wari/motion.js +60 -0
- package/src/wari/route-client.d.ts +10 -0
- package/src/wari/route-client.js +270 -0
- package/src/wari/route.d.ts +48 -0
- package/src/wari/route.js +71 -0
- package/src/wari/trip-client.js +152 -4
- package/src/wari/trip.d.ts +51 -0
- package/src/wari/trip.js +64 -4
- package/wari.d.ts +8 -2
- package/wari.js +6 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface SidebarLink {
|
|
3
|
+
label: string;
|
|
4
|
+
href: string;
|
|
5
|
+
/** Small counter or text at the end. */
|
|
6
|
+
badge?: string | number;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
groups: readonly {
|
|
12
|
+
label: string;
|
|
13
|
+
items: readonly (SidebarLink & { children?: readonly SidebarLink[] })[];
|
|
14
|
+
/** The group title opens and closes the group. */
|
|
15
|
+
collapsible?: boolean;
|
|
16
|
+
/** Initial state of a collapsible group (open by default). */
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
activeHref?: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
const { groups, activeHref, label = 'Navegación', id, class: className } = Astro.props;
|
|
25
|
+
const hasBadge = (item: SidebarLink) => item.badge !== undefined && item.badge !== '';
|
|
26
|
+
---
|
|
27
|
+
<directo-sidebar style="display: contents">
|
|
28
|
+
<nav id={id} class:list={['ds-sidebar', className]} aria-label={label}>
|
|
29
|
+
{Astro.slots.has('header') && <div class="ds-sidebar-header"><slot name="header" /></div>}
|
|
30
|
+
{groups.map(group => {
|
|
31
|
+
const list = <ul>{group.items.map(item => <li>
|
|
32
|
+
{item.disabled
|
|
33
|
+
? <span class="ds-sidebar-link" aria-disabled="true"><span class="ds-sidebar-text">{item.label}</span>{hasBadge(item) && <span class="ds-sidebar-badge">{item.badge}</span>}</span>
|
|
34
|
+
: <a class="ds-sidebar-link" href={item.href} aria-current={activeHref === item.href ? 'page' : undefined}><span class="ds-sidebar-text">{item.label}</span>{hasBadge(item) && <span class="ds-sidebar-badge">{item.badge}</span>}</a>}
|
|
35
|
+
{!!item.children?.length && <ul>{item.children.map(child => <li>
|
|
36
|
+
{child.disabled
|
|
37
|
+
? <span class="ds-sidebar-link" aria-disabled="true"><span class="ds-sidebar-text">{child.label}</span>{hasBadge(child) && <span class="ds-sidebar-badge">{child.badge}</span>}</span>
|
|
38
|
+
: <a class="ds-sidebar-link" href={child.href} aria-current={activeHref === child.href ? 'page' : undefined}><span class="ds-sidebar-text">{child.label}</span>{hasBadge(child) && <span class="ds-sidebar-badge">{child.badge}</span>}</a>}
|
|
39
|
+
</li>)}</ul>}
|
|
40
|
+
</li>)}</ul>;
|
|
41
|
+
return group.collapsible
|
|
42
|
+
? <details class="ds-sidebar-group" open={group.defaultOpen ?? true}><summary>{group.label}</summary>{list}</details>
|
|
43
|
+
: <section class="ds-sidebar-group" aria-label={group.label}><p>{group.label}</p>{list}</section>;
|
|
44
|
+
})}
|
|
45
|
+
{Astro.slots.has('footer') && <div class="ds-sidebar-footer"><slot name="footer" /></div>}
|
|
46
|
+
</nav>
|
|
47
|
+
</directo-sidebar>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
class DirectoSidebarElement extends HTMLElement {
|
|
51
|
+
connectedCallback() { this.addEventListener('click', this.navigate); }
|
|
52
|
+
disconnectedCallback() { this.removeEventListener('click', this.navigate); }
|
|
53
|
+
|
|
54
|
+
/** Emits ds-navigate (cancelable). Call event.preventDefault() on it to route without reloading the page. */
|
|
55
|
+
private navigate = (event: MouseEvent) => {
|
|
56
|
+
const link = event.target instanceof Element ? event.target.closest<HTMLAnchorElement>('a.ds-sidebar-link') : null;
|
|
57
|
+
if (!link) return;
|
|
58
|
+
const detail = { href: link.getAttribute('href') ?? '', label: link.querySelector('.ds-sidebar-text')?.textContent ?? '' };
|
|
59
|
+
const allowed = this.dispatchEvent(new CustomEvent('ds-navigate', { bubbles: true, cancelable: true, detail }));
|
|
60
|
+
if (!allowed) event.preventDefault();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (!customElements.get('directo-sidebar')) customElements.define('directo-sidebar', DirectoSidebarElement);
|
|
64
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
items: readonly {
|
|
4
|
+
id: string; title: string; dateTime?: string; dateLabel?: string; actor?: string; description?: string;
|
|
5
|
+
/** Color of the dot. */
|
|
6
|
+
variant?: 'default' | 'info' | 'success' | 'warning' | 'error';
|
|
7
|
+
/** Marks the step that is happening now (aria-current="step"). */
|
|
8
|
+
current?: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
label?: string;
|
|
11
|
+
emptyMessage?: string;
|
|
12
|
+
density?: 'comfortable' | 'compact';
|
|
13
|
+
id?: string;
|
|
14
|
+
class?: string;
|
|
15
|
+
}
|
|
16
|
+
const { items, label = 'Historial', emptyMessage = 'Sin eventos registrados.', density = 'comfortable', id, class: className } = Astro.props;
|
|
17
|
+
---
|
|
18
|
+
{items.length ? <ol id={id} class:list={['ds-timeline', className]} aria-label={label} data-density={density}>
|
|
19
|
+
{items.map(item => <li data-variant={item.variant && item.variant !== 'default' ? item.variant : undefined} aria-current={item.current ? 'step' : undefined}>
|
|
20
|
+
<strong>{item.title}</strong>
|
|
21
|
+
{item.dateTime && <time datetime={item.dateTime}>{item.dateLabel ?? item.dateTime}</time>}
|
|
22
|
+
{item.actor && <span>{item.actor}</span>}
|
|
23
|
+
{item.description && <div>{item.description}</div>}
|
|
24
|
+
</li>)}
|
|
25
|
+
</ol> : <p id={id} class:list={['ds-timeline', className]} data-empty="true">{emptyMessage}</p>}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Nombre del cliente; se recorta con "…" y el texto completo queda en `title`. */
|
|
4
|
+
name: string;
|
|
5
|
+
company?: string;
|
|
6
|
+
/** Teléfono: se muestra como enlace `tel:`. */
|
|
7
|
+
phone?: string;
|
|
8
|
+
/** Cliente VIP: franja amarilla. vip={false}: franja celeste ("sin VIP" en Figma). */
|
|
9
|
+
vip?: boolean;
|
|
10
|
+
/** Color de la ficha a mano; si no se indica, lo decide `vip` (por defecto amarillo). */
|
|
11
|
+
tone?: 'warning' | 'info' | 'neutral';
|
|
12
|
+
showRates?: boolean;
|
|
13
|
+
showInfo?: boolean;
|
|
14
|
+
showEdit?: boolean;
|
|
15
|
+
ratesLabel?: string;
|
|
16
|
+
infoLabel?: string;
|
|
17
|
+
editLabel?: string;
|
|
18
|
+
/** Observaciones de solo lectura. */
|
|
19
|
+
notes?: string;
|
|
20
|
+
notesLabel?: string;
|
|
21
|
+
notesHint?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
class?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
name, company, phone, vip, tone, showRates = true, showInfo = true, showEdit = true, ratesLabel = 'Tarifas',
|
|
28
|
+
infoLabel = 'Ver información del cliente', editLabel = 'Editar cliente', notes, notesLabel = 'Observaciones del cliente',
|
|
29
|
+
notesHint = '(no editable)', disabled = false, class: className,
|
|
30
|
+
} = Astro.props;
|
|
31
|
+
const hasFields = Astro.slots.has('default');
|
|
32
|
+
const bannerTone = tone ?? (vip === false ? 'info' : 'warning');
|
|
33
|
+
---
|
|
34
|
+
<div class:list={['ds-wclient-details', className]} data-ds-wclient-details>
|
|
35
|
+
<div class="ds-wclient-summary">
|
|
36
|
+
<div class="ds-wclient-banner" data-tone={bannerTone}>
|
|
37
|
+
<p class="ds-wclient-name" title={name}>{name}</p>
|
|
38
|
+
{company && <span class="ds-wclient-company" title={company}>{company}</span>}
|
|
39
|
+
{phone && (
|
|
40
|
+
<a class="ds-wclient-phone" href={`tel:${phone.replace(/[^\d+]/g, '')}`}>
|
|
41
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 3.5h3.2l1.6 4-2 1.3a10.5 10.5 0 0 0 5.4 5.4l1.3-2 4 1.6V17a2 2 0 0 1-2 2A15.5 15.5 0 0 1 3 5.5a2 2 0 0 1 2-2Z"/></svg>{phone}
|
|
42
|
+
</a>
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
{(showRates || showInfo || showEdit) && (
|
|
46
|
+
<div class="ds-wclient-actions">
|
|
47
|
+
{showRates && <button type="button" class="ds-wclient-rates" data-ds-action="rates" disabled={disabled}>{ratesLabel}</button>}
|
|
48
|
+
{(showInfo || showEdit) && (
|
|
49
|
+
<div>
|
|
50
|
+
{showInfo && (
|
|
51
|
+
<button type="button" class="ds-wclient-icon" data-ds-action="info" aria-label={infoLabel} title={infoLabel} disabled={disabled}>
|
|
52
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="9" fill="currentColor" stroke="none"/><path d="M12 11v5.5M12 7.6v.1" stroke="#fff" stroke-width="2.4"/></svg>
|
|
53
|
+
</button>
|
|
54
|
+
)}
|
|
55
|
+
{showEdit && (
|
|
56
|
+
<button type="button" class="ds-wclient-icon" data-ds-action="edit" aria-label={editLabel} title={editLabel} disabled={disabled}>
|
|
57
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M4 20h4.5L19 9.5 14.5 5 4 15.5z" fill="currentColor" stroke="none"/><path d="M13 20h7"/></svg>
|
|
58
|
+
</button>
|
|
59
|
+
)}
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
{hasFields && <div class="ds-wclient-fields"><slot /></div>}
|
|
66
|
+
{notes != null && (
|
|
67
|
+
<div class="ds-wclient-notes">
|
|
68
|
+
<span>{notesLabel} <em>{notesHint}</em></span>
|
|
69
|
+
<p>{notes}</p>
|
|
70
|
+
</div>
|
|
71
|
+
)}
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<script>
|
|
75
|
+
// Emits on the details element: "ds-rates", "ds-info" and "ds-edit".
|
|
76
|
+
function initClientDetails() {
|
|
77
|
+
document.querySelectorAll<HTMLElement>('[data-ds-wclient-details]:not([data-ds-ready])').forEach(root => {
|
|
78
|
+
root.dataset.dsReady = '';
|
|
79
|
+
root.addEventListener('click', event => {
|
|
80
|
+
const action = (event.target as Element).closest<HTMLElement>('[data-ds-action]')?.dataset.dsAction;
|
|
81
|
+
if (action) root.dispatchEvent(new CustomEvent(`ds-${action}`, { bubbles: true }));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
initClientDetails();
|
|
86
|
+
document.addEventListener('astro:page-load', initClientDetails);
|
|
87
|
+
</script>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
title?: string;
|
|
4
|
+
headingLevel?: 2 | 3 | 4;
|
|
5
|
+
/** Texto inicial del buscador. */
|
|
6
|
+
value?: string;
|
|
7
|
+
/** Muestra "Crear usuario" como botón (emite `ds-create`). */
|
|
8
|
+
showCreate?: boolean;
|
|
9
|
+
/** Convierte "Crear usuario" en un enlace. */
|
|
10
|
+
createHref?: string;
|
|
11
|
+
createLabel?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
searchLabel?: string;
|
|
14
|
+
/** Nombre del campo (por defecto "q"). */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Si se indica, el formulario se envía de forma nativa a esa URL (GET). */
|
|
17
|
+
action?: string;
|
|
18
|
+
/** Barra de carga al cargar la página. En el cliente, activa o quita `aria-busy="true"` en la tarjeta. */
|
|
19
|
+
loading?: boolean;
|
|
20
|
+
loadingLabel?: string;
|
|
21
|
+
/** "auto" (por defecto): "Crear usuario" solo con el buscador vacío y sin cargar, como en Figma. */
|
|
22
|
+
createMode?: 'auto' | 'always' | 'never';
|
|
23
|
+
/** Oculta el buscador (estado bloqueado: solo se ven los datos del cliente). */
|
|
24
|
+
showSearch?: boolean;
|
|
25
|
+
hoverable?: boolean;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
title = 'Cliente / usuario', headingLevel = 3, value = '', showCreate = true, createHref, createLabel = 'Crear usuario',
|
|
32
|
+
placeholder = 'Puedes filtrar por nombre o número', searchLabel = 'Buscar cliente por nombre o número', name = 'q', action,
|
|
33
|
+
hoverable = true, disabled = false, loading = false, loadingLabel = 'Buscando cliente…', createMode = 'auto', showSearch = true,
|
|
34
|
+
class: className,
|
|
35
|
+
} = Astro.props;
|
|
36
|
+
const createHidden = createMode === 'never' || (createMode === 'auto' && (value.trim() !== '' || loading));
|
|
37
|
+
const id = `ds-wclient-${Math.random().toString(36).slice(2, 9)}`;
|
|
38
|
+
const Heading = `h${headingLevel}`;
|
|
39
|
+
const plus = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M12 4v16M4 12h16"/></svg>';
|
|
40
|
+
---
|
|
41
|
+
<section class:list={['ds-wcard', 'ds-wclient', className]} aria-labelledby={`${id}-title`} data-hover={hoverable ? 'lift' : undefined}
|
|
42
|
+
aria-busy={loading ? 'true' : undefined} data-create={createMode} data-ds-wclient>
|
|
43
|
+
<header class="ds-wcard-header">
|
|
44
|
+
<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"><rect x="3.5" y="3.5" width="17" height="17" rx="2.5"/><circle cx="12" cy="10" r="3"/><path d="M6.5 20c.9-2.7 3-4 5.5-4s4.6 1.3 5.5 4"/></svg>
|
|
45
|
+
<Heading id={`${id}-title`} class="ds-wcard-title" title={title}>{title}</Heading>
|
|
46
|
+
{createHref
|
|
47
|
+
? <a class="ds-wcard-action" href={createHref} data-ds-create hidden={createHidden}><Fragment set:html={plus} />{createLabel}</a>
|
|
48
|
+
: showCreate && <button type="button" class="ds-wcard-action" data-ds-create hidden={createHidden} disabled={disabled}><Fragment set:html={plus} />{createLabel}</button>}
|
|
49
|
+
</header>
|
|
50
|
+
{showSearch && <form role="search" class="ds-input ds-wsearch" action={action} data-native={action ? 'true' : undefined}>
|
|
51
|
+
<label for={id} class="ds-wvisually-hidden">{searchLabel}</label>
|
|
52
|
+
<div class="ds-input-shell">
|
|
53
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m20 20-4.8-4.8"/></svg>
|
|
54
|
+
<input id={id} type="search" name={name} value={value} placeholder={placeholder} autocomplete="off" enterkeyhint="search" disabled={disabled} />
|
|
55
|
+
</div>
|
|
56
|
+
</form>}
|
|
57
|
+
<div class="ds-wclient-progress" role="progressbar" aria-label={loadingLabel} data-ds-progress></div>
|
|
58
|
+
<div class="ds-wclient-results"><slot /></div>
|
|
59
|
+
</section>
|
|
60
|
+
|
|
61
|
+
<script>
|
|
62
|
+
// Emits on the card: "ds-change" (texto en cada tecla), "ds-search" (Enter) and "ds-create" (botón).
|
|
63
|
+
function initClientSearch() {
|
|
64
|
+
document.querySelectorAll<HTMLElement>('[data-ds-wclient]:not([data-ds-ready])').forEach(root => {
|
|
65
|
+
root.dataset.dsReady = '';
|
|
66
|
+
const form = root.querySelector<HTMLFormElement>('form');
|
|
67
|
+
const input = form?.querySelector<HTMLInputElement>('input');
|
|
68
|
+
const create = root.querySelector<HTMLElement>('[data-ds-create]');
|
|
69
|
+
const emit = (type: string, detail?: string) => root.dispatchEvent(new CustomEvent(type, { detail, bubbles: true }));
|
|
70
|
+
// "Crear usuario": data-create="auto" lo oculta al escribir o mientras carga; "never" / "always" lo fuerzan.
|
|
71
|
+
// Puedes cambiar data-create o aria-busy desde tu código y el botón se actualiza solo.
|
|
72
|
+
const syncCreate = () => {
|
|
73
|
+
if (!create) return;
|
|
74
|
+
const mode = root.dataset.create;
|
|
75
|
+
create.hidden = mode === 'never' || (mode === 'auto' && (Boolean(input?.value.trim()) || root.getAttribute('aria-busy') === 'true'));
|
|
76
|
+
};
|
|
77
|
+
new MutationObserver(syncCreate).observe(root, { attributes: true, attributeFilter: ['aria-busy', 'data-create'] });
|
|
78
|
+
input?.addEventListener('input', () => { syncCreate(); emit('ds-change', input.value); });
|
|
79
|
+
form?.addEventListener('submit', event => {
|
|
80
|
+
if (!form.dataset.native) event.preventDefault();
|
|
81
|
+
emit('ds-search', input?.value.trim() ?? '');
|
|
82
|
+
});
|
|
83
|
+
create?.addEventListener('click', () => emit('ds-create'));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
initClientSearch();
|
|
87
|
+
document.addEventListener('astro:page-load', initClientSearch);
|
|
88
|
+
</script>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
/** `{ name, phone }` inicial. */
|
|
4
|
+
value?: { name?: string; phone?: string };
|
|
5
|
+
/** Barra de carga al cargar la página. En el cliente, activa o quita `aria-busy="true"` en el grupo. */
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
loadingLabel?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
namePlaceholder?: string;
|
|
10
|
+
phonePlaceholder?: string;
|
|
11
|
+
nameLabel?: string;
|
|
12
|
+
phoneLabel?: string;
|
|
13
|
+
clearLabel?: string;
|
|
14
|
+
showClear?: boolean;
|
|
15
|
+
/** Nombres de los campos al enviar un formulario. */
|
|
16
|
+
nameInputName?: string;
|
|
17
|
+
phoneInputName?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
id?: string;
|
|
20
|
+
class?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
value = {}, loading = false, loadingLabel = 'Buscando pasajero…', label = 'Pasajero', namePlaceholder = 'Nombre del pasajero',
|
|
25
|
+
phonePlaceholder = 'Ingresa el número del pasajero', nameLabel = 'Nombre del pasajero', phoneLabel = 'Número del pasajero',
|
|
26
|
+
clearLabel = 'Quitar pasajero', showClear = true, nameInputName, phoneInputName, disabled = false, id, class: className,
|
|
27
|
+
} = Astro.props;
|
|
28
|
+
const name = value.name ?? '';
|
|
29
|
+
const phone = value.phone ?? '';
|
|
30
|
+
const phonePath = 'M5 3.5h3.2l1.6 4-2 1.3a10.5 10.5 0 0 0 5.4 5.4l1.3-2 4 1.6V17a2 2 0 0 1-2 2A15.5 15.5 0 0 1 3 5.5a2 2 0 0 1 2-2Z';
|
|
31
|
+
---
|
|
32
|
+
<div id={id} class:list={['ds-wpassenger', className]} role="group" aria-label={label} aria-busy={loading ? 'true' : undefined} data-ds-wpassenger>
|
|
33
|
+
<div class="ds-wpassenger-row">
|
|
34
|
+
<label class="ds-wpassenger-field">
|
|
35
|
+
<svg width="16" height="16" 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="8" r="3.5"/><path d="M5 20c.8-3.5 3.6-5.5 7-5.5s6.2 2 7 5.5"/></svg>
|
|
36
|
+
<input class="ds-wpassenger-input" type="text" autocomplete="name" name={nameInputName} placeholder={namePlaceholder} aria-label={nameLabel}
|
|
37
|
+
value={name} disabled={disabled} data-field="name" />
|
|
38
|
+
</label>
|
|
39
|
+
<label class="ds-wpassenger-field">
|
|
40
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-icon="empty" hidden={phone !== ''}><path d={phonePath}/></svg>
|
|
41
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-icon="filled" hidden={phone === ''}><path d={phonePath}/><path d="M15 4h5M15 7h5M17 10h3"/></svg>
|
|
42
|
+
<input class="ds-wpassenger-input" type="tel" autocomplete="tel" inputmode="tel" name={phoneInputName} placeholder={phonePlaceholder} aria-label={phoneLabel}
|
|
43
|
+
value={phone} disabled={disabled} data-field="phone" />
|
|
44
|
+
</label>
|
|
45
|
+
{showClear && <button type="button" class="ds-wpassenger-clear" aria-label={clearLabel} title={clearLabel} disabled={disabled} data-ds-clear>
|
|
46
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="9.5" fill="currentColor"/><path d="m9 9 6 6M15 9l-6 6" stroke="#fff" stroke-width="2"/></svg>
|
|
47
|
+
</button>}
|
|
48
|
+
</div>
|
|
49
|
+
<div class="ds-wclient-progress ds-wpassenger-progress" role="progressbar" aria-label={loadingLabel} data-ds-progress></div>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<script>
|
|
53
|
+
// Emits on the group: "ds-change" ({ name, phone } en cada tecla) and "ds-clear" (botón ⓧ, después de vaciar los campos).
|
|
54
|
+
// Carga: group.setAttribute('aria-busy', 'true') / removeAttribute('aria-busy'). Valor desde tu código: group.dsSetValue({ name, phone }).
|
|
55
|
+
type PassengerRoot = HTMLElement & { dsSetValue?: (value: { name?: string; phone?: string }) => void };
|
|
56
|
+
function initPassengerFields() {
|
|
57
|
+
document.querySelectorAll<PassengerRoot>('[data-ds-wpassenger]:not([data-ds-ready])').forEach(root => {
|
|
58
|
+
root.dataset.dsReady = '';
|
|
59
|
+
const name = root.querySelector<HTMLInputElement>('[data-field="name"]')!;
|
|
60
|
+
const phone = root.querySelector<HTMLInputElement>('[data-field="phone"]')!;
|
|
61
|
+
const read = () => ({ name: name.value, phone: phone.value });
|
|
62
|
+
const syncIcon = () => {
|
|
63
|
+
root.querySelector<SVGElement>('[data-icon="empty"]')?.toggleAttribute('hidden', phone.value !== '');
|
|
64
|
+
root.querySelector<SVGElement>('[data-icon="filled"]')?.toggleAttribute('hidden', phone.value === '');
|
|
65
|
+
};
|
|
66
|
+
const emit = (type: string, detail?: unknown) => root.dispatchEvent(new CustomEvent(type, { detail, bubbles: true }));
|
|
67
|
+
for (const input of [name, phone]) input.addEventListener('input', () => { syncIcon(); emit('ds-change', read()); });
|
|
68
|
+
root.querySelector('[data-ds-clear]')?.addEventListener('click', () => {
|
|
69
|
+
name.value = '';
|
|
70
|
+
phone.value = '';
|
|
71
|
+
syncIcon();
|
|
72
|
+
emit('ds-change', read());
|
|
73
|
+
emit('ds-clear');
|
|
74
|
+
});
|
|
75
|
+
root.dsSetValue = value => {
|
|
76
|
+
name.value = value.name ?? '';
|
|
77
|
+
phone.value = value.phone ?? '';
|
|
78
|
+
syncIcon();
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
initPassengerFields();
|
|
83
|
+
document.addEventListener('astro:page-load', initPassengerFields);
|
|
84
|
+
</script>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { routeHtml } from '../wari/route-client.js';
|
|
3
|
+
import { normalizeRoute } from '../wari/route.js';
|
|
4
|
+
import type { WariRouteValue } from '../wari/route';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
/** Ruta inicial: { stops, passenger, tolls }. Sin valor: origen, un destino y un peaje vacío. */
|
|
8
|
+
value?: Partial<WariRouteValue>;
|
|
9
|
+
title?: string;
|
|
10
|
+
headingLevel?: 2 | 3 | 4;
|
|
11
|
+
maxStops?: number;
|
|
12
|
+
maxTolls?: number;
|
|
13
|
+
showPassengers?: boolean;
|
|
14
|
+
showTolls?: boolean;
|
|
15
|
+
/** Envía la ruta como JSON en un campo oculto con este nombre. */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** Simula "Invirtiendo direcciones..." durante estos milisegundos (para maquetas). En tu app pon aria-busy="true". */
|
|
18
|
+
invertDelay?: number;
|
|
19
|
+
invertingLabel?: string;
|
|
20
|
+
invertedMessage?: string;
|
|
21
|
+
routePassengerNote?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
class?: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
value, title = 'Ruta', headingLevel = 3, maxStops = 10, maxTolls = 5, showPassengers = true, showTolls = true, name, invertDelay,
|
|
29
|
+
invertingLabel, invertedMessage, routePassengerNote, disabled = false, class: className, id,
|
|
30
|
+
} = Astro.props;
|
|
31
|
+
const baseId = `ds-wroute-${Math.random().toString(36).slice(2, 9)}`;
|
|
32
|
+
const route = normalizeRoute(value);
|
|
33
|
+
const options = { title, headingLevel, maxStops, maxTolls, showPassengers, showTolls, disabled, invertingLabel, invertedMessage, routePassengerNote };
|
|
34
|
+
const definedOptions = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== undefined));
|
|
35
|
+
---
|
|
36
|
+
<section id={id} class:list={['ds-wcard', 'ds-wroute', className]} data-ds-wroute aria-labelledby={`${baseId}-title`} data-base-id={baseId}
|
|
37
|
+
data-value={JSON.stringify(route)} data-title={title} data-heading-level={headingLevel} data-max-stops={maxStops} data-max-tolls={maxTolls}
|
|
38
|
+
data-show-passengers={String(showPassengers)} data-show-tolls={String(showTolls)} data-disabled={String(disabled)}
|
|
39
|
+
data-invert-delay={invertDelay} data-inverting-label={invertingLabel} data-inverted-message={invertedMessage}
|
|
40
|
+
data-route-passenger-note={routePassengerNote}>
|
|
41
|
+
{name && <input type="hidden" name={name} value={JSON.stringify(route)} data-ds-value />}
|
|
42
|
+
<div data-ds-route-content style="display:contents" set:html={routeHtml(route, definedOptions, baseId)} />
|
|
43
|
+
</section>
|
|
44
|
+
|
|
45
|
+
<script>
|
|
46
|
+
import { initWariRoute } from '../wari/route-client.js';
|
|
47
|
+
initWariRoute();
|
|
48
|
+
document.addEventListener('astro:page-load', () => initWariRoute());
|
|
49
|
+
</script>
|
|
@@ -3,6 +3,10 @@ import { clampCount } from '../wari/trip.js';
|
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
5
|
label?: string;
|
|
6
|
+
/** Nombre accesible cuando no hay `label` visible. */
|
|
7
|
+
ariaLabel?: string;
|
|
8
|
+
/** 'outlined': botones con borde y más alto, como el contador del Booster en Figma. */
|
|
9
|
+
variant?: 'filled' | 'outlined';
|
|
6
10
|
value?: number;
|
|
7
11
|
min?: number;
|
|
8
12
|
max?: number;
|
|
@@ -11,21 +15,22 @@ interface Props {
|
|
|
11
15
|
id?: string;
|
|
12
16
|
disabled?: boolean;
|
|
13
17
|
class?: string;
|
|
18
|
+
[attribute: `data-${string}`]: unknown;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
const { label, value = 1, min = 1, max = 99, name, disabled = false, class: className } = Astro.props;
|
|
21
|
+
const { label, ariaLabel, variant = 'filled', value = 1, min = 1, max = 99, name, disabled = false, class: className, id: _id, ...rest } = Astro.props;
|
|
17
22
|
const id = Astro.props.id ?? `ds-wstepper-${Math.random().toString(36).slice(2, 9)}`;
|
|
18
23
|
const current = clampCount(value, min, max);
|
|
19
|
-
const subject = label
|
|
24
|
+
const subject = (label ?? ariaLabel ?? 'cantidad').toLowerCase();
|
|
20
25
|
---
|
|
21
26
|
<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">
|
|
27
|
+
data-disabled={String(disabled)} data-label="lg" data-variant={variant} {...rest}>
|
|
23
28
|
{label && <label for={id}>{label}</label>}
|
|
24
29
|
<div class="ds-input-shell">
|
|
25
30
|
<button type="button" class="ds-wstepper-button" aria-label={`Disminuir ${subject}`} aria-controls={id} disabled={disabled || current <= min}>
|
|
26
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="M5 12h14"/></svg>
|
|
27
32
|
</button>
|
|
28
|
-
<input id={id} type="text" inputmode="numeric" role="spinbutton" name={name} value={String(current)} disabled={disabled}
|
|
33
|
+
<input id={id} type="text" inputmode="numeric" role="spinbutton" name={name} value={String(current)} disabled={disabled} aria-label={label ? undefined : ariaLabel}
|
|
29
34
|
aria-valuenow={current} aria-valuemin={min} aria-valuemax={max} />
|
|
30
35
|
<button type="button" class="ds-wstepper-button" aria-label={`Aumentar ${subject}`} aria-controls={id} disabled={disabled || current >= max}>
|
|
31
36
|
<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>
|
|
@@ -1,29 +1,107 @@
|
|
|
1
1
|
---
|
|
2
|
+
import WariSelect from './WariSelect.astro';
|
|
3
|
+
import WariStepper from './WariStepper.astro';
|
|
2
4
|
import type { WariOption } from '../wari/trip';
|
|
3
5
|
|
|
4
6
|
interface Props {
|
|
5
7
|
/** Nombre del grupo para lectores de pantalla (no se muestra). */
|
|
6
8
|
legend: string;
|
|
9
|
+
/**
|
|
10
|
+
* Interruptores. Con `description`, `note`, `maxQuantity` o `choices`, al activarlo se despliega su panel:
|
|
11
|
+
* contador (Booster) o una lista por unidad con + y papelera (Carseat).
|
|
12
|
+
*/
|
|
7
13
|
items: WariOption[];
|
|
8
14
|
/** Valores activos al cargar. */
|
|
9
15
|
value?: string[];
|
|
16
|
+
/** Cantidad inicial de cada interruptor activo con `maxQuantity` (p. ej. { booster: 2 }). */
|
|
17
|
+
quantities?: Record<string, number>;
|
|
18
|
+
/** Opciones iniciales de cada interruptor activo con `choices` (p. ej. { carseat: ['0-2', '3-5'] }). */
|
|
19
|
+
choices?: Record<string, string[]>;
|
|
20
|
+
/** Texto inicial de los campos de cada interruptor activo con `fields` (p. ej. { carga: { weight: '20' } }). */
|
|
21
|
+
fields?: Record<string, Record<string, string>>;
|
|
10
22
|
orientation?: 'vertical' | 'horizontal';
|
|
11
|
-
/** Envía cada interruptor activo como name=value. */
|
|
23
|
+
/** Envía cada interruptor activo como name=value y su cantidad u opciones como name.value. */
|
|
12
24
|
name?: string;
|
|
13
25
|
disabled?: boolean;
|
|
14
26
|
class?: string;
|
|
15
27
|
}
|
|
16
28
|
|
|
17
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
legend, items, value = [], quantities = {}, choices = {}, fields = {}, orientation = 'vertical', name, disabled = false, class: className,
|
|
31
|
+
} = Astro.props;
|
|
32
|
+
const baseId = `ds-wswitches-${Math.random().toString(36).slice(2, 9)}`;
|
|
33
|
+
const trash = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 6.5h15M9.5 6.5V4.5h5v2M6.5 6.5l1 13h9l1-13M10.5 10v6M13.5 10v6"/></svg>';
|
|
34
|
+
const plus = '<svg 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>';
|
|
18
35
|
---
|
|
19
36
|
<fieldset class:list={['ds-wswitches', className]} data-ds-wswitches data-orientation={orientation} disabled={disabled}>
|
|
20
37
|
<legend>{legend}</legend>
|
|
21
|
-
{items.map(item =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
{items.map((item, index) => {
|
|
39
|
+
const checked = value.includes(item.value);
|
|
40
|
+
const hasChoices = Boolean(item.choices?.length);
|
|
41
|
+
const hasFields = Boolean(item.fields?.length);
|
|
42
|
+
const expandable = Boolean(item.description || item.note || item.maxQuantity || hasChoices || hasFields);
|
|
43
|
+
const panelId = `${baseId}-panel-${index}`;
|
|
44
|
+
const descId = `${baseId}-desc-${index}`;
|
|
45
|
+
const max = item.maxQuantity ?? 1;
|
|
46
|
+
const units = checked && hasChoices ? (choices[item.value]?.length ? choices[item.value] : [item.choices![0].value]).slice(0, max) : [];
|
|
47
|
+
const fieldName = name ? `${name}.${item.value}` : undefined;
|
|
48
|
+
return (
|
|
49
|
+
<div class="ds-wswitch-item">
|
|
50
|
+
<label class="ds-wswitch">
|
|
51
|
+
<span>{item.label}</span>
|
|
52
|
+
<input type="checkbox" role="switch" name={name} value={item.value} checked={checked} disabled={item.disabled}
|
|
53
|
+
aria-controls={expandable ? panelId : undefined} aria-expanded={expandable ? String(checked) : undefined}
|
|
54
|
+
aria-describedby={expandable && item.description ? descId : undefined} />
|
|
55
|
+
</label>
|
|
56
|
+
{expandable && (
|
|
57
|
+
<div id={panelId} class="ds-wswitch-panel" hidden={!checked}>
|
|
58
|
+
{item.description && <p id={descId} class="ds-wswitch-desc">{item.description}</p>}
|
|
59
|
+
{hasChoices && (
|
|
60
|
+
<div class="ds-wswitch-units" role="group" aria-label={item.label} data-ds-units={item.value} data-label={item.label} data-max={max}>
|
|
61
|
+
{units.map((unit, unitIndex) => (
|
|
62
|
+
<div class="ds-wswitch-unit">
|
|
63
|
+
<WariSelect ariaLabel={`${item.label} ${unitIndex + 1}`} options={item.choices!} value={unit} name={fieldName}
|
|
64
|
+
disabled={disabled || item.disabled} />
|
|
65
|
+
<button type="button" class="ds-wswitch-unit-button" data-ds-unit-remove hidden={units.length < 2}
|
|
66
|
+
aria-label={`Quitar ${item.label} ${unitIndex + 1}`} disabled={disabled || item.disabled}><Fragment set:html={trash} /></button>
|
|
67
|
+
<button type="button" class="ds-wswitch-unit-button" data-ds-unit-add hidden={unitIndex !== units.length - 1 || units.length >= max}
|
|
68
|
+
aria-label={`Agregar otro ${item.label}`} disabled={disabled || item.disabled}><Fragment set:html={plus} /></button>
|
|
69
|
+
</div>
|
|
70
|
+
))}
|
|
71
|
+
<template data-ds-unit-template>
|
|
72
|
+
<div class="ds-wswitch-unit">
|
|
73
|
+
<WariSelect ariaLabel={`${item.label} 1`} options={item.choices!} value={item.choices![0].value} name={fieldName}
|
|
74
|
+
disabled={disabled || item.disabled} />
|
|
75
|
+
<button type="button" class="ds-wswitch-unit-button" data-ds-unit-remove aria-label={`Quitar ${item.label} 1`}
|
|
76
|
+
disabled={disabled || item.disabled}><Fragment set:html={trash} /></button>
|
|
77
|
+
<button type="button" class="ds-wswitch-unit-button" data-ds-unit-add aria-label={`Agregar otro ${item.label}`}
|
|
78
|
+
disabled={disabled || item.disabled}><Fragment set:html={plus} /></button>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
{hasFields && (
|
|
84
|
+
<div class="ds-wswitch-fields" role="group" aria-label={item.label} data-ds-fields={item.value}>
|
|
85
|
+
{item.fields!.map(field => (
|
|
86
|
+
<input class="ds-wswitch-field" type="text" inputmode={field.inputMode ?? 'text'} autocomplete="off"
|
|
87
|
+
aria-label={field.label} placeholder={field.placeholder} data-field={field.name}
|
|
88
|
+
data-fixed={field.width ? 'true' : undefined} style={field.width ? `width:${field.width}` : undefined}
|
|
89
|
+
value={checked ? (fields[item.value]?.[field.name] ?? '') : ''} disabled={disabled || item.disabled || !checked}
|
|
90
|
+
name={fieldName ? `${fieldName}.${field.name}` : undefined} />
|
|
91
|
+
))}
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
{!hasChoices && item.maxQuantity != null && (
|
|
95
|
+
<WariStepper ariaLabel={`Cantidad de ${item.label}`} variant="outlined" min={1} max={item.maxQuantity}
|
|
96
|
+
value={quantities[item.value] ?? 1} name={fieldName}
|
|
97
|
+
disabled={disabled || item.disabled || !checked} data-ds-quantity={item.value} />
|
|
98
|
+
)}
|
|
99
|
+
{item.note && <p class="ds-wswitch-note" role="note">{item.note}</p>}
|
|
100
|
+
</div>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
})}
|
|
27
105
|
</fieldset>
|
|
28
106
|
|
|
29
107
|
<script>
|
|
@@ -47,7 +47,7 @@ const modes = [{ value: 'hourly', label: hourlyLabel }, { value: 'delivery', lab
|
|
|
47
47
|
<WariSwitchList legend="Modalidad del viaje" orientation="horizontal" items={modes} name={field('mode')} disabled={disabled}
|
|
48
48
|
value={[value.hourly ? 'hourly' : '', value.delivery ? 'delivery' : ''].filter(Boolean)} />
|
|
49
49
|
</div>
|
|
50
|
-
<WariSwitchList legend="Extras" items={extras} value={value.extras} name={field('extras')} disabled={disabled} />
|
|
50
|
+
<WariSwitchList legend="Extras" items={extras} value={value.extras} quantities={value.extraQuantities ?? {}} choices={value.extraChoices ?? {}} fields={value.extraFields ?? {}} name={field('extras')} disabled={disabled} />
|
|
51
51
|
<WariStepper label={vehiclesLabel} value={value.vehicles} min={1} max={maxVehicles} name={field('vehicles')} disabled={disabled} />
|
|
52
52
|
<WariSelect label={paymentLabel} options={paymentMethods} value={value.payment} name={field('payment')} disabled={disabled} />
|
|
53
53
|
</div>
|
package/src/files.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type FileRejectionReason = 'type' | 'size' | 'count';
|
|
2
|
+
export interface FileRejection {
|
|
3
|
+
file: File;
|
|
4
|
+
reason: FileRejectionReason;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FileRules {
|
|
8
|
+
/** Same syntax as the input accept attribute: ".pdf", "image/*", "application/pdf". */
|
|
9
|
+
accept?: string;
|
|
10
|
+
/** Maximum size of each file, in bytes. */
|
|
11
|
+
maxBytes?: number;
|
|
12
|
+
/** Maximum number of files kept at once (only with multiple). */
|
|
13
|
+
maxFiles?: number;
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** 1536 → "1.5 KB". */
|
|
17
|
+
export declare function formatBytes(bytes: number): string;
|
|
18
|
+
/** True when the file matches one of the accept rules (or there are none). */
|
|
19
|
+
export declare function acceptsFile(file: Pick<File, 'name' | 'type'>, accept?: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Adds `incoming` to the `current` selection: with multiple the files are appended (without duplicates),
|
|
22
|
+
* otherwise the first valid file replaces the selection. Returns the kept files and why the others were left out.
|
|
23
|
+
*/
|
|
24
|
+
export declare function selectFiles(current: readonly File[], incoming: readonly File[], rules?: FileRules): {
|
|
25
|
+
files: File[];
|
|
26
|
+
rejections: FileRejection[];
|
|
27
|
+
};
|