@directo-ui/astro 0.0.0-stage → 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.
- package/README.md +51 -2
- package/components.css +1159 -0
- package/index.d.ts +31 -0
- package/index.js +31 -0
- package/package.json +69 -4
- package/src/components/Accordion.astro +8 -0
- package/src/components/AccordionItem.astro +14 -0
- package/src/components/Alert.astro +42 -0
- package/src/components/Avatar.astro +21 -0
- package/src/components/Badge.astro +13 -0
- package/src/components/BottomSheet.astro +23 -0
- package/src/components/Breadcrumb.astro +18 -0
- package/src/components/Button.astro +31 -0
- package/src/components/Card.astro +25 -0
- package/src/components/Checkbox.astro +14 -0
- package/src/components/DatePicker.astro +25 -0
- package/src/components/Divider.astro +11 -0
- package/src/components/Dropdown.astro +71 -0
- package/src/components/EmptyState.astro +15 -0
- package/src/components/IconButton.astro +18 -0
- package/src/components/Modal.astro +34 -0
- package/src/components/MultiSelect.astro +108 -0
- package/src/components/Pagination.astro +30 -0
- package/src/components/Progress.astro +20 -0
- package/src/components/RadioGroup.astro +24 -0
- package/src/components/Select.astro +29 -0
- package/src/components/Skeleton.astro +13 -0
- package/src/components/Spinner.astro +17 -0
- package/src/components/StatusTag.astro +18 -0
- package/src/components/Switch.astro +13 -0
- package/src/components/Tabs.astro +60 -0
- package/src/components/TextField.astro +24 -0
- package/src/components/Textarea.astro +41 -0
- package/src/components/Toaster.astro +8 -0
- package/src/components/Tooltip.astro +31 -0
- package/src/components/WariDateField.astro +56 -0
- package/src/components/WariSchedule.astro +48 -0
- package/src/components/WariSelect.astro +76 -0
- package/src/components/WariServiceMeta.astro +19 -0
- package/src/components/WariStatusSelect.astro +20 -0
- package/src/components/WariStepper.astro +40 -0
- package/src/components/WariSwitchList.astro +33 -0
- package/src/components/WariTimeField.astro +50 -0
- package/src/components/WariTripAttributes.astro +60 -0
- package/src/modal.d.ts +3 -0
- package/src/modal.js +39 -0
- package/src/pagination.d.ts +2 -0
- package/src/pagination.js +16 -0
- package/src/toast.d.ts +9 -0
- package/src/toast.js +66 -0
- package/src/wari/datetime.d.ts +57 -0
- package/src/wari/datetime.js +151 -0
- package/src/wari/logic.d.ts +8 -0
- package/src/wari/logic.js +41 -0
- package/src/wari/multiselect.d.ts +2 -0
- package/src/wari/multiselect.js +169 -0
- package/src/wari/pickers.d.ts +2 -0
- package/src/wari/pickers.js +369 -0
- package/src/wari/statuses.d.ts +14 -0
- package/src/wari/statuses.js +15 -0
- package/src/wari/trip-client.d.ts +4 -0
- package/src/wari/trip-client.js +222 -0
- package/src/wari/trip.d.ts +56 -0
- package/src/wari/trip.js +69 -0
- package/styles.css +3 -0
- package/tokens.css +321 -0
- package/wari.d.ts +20 -0
- package/wari.js +16 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
import StatusTag from './StatusTag.astro';
|
|
3
|
+
import { selectionState, selectionSummary } from '../wari/logic.js';
|
|
4
|
+
|
|
5
|
+
export interface MultiSelectOption {
|
|
6
|
+
value: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** Muestra la opción como etiqueta de estado con ese color (p. ej. "libre"). */
|
|
9
|
+
status?: string;
|
|
10
|
+
color?: { background: string; foreground: string };
|
|
11
|
+
/** Texto secundario a la derecha de la etiqueta. */
|
|
12
|
+
description?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Props {
|
|
17
|
+
options: MultiSelectOption[];
|
|
18
|
+
/** Valores seleccionados al cargar la página. */
|
|
19
|
+
value?: string[];
|
|
20
|
+
label?: string;
|
|
21
|
+
ariaLabel?: string;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
searchPlaceholder?: string;
|
|
24
|
+
/** Texto de la fila que marca todo; `false` la oculta. */
|
|
25
|
+
allLabel?: string | false;
|
|
26
|
+
maxTags?: number;
|
|
27
|
+
/** Texto de ayuda fijo; si no se indica se muestra "N elementos seleccionados". */
|
|
28
|
+
supportingText?: string;
|
|
29
|
+
summary?: boolean;
|
|
30
|
+
emptyMessage?: string;
|
|
31
|
+
error?: boolean;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
required?: boolean;
|
|
34
|
+
/** Envía un campo oculto por valor seleccionado dentro de un <form>. */
|
|
35
|
+
name?: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
size?: 'sm' | 'md' | 'lg';
|
|
38
|
+
class?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const {
|
|
42
|
+
options, value = [], label, ariaLabel, placeholder = 'Seleccionar', searchPlaceholder = 'Buscar…', allLabel = 'Todos',
|
|
43
|
+
maxTags = 2, supportingText, summary = true, emptyMessage = 'Sin coincidencias', error = false, disabled = false,
|
|
44
|
+
required = false, name, size = 'md', class: className,
|
|
45
|
+
} = Astro.props;
|
|
46
|
+
const id = Astro.props.id ?? `ds-multiselect-${Math.random().toString(36).slice(2, 9)}`;
|
|
47
|
+
const selected = options.filter(option => value.includes(option.value));
|
|
48
|
+
const state = selectionState(value, options);
|
|
49
|
+
const asTags = options.some(option => option.status || option.color);
|
|
50
|
+
const hint = supportingText || (summary ? selectionSummary(selected.length) : '');
|
|
51
|
+
const showAll = Boolean(allLabel) && options.length > 0;
|
|
52
|
+
const allSelected = state === 'all' && Boolean(allLabel);
|
|
53
|
+
---
|
|
54
|
+
<div class:list={['ds-input', 'ds-multiselect', className]} data-ds-multiselect data-open="false"
|
|
55
|
+
data-error={String(error)} data-disabled={String(disabled)} data-size={size}
|
|
56
|
+
data-max-tags={maxTags} data-summary={String(summary)} data-supporting-text={supportingText}
|
|
57
|
+
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
|
+
<div class="ds-multiselect-anchor">
|
|
60
|
+
<div class="ds-input-shell">
|
|
61
|
+
<div class="ds-multiselect-values" aria-hidden="true" hidden={selected.length === 0}>
|
|
62
|
+
{allSelected
|
|
63
|
+
? (asTags ? <StatusTag status="todos" data-tag>{allLabel}</StatusTag> : <span class="ds-multiselect-option-label" data-tag>{allLabel}</span>)
|
|
64
|
+
: selected.slice(0, maxTags).map(option => asTags
|
|
65
|
+
? <StatusTag status={option.status} color={option.color} data-tag>{option.label}</StatusTag>
|
|
66
|
+
: <span class="ds-multiselect-option-label" data-tag>{option.label}</span>)}
|
|
67
|
+
{!allSelected && selected.length > maxTags && <span class="ds-multiselect-more">+{selected.length - maxTags}</span>}
|
|
68
|
+
</div>
|
|
69
|
+
<input id={id} class="ds-multiselect-input" type="text" role="combobox" autocomplete="off"
|
|
70
|
+
aria-expanded="false" aria-controls={`${id}-listbox`} aria-autocomplete="list"
|
|
71
|
+
aria-label={label ? undefined : ariaLabel} aria-invalid={error ? 'true' : undefined} aria-required={required ? 'true' : undefined}
|
|
72
|
+
aria-describedby={hint ? `${id}-hint` : undefined}
|
|
73
|
+
placeholder={selected.length ? '' : placeholder} disabled={disabled} />
|
|
74
|
+
<button type="button" class="ds-multiselect-caret" tabindex="-1" aria-hidden="true" disabled={disabled}>
|
|
75
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m4 6 4 4 4-4" /></svg>
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
<ul id={`${id}-listbox`} class="ds-multiselect-list" role="listbox" aria-multiselectable="true" hidden
|
|
79
|
+
aria-labelledby={label ? `${id}-label` : undefined} aria-label={label ? undefined : ariaLabel}>
|
|
80
|
+
{showAll && (
|
|
81
|
+
<li id={`${id}-option-all`} role="option" class="ds-multiselect-option" data-all
|
|
82
|
+
aria-selected={String(state === 'all')} data-indeterminate={String(state === 'some')}>
|
|
83
|
+
<span class="ds-multiselect-check" aria-hidden="true"></span>
|
|
84
|
+
{asTags ? <StatusTag status="todos" data-tag>{allLabel}</StatusTag> : <span class="ds-multiselect-option-label" data-tag>{allLabel}</span>}
|
|
85
|
+
</li>
|
|
86
|
+
)}
|
|
87
|
+
{options.map((option, index) => (
|
|
88
|
+
<li id={`${id}-option-${index}`} role="option" class="ds-multiselect-option" data-value={option.value} data-label={option.label}
|
|
89
|
+
aria-selected={String(value.includes(option.value))} aria-disabled={option.disabled ? 'true' : undefined}>
|
|
90
|
+
<span class="ds-multiselect-check" aria-hidden="true"></span>
|
|
91
|
+
{asTags
|
|
92
|
+
? <StatusTag status={option.status} color={option.color} data-tag>{option.label}</StatusTag>
|
|
93
|
+
: <span class="ds-multiselect-option-label" data-tag>{option.label}</span>}
|
|
94
|
+
{option.description && <span class="ds-multiselect-option-label">{option.description}</span>}
|
|
95
|
+
</li>
|
|
96
|
+
))}
|
|
97
|
+
<li class="ds-multiselect-empty" role="presentation" hidden>{emptyMessage}</li>
|
|
98
|
+
</ul>
|
|
99
|
+
</div>
|
|
100
|
+
<small id={`${id}-hint`} class="ds-multiselect-hint" aria-live="polite" hidden={!hint}>{hint}</small>
|
|
101
|
+
<span class="ds-multiselect-inputs">{name && value.map(item => <input type="hidden" name={name} value={item} />)}</span>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<script>
|
|
105
|
+
import { initMultiSelects } from '../wari/multiselect.js';
|
|
106
|
+
initMultiSelects();
|
|
107
|
+
document.addEventListener('astro:page-load', () => initMultiSelects());
|
|
108
|
+
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { paginationRange } from '../pagination.js';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
page: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
/** URL pattern; "{page}" is replaced, e.g. "/blog/{page}" or "?page={page}". */
|
|
8
|
+
href: string;
|
|
9
|
+
siblings?: number;
|
|
10
|
+
variant?: 'default' | 'outlined';
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { page, totalPages, href, siblings = 1, variant = 'default', label = 'Paginación' } = Astro.props;
|
|
15
|
+
const url = (target: number) => href.replace('{page}', String(target));
|
|
16
|
+
const tokens = paginationRange(page, totalPages, siblings);
|
|
17
|
+
---
|
|
18
|
+
<nav class="ds-pagination" aria-label={label} data-variant={variant}>
|
|
19
|
+
<ul>
|
|
20
|
+
<li>{page > 1
|
|
21
|
+
? <a class="ds-page" href={url(page - 1)} rel="prev" aria-label="Página anterior">‹</a>
|
|
22
|
+
: <span class="ds-page" aria-disabled="true" aria-hidden="true">‹</span>}</li>
|
|
23
|
+
{tokens.map(token => typeof token === 'number'
|
|
24
|
+
? <li><a class="ds-page" href={url(token)} aria-current={token === page ? 'page' : undefined} aria-label={`Página ${token}`}>{token}</a></li>
|
|
25
|
+
: <li><span class="ds-page-ellipsis" aria-hidden="true">…</span></li>)}
|
|
26
|
+
<li>{page < totalPages
|
|
27
|
+
? <a class="ds-page" href={url(page + 1)} rel="next" aria-label="Página siguiente">›</a>
|
|
28
|
+
: <span class="ds-page" aria-disabled="true" aria-hidden="true">›</span>}</li>
|
|
29
|
+
</ul>
|
|
30
|
+
</nav>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
value?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
label?: string;
|
|
6
|
+
showValue?: boolean;
|
|
7
|
+
size?: 'sm' | 'md' | 'lg';
|
|
8
|
+
variant?: 'primary' | 'success' | 'warning' | 'error';
|
|
9
|
+
indeterminate?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { value = 0, max = 100, label, showValue = true, size = 'md', variant = 'primary', indeterminate = false } = Astro.props;
|
|
13
|
+
const safeMax = max > 0 ? max : 100;
|
|
14
|
+
const percentage = Math.round(Math.min(100, Math.max(0, (Number.isFinite(value) ? value : 0) / safeMax * 100)));
|
|
15
|
+
---
|
|
16
|
+
<div class="ds-progress" role="progressbar" data-size={size} data-variant={variant} data-indeterminate={indeterminate ? 'true' : undefined}
|
|
17
|
+
aria-label={label ?? 'Progreso'} aria-valuemin="0" aria-valuemax="100" aria-valuenow={indeterminate ? undefined : percentage}>
|
|
18
|
+
{label && <span class="ds-progress-header"><span>{label}</span>{showValue && !indeterminate && <span>{percentage}%</span>}</span>}
|
|
19
|
+
<span class="ds-progress-track" aria-hidden="true"><span class="ds-progress-value" style={`width:${percentage}%`} /></span>
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
export interface Option { value: string; label: string; disabled?: boolean }
|
|
3
|
+
interface Props {
|
|
4
|
+
name: string;
|
|
5
|
+
options: Option[];
|
|
6
|
+
label?: string;
|
|
7
|
+
value?: string;
|
|
8
|
+
orientation?: 'vertical' | 'horizontal';
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { name, options, label, value, orientation = 'vertical', disabled = false, required = false } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
<fieldset class="ds-radio-group" data-orientation={orientation} disabled={disabled}>
|
|
16
|
+
{label && <legend>{label}</legend>}
|
|
17
|
+
{options.map((option, index) => (
|
|
18
|
+
<label class="ds-choice">
|
|
19
|
+
<input type="radio" name={name} value={option.value} checked={option.value === value}
|
|
20
|
+
disabled={option.disabled} required={required && index === 0} />
|
|
21
|
+
{option.label}
|
|
22
|
+
</label>
|
|
23
|
+
))}
|
|
24
|
+
</fieldset>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
|
|
4
|
+
export interface Option { value: string; label: string; disabled?: boolean }
|
|
5
|
+
interface Props extends Omit<HTMLAttributes<'select'>, 'size'> {
|
|
6
|
+
label?: string;
|
|
7
|
+
supportingText?: string;
|
|
8
|
+
error?: boolean;
|
|
9
|
+
options?: Option[];
|
|
10
|
+
value?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
size?: 'sm' | 'md' | 'lg';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { label, supportingText, error = false, options = [], value, placeholder, size = 'md', id, disabled = false, required = false, ...rest } = Astro.props;
|
|
16
|
+
const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
|
|
17
|
+
const hintId = supportingText ? `${fieldId}-hint` : undefined;
|
|
18
|
+
---
|
|
19
|
+
<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
|
+
<div class="ds-input-shell ds-select-native">
|
|
22
|
+
<select {...rest} id={fieldId} disabled={disabled} required={required} aria-invalid={error ? 'true' : undefined} aria-describedby={hintId}>
|
|
23
|
+
{placeholder && <option value="" disabled selected={!value}>{placeholder}</option>}
|
|
24
|
+
{options.map(option => <option value={option.value} disabled={option.disabled} selected={option.value === value}>{option.label}</option>)}
|
|
25
|
+
<slot />
|
|
26
|
+
</select>
|
|
27
|
+
</div>
|
|
28
|
+
{supportingText && <small id={hintId}>{supportingText}</small>}
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
lines?: number;
|
|
4
|
+
avatar?: boolean;
|
|
5
|
+
label?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { lines = 3, avatar = false, label = 'Cargando contenido' } = Astro.props;
|
|
9
|
+
---
|
|
10
|
+
<div role="status" aria-label={label} style={avatar ? 'display:flex;gap:12px;align-items:flex-start' : undefined}>
|
|
11
|
+
{avatar && <span class="ds-skeleton-circle" aria-hidden="true" />}
|
|
12
|
+
<span class="ds-skeleton" aria-hidden="true">{Array.from({ length: Math.max(1, lines) }, () => <span />)}</span>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props {
|
|
3
|
+
size?: 'sm' | 'md' | 'lg';
|
|
4
|
+
label?: string;
|
|
5
|
+
showLabel?: boolean;
|
|
6
|
+
/** "dots" renders three pulsing dots. */
|
|
7
|
+
variant?: 'spinner' | 'dots';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { size = 'md', label = 'Cargando', showLabel = false, variant = 'spinner' } = Astro.props;
|
|
11
|
+
---
|
|
12
|
+
<span class="ds-loading" role="status" aria-label={showLabel ? undefined : label}>
|
|
13
|
+
{variant === 'dots'
|
|
14
|
+
? <span class="ds-loading-dots" aria-hidden="true"><span /><span /><span /></span>
|
|
15
|
+
: <span class="ds-spinner" data-size={size} aria-hidden="true" />}
|
|
16
|
+
{showLabel && <span>{label}</span>}
|
|
17
|
+
</span>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { wariStatusLabel } from '../wari/statuses.js';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
/** Estado de Wari ("libre", "aceptado"…) o "todos". Sin contenido, muestra su nombre. */
|
|
6
|
+
status?: string;
|
|
7
|
+
size?: 'sm' | 'md';
|
|
8
|
+
/** Colores propios para un estado que no está en la lista. */
|
|
9
|
+
color?: { background: string; foreground: string };
|
|
10
|
+
class?: string;
|
|
11
|
+
[attribute: `data-${string}`]: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { status, size = 'md', color, class: className, ...rest } = Astro.props;
|
|
15
|
+
const style = color ? `--ds-status-bg:${color.background};--ds-status-fg:${color.foreground}` : undefined;
|
|
16
|
+
const fallback = status && status !== 'todos' ? wariStatusLabel(status) : 'Todos';
|
|
17
|
+
---
|
|
18
|
+
<span class:list={['ds-status', className]} data-status={status} data-size={size} style={style} {...rest}><span><slot>{fallback}</slot></span></span>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<'input'>, 'type' | 'role'> {
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const { label, class: className, ...rest } = Astro.props;
|
|
9
|
+
---
|
|
10
|
+
<label class:list={['ds-choice', className]}>
|
|
11
|
+
<input {...rest} type="checkbox" role="switch" />
|
|
12
|
+
{label}
|
|
13
|
+
</label>
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +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>
|
|
@@ -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>
|