@directo-ui/astro 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components.css +231 -0
- package/index.d.ts +47 -31
- package/index.js +46 -31
- package/package.json +5 -1
- package/src/close-icon.d.ts +2 -0
- package/src/close-icon.js +9 -0
- package/src/components/Alert.astro +2 -1
- package/src/components/Autocomplete.astro +107 -0
- package/src/components/Badge.astro +28 -13
- package/src/components/BottomSheet.astro +2 -1
- package/src/components/CellText.astro +17 -0
- package/src/components/Chip.astro +21 -0
- package/src/components/ChipGroup.astro +30 -0
- package/src/components/CloseButton.astro +18 -0
- package/src/components/DataTable.astro +168 -0
- package/src/components/DatePicker.astro +2 -1
- package/src/components/DateRangePicker.astro +107 -0
- package/src/components/Drawer.astro +41 -0
- package/src/components/Dropdown.astro +3 -2
- package/src/components/FieldLabel.astro +14 -0
- package/src/components/FileUpload.astro +153 -0
- package/src/components/FilterBar.astro +68 -0
- package/src/components/Modal.astro +4 -2
- package/src/components/MultiSelect.astro +2 -1
- package/src/components/Select.astro +2 -1
- package/src/components/Sidebar.astro +64 -0
- package/src/components/StatusTag.astro +4 -2
- package/src/components/Tabs.astro +60 -60
- package/src/components/TextField.astro +2 -1
- package/src/components/Textarea.astro +2 -1
- package/src/components/Timeline.astro +25 -0
- package/src/components/WariDateField.astro +2 -1
- package/src/components/WariDriverInbox.astro +74 -0
- package/src/components/WariSelect.astro +2 -1
- package/src/components/WariTimeField.astro +2 -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/toast.d.ts +2 -0
- package/src/toast.js +18 -7
- package/src/wari/inbox.d.ts +13 -0
- package/src/wari/inbox.js +28 -0
- package/wari.d.ts +3 -0
- package/wari.js +2 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Button from './Button.astro';
|
|
3
|
+
import Chip from './Chip.astro';
|
|
4
|
+
interface ActiveFilter {
|
|
5
|
+
label: string;
|
|
6
|
+
/** Link that removes the filter (server-rendered pages). */
|
|
7
|
+
removeHref?: string;
|
|
8
|
+
/** Without removeHref the chip is a button that emits ds-filter-remove with this id. */
|
|
9
|
+
id?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
label?: string;
|
|
14
|
+
activeFilters?: readonly ActiveFilter[];
|
|
15
|
+
/** Link that removes every filter. */
|
|
16
|
+
clearHref?: string;
|
|
17
|
+
/** Without clearHref: shows a button that emits ds-filters-clear. */
|
|
18
|
+
clearable?: boolean;
|
|
19
|
+
clearLabel?: string;
|
|
20
|
+
/** Number of results, announced to screen readers. */
|
|
21
|
+
resultCount?: number;
|
|
22
|
+
resultSingular?: string;
|
|
23
|
+
resultPlural?: string;
|
|
24
|
+
/** Renders a GET search form that sends the named fields to this URL (use "" for the same page). */
|
|
25
|
+
action?: string;
|
|
26
|
+
id?: string;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
label = 'Filtros', activeFilters = [], clearHref, clearable = false, clearLabel = 'Limpiar filtros',
|
|
32
|
+
resultCount, resultSingular = 'resultado', resultPlural = 'resultados', action, id, class: className,
|
|
33
|
+
} = Astro.props;
|
|
34
|
+
const Tag = action === undefined ? 'div' : 'form';
|
|
35
|
+
const formProps = action === undefined ? { role: 'group' } : { role: 'search', method: 'get', action };
|
|
36
|
+
---
|
|
37
|
+
<directo-filter-bar style="display: contents">
|
|
38
|
+
<Tag id={id} class:list={['ds-filter-bar', className]} aria-label={label} {...formProps}>
|
|
39
|
+
<div class="ds-filter-fields"><slot /></div>
|
|
40
|
+
{Astro.slots.has('actions') && <div class="ds-filter-actions"><slot name="actions" /></div>}
|
|
41
|
+
{(activeFilters.length > 0 || resultCount !== undefined) && <div class="ds-filter-active">
|
|
42
|
+
{resultCount !== undefined && <span class="ds-filter-count" role="status">{resultCount} {resultCount === 1 ? resultSingular : resultPlural}</span>}
|
|
43
|
+
{activeFilters.map(filter => filter.removeHref !== undefined
|
|
44
|
+
? <Chip href={filter.removeHref} removable aria-label={`Quitar filtro: ${filter.label}`}>{filter.label}</Chip>
|
|
45
|
+
: <Chip removable data-filter-id={filter.id} aria-label={`Quitar filtro: ${filter.label}`}>{filter.label}</Chip>)}
|
|
46
|
+
{activeFilters.length > 0 && clearHref && <Button href={clearHref} variant="text" size="sm">{clearLabel}</Button>}
|
|
47
|
+
{activeFilters.length > 0 && !clearHref && clearable && <Button variant="text" size="sm" data-filters-clear>{clearLabel}</Button>}
|
|
48
|
+
</div>}
|
|
49
|
+
</Tag>
|
|
50
|
+
</directo-filter-bar>
|
|
51
|
+
|
|
52
|
+
<script>
|
|
53
|
+
class DirectoFilterBarElement extends HTMLElement {
|
|
54
|
+
connectedCallback() { this.addEventListener('click', this.handleClick); }
|
|
55
|
+
disconnectedCallback() { this.removeEventListener('click', this.handleClick); }
|
|
56
|
+
|
|
57
|
+
private handleClick = (event: MouseEvent) => {
|
|
58
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
59
|
+
const chip = target?.closest<HTMLButtonElement>('button[data-filter-id]');
|
|
60
|
+
if (chip) {
|
|
61
|
+
this.dispatchEvent(new CustomEvent('ds-filter-remove', { bubbles: true, detail: chip.dataset.filterId }));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (target?.closest('button[data-filters-clear]')) this.dispatchEvent(new CustomEvent('ds-filters-clear', { bubbles: true }));
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (!customElements.get('directo-filter-bar')) customElements.define('directo-filter-bar', DirectoFilterBarElement);
|
|
68
|
+
</script>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
+
import Button from './Button.astro';
|
|
3
|
+
import CloseButton from './CloseButton.astro';
|
|
2
4
|
interface Props {
|
|
3
5
|
/** Used by triggers: <Button data-ds-open="my-id">. */
|
|
4
6
|
id: string;
|
|
@@ -22,9 +24,9 @@ const { id, title, description, size = 'md', closeLabel = 'Cerrar', open = false
|
|
|
22
24
|
<div class="ds-modal-body"><slot /></div>
|
|
23
25
|
<div class="ds-modal-footer">
|
|
24
26
|
<slot name="footer" />
|
|
25
|
-
{closeLabel && <
|
|
27
|
+
{closeLabel && <Button variant="secondary" data-ds-close>{closeLabel}</Button>}
|
|
26
28
|
</div>
|
|
27
|
-
<
|
|
29
|
+
<CloseButton class="ds-modal-close" label="Cerrar diálogo" data-ds-close />
|
|
28
30
|
</dialog>
|
|
29
31
|
|
|
30
32
|
<script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import StatusTag from './StatusTag.astro';
|
|
3
4
|
import { selectionState, selectionSummary } from '../wari/logic.js';
|
|
4
5
|
|
|
@@ -55,7 +56,7 @@ const allSelected = state === 'all' && Boolean(allLabel);
|
|
|
55
56
|
data-error={String(error)} data-disabled={String(disabled)} data-size={size}
|
|
56
57
|
data-max-tags={maxTags} data-summary={String(summary)} data-supporting-text={supportingText}
|
|
57
58
|
data-name={name} data-placeholder={placeholder} data-search-placeholder={searchPlaceholder}>
|
|
58
|
-
{label && <
|
|
59
|
+
{label && <FieldLabel id={`${id}-label`} for={id} required={required}>{label}</FieldLabel>}
|
|
59
60
|
<div class="ds-multiselect-anchor">
|
|
60
61
|
<div class="ds-input-shell">
|
|
61
62
|
<div class="ds-multiselect-values" aria-hidden="true" hidden={selected.length === 0}>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import type { HTMLAttributes } from 'astro/types';
|
|
3
4
|
|
|
4
5
|
export interface Option { value: string; label: string; disabled?: boolean }
|
|
@@ -17,7 +18,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
|
|
|
17
18
|
const hintId = supportingText ? `${fieldId}-hint` : undefined;
|
|
18
19
|
---
|
|
19
20
|
<div class="ds-input" data-error={String(error)} data-disabled={String(Boolean(disabled))} data-size={size}>
|
|
20
|
-
{label && <
|
|
21
|
+
{label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
|
|
21
22
|
<div class="ds-input-shell ds-select-native">
|
|
22
23
|
<select {...rest} id={fieldId} disabled={disabled} required={required} aria-invalid={error ? 'true' : undefined} aria-describedby={hintId}>
|
|
23
24
|
{placeholder && <option value="" disabled selected={!value}>{placeholder}</option>}
|
|
@@ -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>
|
|
@@ -5,14 +5,16 @@ interface Props {
|
|
|
5
5
|
/** Estado de Wari ("libre", "aceptado"…) o "todos". Sin contenido, muestra su nombre. */
|
|
6
6
|
status?: string;
|
|
7
7
|
size?: 'sm' | 'md';
|
|
8
|
+
/** Small dot of the same color before the text (Figma tables). */
|
|
9
|
+
dot?: boolean;
|
|
8
10
|
/** Colores propios para un estado que no está en la lista. */
|
|
9
11
|
color?: { background: string; foreground: string };
|
|
10
12
|
class?: string;
|
|
11
13
|
[attribute: `data-${string}`]: unknown;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
const { status, size = 'md', color, class: className, ...rest } = Astro.props;
|
|
16
|
+
const { status, size = 'md', dot = false, color, class: className, ...rest } = Astro.props;
|
|
15
17
|
const style = color ? `--ds-status-bg:${color.background};--ds-status-fg:${color.foreground}` : undefined;
|
|
16
18
|
const fallback = status && status !== 'todos' ? wariStatusLabel(status) : 'Todos';
|
|
17
19
|
---
|
|
18
|
-
<span class:list={['ds-status', className]} data-status={status} data-size={size} style={style} {...rest}><span><slot>{fallback}</slot></span></span>
|
|
20
|
+
<span class:list={['ds-status', className]} data-status={status} data-size={size} data-dot={dot ? '' : undefined} style={style} {...rest}><span><slot>{fallback}</slot></span></span>
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
---
|
|
2
|
-
export interface TabItem { value: string; label: string; disabled?: boolean }
|
|
3
|
-
interface Props {
|
|
4
|
-
/** Each item renders the slot with the same name as its value. */
|
|
5
|
-
items: TabItem[];
|
|
6
|
-
value?: string;
|
|
7
|
-
label?: string;
|
|
8
|
-
variant?: 'default' | 'pills' | 'enclosed';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const { items, value, label, variant = 'default' } = Astro.props;
|
|
12
|
-
const active = value ?? items.find(item => !item.disabled)?.value;
|
|
13
|
-
const base = `ds-tabs-${Math.random().toString(36).slice(2, 9)}`;
|
|
14
|
-
const panels = await Promise.all(items.map(item => Astro.slots.render(item.value)));
|
|
15
|
-
---
|
|
16
|
-
<div class="ds-tabs" data-ds-tabs>
|
|
17
|
-
<div class="ds-tabs-list" role="tablist" aria-label={label} data-variant={variant}>
|
|
18
|
-
{items.map(item => (
|
|
19
|
-
<button type="button" class="ds-tab" role="tab" id={`${base}-${item.value}-tab`} aria-controls={`${base}-${item.value}-panel`}
|
|
20
|
-
aria-selected={String(item.value === active)} tabindex={item.value === active ? 0 : -1} disabled={item.disabled}
|
|
21
|
-
data-value={item.value}>{item.label}</button>
|
|
22
|
-
))}
|
|
23
|
-
</div>
|
|
24
|
-
{items.map((item, index) => (
|
|
25
|
-
<div class="ds-tab-panel" role="tabpanel" tabindex="0" id={`${base}-${item.value}-panel`}
|
|
26
|
-
aria-labelledby={`${base}-${item.value}-tab`} hidden={item.value !== active} set:html={panels[index]} />
|
|
27
|
-
))}
|
|
28
|
-
</div>
|
|
29
|
-
|
|
30
|
-
<script>
|
|
31
|
-
function initTabs() {
|
|
32
|
-
document.querySelectorAll<HTMLElement>('[data-ds-tabs]:not([data-ds-ready])').forEach(root => {
|
|
33
|
-
root.dataset.dsReady = '';
|
|
34
|
-
const tabs = [...root.querySelectorAll<HTMLButtonElement>(':scope > .ds-tabs-list > [role="tab"]')];
|
|
35
|
-
const select = (tab: HTMLButtonElement, focus = false) => {
|
|
36
|
-
for (const item of tabs) {
|
|
37
|
-
const selected = item === tab;
|
|
38
|
-
item.setAttribute('aria-selected', String(selected));
|
|
39
|
-
item.tabIndex = selected ? 0 : -1;
|
|
40
|
-
const panel = document.getElementById(item.getAttribute('aria-controls') ?? '');
|
|
41
|
-
if (panel) panel.hidden = !selected;
|
|
42
|
-
}
|
|
43
|
-
if (focus) tab.focus();
|
|
44
|
-
root.dispatchEvent(new CustomEvent('ds-change', { detail: tab.dataset.value, bubbles: true }));
|
|
45
|
-
};
|
|
46
|
-
tabs.forEach(tab => tab.addEventListener('click', () => select(tab)));
|
|
47
|
-
root.querySelector(':scope > .ds-tabs-list')?.addEventListener('keydown', event => {
|
|
48
|
-
const key = (event as KeyboardEvent).key;
|
|
49
|
-
const enabled = tabs.filter(tab => !tab.disabled);
|
|
50
|
-
const index = enabled.indexOf(document.activeElement as HTMLButtonElement);
|
|
51
|
-
const next = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: enabled.length - 1 }[key];
|
|
52
|
-
if (next === undefined || !enabled.length) return;
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
select(enabled[(next + enabled.length) % enabled.length], true);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
initTabs();
|
|
59
|
-
document.addEventListener('astro:page-load', initTabs);
|
|
60
|
-
</script>
|
|
1
|
+
---
|
|
2
|
+
export interface TabItem { value: string; label: string; disabled?: boolean }
|
|
3
|
+
interface Props {
|
|
4
|
+
/** Each item renders the slot with the same name as its value. */
|
|
5
|
+
items: TabItem[];
|
|
6
|
+
value?: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
variant?: 'default' | 'pills' | 'enclosed' | 'segmented';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { items, value, label, variant = 'default' } = Astro.props;
|
|
12
|
+
const active = value ?? items.find(item => !item.disabled)?.value;
|
|
13
|
+
const base = `ds-tabs-${Math.random().toString(36).slice(2, 9)}`;
|
|
14
|
+
const panels = await Promise.all(items.map(item => Astro.slots.render(item.value)));
|
|
15
|
+
---
|
|
16
|
+
<div class="ds-tabs" data-ds-tabs>
|
|
17
|
+
<div class="ds-tabs-list" role="tablist" aria-label={label} data-variant={variant}>
|
|
18
|
+
{items.map(item => (
|
|
19
|
+
<button type="button" class="ds-tab" role="tab" id={`${base}-${item.value}-tab`} aria-controls={`${base}-${item.value}-panel`}
|
|
20
|
+
aria-selected={String(item.value === active)} tabindex={item.value === active ? 0 : -1} disabled={item.disabled}
|
|
21
|
+
data-value={item.value}>{item.label}</button>
|
|
22
|
+
))}
|
|
23
|
+
</div>
|
|
24
|
+
{items.map((item, index) => (
|
|
25
|
+
<div class="ds-tab-panel" role="tabpanel" tabindex="0" id={`${base}-${item.value}-panel`}
|
|
26
|
+
aria-labelledby={`${base}-${item.value}-tab`} hidden={item.value !== active} set:html={panels[index]} />
|
|
27
|
+
))}
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<script>
|
|
31
|
+
function initTabs() {
|
|
32
|
+
document.querySelectorAll<HTMLElement>('[data-ds-tabs]:not([data-ds-ready])').forEach(root => {
|
|
33
|
+
root.dataset.dsReady = '';
|
|
34
|
+
const tabs = [...root.querySelectorAll<HTMLButtonElement>(':scope > .ds-tabs-list > [role="tab"]')];
|
|
35
|
+
const select = (tab: HTMLButtonElement, focus = false) => {
|
|
36
|
+
for (const item of tabs) {
|
|
37
|
+
const selected = item === tab;
|
|
38
|
+
item.setAttribute('aria-selected', String(selected));
|
|
39
|
+
item.tabIndex = selected ? 0 : -1;
|
|
40
|
+
const panel = document.getElementById(item.getAttribute('aria-controls') ?? '');
|
|
41
|
+
if (panel) panel.hidden = !selected;
|
|
42
|
+
}
|
|
43
|
+
if (focus) tab.focus();
|
|
44
|
+
root.dispatchEvent(new CustomEvent('ds-change', { detail: tab.dataset.value, bubbles: true }));
|
|
45
|
+
};
|
|
46
|
+
tabs.forEach(tab => tab.addEventListener('click', () => select(tab)));
|
|
47
|
+
root.querySelector(':scope > .ds-tabs-list')?.addEventListener('keydown', event => {
|
|
48
|
+
const key = (event as KeyboardEvent).key;
|
|
49
|
+
const enabled = tabs.filter(tab => !tab.disabled);
|
|
50
|
+
const index = enabled.indexOf(document.activeElement as HTMLButtonElement);
|
|
51
|
+
const next = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: enabled.length - 1 }[key];
|
|
52
|
+
if (next === undefined || !enabled.length) return;
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
select(enabled[(next + enabled.length) % enabled.length], true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
initTabs();
|
|
59
|
+
document.addEventListener('astro:page-load', initTabs);
|
|
60
|
+
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import type { HTMLAttributes } from 'astro/types';
|
|
3
4
|
|
|
4
5
|
interface Props extends Omit<HTMLAttributes<'input'>, 'size'> {
|
|
@@ -13,7 +14,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
|
|
|
13
14
|
const hintId = supportingText ? `${fieldId}-hint` : undefined;
|
|
14
15
|
---
|
|
15
16
|
<div class="ds-input" data-error={String(error)} data-disabled={String(Boolean(disabled))} data-size={size}>
|
|
16
|
-
{label && <
|
|
17
|
+
{label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
|
|
17
18
|
<div class="ds-input-shell">
|
|
18
19
|
{Astro.slots.has('start') && <span class="ds-input-icon" aria-hidden="true"><slot name="start" /></span>}
|
|
19
20
|
<input {...rest} id={fieldId} type={type} disabled={disabled} required={required}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import type { HTMLAttributes } from 'astro/types';
|
|
3
4
|
|
|
4
5
|
interface Props extends HTMLAttributes<'textarea'> {
|
|
@@ -15,7 +16,7 @@ const fieldId = id ?? `ds-field-${Math.random().toString(36).slice(2, 9)}`;
|
|
|
15
16
|
const hintId = supportingText ? `${fieldId}-hint` : undefined;
|
|
16
17
|
---
|
|
17
18
|
<div class="ds-input" data-multiline="true" data-error={String(error)} data-disabled={String(Boolean(disabled))}>
|
|
18
|
-
{label && <
|
|
19
|
+
{label && <FieldLabel for={fieldId} required={required}>{label}</FieldLabel>}
|
|
19
20
|
<div class="ds-input-shell">
|
|
20
21
|
<textarea {...rest} id={fieldId} rows={rows} maxlength={maxlength} disabled={disabled} required={required}
|
|
21
22
|
aria-invalid={error ? 'true' : undefined} aria-describedby={hintId} data-ds-count={showCount && maxlength ? '' : undefined}>{value}</textarea>
|
|
@@ -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>}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import { formatDisplayDate, longDateLabel } from '../wari/datetime.js';
|
|
3
4
|
|
|
4
5
|
export interface Props {
|
|
@@ -34,7 +35,7 @@ const id = Astro.props.id ?? `ds-wdate-${Math.random().toString(36).slice(2, 9)}
|
|
|
34
35
|
<div class:list={['ds-input', 'ds-wfield', className]} data-ds-wfield="date" data-open="false" data-align={align}
|
|
35
36
|
data-error={String(error)} data-disabled={String(disabled)} data-min={min} data-max={max} data-locale={locale}
|
|
36
37
|
data-week-start={weekStartsOn} data-cancel-label={cancelLabel} data-ok-label={okLabel}>
|
|
37
|
-
{label && <
|
|
38
|
+
{label && <FieldLabel for={id} required={required}>{label}</FieldLabel>}
|
|
38
39
|
<div class="ds-wfield-anchor">
|
|
39
40
|
<div class="ds-input-shell">
|
|
40
41
|
<input id={id} type="text" inputmode="numeric" autocomplete="off" placeholder={placeholder} value={formatDisplayDate(value)}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Button from './Button.astro';
|
|
3
|
+
import ChipGroup from './ChipGroup.astro';
|
|
4
|
+
import Tabs from './Tabs.astro';
|
|
5
|
+
import { expandIconPath, funnelIconPath, wariInboxFilters, wariInboxTabs } from '../wari/inbox.js';
|
|
6
|
+
import type { WariInboxOption } from '../wari/inbox.js';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
label?: string;
|
|
10
|
+
tabs?: readonly WariInboxOption[];
|
|
11
|
+
/** Tab shown first. */
|
|
12
|
+
tab?: string;
|
|
13
|
+
/** Filter chips of each tab, by tab value. */
|
|
14
|
+
filters?: Readonly<Record<string, readonly WariInboxOption[]>>;
|
|
15
|
+
/** Shows "Filtros avanzados" (emits ds-advanced-filters). */
|
|
16
|
+
advancedFilters?: boolean;
|
|
17
|
+
/** Shows "Ver lista completa" (emits ds-view-all). */
|
|
18
|
+
viewAll?: boolean;
|
|
19
|
+
advancedFiltersLabel?: string;
|
|
20
|
+
viewAllLabel?: string;
|
|
21
|
+
class?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Wari "Bandeja interna del conductor": Tabs (segmented) + ChipGroup + Button around the content of each tab.
|
|
26
|
+
* Put each tab's table in a slot named like the tab: slot="historial", slot="mensajes"…
|
|
27
|
+
*/
|
|
28
|
+
const {
|
|
29
|
+
label = 'Bandeja interna del conductor', tabs = wariInboxTabs, tab, filters = wariInboxFilters, advancedFilters = true, viewAll = true,
|
|
30
|
+
advancedFiltersLabel = 'Filtros avanzados', viewAllLabel = 'Ver lista completa', class: className,
|
|
31
|
+
} = Astro.props;
|
|
32
|
+
const panels = await Promise.all(tabs.map(item => Astro.slots.render(item.value)));
|
|
33
|
+
---
|
|
34
|
+
<section class:list={['ds-winbox', className]} aria-label={label} data-ds-winbox>
|
|
35
|
+
<Tabs items={[...tabs]} value={tab} variant="segmented" label={label}>
|
|
36
|
+
{tabs.map((item, index) => <Fragment slot={item.value}>
|
|
37
|
+
<div class="ds-winbox-toolbar">
|
|
38
|
+
{(filters[item.value]?.length ?? 0) > 0 && <ChipGroup label={`Filtrar ${item.label.toLowerCase()}`} variant="brand"
|
|
39
|
+
options={filters[item.value]} data-tab={item.value} />}
|
|
40
|
+
{(advancedFilters || viewAll) && <div class="ds-winbox-actions">
|
|
41
|
+
<slot name="actions" />
|
|
42
|
+
{advancedFilters && <Button variant="secondary" data-winbox-action="advanced-filters" data-tab={item.value}>
|
|
43
|
+
<span class="ds-button-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d={funnelIconPath} /></svg></span>{advancedFiltersLabel}
|
|
44
|
+
</Button>}
|
|
45
|
+
{viewAll && <Button data-winbox-action="view-all" data-tab={item.value}>
|
|
46
|
+
<span class="ds-button-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor"
|
|
47
|
+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d={expandIconPath} /></svg></span>{viewAllLabel}
|
|
48
|
+
</Button>}
|
|
49
|
+
</div>}
|
|
50
|
+
</div>
|
|
51
|
+
<Fragment set:html={panels[index]} />
|
|
52
|
+
</Fragment>)}
|
|
53
|
+
</Tabs>
|
|
54
|
+
</section>
|
|
55
|
+
|
|
56
|
+
<script>
|
|
57
|
+
// Events on the section: ds-tab-change (tab), ds-filter-change ({ filter, tab }), ds-advanced-filters and ds-view-all (tab).
|
|
58
|
+
document.addEventListener('ds-change', event => {
|
|
59
|
+
const target = event.target instanceof HTMLElement ? event.target : null;
|
|
60
|
+
const inbox = target?.closest('[data-ds-winbox]');
|
|
61
|
+
if (!target || !inbox) return;
|
|
62
|
+
const detail = (event as CustomEvent<string>).detail;
|
|
63
|
+
if (target.matches('[data-ds-tabs]') && target.parentElement === inbox) {
|
|
64
|
+
inbox.dispatchEvent(new CustomEvent('ds-tab-change', { bubbles: true, detail }));
|
|
65
|
+
} else if (target.matches('[data-ds-chip-group][data-tab]')) {
|
|
66
|
+
inbox.dispatchEvent(new CustomEvent('ds-filter-change', { bubbles: true, detail: { filter: detail, tab: target.dataset.tab } }));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
document.addEventListener('click', event => {
|
|
70
|
+
const button = event.target instanceof Element ? event.target.closest<HTMLElement>('[data-ds-winbox] [data-winbox-action]') : null;
|
|
71
|
+
if (!button) return;
|
|
72
|
+
button.closest('[data-ds-winbox]')?.dispatchEvent(new CustomEvent(`ds-${button.dataset.winboxAction}`, { bubbles: true, detail: button.dataset.tab }));
|
|
73
|
+
});
|
|
74
|
+
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import WariServiceMeta from './WariServiceMeta.astro';
|
|
3
4
|
import { serviceMeta } from '../wari/trip.js';
|
|
4
5
|
import type { WariService } from '../wari/trip';
|
|
@@ -41,7 +42,7 @@ const selectedMeta = metaLabel(selected);
|
|
|
41
42
|
---
|
|
42
43
|
<div class:list={['ds-input', 'ds-wfield', 'ds-wselect', className]} data-ds-wselect data-open="false" data-error={String(error)}
|
|
43
44
|
data-disabled={String(disabled)} data-label="lg" data-placeholder={placeholder}>
|
|
44
|
-
{label && <
|
|
45
|
+
{label && <FieldLabel id={`${id}-label`} required={required}>{label}</FieldLabel>}
|
|
45
46
|
<div class="ds-wfield-anchor">
|
|
46
47
|
<div class="ds-input-shell" role="combobox" tabindex={disabled ? -1 : 0} aria-haspopup="listbox" aria-expanded="false"
|
|
47
48
|
aria-controls={`${id}-listbox`} aria-labelledby={label ? `${id}-label ${id}-value` : undefined} aria-label={label ? undefined : ariaLabel}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import FieldLabel from './FieldLabel.astro';
|
|
2
3
|
import { formatDisplayTime } from '../wari/datetime.js';
|
|
3
4
|
|
|
4
5
|
export interface Props {
|
|
@@ -28,7 +29,7 @@ const id = Astro.props.id ?? `ds-wtime-${Math.random().toString(36).slice(2, 9)}
|
|
|
28
29
|
---
|
|
29
30
|
<div class:list={['ds-input', 'ds-wfield', className]} data-ds-wfield="time" data-open="false" data-align={align}
|
|
30
31
|
data-error={String(error)} data-disabled={String(disabled)} data-title={title} data-cancel-label={cancelLabel} data-ok-label={okLabel}>
|
|
31
|
-
{label && <
|
|
32
|
+
{label && <FieldLabel for={id} required={required}>{label}</FieldLabel>}
|
|
32
33
|
<div class="ds-wfield-anchor">
|
|
33
34
|
<div class="ds-input-shell">
|
|
34
35
|
<input id={id} type="text" autocomplete="off" placeholder={placeholder} value={formatDisplayTime(value)}
|
package/src/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
|
+
};
|
package/src/files.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// File selection rules shared by FileUpload in React, Angular and Astro (same file in the three packages).
|
|
2
|
+
/** 1536 → "1.5 KB". */
|
|
3
|
+
export function formatBytes(bytes) {
|
|
4
|
+
if (!Number.isFinite(bytes) || bytes < 1024)
|
|
5
|
+
return `${Math.max(0, Math.round(bytes || 0))} B`;
|
|
6
|
+
const units = ['KB', 'MB', 'GB'];
|
|
7
|
+
let value = bytes / 1024;
|
|
8
|
+
let unit = 0;
|
|
9
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
10
|
+
value /= 1024;
|
|
11
|
+
unit++;
|
|
12
|
+
}
|
|
13
|
+
return `${Number(value.toFixed(value < 10 ? 1 : 0))} ${units[unit]}`;
|
|
14
|
+
}
|
|
15
|
+
/** True when the file matches one of the accept rules (or there are none). */
|
|
16
|
+
export function acceptsFile(file, accept) {
|
|
17
|
+
const rules = accept?.toLowerCase().split(',').map(rule => rule.trim()).filter(Boolean) ?? [];
|
|
18
|
+
if (!rules.length)
|
|
19
|
+
return true;
|
|
20
|
+
const type = file.type.toLowerCase();
|
|
21
|
+
const name = file.name.toLowerCase();
|
|
22
|
+
return rules.some(rule => rule.startsWith('.') ? name.endsWith(rule)
|
|
23
|
+
: rule.endsWith('/*') ? type.startsWith(rule.slice(0, -1)) : type === rule);
|
|
24
|
+
}
|
|
25
|
+
const sameFile = (a, b) => a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
|
|
26
|
+
/**
|
|
27
|
+
* Adds `incoming` to the `current` selection: with multiple the files are appended (without duplicates),
|
|
28
|
+
* otherwise the first valid file replaces the selection. Returns the kept files and why the others were left out.
|
|
29
|
+
*/
|
|
30
|
+
export function selectFiles(current, incoming, rules = {}) {
|
|
31
|
+
const rejections = [];
|
|
32
|
+
const files = rules.multiple ? [...current] : [];
|
|
33
|
+
const limit = rules.multiple ? (rules.maxFiles && rules.maxFiles > 0 ? Math.floor(rules.maxFiles) : Infinity) : 1;
|
|
34
|
+
for (const file of incoming) {
|
|
35
|
+
if (!acceptsFile(file, rules.accept)) {
|
|
36
|
+
rejections.push({ file, reason: 'type', message: `${file.name}: formato no admitido.` });
|
|
37
|
+
}
|
|
38
|
+
else if (rules.maxBytes !== undefined && file.size > rules.maxBytes) {
|
|
39
|
+
rejections.push({ file, reason: 'size', message: `${file.name}: supera el tamaño máximo (${formatBytes(rules.maxBytes)}).` });
|
|
40
|
+
}
|
|
41
|
+
else if (files.some(kept => sameFile(kept, file))) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
else if (files.length >= limit) {
|
|
45
|
+
rejections.push({ file, reason: 'count', message: `${file.name}: solo se permiten ${limit} archivo${limit === 1 ? '' : 's'}.` });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
files.push(file);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { files, rejections };
|
|
52
|
+
}
|
package/src/modal.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function initModals(root?: ParentNode): void;
|
|
2
|
-
export declare function openModal(id: string, opener?: HTMLElement): void;
|
|
3
|
-
export declare function closeModal(id: string): void;
|
|
1
|
+
export declare function initModals(root?: ParentNode | Event): void;
|
|
2
|
+
export declare function openModal(id: string, opener?: HTMLElement): void;
|
|
3
|
+
export declare function closeModal(id: string): void;
|