@faast-app/ui 0.0.0-stage → 0.7.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 +13 -2
- package/dist/components/Alert.d.ts +30 -0
- package/dist/components/Alert.js +19 -0
- package/dist/components/AppShell.d.ts +63 -0
- package/dist/components/AppShell.js +80 -0
- package/dist/components/Avatar.d.ts +18 -0
- package/dist/components/Avatar.js +21 -0
- package/dist/components/Badge.d.ts +24 -0
- package/dist/components/Badge.js +10 -0
- package/dist/components/Button.d.ts +71 -0
- package/dist/components/Button.js +40 -0
- package/dist/components/Card.d.ts +23 -0
- package/dist/components/Card.js +17 -0
- package/dist/components/Chip.d.ts +16 -0
- package/dist/components/Chip.js +9 -0
- package/dist/components/Choice.d.ts +38 -0
- package/dist/components/Choice.js +53 -0
- package/dist/components/Dialog.d.ts +44 -0
- package/dist/components/Dialog.js +51 -0
- package/dist/components/EmptyState.d.ts +16 -0
- package/dist/components/EmptyState.js +8 -0
- package/dist/components/FileDropArea.d.ts +62 -0
- package/dist/components/FileDropArea.js +90 -0
- package/dist/components/FormField.d.ts +35 -0
- package/dist/components/FormField.js +32 -0
- package/dist/components/HelpMenu.d.ts +46 -0
- package/dist/components/HelpMenu.js +104 -0
- package/dist/components/Icon.d.ts +24 -0
- package/dist/components/Icon.js +195 -0
- package/dist/components/Input.d.ts +37 -0
- package/dist/components/Input.js +31 -0
- package/dist/components/KpiStrip.d.ts +32 -0
- package/dist/components/KpiStrip.js +14 -0
- package/dist/components/LockScreen.d.ts +34 -0
- package/dist/components/LockScreen.js +22 -0
- package/dist/components/Logo.d.ts +27 -0
- package/dist/components/Logo.js +12 -0
- package/dist/components/Navigation.d.ts +37 -0
- package/dist/components/Navigation.js +29 -0
- package/dist/components/OptionList.d.ts +27 -0
- package/dist/components/OptionList.js +18 -0
- package/dist/components/OtpInput.d.ts +31 -0
- package/dist/components/OtpInput.js +102 -0
- package/dist/components/Pagination.d.ts +31 -0
- package/dist/components/Pagination.js +41 -0
- package/dist/components/PasswordField.d.ts +32 -0
- package/dist/components/PasswordField.js +29 -0
- package/dist/components/SegmentedControl.d.ts +35 -0
- package/dist/components/SegmentedControl.js +52 -0
- package/dist/components/Select.d.ts +15 -0
- package/dist/components/Select.js +10 -0
- package/dist/components/SessionTimeoutDialog.d.ts +39 -0
- package/dist/components/SessionTimeoutDialog.js +62 -0
- package/dist/components/Spinner.d.ts +25 -0
- package/dist/components/Spinner.js +15 -0
- package/dist/components/StatTiles.d.ts +35 -0
- package/dist/components/StatTiles.js +12 -0
- package/dist/components/Stepper.d.ts +26 -0
- package/dist/components/Stepper.js +26 -0
- package/dist/components/StickyActionBar.d.ts +28 -0
- package/dist/components/StickyActionBar.js +12 -0
- package/dist/components/Table.d.ts +69 -0
- package/dist/components/Table.js +73 -0
- package/dist/components/TenantMark.d.ts +27 -0
- package/dist/components/TenantMark.js +15 -0
- package/dist/components/Timeline.d.ts +31 -0
- package/dist/components/Timeline.js +18 -0
- package/dist/components/Toast.d.ts +43 -0
- package/dist/components/Toast.js +46 -0
- package/dist/components/Toggletip.d.ts +26 -0
- package/dist/components/Toggletip.js +47 -0
- package/dist/components/Tooltip.d.ts +24 -0
- package/dist/components/Tooltip.js +73 -0
- package/dist/components/Tour.d.ts +66 -0
- package/dist/components/Tour.js +161 -0
- package/dist/components/TourOffer.d.ts +22 -0
- package/dist/components/TourOffer.js +33 -0
- package/dist/components/WelcomeDialog.d.ts +45 -0
- package/dist/components/WelcomeDialog.js +38 -0
- package/dist/data-table/components/ClientDataTable.d.ts +22 -0
- package/dist/data-table/components/ClientDataTable.js +29 -0
- package/dist/data-table/components/DataTableFooter.d.ts +11 -0
- package/dist/data-table/components/DataTableFooter.js +16 -0
- package/dist/data-table/components/DataTableView.d.ts +9 -0
- package/dist/data-table/components/DataTableView.js +95 -0
- package/dist/data-table/components/ServerDataTable.d.ts +16 -0
- package/dist/data-table/components/ServerDataTable.js +17 -0
- package/dist/data-table/core/columnVisibility.d.ts +15 -0
- package/dist/data-table/core/columnVisibility.js +34 -0
- package/dist/data-table/core/constants.d.ts +20 -0
- package/dist/data-table/core/constants.js +21 -0
- package/dist/data-table/core/filters/registry.d.ts +33 -0
- package/dist/data-table/core/filters/registry.js +393 -0
- package/dist/data-table/core/filters/types.d.ts +88 -0
- package/dist/data-table/core/filters/types.js +1 -0
- package/dist/data-table/core/group.d.ts +15 -0
- package/dist/data-table/core/group.js +73 -0
- package/dist/data-table/core/paginate.d.ts +13 -0
- package/dist/data-table/core/paginate.js +27 -0
- package/dist/data-table/core/query.d.ts +65 -0
- package/dist/data-table/core/query.js +138 -0
- package/dist/data-table/core/search.d.ts +10 -0
- package/dist/data-table/core/search.js +35 -0
- package/dist/data-table/core/selection.d.ts +24 -0
- package/dist/data-table/core/selection.js +59 -0
- package/dist/data-table/core/sort.d.ts +14 -0
- package/dist/data-table/core/sort.js +41 -0
- package/dist/data-table/core/text.d.ts +5 -0
- package/dist/data-table/core/text.js +27 -0
- package/dist/data-table/core/types.d.ts +40 -0
- package/dist/data-table/core/types.js +1 -0
- package/dist/data-table/core/url.d.ts +43 -0
- package/dist/data-table/core/url.js +194 -0
- package/dist/data-table/hooks/common.d.ts +14 -0
- package/dist/data-table/hooks/common.js +30 -0
- package/dist/data-table/hooks/small-hooks.d.ts +12 -0
- package/dist/data-table/hooks/small-hooks.js +111 -0
- package/dist/data-table/hooks/useClientDataTable.d.ts +35 -0
- package/dist/data-table/hooks/useClientDataTable.js +311 -0
- package/dist/data-table/hooks/useServerDataTable.d.ts +38 -0
- package/dist/data-table/hooks/useServerDataTable.js +209 -0
- package/dist/data-table/hooks/useServerRows.d.ts +27 -0
- package/dist/data-table/hooks/useServerRows.js +82 -0
- package/dist/data-table/hooks/useTableState.d.ts +39 -0
- package/dist/data-table/hooks/useTableState.js +219 -0
- package/dist/data-table/index.d.ts +42 -0
- package/dist/data-table/index.js +22 -0
- package/dist/data-table/labels.d.ts +77 -0
- package/dist/data-table/labels.js +77 -0
- package/dist/data-table/toolbar/ActiveFilters.d.ts +10 -0
- package/dist/data-table/toolbar/ActiveFilters.js +53 -0
- package/dist/data-table/toolbar/BulkActionBar.d.ts +15 -0
- package/dist/data-table/toolbar/BulkActionBar.js +22 -0
- package/dist/data-table/toolbar/ColumnVisibilityDialog.d.ts +7 -0
- package/dist/data-table/toolbar/ColumnVisibilityDialog.js +15 -0
- package/dist/data-table/toolbar/DataTableToolbar.d.ts +19 -0
- package/dist/data-table/toolbar/DataTableToolbar.js +12 -0
- package/dist/data-table/toolbar/FilterFields.d.ts +11 -0
- package/dist/data-table/toolbar/FilterFields.js +58 -0
- package/dist/data-table/toolbar/FiltersControl.d.ts +34 -0
- package/dist/data-table/toolbar/FiltersControl.js +70 -0
- package/dist/data-table/toolbar/PageSizeSelect.d.ts +7 -0
- package/dist/data-table/toolbar/PageSizeSelect.js +12 -0
- package/dist/data-table/toolbar/QuickFilters.d.ts +7 -0
- package/dist/data-table/toolbar/QuickFilters.js +9 -0
- package/dist/data-table/toolbar/ResultsCount.d.ts +7 -0
- package/dist/data-table/toolbar/ResultsCount.js +9 -0
- package/dist/data-table/toolbar/SearchField.d.ts +36 -0
- package/dist/data-table/toolbar/SearchField.js +64 -0
- package/dist/data-table/toolbar/SortSelect.d.ts +10 -0
- package/dist/data-table/toolbar/SortSelect.js +30 -0
- package/dist/data-table/types.d.ts +334 -0
- package/dist/data-table/types.js +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +49 -0
- package/dist/styles.css +4668 -0
- package/dist/theme/ThemeProvider.d.ts +33 -0
- package/dist/theme/ThemeProvider.js +77 -0
- package/dist/theme/ThemeToggle.d.ts +16 -0
- package/dist/theme/ThemeToggle.js +27 -0
- package/dist/utils/cx.d.ts +2 -0
- package/dist/utils/cx.js +4 -0
- package/dist/utils/devWarn.d.ts +2 -0
- package/dist/utils/devWarn.js +10 -0
- package/dist/utils/tourGeometry.d.ts +61 -0
- package/dist/utils/tourGeometry.js +135 -0
- package/dist/utils/useFloatingPosition.d.ts +9 -0
- package/dist/utils/useFloatingPosition.js +45 -0
- package/dist/utils/useModalDialog.d.ts +7 -0
- package/dist/utils/useModalDialog.js +49 -0
- package/dist/utils/useTourAnchorRect.d.ts +6 -0
- package/dist/utils/useTourAnchorRect.js +40 -0
- package/package.json +50 -4
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef, useState, } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { mergeDescribedBy } from './FormField.js';
|
|
5
|
+
const onlyDigits = (text) => text.replace(/\D/g, '');
|
|
6
|
+
/**
|
|
7
|
+
* One-time code entry as N single-digit cells in a fieldset. Paste (or the platform's
|
|
8
|
+
* one-time-code autofill) of the whole code fills every cell; arrows, Home/End and
|
|
9
|
+
* Backspace move between cells.
|
|
10
|
+
*/
|
|
11
|
+
export function OtpInput({ length = 6, value: valueProp, defaultValue = '', onChange, onComplete, legend = 'Código de verificación', hideLegend = false, hint, error, disabled = false, name, digitLabel = (position, total) => `Dígito ${position} de ${total}`, id, className, }) {
|
|
12
|
+
const autoId = useId();
|
|
13
|
+
const baseId = id ?? `faast-otp-${autoId}`;
|
|
14
|
+
const hintId = hint ? `${baseId}-hint` : undefined;
|
|
15
|
+
const errorId = error ? `${baseId}-error` : undefined;
|
|
16
|
+
const [inner, setInner] = useState(() => onlyDigits(defaultValue).slice(0, length));
|
|
17
|
+
const value = onlyDigits(valueProp ?? inner).slice(0, length);
|
|
18
|
+
const cells = useRef([]);
|
|
19
|
+
const focusCell = (index) => {
|
|
20
|
+
const target = cells.current[Math.max(0, Math.min(length - 1, index))];
|
|
21
|
+
target?.focus();
|
|
22
|
+
target?.select();
|
|
23
|
+
};
|
|
24
|
+
const commit = (next) => {
|
|
25
|
+
const clean = onlyDigits(next).slice(0, length);
|
|
26
|
+
if (valueProp === undefined)
|
|
27
|
+
setInner(clean);
|
|
28
|
+
onChange?.(clean);
|
|
29
|
+
if (clean.length === length && clean !== value)
|
|
30
|
+
onComplete?.(clean);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The code behaves like one text value spread over cells: writing at a cell past the end
|
|
34
|
+
* appends, writing over a digit replaces it, and the next cell takes focus.
|
|
35
|
+
*/
|
|
36
|
+
const writeAt = (index, digits) => {
|
|
37
|
+
if (!digits)
|
|
38
|
+
return;
|
|
39
|
+
const start = Math.min(index, value.length);
|
|
40
|
+
commit(value.slice(0, start) + digits + value.slice(start + digits.length));
|
|
41
|
+
focusCell(Math.min(start + digits.length, length - 1));
|
|
42
|
+
};
|
|
43
|
+
/** Removes the digit at `index`; later digits shift left. */
|
|
44
|
+
const clearAt = (index) => {
|
|
45
|
+
commit(value.slice(0, index) + value.slice(index + 1));
|
|
46
|
+
};
|
|
47
|
+
const onKeyDown = (index) => (event) => {
|
|
48
|
+
switch (event.key) {
|
|
49
|
+
case 'Backspace':
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
if (value[index] !== undefined)
|
|
52
|
+
clearAt(index);
|
|
53
|
+
else if (index > 0) {
|
|
54
|
+
clearAt(index - 1);
|
|
55
|
+
focusCell(index - 1);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'Delete':
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
clearAt(index);
|
|
61
|
+
break;
|
|
62
|
+
case 'ArrowLeft':
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
focusCell(index - 1);
|
|
65
|
+
break;
|
|
66
|
+
case 'ArrowRight':
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
focusCell(index + 1);
|
|
69
|
+
break;
|
|
70
|
+
case 'Home':
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
focusCell(0);
|
|
73
|
+
break;
|
|
74
|
+
case 'End':
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
focusCell(length - 1);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const onPaste = (index) => (event) => {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
const digits = onlyDigits(event.clipboardData.getData('text'));
|
|
83
|
+
// A full code always fills from the first cell.
|
|
84
|
+
writeAt(digits.length >= length ? 0 : index, digits);
|
|
85
|
+
};
|
|
86
|
+
const describedBy = mergeDescribedBy(hintId, errorId);
|
|
87
|
+
return (_jsxs("fieldset", { className: cx('faast-otp', Boolean(error) && 'faast-otp--invalid', className), id: baseId, disabled: disabled, children: [_jsx("legend", { className: cx('faast-otp__legend', hideLegend && 'faast-sr-only'), children: legend }), _jsx("div", { className: "faast-otp__cells faast-num", children: Array.from({ length }, (_, index) => (_jsx("input", { ref: (node) => {
|
|
88
|
+
cells.current[index] = node;
|
|
89
|
+
}, className: "faast-input faast-otp__cell", type: "text", inputMode: "numeric", pattern: "[0-9]*", autoComplete: index === 0 ? 'one-time-code' : 'off', spellCheck: false, autoCorrect: "off", "aria-label": digitLabel(index + 1, length), "aria-invalid": error ? true : undefined, "aria-describedby": describedBy, value: value[index] ?? '', onChange: (event) => {
|
|
90
|
+
const digits = onlyDigits(event.target.value);
|
|
91
|
+
if (!digits) {
|
|
92
|
+
clearAt(index);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Typing over a filled cell yields two characters; keep the new one. Autofill
|
|
96
|
+
// or an IME may deliver the whole code into one cell.
|
|
97
|
+
const incoming = digits.length === 2 && value[index] !== undefined
|
|
98
|
+
? digits.replace(value[index], '') || digits[1]
|
|
99
|
+
: digits;
|
|
100
|
+
writeAt(digits.length >= length ? 0 : index, incoming);
|
|
101
|
+
}, onKeyDown: onKeyDown(index), onPaste: onPaste(index), onFocus: (event) => event.target.select(), "data-testid": `otp-cell-${index + 1}` }, index))) }), name && _jsx("input", { type: "hidden", name: name, value: value }), hint && (_jsx("p", { className: "faast-field__hint", id: hintId, children: hint })), _jsx("p", { className: "faast-field__error", id: `${baseId}-error`, "aria-live": "polite", children: error })] }));
|
|
102
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface PaginationLabels {
|
|
2
|
+
nav: string;
|
|
3
|
+
previous: string;
|
|
4
|
+
next: string;
|
|
5
|
+
/** Accessible name of a page button. */
|
|
6
|
+
page: (page: number) => string;
|
|
7
|
+
/** Compact summary shown on phones. */
|
|
8
|
+
summary: (page: number, pageCount: number) => string;
|
|
9
|
+
}
|
|
10
|
+
export interface PaginationProps {
|
|
11
|
+
/** Current page, 1-based. */
|
|
12
|
+
page: number;
|
|
13
|
+
pageCount: number;
|
|
14
|
+
onPageChange: (page: number) => void;
|
|
15
|
+
/** Pages shown on each side of the current one (wide screens). Default 1. */
|
|
16
|
+
siblings?: number;
|
|
17
|
+
labels?: Partial<PaginationLabels>;
|
|
18
|
+
/**
|
|
19
|
+
* Announce page changes through the built-in polite summary. Set `false` when the parent
|
|
20
|
+
* already owns a live region (the data tables do). Default `true`.
|
|
21
|
+
*/
|
|
22
|
+
live?: boolean;
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Returns page numbers with `null` for gaps, e.g. `[1, null, 4, 5, 6, null, 10]`. */
|
|
26
|
+
export declare function paginationRange(page: number, pageCount: number, siblings?: number): Array<number | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Page navigation. Phones show Previous / "Página 2 de 10" / Next; wider screens add the
|
|
29
|
+
* page numbers. Every control is a 44px button.
|
|
30
|
+
*/
|
|
31
|
+
export declare function Pagination({ page, pageCount, onPageChange, siblings, labels, live, className, }: PaginationProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
import { Icon } from './Icon.js';
|
|
4
|
+
const DEFAULT_LABELS = {
|
|
5
|
+
nav: 'Paginación',
|
|
6
|
+
previous: 'Anterior',
|
|
7
|
+
next: 'Siguiente',
|
|
8
|
+
page: (page) => `Página ${page}`,
|
|
9
|
+
summary: (page, count) => `Página ${page} de ${count}`,
|
|
10
|
+
};
|
|
11
|
+
/** Returns page numbers with `null` for gaps, e.g. `[1, null, 4, 5, 6, null, 10]`. */
|
|
12
|
+
export function paginationRange(page, pageCount, siblings = 1) {
|
|
13
|
+
const total = Math.max(1, pageCount);
|
|
14
|
+
const current = Math.min(Math.max(1, page), total);
|
|
15
|
+
const start = Math.max(2, current - siblings);
|
|
16
|
+
const end = Math.min(total - 1, current + siblings);
|
|
17
|
+
const range = [1];
|
|
18
|
+
if (start > 2)
|
|
19
|
+
range.push(null);
|
|
20
|
+
for (let p = start; p <= end; p++)
|
|
21
|
+
range.push(p);
|
|
22
|
+
if (end < total - 1)
|
|
23
|
+
range.push(null);
|
|
24
|
+
if (total > 1)
|
|
25
|
+
range.push(total);
|
|
26
|
+
return range;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Page navigation. Phones show Previous / "Página 2 de 10" / Next; wider screens add the
|
|
30
|
+
* page numbers. Every control is a 44px button.
|
|
31
|
+
*/
|
|
32
|
+
export function Pagination({ page, pageCount, onPageChange, siblings = 1, labels, live = true, className, }) {
|
|
33
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
34
|
+
const total = Math.max(1, pageCount);
|
|
35
|
+
const current = Math.min(Math.max(1, page), total);
|
|
36
|
+
const go = (p) => {
|
|
37
|
+
if (p !== current && p >= 1 && p <= total)
|
|
38
|
+
onPageChange(p);
|
|
39
|
+
};
|
|
40
|
+
return (_jsxs("nav", { className: cx('faast-pagination', className), "aria-label": text.nav, children: [_jsxs("button", { type: "button", className: "faast-pagination__step", onClick: () => go(current - 1), disabled: current <= 1, children: [_jsx(Icon, { name: "chevron-left", size: 16 }), _jsx("span", { children: text.previous })] }), _jsx("span", { className: "faast-pagination__summary faast-num", "aria-live": live ? 'polite' : undefined, children: text.summary(current, total) }), _jsx("ul", { className: "faast-pagination__pages", children: paginationRange(current, total, siblings).map((p, index) => p === null ? (_jsx("li", { className: "faast-pagination__gap", "aria-hidden": "true", children: "\u2026" }, `gap-${index}`)) : (_jsx("li", { children: _jsx("button", { type: "button", className: "faast-pagination__page faast-num", "aria-label": text.page(p), "aria-current": p === current ? 'page' : undefined, onClick: () => go(p), children: p }) }, p))) }), _jsxs("button", { type: "button", className: "faast-pagination__step", onClick: () => go(current + 1), disabled: current >= total, children: [_jsx("span", { children: text.next }), _jsx(Icon, { name: "chevron-right", size: 16 })] })] }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type TextFieldProps } from './Input.js';
|
|
3
|
+
export interface PasswordFieldLabels {
|
|
4
|
+
/** Toggle name while the password is hidden. Default "Mostrar contraseña". */
|
|
5
|
+
show: string;
|
|
6
|
+
/** Toggle name while the password is visible. Default "Ocultar contraseña". */
|
|
7
|
+
hide: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PasswordFieldProps extends Omit<TextFieldProps, 'type' | 'label' | 'leadingIcon' | 'trailingAction' | 'autoComplete'> {
|
|
10
|
+
/** Visible label. Default "Contraseña". */
|
|
11
|
+
label?: ReactNode;
|
|
12
|
+
/** `current-password` (sign-in, default) or `new-password` (set or change). */
|
|
13
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
14
|
+
/**
|
|
15
|
+
* Visible requirements (e.g. "Mínimo 12 caracteres."), shown under the field and linked
|
|
16
|
+
* to it with `aria-describedby`.
|
|
17
|
+
*/
|
|
18
|
+
requirements?: ReactNode;
|
|
19
|
+
/** Shows the lock icon inside the field. Default `true`. */
|
|
20
|
+
showLeadingIcon?: boolean;
|
|
21
|
+
/** Controlled visibility. */
|
|
22
|
+
visible?: boolean;
|
|
23
|
+
defaultVisible?: boolean;
|
|
24
|
+
onVisibleChange?: (visible: boolean) => void;
|
|
25
|
+
labels?: Partial<PasswordFieldLabels>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Password input with a lock icon and an eye / eye-off toggle that reveals the text.
|
|
29
|
+
* The toggle is a real button (`aria-pressed`, `aria-controls`); the value is never copied
|
|
30
|
+
* or stored by the component.
|
|
31
|
+
*/
|
|
32
|
+
export declare const PasswordField: import("react").ForwardRefExoticComponent<PasswordFieldProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId, useState } from 'react';
|
|
3
|
+
import { IconButton } from './Button.js';
|
|
4
|
+
import { Icon } from './Icon.js';
|
|
5
|
+
import { TextField } from './Input.js';
|
|
6
|
+
const DEFAULT_LABELS = {
|
|
7
|
+
show: 'Mostrar contraseña',
|
|
8
|
+
hide: 'Ocultar contraseña',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Password input with a lock icon and an eye / eye-off toggle that reveals the text.
|
|
12
|
+
* The toggle is a real button (`aria-pressed`, `aria-controls`); the value is never copied
|
|
13
|
+
* or stored by the component.
|
|
14
|
+
*/
|
|
15
|
+
export const PasswordField = forwardRef(function PasswordField({ label = 'Contraseña', autoComplete = 'current-password', requirements, showLeadingIcon = true, visible: visibleProp, defaultVisible = false, onVisibleChange, labels, id, disabled, 'aria-describedby': describedBy, ...rest }, ref) {
|
|
16
|
+
const autoId = useId();
|
|
17
|
+
const inputId = id ?? `faast-password-${autoId}`;
|
|
18
|
+
const requirementsId = requirements ? `${inputId}-requirements` : undefined;
|
|
19
|
+
const [innerVisible, setInnerVisible] = useState(defaultVisible);
|
|
20
|
+
const visible = visibleProp ?? innerVisible;
|
|
21
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
22
|
+
const toggle = () => {
|
|
23
|
+
const next = !visible;
|
|
24
|
+
if (visibleProp === undefined)
|
|
25
|
+
setInnerVisible(next);
|
|
26
|
+
onVisibleChange?.(next);
|
|
27
|
+
};
|
|
28
|
+
return (_jsx(TextField, { ref: ref, ...rest, id: inputId, label: label, disabled: disabled, type: visible ? 'text' : 'password', autoComplete: autoComplete, autoCapitalize: "none", autoCorrect: "off", spellCheck: false, leadingIcon: showLeadingIcon ? 'lock' : undefined, "aria-describedby": [describedBy, requirementsId].filter(Boolean).join(' ') || undefined, trailingAction: _jsx(IconButton, { label: visible ? text.hide : text.show, icon: _jsx(Icon, { name: visible ? 'eye-off' : 'eye' }), "aria-pressed": visible, "aria-controls": inputId, disabled: disabled, onClick: toggle, "data-testid": "password-visibility-toggle" }), afterControl: requirements ? (_jsx("div", { className: "faast-password__requirements", id: requirementsId, children: requirements })) : undefined }));
|
|
29
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface SegmentedOption {
|
|
3
|
+
value: string;
|
|
4
|
+
/** Main text of the option ("S/"). */
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
/** Small secondary text after the label ("PEN"). Read as part of the option name. */
|
|
7
|
+
hint?: ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/** Rendered as `data-testid` on the option button (end-to-end selectors). */
|
|
10
|
+
testId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SegmentedControlProps {
|
|
13
|
+
/** Accessible name of the group ("Moneda"). Required. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Show the label next to the control. When false it stays for assistive technology. Default `true`. */
|
|
16
|
+
labelVisible?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Where the visible label sits: `inline` (default) before the control, `top` above it
|
|
19
|
+
* (a stacked field-like label, 12.5px).
|
|
20
|
+
*/
|
|
21
|
+
labelPosition?: 'inline' | 'top';
|
|
22
|
+
options: readonly SegmentedOption[];
|
|
23
|
+
value: string;
|
|
24
|
+
onChange: (value: string) => void;
|
|
25
|
+
/** Disables every option. */
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Single choice among a few short options (currency, view mode) drawn as a joined track.
|
|
31
|
+
* `radiogroup` pattern: one tab stop (the selected option), arrow keys move and select,
|
|
32
|
+
* Home and End jump to the first and last option. Options are 36px on desktop and 44px on
|
|
33
|
+
* touch screens and phones.
|
|
34
|
+
*/
|
|
35
|
+
export declare function SegmentedControl({ label, labelVisible, labelPosition, options, value, onChange, disabled, className, }: SegmentedControlProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
/**
|
|
5
|
+
* Single choice among a few short options (currency, view mode) drawn as a joined track.
|
|
6
|
+
* `radiogroup` pattern: one tab stop (the selected option), arrow keys move and select,
|
|
7
|
+
* Home and End jump to the first and last option. Options are 36px on desktop and 44px on
|
|
8
|
+
* touch screens and phones.
|
|
9
|
+
*/
|
|
10
|
+
export function SegmentedControl({ label, labelVisible = true, labelPosition = 'inline', options, value, onChange, disabled = false, className, }) {
|
|
11
|
+
const labelId = `${useId()}-label`;
|
|
12
|
+
const refs = useRef([]);
|
|
13
|
+
const enabled = options.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0);
|
|
14
|
+
const selectedIndex = options.findIndex((o) => o.value === value);
|
|
15
|
+
// Roving tabindex: the selected option, or the first enabled one when nothing is selected.
|
|
16
|
+
const tabStop = selectedIndex >= 0 && !options[selectedIndex]?.disabled ? selectedIndex : (enabled[0] ?? -1);
|
|
17
|
+
const move = (from, key) => {
|
|
18
|
+
const at = enabled.indexOf(from);
|
|
19
|
+
if (key === 'ArrowRight' || key === 'ArrowDown')
|
|
20
|
+
return enabled[(at + 1) % enabled.length] ?? null;
|
|
21
|
+
if (key === 'ArrowLeft' || key === 'ArrowUp')
|
|
22
|
+
return enabled[(at - 1 + enabled.length) % enabled.length] ?? null;
|
|
23
|
+
if (key === 'Home')
|
|
24
|
+
return enabled[0] ?? null;
|
|
25
|
+
if (key === 'End')
|
|
26
|
+
return enabled[enabled.length - 1] ?? null;
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
const onKeyDown = (event, index) => {
|
|
30
|
+
if (disabled || enabled.length === 0)
|
|
31
|
+
return;
|
|
32
|
+
const next = move(index, event.key);
|
|
33
|
+
if (next === null)
|
|
34
|
+
return;
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
const option = options[next];
|
|
37
|
+
if (!option)
|
|
38
|
+
return;
|
|
39
|
+
refs.current[next]?.focus();
|
|
40
|
+
if (option.value !== value)
|
|
41
|
+
onChange(option.value);
|
|
42
|
+
};
|
|
43
|
+
return (_jsxs("div", { className: cx('faast-segmented-wrap', labelPosition === 'top' && 'faast-segmented-wrap--top', className), children: [_jsx("span", { id: labelId, className: cx('faast-segmented__label', !labelVisible && 'faast-sr-only'), children: label }), _jsx("div", { role: "radiogroup", "aria-labelledby": labelId, "aria-disabled": disabled || undefined, className: "faast-segmented", children: options.map((option, index) => {
|
|
44
|
+
const checked = index === selectedIndex;
|
|
45
|
+
return (_jsxs("button", { ref: (node) => {
|
|
46
|
+
refs.current[index] = node;
|
|
47
|
+
}, type: "button", role: "radio", "aria-checked": checked, disabled: disabled || option.disabled, tabIndex: index === tabStop ? 0 : -1, className: "faast-segmented__option", "data-testid": option.testId, onClick: () => {
|
|
48
|
+
if (!checked)
|
|
49
|
+
onChange(option.value);
|
|
50
|
+
}, onKeyDown: (event) => onKeyDown(event, index), children: [_jsx("span", { children: option.label }), option.hint && _jsx("span", { className: "faast-segmented__hint", children: option.hint })] }, option.value));
|
|
51
|
+
}) })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode, type SelectHTMLAttributes } from 'react';
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
|
|
8
|
+
/** Options as data; or pass `<option>` children. */
|
|
9
|
+
options?: SelectOption[];
|
|
10
|
+
/** Adds a first, empty option with this text (e.g. "Selecciona…"). */
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/** Native select (best mobile behaviour) with themed colours for Windows dark mode. */
|
|
15
|
+
export declare const Select: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<HTMLSelectElement>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { Icon } from './Icon.js';
|
|
5
|
+
import { useFieldProps } from './Input.js';
|
|
6
|
+
/** Native select (best mobile behaviour) with themed colours for Windows dark mode. */
|
|
7
|
+
export const Select = forwardRef(function Select({ options, placeholder, className, children, ...rest }, ref) {
|
|
8
|
+
const field = useFieldProps(rest);
|
|
9
|
+
return (_jsxs("span", { className: cx('faast-select', className), children: [_jsxs("select", { ref: ref, className: "faast-input faast-select__control", ...rest, ...field, children: [placeholder !== undefined && _jsx("option", { value: "", children: placeholder }), options?.map((o) => (_jsx("option", { value: o.value, disabled: o.disabled, children: o.label }, o.value))), children] }), _jsx("span", { className: "faast-select__icon", children: _jsx(Icon, { name: "chevron-down", size: 16 }) })] }));
|
|
10
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface SessionTimeoutDialogLabels {
|
|
3
|
+
/** Default "Tu sesión está por expirar". */
|
|
4
|
+
title: string;
|
|
5
|
+
/** Default "Por seguridad la cerraremos por inactividad. Tu avance se mantiene si continúas." */
|
|
6
|
+
description: string;
|
|
7
|
+
/** Primary action (Title Case). Default "Continuar Sesión". */
|
|
8
|
+
continue: string;
|
|
9
|
+
/** Default "Cerrar Sesión". */
|
|
10
|
+
signOut: string;
|
|
11
|
+
/** Polite announcement at the 60, 30 and 10 second marks. */
|
|
12
|
+
remaining: (seconds: number) => string;
|
|
13
|
+
}
|
|
14
|
+
export interface SessionTimeoutDialogProps {
|
|
15
|
+
open: boolean;
|
|
16
|
+
/** Seconds left before the session ends. The owner ticks it; this component keeps no timer. */
|
|
17
|
+
secondsLeft: number;
|
|
18
|
+
/** Length of the warning window, for the bar. */
|
|
19
|
+
totalSeconds: number;
|
|
20
|
+
/** "Continuar Sesión" and Esc. The owner extends the session on the server. */
|
|
21
|
+
onContinue: () => void;
|
|
22
|
+
onSignOut: () => void;
|
|
23
|
+
/** Shows a spinner on "Continuar Sesión" while the extension request runs. */
|
|
24
|
+
continuing?: boolean;
|
|
25
|
+
/** Urgent (danger) style at or below this many seconds. Default 10. */
|
|
26
|
+
urgentAt?: number;
|
|
27
|
+
/** Small print under the actions (e.g. the absolute session limit). */
|
|
28
|
+
footnote?: ReactNode;
|
|
29
|
+
labels?: Partial<SessionTimeoutDialogLabels>;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
/** `m:ss`, never negative. */
|
|
33
|
+
export declare function formatCountdown(seconds: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Presentational idle-timeout warning (`role="alertdialog"`). It shows a countdown with a
|
|
36
|
+
* draining bar and two actions; it never decides when the session ends. Focus starts on
|
|
37
|
+
* "Continuar Sesión". Bottom sheet below 600px, centred dialog above.
|
|
38
|
+
*/
|
|
39
|
+
export declare function SessionTimeoutDialog({ open, secondsLeft, totalSeconds, onContinue, onSignOut, continuing, urgentAt, footnote, labels, className, }: SessionTimeoutDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { useModalDialog } from '../utils/useModalDialog.js';
|
|
5
|
+
import { Button } from './Button.js';
|
|
6
|
+
import { Icon } from './Icon.js';
|
|
7
|
+
const DEFAULT_LABELS = {
|
|
8
|
+
title: 'Tu sesión está por expirar',
|
|
9
|
+
description: 'Por seguridad la cerraremos por inactividad. Tu avance se mantiene si continúas.',
|
|
10
|
+
continue: 'Continuar Sesión',
|
|
11
|
+
signOut: 'Cerrar Sesión',
|
|
12
|
+
remaining: (seconds) => seconds === 1 ? 'Queda 1 segundo de sesión.' : `Quedan ${seconds} segundos de sesión.`,
|
|
13
|
+
};
|
|
14
|
+
/** Marks at which the remaining time is announced to screen readers. */
|
|
15
|
+
const ANNOUNCE_AT = [60, 30, 10];
|
|
16
|
+
const IDLE = { mark: Number.POSITIVE_INFINITY, message: '' };
|
|
17
|
+
/** `m:ss`, never negative. */
|
|
18
|
+
export function formatCountdown(seconds) {
|
|
19
|
+
const safe = Math.max(0, Math.ceil(seconds));
|
|
20
|
+
const m = Math.floor(safe / 60);
|
|
21
|
+
const s = safe % 60;
|
|
22
|
+
return `${m}:${s.toString().padStart(2, '0')}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Presentational idle-timeout warning (`role="alertdialog"`). It shows a countdown with a
|
|
26
|
+
* draining bar and two actions; it never decides when the session ends. Focus starts on
|
|
27
|
+
* "Continuar Sesión". Bottom sheet below 600px, centred dialog above.
|
|
28
|
+
*/
|
|
29
|
+
export function SessionTimeoutDialog({ open, secondsLeft, totalSeconds, onContinue, onSignOut, continuing = false, urgentAt = 10, footnote, labels, className, }) {
|
|
30
|
+
const ref = useRef(null);
|
|
31
|
+
const continueRef = useRef(null);
|
|
32
|
+
const onContinueRef = useRef(onContinue);
|
|
33
|
+
const id = useId();
|
|
34
|
+
const titleId = `${id}-title`;
|
|
35
|
+
const descriptionId = `${id}-description`;
|
|
36
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
37
|
+
const urgent = secondsLeft <= urgentAt;
|
|
38
|
+
const ratio = totalSeconds > 0 ? Math.min(1, Math.max(0, secondsLeft / totalSeconds)) : 0;
|
|
39
|
+
// Announce once per mark, even when ticks skip a second (state adjusted during render,
|
|
40
|
+
// no effect and no timer).
|
|
41
|
+
const [spoken, setSpoken] = useState(IDLE);
|
|
42
|
+
if (!open && spoken !== IDLE)
|
|
43
|
+
setSpoken(IDLE);
|
|
44
|
+
if (open) {
|
|
45
|
+
const crossed = ANNOUNCE_AT.filter((mark) => secondsLeft <= mark && mark < spoken.mark);
|
|
46
|
+
if (crossed.length > 0) {
|
|
47
|
+
setSpoken({
|
|
48
|
+
mark: Math.min(...crossed),
|
|
49
|
+
message: text.remaining(Math.max(0, Math.ceil(secondsLeft))),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
onContinueRef.current = onContinue;
|
|
55
|
+
});
|
|
56
|
+
useModalDialog(ref, open, () => continueRef.current?.focus());
|
|
57
|
+
return (_jsxs("dialog", { ref: ref, role: "alertdialog", "aria-modal": "true", "aria-labelledby": titleId, "aria-describedby": descriptionId, className: cx('faast-session-dialog', urgent && 'faast-session-dialog--urgent', className), onCancel: (event) => {
|
|
58
|
+
// Esc means "I am here": the owner decides, like "Continuar Sesión".
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
onContinueRef.current();
|
|
61
|
+
}, "data-testid": "session-timeout-dialog", children: [_jsx("p", { className: "faast-sr-only", "aria-live": "polite", "aria-atomic": "true", children: spoken.message }), open && (_jsxs("div", { className: "faast-session-dialog__panel", children: [_jsxs("div", { className: "faast-session-dialog__head", children: [_jsx("span", { className: "faast-session-dialog__badge", children: _jsx(Icon, { name: "timer" }) }), _jsxs("div", { children: [_jsx("h2", { className: "faast-session-dialog__title", id: titleId, children: text.title }), _jsx("p", { className: "faast-session-dialog__description", id: descriptionId, children: text.description })] })] }), _jsxs("div", { className: "faast-session-dialog__count", "aria-hidden": "true", children: [_jsx("span", { className: "faast-session-dialog__clock faast-num", "data-testid": "session-countdown", children: formatCountdown(secondsLeft) }), _jsx("span", { className: "faast-session-dialog__track", children: _jsx("span", { className: "faast-session-dialog__bar", style: { transform: `scaleX(${ratio})` } }) })] }), _jsxs("div", { className: "faast-session-dialog__actions", children: [_jsx(Button, { leadingIcon: _jsx(Icon, { name: "log-out" }), onClick: onSignOut, "data-testid": "session-sign-out", children: text.signOut }), _jsx(Button, { ref: continueRef, variant: "primary", leadingIcon: _jsx(Icon, { name: "refresh-cw" }), loading: continuing, onClick: onContinue, "data-testid": "session-continue", children: text.continue })] }), footnote && _jsx("p", { className: "faast-session-dialog__footnote", children: footnote })] }))] }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
size?: 'sm' | 'md' | 'lg';
|
|
4
|
+
/** Announced to assistive technology. Default "Cargando…". */
|
|
5
|
+
label?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Indeterminate progress indicator (`role="status"`). */
|
|
8
|
+
export declare function Spinner({ size, label, className, ...rest }: SpinnerProps): import("react").JSX.Element;
|
|
9
|
+
export interface SkeletonProps extends HTMLAttributes<HTMLSpanElement> {
|
|
10
|
+
/** CSS width, e.g. `120px` or `60%`. Default `100%`. */
|
|
11
|
+
width?: string;
|
|
12
|
+
/** CSS height; match the real content (a 24px value gets a 24px bar). Default `1em`. */
|
|
13
|
+
height?: string;
|
|
14
|
+
radius?: 'xs' | 'sm' | 'md' | 'full';
|
|
15
|
+
}
|
|
16
|
+
/** Flat placeholder block at the size of the content it replaces. Hidden from AT. */
|
|
17
|
+
export declare function Skeleton({ width, height, radius, className, style, ...rest }: SkeletonProps): import("react").JSX.Element;
|
|
18
|
+
export interface LoadingStateProps extends HTMLAttributes<HTMLDivElement> {
|
|
19
|
+
/** Visible and announced text. Default "Cargando…". */
|
|
20
|
+
label?: string;
|
|
21
|
+
/** Optional placeholder layout (e.g. Skeletons) shown under the label. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/** A block-level loading state with a polite live region. */
|
|
25
|
+
export declare function LoadingState({ label, children, className, ...rest }: LoadingStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
/** Indeterminate progress indicator (`role="status"`). */
|
|
4
|
+
export function Spinner({ size = 'md', label = 'Cargando…', className, ...rest }) {
|
|
5
|
+
return (_jsxs("span", { role: "status", className: cx('faast-spinner', `faast-spinner--${size}`, className), ...rest, children: [_jsx("span", { className: "faast-spinner__ring", "aria-hidden": "true" }), _jsx("span", { className: "faast-sr-only", children: label })] }));
|
|
6
|
+
}
|
|
7
|
+
/** Flat placeholder block at the size of the content it replaces. Hidden from AT. */
|
|
8
|
+
export function Skeleton({ width = '100%', height = '1em', radius = 'xs', className, style, ...rest }) {
|
|
9
|
+
const css = { width, height, ...style };
|
|
10
|
+
return (_jsx("span", { "aria-hidden": "true", className: cx('faast-skeleton', `faast-skeleton--${radius}`, className), style: css, ...rest }));
|
|
11
|
+
}
|
|
12
|
+
/** A block-level loading state with a polite live region. */
|
|
13
|
+
export function LoadingState({ label = 'Cargando…', children, className, ...rest }) {
|
|
14
|
+
return (_jsxs("div", { className: cx('faast-loading-state', className), "aria-live": "polite", "aria-busy": "true", ...rest, children: [_jsxs("div", { className: "faast-loading-state__row", children: [_jsx("span", { className: "faast-spinner faast-spinner--md", "aria-hidden": "true", children: _jsx("span", { className: "faast-spinner__ring" }) }), _jsx("span", { children: label })] }), children] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { Status } from './Badge.js';
|
|
3
|
+
/** Colour of the square marker before a tile label. `accent` is the brand green. */
|
|
4
|
+
export type StatTileTone = Status | 'accent';
|
|
5
|
+
export interface StatTileItem {
|
|
6
|
+
id: string;
|
|
7
|
+
/** Short name of the figure ("En evaluación"). Read with its value. */
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
/** The figure, already formatted by the app ("S/ 12,345.60"). One line, ellipsis on overflow. */
|
|
10
|
+
value: ReactNode;
|
|
11
|
+
/** Small text under the value ("3 operaciones"). */
|
|
12
|
+
caption?: ReactNode;
|
|
13
|
+
/** Marker colour; the label stays the real signal. Default `neutral`. */
|
|
14
|
+
tone?: StatTileTone;
|
|
15
|
+
}
|
|
16
|
+
export interface StatTilesProps {
|
|
17
|
+
items: readonly StatTileItem[];
|
|
18
|
+
/** Accessible name of the group of figures ("Totales en soles"). Required. */
|
|
19
|
+
label: string;
|
|
20
|
+
/**
|
|
21
|
+
* Columns of the wide layout (container at least 640px wide). Narrower containers show two
|
|
22
|
+
* columns. Default: one column per item, at most 4.
|
|
23
|
+
*/
|
|
24
|
+
columns?: number;
|
|
25
|
+
/** The figures are being refreshed: sets `aria-busy` and dims the values. */
|
|
26
|
+
busy?: boolean;
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Bordered tiles with a status marker, a label, a figure and a caption. The layout follows
|
|
31
|
+
* the width of the container (container queries), not the viewport: two columns below 640px,
|
|
32
|
+
* `columns` (default up to 4) from 640px. A description list, so each figure is read with
|
|
33
|
+
* its label.
|
|
34
|
+
*/
|
|
35
|
+
export declare function StatTiles({ items, label, columns, busy, className }: StatTilesProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
/**
|
|
4
|
+
* Bordered tiles with a status marker, a label, a figure and a caption. The layout follows
|
|
5
|
+
* the width of the container (container queries), not the viewport: two columns below 640px,
|
|
6
|
+
* `columns` (default up to 4) from 640px. A description list, so each figure is read with
|
|
7
|
+
* its label.
|
|
8
|
+
*/
|
|
9
|
+
export function StatTiles({ items, label, columns, busy = false, className }) {
|
|
10
|
+
const wide = Math.max(1, Math.min(Math.floor(columns ?? Math.min(items.length, 4)), 6));
|
|
11
|
+
return (_jsx("div", { className: cx('faast-stat-tiles', className), role: "group", "aria-label": label, children: _jsx("dl", { className: cx('faast-stat-tiles__grid', busy && 'faast-stat-tiles__grid--busy'), "aria-busy": busy || undefined, style: { '--faast-stat-columns': wide }, children: items.map((item) => (_jsxs("div", { className: cx('faast-stat-tile', `faast-stat-tile--${item.tone ?? 'neutral'}`), children: [_jsxs("dt", { className: "faast-stat-tile__label", children: [_jsx("span", { className: "faast-stat-tile__marker", "aria-hidden": "true" }), _jsx("span", { className: "faast-stat-tile__label-text", children: item.label })] }), _jsx("dd", { className: "faast-stat-tile__value faast-num", children: item.value }), item.caption != null && _jsx("dd", { className: "faast-stat-tile__caption", children: item.caption })] }, item.id))) }) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type StepState = 'done' | 'current' | 'pending';
|
|
3
|
+
export interface StepperStep {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
state: StepState;
|
|
7
|
+
}
|
|
8
|
+
export interface StepperProps {
|
|
9
|
+
steps: readonly StepperStep[];
|
|
10
|
+
/** Accessible name of the navigation landmark ("Progreso de la solicitud"). Required. */
|
|
11
|
+
label: string;
|
|
12
|
+
/**
|
|
13
|
+
* Text of the compact variant (below 640px). Receives the 1-based number of the current
|
|
14
|
+
* step, the total and the current step label. Default: "**Paso 1 de 3** · Selecciona".
|
|
15
|
+
*/
|
|
16
|
+
compactLabel?: (current: number, total: number, stepLabel: string) => ReactNode;
|
|
17
|
+
/** Words read after each step name. Defaults are Spanish. */
|
|
18
|
+
stateLabels?: Partial<Record<StepState, string>>;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Progress of a short, linear flow (2 to 5 steps) computed by the app from its own state.
|
|
23
|
+
* From 640px it is a full-width row of numbered markers joined by connectors; below 640px it
|
|
24
|
+
* collapses to "Paso 1 de 3 · Nombre" with a thin progress bar. Not interactive.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Stepper({ steps, label, compactLabel, stateLabels, className, }: StepperProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
import { Icon } from './Icon.js';
|
|
4
|
+
const DEFAULT_STATE_LABELS = {
|
|
5
|
+
done: 'completado',
|
|
6
|
+
current: 'paso actual',
|
|
7
|
+
pending: 'pendiente',
|
|
8
|
+
};
|
|
9
|
+
function defaultCompactLabel(current, total, stepLabel) {
|
|
10
|
+
return (_jsxs(_Fragment, { children: [_jsxs("b", { children: ["Paso ", current, " de ", total] }), ' · ', stepLabel] }));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Progress of a short, linear flow (2 to 5 steps) computed by the app from its own state.
|
|
14
|
+
* From 640px it is a full-width row of numbered markers joined by connectors; below 640px it
|
|
15
|
+
* collapses to "Paso 1 de 3 · Nombre" with a thin progress bar. Not interactive.
|
|
16
|
+
*/
|
|
17
|
+
export function Stepper({ steps, label, compactLabel = defaultCompactLabel, stateLabels, className, }) {
|
|
18
|
+
const words = { ...DEFAULT_STATE_LABELS, ...stateLabels };
|
|
19
|
+
const total = steps.length;
|
|
20
|
+
const currentIndex = steps.findIndex((step) => step.state === 'current');
|
|
21
|
+
const doneCount = steps.filter((step) => step.state === 'done').length;
|
|
22
|
+
const position = currentIndex >= 0 ? currentIndex + 1 : Math.min(doneCount + 1, total);
|
|
23
|
+
const currentStep = steps[position - 1];
|
|
24
|
+
const progress = total === 0 ? 0 : Math.round((position / total) * 100);
|
|
25
|
+
return (_jsxs("nav", { "aria-label": label, className: cx('faast-stepper', className), children: [_jsx("ol", { className: "faast-stepper__list", children: steps.map((step, index) => (_jsxs("li", { className: cx('faast-stepper__step', `faast-stepper__step--${step.state}`), "aria-current": step.state === 'current' ? 'step' : undefined, children: [_jsx("span", { className: "faast-stepper__marker", "aria-hidden": "true", children: step.state === 'done' ? (_jsx(Icon, { name: "check", size: 14, strokeWidth: 2.75 })) : (index + 1) }), _jsx("span", { className: "faast-stepper__label", children: step.label }), _jsx("span", { className: "faast-sr-only", children: `, ${words[step.state]}` })] }, step.id))) }), currentStep && (_jsxs("div", { className: "faast-stepper__compact", children: [_jsx("p", { className: "faast-stepper__compact-text", children: compactLabel(position, total, currentStep.label) }), _jsx("div", { className: "faast-stepper__bar", "aria-hidden": "true", children: _jsx("span", { style: { width: `${progress}%` } }) })] }))] }));
|
|
26
|
+
}
|