@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
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @faast-app/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Accessible, mobile-first React components (React 18.2+ or 19 as a peer dependency). Requires `@faast-app/tokens` and `@faast-app/themes`; icons come from `lucide-react` behind the
|
|
4
|
+
allowlisted `<Icon name>` component (never import Lucide directly).
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import '@faast-app/ui/styles.css' // after the tokens/themes stylesheets
|
|
8
|
+
import { AppShell, Button, ThemeProvider } from '@faast-app/ui'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Data tables (`ClientDataTable`, `ServerDataTable`, toolbar and hooks): see `docs/data-tables.md`.
|
|
12
|
+
|
|
13
|
+
Part of the FaaST shared libraries (`librerias`). Private package; see the repository docs
|
|
14
|
+
(`docs/distribution.md`) for how to consume it.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
export type AlertStatus = 'info' | 'success' | 'warning' | 'danger';
|
|
4
|
+
export interface AlertProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
5
|
+
status?: AlertStatus;
|
|
6
|
+
title?: ReactNode;
|
|
7
|
+
/** Trailing action (e.g. a Button). */
|
|
8
|
+
action?: ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* `polite` (default for info/success/warning) or `assertive` (default for danger) when the
|
|
11
|
+
* alert appears dynamically; `off` for alerts present on page load.
|
|
12
|
+
*/
|
|
13
|
+
live?: 'polite' | 'assertive' | 'off';
|
|
14
|
+
/** Overrides the default icon of the status (info, circle-check, triangle-alert, circle-x). */
|
|
15
|
+
icon?: IconName;
|
|
16
|
+
}
|
|
17
|
+
/** Inline feedback message with an icon, a title and optional action. */
|
|
18
|
+
export declare function Alert({ status, title, action, live, icon, className, children, ...rest }: AlertProps): import("react").JSX.Element;
|
|
19
|
+
export interface ErrorStateProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
20
|
+
/** What failed, in one sentence. Default "No se pudo cargar la información." */
|
|
21
|
+
title?: ReactNode;
|
|
22
|
+
/** When the data was last good, or what to do next. */
|
|
23
|
+
description?: ReactNode;
|
|
24
|
+
onRetry?: () => void;
|
|
25
|
+
/** Retry button label (Title Case). Default "Reintentar". */
|
|
26
|
+
retryLabel?: string;
|
|
27
|
+
retrying?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Error shown inside the block that failed, with a retry action. */
|
|
30
|
+
export declare function ErrorState({ title, description, onRetry, retryLabel, retrying, className, ...rest }: ErrorStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
import { Button } from './Button.js';
|
|
4
|
+
import { Icon } from './Icon.js';
|
|
5
|
+
const ICONS = {
|
|
6
|
+
info: 'info',
|
|
7
|
+
success: 'circle-check',
|
|
8
|
+
warning: 'triangle-alert',
|
|
9
|
+
danger: 'circle-x',
|
|
10
|
+
};
|
|
11
|
+
/** Inline feedback message with an icon, a title and optional action. */
|
|
12
|
+
export function Alert({ status = 'info', title, action, live, icon, className, children, ...rest }) {
|
|
13
|
+
const politeness = live ?? (status === 'danger' ? 'assertive' : 'polite');
|
|
14
|
+
return (_jsxs("div", { role: politeness === 'assertive' ? 'alert' : politeness === 'polite' ? 'status' : undefined, className: cx('faast-alert', `faast-alert--${status}`, className), ...rest, children: [_jsx("span", { className: "faast-alert__icon", children: _jsx(Icon, { name: icon ?? ICONS[status], size: 16 }) }), _jsxs("div", { className: "faast-alert__content", children: [title && _jsx("p", { className: "faast-alert__title", children: title }), children && _jsx("div", { className: "faast-alert__body", children: children })] }), action && _jsx("div", { className: "faast-alert__action", children: action })] }));
|
|
15
|
+
}
|
|
16
|
+
/** Error shown inside the block that failed, with a retry action. */
|
|
17
|
+
export function ErrorState({ title = 'No se pudo cargar la información.', description, onRetry, retryLabel = 'Reintentar', retrying = false, className, ...rest }) {
|
|
18
|
+
return (_jsxs("div", { role: "alert", className: cx('faast-error-state', className), ...rest, children: [_jsx("span", { className: "faast-error-state__icon", children: _jsx(Icon, { name: "circle-x", size: 16 }) }), _jsxs("div", { className: "faast-error-state__content", children: [_jsx("p", { className: "faast-error-state__title", children: title }), description && _jsx("p", { className: "faast-error-state__description", children: description })] }), onRetry && (_jsx(Button, { variant: "secondary", onClick: onRetry, loading: retrying, children: retryLabel }))] }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface AppShellLabels {
|
|
3
|
+
skipLink: string;
|
|
4
|
+
openMenu: string;
|
|
5
|
+
closeMenu: string;
|
|
6
|
+
/** Accessible name of the mobile menu dialog. */
|
|
7
|
+
menu: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `data-tour` values the application puts on the shell parts a guided tour can highlight. Only
|
|
11
|
+
* the static (md and up) sidebar and the phone top bar carry them, never the drawer copy.
|
|
12
|
+
*/
|
|
13
|
+
export interface AppShellTourAnchors {
|
|
14
|
+
/** The static sidebar (`<aside>`). */
|
|
15
|
+
sidebar?: string;
|
|
16
|
+
/** Brand and portal block at the top of the static sidebar. */
|
|
17
|
+
sidebarTop?: string;
|
|
18
|
+
/** The phone menu button. */
|
|
19
|
+
menuButton?: string;
|
|
20
|
+
/** The brand in the phone top bar. */
|
|
21
|
+
topBarBrand?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AppShellProps {
|
|
24
|
+
/** Product mark (usually `<Logo>`), shown in the sidebar and in the phone top bar. */
|
|
25
|
+
brand: ReactNode;
|
|
26
|
+
/** Navigation (usually `<SideNav>`). Static from md up; an off-canvas drawer on phones. */
|
|
27
|
+
sidebar: ReactNode;
|
|
28
|
+
/** Middle of the top bar (search, scope switcher, page name). */
|
|
29
|
+
topBar?: ReactNode;
|
|
30
|
+
/** Right end of the top bar (ThemeToggle, account). */
|
|
31
|
+
actions?: ReactNode;
|
|
32
|
+
/** Extra sidebar content under the brand (e.g. portal/tenant scope). Use `SidebarPortal` for the portal line. */
|
|
33
|
+
sidebarHeader?: ReactNode;
|
|
34
|
+
/** Sidebar footer under a divider (e.g. the acting organization and its tax id). Use `SidebarFooter`. */
|
|
35
|
+
sidebarFooter?: ReactNode;
|
|
36
|
+
labels?: Partial<AppShellLabels>;
|
|
37
|
+
/** Optional `data-tour` anchors for a guided tour. */
|
|
38
|
+
tourAnchors?: AppShellTourAnchors;
|
|
39
|
+
/** Id of the main landmark (skip-link target). Default `faast-main`. */
|
|
40
|
+
mainId?: string;
|
|
41
|
+
className?: string;
|
|
42
|
+
children?: ReactNode;
|
|
43
|
+
}
|
|
44
|
+
export interface SidebarPortalProps extends HTMLAttributes<HTMLParagraphElement> {
|
|
45
|
+
/** Name of the active portal ("Portal Pagadores"). */
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}
|
|
48
|
+
/** Second line of the sidebar header: a green status dot and the portal name. */
|
|
49
|
+
export declare function SidebarPortal({ className, children, ...rest }: SidebarPortalProps): import("react").JSX.Element;
|
|
50
|
+
export interface SidebarFooterProps extends HTMLAttributes<HTMLDivElement> {
|
|
51
|
+
/** Strong first line (organization name). */
|
|
52
|
+
name: ReactNode;
|
|
53
|
+
/** Secondary line (tax id). */
|
|
54
|
+
detail?: ReactNode;
|
|
55
|
+
}
|
|
56
|
+
/** Bottom block of the sidebar under a divider: who the session works for. */
|
|
57
|
+
export declare function SidebarFooter({ name, detail, className, ...rest }: SidebarFooterProps): import("react").JSX.Element;
|
|
58
|
+
/**
|
|
59
|
+
* Generic app layout, mobile-first: on phones a 56px top bar with a menu button opens the
|
|
60
|
+
* navigation in a modal drawer (native `<dialog>`: focus trap, Esc, focus return); from the
|
|
61
|
+
* md breakpoint the sidebar is static. Includes a skip link and respects safe-area insets.
|
|
62
|
+
*/
|
|
63
|
+
export declare function AppShell({ brand, sidebar, topBar, actions, sidebarHeader, sidebarFooter, labels, tourAnchors, mainId, className, children, }: AppShellProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { breakpoint } from '@faast-app/tokens';
|
|
3
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
4
|
+
import { cx } from '../utils/cx.js';
|
|
5
|
+
import { IconButton } from './Button.js';
|
|
6
|
+
import { Icon } from './Icon.js';
|
|
7
|
+
import { TopBar } from './Navigation.js';
|
|
8
|
+
/** Second line of the sidebar header: a green status dot and the portal name. */
|
|
9
|
+
export function SidebarPortal({ className, children, ...rest }) {
|
|
10
|
+
return (_jsxs("p", { className: cx('faast-sidebar-portal', className), ...rest, children: [_jsx("span", { className: "faast-sidebar-portal__dot", "aria-hidden": "true" }), children] }));
|
|
11
|
+
}
|
|
12
|
+
/** Bottom block of the sidebar under a divider: who the session works for. */
|
|
13
|
+
export function SidebarFooter({ name, detail, className, ...rest }) {
|
|
14
|
+
return (_jsxs("div", { className: cx('faast-sidebar-footer', className), ...rest, children: [_jsx("span", { className: "faast-sidebar-footer__title", children: name }), detail && _jsx("span", { className: "faast-sidebar-footer__detail", children: detail })] }));
|
|
15
|
+
}
|
|
16
|
+
const DEFAULT_LABELS = {
|
|
17
|
+
skipLink: 'Saltar al Contenido',
|
|
18
|
+
openMenu: 'Abrir Menú',
|
|
19
|
+
closeMenu: 'Cerrar Menú',
|
|
20
|
+
menu: 'Menú',
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Generic app layout, mobile-first: on phones a 56px top bar with a menu button opens the
|
|
24
|
+
* navigation in a modal drawer (native `<dialog>`: focus trap, Esc, focus return); from the
|
|
25
|
+
* md breakpoint the sidebar is static. Includes a skip link and respects safe-area insets.
|
|
26
|
+
*/
|
|
27
|
+
export function AppShell({ brand, sidebar, topBar, actions, sidebarHeader, sidebarFooter, labels, tourAnchors, mainId = 'faast-main', className, children, }) {
|
|
28
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
29
|
+
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
30
|
+
const drawerRef = useRef(null);
|
|
31
|
+
const menuButtonRef = useRef(null);
|
|
32
|
+
const drawerId = `${useId()}-drawer`;
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const drawer = drawerRef.current;
|
|
35
|
+
if (!drawer)
|
|
36
|
+
return;
|
|
37
|
+
if (drawerOpen && !drawer.open) {
|
|
38
|
+
if (typeof drawer.showModal === 'function')
|
|
39
|
+
drawer.showModal();
|
|
40
|
+
else
|
|
41
|
+
drawer.setAttribute('open', '');
|
|
42
|
+
}
|
|
43
|
+
else if (!drawerOpen && drawer.open) {
|
|
44
|
+
if (typeof drawer.close === 'function')
|
|
45
|
+
drawer.close();
|
|
46
|
+
else
|
|
47
|
+
drawer.removeAttribute('open');
|
|
48
|
+
menuButtonRef.current?.focus();
|
|
49
|
+
}
|
|
50
|
+
}, [drawerOpen]);
|
|
51
|
+
// Close the drawer if the viewport grows past md while it is open.
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
54
|
+
return;
|
|
55
|
+
const query = window.matchMedia(`(min-width: ${breakpoint.md}px)`);
|
|
56
|
+
const onChange = (event) => {
|
|
57
|
+
if (event.matches)
|
|
58
|
+
setDrawerOpen(false);
|
|
59
|
+
};
|
|
60
|
+
query.addEventListener('change', onChange);
|
|
61
|
+
return () => query.removeEventListener('change', onChange);
|
|
62
|
+
}, []);
|
|
63
|
+
// Backdrop clicks and link activation inside the drawer close it.
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const drawer = drawerRef.current;
|
|
66
|
+
if (!drawer)
|
|
67
|
+
return;
|
|
68
|
+
const onClick = (event) => {
|
|
69
|
+
const target = event.target;
|
|
70
|
+
if (target === drawer || target?.closest('a[href]'))
|
|
71
|
+
setDrawerOpen(false);
|
|
72
|
+
};
|
|
73
|
+
drawer.addEventListener('click', onClick);
|
|
74
|
+
return () => drawer.removeEventListener('click', onClick);
|
|
75
|
+
}, []);
|
|
76
|
+
return (_jsxs("div", { className: cx('faast-shell', className), children: [_jsx("a", { className: "faast-skip-link", href: `#${mainId}`, children: text.skipLink }), _jsxs("aside", { className: "faast-shell__sidebar", "data-tour": tourAnchors?.sidebar, children: [_jsxs("div", { className: "faast-shell__sidebar-top", "data-tour": tourAnchors?.sidebarTop, children: [_jsx("div", { className: "faast-shell__brand", children: brand }), sidebarHeader && _jsx("div", { className: "faast-shell__sidebar-header", children: sidebarHeader })] }), sidebar, sidebarFooter] }), _jsx("dialog", { ref: drawerRef, id: drawerId, className: "faast-shell__drawer", "aria-label": text.menu, "aria-modal": "true", onCancel: (event) => {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
setDrawerOpen(false);
|
|
79
|
+
}, children: drawerOpen && (_jsxs("div", { className: "faast-shell__drawer-panel", children: [_jsxs("div", { className: "faast-shell__sidebar-top", children: [_jsxs("div", { className: "faast-shell__drawer-head", children: [_jsx("div", { className: "faast-shell__brand", children: brand }), _jsx(IconButton, { label: text.closeMenu, icon: _jsx(Icon, { name: "x", size: 16 }), onClick: () => setDrawerOpen(false) })] }), sidebarHeader && _jsx("div", { className: "faast-shell__sidebar-header", children: sidebarHeader })] }), sidebar, sidebarFooter] })) }), _jsxs("div", { className: "faast-shell__column", children: [_jsx(TopBar, { className: "faast-shell__topbar", start: _jsxs(_Fragment, { children: [_jsx(IconButton, { ref: menuButtonRef, className: "faast-shell__menu-button", label: text.openMenu, icon: _jsx(Icon, { name: "menu", size: 16 }), "aria-haspopup": "dialog", "aria-expanded": drawerOpen, "aria-controls": drawerOpen ? drawerId : undefined, onClick: () => setDrawerOpen(true), "data-tour": tourAnchors?.menuButton }), _jsx("div", { className: "faast-shell__topbar-brand", "data-tour": tourAnchors?.topBarBrand, children: brand })] }), end: actions, children: topBar }), _jsx("main", { id: mainId, className: "faast-shell__main", tabIndex: -1, children: children })] })] }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
export interface AvatarProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
|
|
3
|
+
/** Person's display name: the accessible name and the source of the initials. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Override the derived initials (max two characters are shown). */
|
|
6
|
+
initials?: string;
|
|
7
|
+
/** 32 (default, top bars) or 48 (identity blocks). */
|
|
8
|
+
size?: 32 | 48;
|
|
9
|
+
/**
|
|
10
|
+
* Hide from assistive technology when the name is already written next to it
|
|
11
|
+
* (avoids reading the name twice). Default `false`.
|
|
12
|
+
*/
|
|
13
|
+
decorative?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** First letter of the first and last words: "Lucía Ramos" -> "LR". */
|
|
16
|
+
export declare function getInitials(name: string): string;
|
|
17
|
+
/** Initials in an accent-tinted circle. */
|
|
18
|
+
export declare function Avatar({ name, initials, size, decorative, className, ...rest }: AvatarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
/** First letter of the first and last words: "Lucía Ramos" -> "LR". */
|
|
4
|
+
export function getInitials(name) {
|
|
5
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
6
|
+
if (words.length === 0)
|
|
7
|
+
return '';
|
|
8
|
+
const first = Array.from(words[0])[0] ?? '';
|
|
9
|
+
const last = words.length > 1 ? (Array.from(words[words.length - 1])[0] ?? '') : '';
|
|
10
|
+
return (first + last).toLocaleUpperCase('es');
|
|
11
|
+
}
|
|
12
|
+
/** Initials in an accent-tinted circle. */
|
|
13
|
+
export function Avatar({ name, initials, size = 32, decorative = false, className, ...rest }) {
|
|
14
|
+
const shown = Array.from(initials ?? getInitials(name))
|
|
15
|
+
.slice(0, 2)
|
|
16
|
+
.join('');
|
|
17
|
+
const a11y = decorative
|
|
18
|
+
? { 'aria-hidden': true }
|
|
19
|
+
: { role: 'img', 'aria-label': name };
|
|
20
|
+
return (_jsx("span", { className: cx('faast-avatar', `faast-avatar--${size}`, className), translate: "no", ...a11y, ...rest, children: _jsx("span", { "aria-hidden": "true", children: shown }) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Status tones. `violet` is limited to status use (an approved operation); it is never a
|
|
4
|
+
* decorative colour.
|
|
5
|
+
*/
|
|
6
|
+
export type Status = 'neutral' | 'success' | 'warning' | 'danger' | 'info' | 'violet';
|
|
7
|
+
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
8
|
+
tone?: Status;
|
|
9
|
+
/**
|
|
10
|
+
* `pill` (default) is a rounded count or label. `tag` is a small square-cornered 11px bold
|
|
11
|
+
* label for the origin or type of a row ("XML", "EXCEL").
|
|
12
|
+
*/
|
|
13
|
+
variant?: 'pill' | 'tag';
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/** Small pill for counts and labels inside rows. Never above a heading. */
|
|
17
|
+
export declare function Badge({ tone, variant, className, ...rest }: BadgeProps): import("react").JSX.Element;
|
|
18
|
+
export interface StatusBadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
19
|
+
status: Status;
|
|
20
|
+
/** The status in words (colour is never the only signal). */
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/** Status pill: a coloured dot plus the status in words. */
|
|
24
|
+
export declare function StatusBadge({ status, className, children, ...rest }: StatusBadgeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '../utils/cx.js';
|
|
3
|
+
/** Small pill for counts and labels inside rows. Never above a heading. */
|
|
4
|
+
export function Badge({ tone = 'neutral', variant = 'pill', className, ...rest }) {
|
|
5
|
+
return (_jsx("span", { className: cx('faast-badge', `faast-badge--${tone}`, variant === 'tag' && 'faast-badge--tag', className), ...rest }));
|
|
6
|
+
}
|
|
7
|
+
/** Status pill: a coloured dot plus the status in words. */
|
|
8
|
+
export function StatusBadge({ status, className, children, ...rest }) {
|
|
9
|
+
return (_jsxs("span", { className: cx('faast-badge', `faast-badge--${status}`, 'faast-status-badge', className), ...rest, children: [_jsx("span", { className: "faast-status-badge__dot", "aria-hidden": "true" }), children] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type MouseEvent, type ReactNode } from 'react';
|
|
2
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
3
|
+
export type ButtonSize = 'md' | 'sm';
|
|
4
|
+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
/** `primary` is the one main action of a view. Default `secondary`. */
|
|
6
|
+
variant?: ButtonVariant;
|
|
7
|
+
/**
|
|
8
|
+
* `md` keeps the 44px touch target everywhere; `sm` is 36px only for fine pointers from
|
|
9
|
+
* the md breakpoint up (it stays 44px on touch screens). Default `md`.
|
|
10
|
+
*/
|
|
11
|
+
size?: ButtonSize;
|
|
12
|
+
/** Shows a spinner, sets `aria-busy` and blocks clicks while keeping the label. */
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
/** Text announced while loading. Default "Cargando…". */
|
|
15
|
+
loadingLabel?: string;
|
|
16
|
+
leadingIcon?: ReactNode;
|
|
17
|
+
trailingIcon?: ReactNode;
|
|
18
|
+
fullWidth?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Looks disabled (faded, `not-allowed`) but stays focusable: sets `aria-disabled="true"`
|
|
21
|
+
* instead of the native `disabled` attribute and suppresses `onClick`. Use it for an action
|
|
22
|
+
* whose reason is explained on click or in a tooltip. Default `false`.
|
|
23
|
+
*/
|
|
24
|
+
softDisabled?: boolean;
|
|
25
|
+
/** Called instead of `onClick` when the button is soft disabled and the user activates it. */
|
|
26
|
+
onSoftDisabledClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface ButtonClassNameOptions {
|
|
29
|
+
variant?: ButtonVariant;
|
|
30
|
+
size?: ButtonSize;
|
|
31
|
+
fullWidth?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The class names of a `Button`, for a link that must look like one (a router `<Link>` or an
|
|
36
|
+
* `<a>`): `<Link className={buttonClassName({ variant: 'primary' })}>`. Put icons and the
|
|
37
|
+
* text in a `<span className="faast-button__label">` as `Button` does.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buttonClassName({ variant, size, fullWidth, className, }?: ButtonClassNameOptions): string;
|
|
40
|
+
/** Action button. Labels use Title Case ("Guardar Cambios"). */
|
|
41
|
+
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
42
|
+
export interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
|
|
43
|
+
/** Accessible name (required: the button shows only an icon). */
|
|
44
|
+
label: string;
|
|
45
|
+
icon: ReactNode;
|
|
46
|
+
variant?: Exclude<ButtonVariant, 'danger'>;
|
|
47
|
+
/** `danger` turns the icon red on hover and focus (delete actions). Default `default`. */
|
|
48
|
+
tone?: 'default' | 'danger';
|
|
49
|
+
/**
|
|
50
|
+
* `md` is a 44px target. `sm` is 36px from 900px with a fine pointer (row actions) and
|
|
51
|
+
* stays 44px on phones and touch screens. Default `md`.
|
|
52
|
+
*/
|
|
53
|
+
size?: 'md' | 'sm';
|
|
54
|
+
/**
|
|
55
|
+
* Visible tooltip on hover and keyboard focus. `true` shows the `label`; a string shows
|
|
56
|
+
* that text instead (e.g. why the action is unavailable) and is also read as the
|
|
57
|
+
* description. Without it the native `title` shows the label.
|
|
58
|
+
*/
|
|
59
|
+
tooltip?: boolean | string;
|
|
60
|
+
/** Looks disabled but stays focusable (keeps the tooltip reachable) and ignores clicks. */
|
|
61
|
+
softDisabled?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Shows a spinner instead of the icon, sets `aria-busy` and ignores clicks while keeping
|
|
64
|
+
* the button focusable. Default `false`.
|
|
65
|
+
*/
|
|
66
|
+
loading?: boolean;
|
|
67
|
+
/** Text announced while loading. Default "Cargando…". */
|
|
68
|
+
loadingLabel?: string;
|
|
69
|
+
}
|
|
70
|
+
/** Icon-only button with a required accessible name; 44px target, optional visible tooltip. */
|
|
71
|
+
export declare const IconButton: import("react").ForwardRefExoticComponent<IconButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId, } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { Spinner } from './Spinner.js';
|
|
5
|
+
/**
|
|
6
|
+
* The class names of a `Button`, for a link that must look like one (a router `<Link>` or an
|
|
7
|
+
* `<a>`): `<Link className={buttonClassName({ variant: 'primary' })}>`. Put icons and the
|
|
8
|
+
* text in a `<span className="faast-button__label">` as `Button` does.
|
|
9
|
+
*/
|
|
10
|
+
export function buttonClassName({ variant = 'secondary', size = 'md', fullWidth = false, className, } = {}) {
|
|
11
|
+
return cx('faast-button', `faast-button--${variant}`, `faast-button--${size}`, fullWidth && 'faast-button--full', className);
|
|
12
|
+
}
|
|
13
|
+
/** Action button. Labels use Title Case ("Guardar Cambios"). */
|
|
14
|
+
export const Button = forwardRef(function Button({ variant = 'secondary', size = 'md', loading = false, loadingLabel = 'Cargando…', leadingIcon, trailingIcon, fullWidth = false, softDisabled = false, onSoftDisabledClick, disabled, type = 'button', className, children, onClick, ...rest }, ref) {
|
|
15
|
+
return (_jsxs("button", { ref: ref, type: type, className: cx(buttonClassName({ variant, size, fullWidth }), loading && 'faast-button--loading', softDisabled && 'faast-button--soft-disabled', className), disabled: disabled, "aria-busy": loading || undefined, "aria-disabled": loading || softDisabled || undefined, onClick: (event) => {
|
|
16
|
+
if (loading) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (softDisabled) {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
onSoftDisabledClick?.(event);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
onClick?.(event);
|
|
26
|
+
}, ...rest, children: [loading ? _jsx(Spinner, { size: "sm", label: loadingLabel }) : leadingIcon, _jsx("span", { className: "faast-button__label", children: children }), !loading && trailingIcon] }));
|
|
27
|
+
});
|
|
28
|
+
/** Icon-only button with a required accessible name; 44px target, optional visible tooltip. */
|
|
29
|
+
export const IconButton = forwardRef(function IconButton({ label, icon, variant = 'ghost', tone = 'default', size = 'md', tooltip, softDisabled = false, loading = false, loadingLabel = 'Cargando…', type = 'button', className, onClick, 'aria-describedby': describedBy, ...rest }, ref) {
|
|
30
|
+
const tipId = `${useId()}-tip`;
|
|
31
|
+
const tipText = tooltip === true ? label : tooltip || undefined;
|
|
32
|
+
const tipDescribes = typeof tooltip === 'string' && tooltip !== label;
|
|
33
|
+
return (_jsxs("button", { ref: ref, type: type, "aria-label": label, title: tipText ? undefined : label, "aria-disabled": softDisabled || loading || undefined, "aria-busy": loading || undefined, "aria-describedby": [tipDescribes ? tipId : undefined, describedBy].filter(Boolean).join(' ') || undefined, className: cx('faast-icon-button', `faast-icon-button--${variant}`, tone === 'danger' && 'faast-icon-button--danger', size === 'sm' && 'faast-icon-button--sm', tipText && 'faast-icon-button--tip', softDisabled && 'faast-icon-button--soft-disabled', loading && 'faast-icon-button--loading', className), onClick: (event) => {
|
|
34
|
+
if (softDisabled || loading) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
onClick?.(event);
|
|
39
|
+
}, ...rest, children: [loading ? _jsx(Spinner, { size: "sm", label: loadingLabel }) : icon, tipText && (_jsx("span", { role: "tooltip", id: tipId, className: "faast-icon-button__tip", children: tipText }))] }));
|
|
40
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface CardProps extends HTMLAttributes<HTMLElement> {
|
|
3
|
+
/** Render as `section` (default, for titled cards), `article` or `div`. */
|
|
4
|
+
as?: 'section' | 'article' | 'div';
|
|
5
|
+
/** Remove inner padding (e.g. for a full-bleed table). */
|
|
6
|
+
flush?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Flat surface with a 1px border; no shadow at rest. */
|
|
9
|
+
export declare const Card: import("react").ForwardRefExoticComponent<CardProps & import("react").RefAttributes<HTMLElement>>;
|
|
10
|
+
export interface CardHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
11
|
+
/** Card title; rendered as a heading. */
|
|
12
|
+
title?: ReactNode;
|
|
13
|
+
/** Heading level for the title. Default 2. */
|
|
14
|
+
level?: 2 | 3 | 4;
|
|
15
|
+
/** Id for the heading, so the card can reference it with `aria-labelledby`. */
|
|
16
|
+
titleId?: string;
|
|
17
|
+
description?: ReactNode;
|
|
18
|
+
/** Trailing content: a status badge, a "Ver Todo" link, one action. */
|
|
19
|
+
actions?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export declare function CardHeader({ title, level, titleId, description, actions, className, children, ...rest }: CardHeaderProps): import("react").JSX.Element;
|
|
22
|
+
export declare function CardBody({ className, ...rest }: HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
|
|
23
|
+
export declare function CardFooter({ className, ...rest }: HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/** Flat surface with a 1px border; no shadow at rest. */
|
|
5
|
+
export const Card = forwardRef(function Card({ as: Tag = 'section', flush = false, className, ...rest }, ref) {
|
|
6
|
+
return (_jsx(Tag, { ref: ref, className: cx('faast-card', flush && 'faast-card--flush', className), ...rest }));
|
|
7
|
+
});
|
|
8
|
+
export function CardHeader({ title, level = 2, titleId, description, actions, className, children, ...rest }) {
|
|
9
|
+
const Heading = `h${level}`;
|
|
10
|
+
return (_jsxs("div", { className: cx('faast-card__header', className), ...rest, children: [_jsxs("div", { className: "faast-card__heading", children: [title && (_jsx(Heading, { className: "faast-card__title", id: titleId, children: title })), description && _jsx("p", { className: "faast-card__description", children: description }), children] }), actions && _jsx("div", { className: "faast-card__actions", children: actions })] }));
|
|
11
|
+
}
|
|
12
|
+
export function CardBody({ className, ...rest }) {
|
|
13
|
+
return _jsx("div", { className: cx('faast-card__body', className), ...rest });
|
|
14
|
+
}
|
|
15
|
+
export function CardFooter({ className, ...rest }) {
|
|
16
|
+
return _jsx("div", { className: cx('faast-card__footer', className), ...rest });
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface ChipProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
|
|
3
|
+
/** Visible text. Put the context in it ("Estado: Aprobada") or in `aria-label`. */
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
/** Result count shown after the label and read as part of the name ("Con XML, 12"). */
|
|
6
|
+
count?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Toggle mode: the chip is a toggle button (`aria-pressed`). Leave undefined for a plain
|
|
9
|
+
* or removable chip.
|
|
10
|
+
*/
|
|
11
|
+
pressed?: boolean;
|
|
12
|
+
/** Removable mode: shows an "x"; give the button a full accessible name with `aria-label`. */
|
|
13
|
+
removable?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Compact filter chip: toggle with an optional count, or removable. 44px target on touch. */
|
|
16
|
+
export declare const Chip: import("react").ForwardRefExoticComponent<ChipProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
const countFormat = new Intl.NumberFormat('es');
|
|
6
|
+
/** Compact filter chip: toggle with an optional count, or removable. 44px target on touch. */
|
|
7
|
+
export const Chip = forwardRef(function Chip({ label, count, pressed, removable = false, className, type = 'button', ...rest }, ref) {
|
|
8
|
+
return (_jsxs("button", { ref: ref, type: type, "aria-pressed": pressed === undefined ? undefined : pressed, className: cx('faast-chip', pressed && 'faast-chip--pressed', removable && 'faast-chip--removable', className), ...rest, children: [_jsx("span", { className: "faast-chip__label", children: label }), count !== undefined && (_jsxs("span", { className: "faast-chip__count faast-num", children: [_jsx("span", { className: "faast-sr-only", children: ", " }), countFormat.format(count)] })), removable && _jsx(Icon, { name: "x", size: 14 })] }));
|
|
9
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type InputHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
interface ChoiceBaseProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
3
|
+
/** Visible label; the label and the control share one hit target. */
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
/** Help text under the label, linked with `aria-describedby`. */
|
|
6
|
+
description?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export interface CheckboxProps extends ChoiceBaseProps {
|
|
9
|
+
/** Mixed state (e.g. "select all" with some rows selected). Exposed as `aria-checked="mixed"`. */
|
|
10
|
+
indeterminate?: boolean;
|
|
11
|
+
/** Keep the label for assistive technology only (e.g. a table row checkbox). */
|
|
12
|
+
labelHidden?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
15
|
+
export type SwitchProps = ChoiceBaseProps;
|
|
16
|
+
/** On/off control: a checkbox with `role="switch"`. */
|
|
17
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<ChoiceBaseProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
18
|
+
export interface RadioGroupProps {
|
|
19
|
+
/** Group label, rendered as the fieldset legend. */
|
|
20
|
+
legend: ReactNode;
|
|
21
|
+
name?: string;
|
|
22
|
+
/** Controlled value. */
|
|
23
|
+
value?: string;
|
|
24
|
+
onChange?: (value: string) => void;
|
|
25
|
+
hint?: ReactNode;
|
|
26
|
+
error?: ReactNode;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** Lay options out in a row from the sm breakpoint. Default `false`. */
|
|
29
|
+
inline?: boolean;
|
|
30
|
+
className?: string;
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
export declare function RadioGroup({ legend, name, value, onChange, hint, error, disabled, inline, className, children, }: RadioGroupProps): import("react").JSX.Element;
|
|
34
|
+
export interface RadioProps extends ChoiceBaseProps {
|
|
35
|
+
value: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const Radio: import("react").ForwardRefExoticComponent<RadioProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef, } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
function useChoiceIds(id, description) {
|
|
5
|
+
const auto = useId();
|
|
6
|
+
const inputId = id ?? `faast-choice-${auto}`;
|
|
7
|
+
return {
|
|
8
|
+
inputId,
|
|
9
|
+
// The wrapping <label> would also include the description in the name; point the name
|
|
10
|
+
// at the label text only and expose the description separately.
|
|
11
|
+
labelId: `${inputId}-label`,
|
|
12
|
+
descriptionId: description ? `${inputId}-desc` : undefined,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export const Checkbox = forwardRef(function Checkbox({ label, description, id, className, indeterminate = false, labelHidden = false, 'aria-describedby': describedBy, ...rest }, ref) {
|
|
16
|
+
const { inputId, labelId, descriptionId } = useChoiceIds(id, description);
|
|
17
|
+
const own = useRef(null);
|
|
18
|
+
const setRef = useCallback((element) => {
|
|
19
|
+
own.current = element;
|
|
20
|
+
if (typeof ref === 'function')
|
|
21
|
+
ref(element);
|
|
22
|
+
else if (ref)
|
|
23
|
+
ref.current = element;
|
|
24
|
+
}, [ref]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (own.current)
|
|
27
|
+
own.current.indeterminate = indeterminate;
|
|
28
|
+
}, [indeterminate]);
|
|
29
|
+
return (_jsxs("label", { className: cx('faast-choice', labelHidden && 'faast-choice--label-hidden', className), htmlFor: inputId, children: [_jsx("input", { ref: setRef, "aria-checked": indeterminate ? 'mixed' : undefined, id: inputId, type: "checkbox", className: "faast-choice__input faast-checkbox", "aria-labelledby": labelId, "aria-describedby": [descriptionId, describedBy].filter(Boolean).join(' ') || undefined, ...rest }), _jsxs("span", { className: cx('faast-choice__text', labelHidden && 'faast-sr-only'), children: [_jsx("span", { className: "faast-choice__label", id: labelId, children: label }), description && (_jsx("span", { className: "faast-choice__description", id: descriptionId, children: description }))] })] }));
|
|
30
|
+
});
|
|
31
|
+
/** On/off control: a checkbox with `role="switch"`. */
|
|
32
|
+
export const Switch = forwardRef(function Switch({ label, description, id, className, 'aria-describedby': describedBy, ...rest }, ref) {
|
|
33
|
+
const { inputId, labelId, descriptionId } = useChoiceIds(id, description);
|
|
34
|
+
return (_jsxs("label", { className: cx('faast-choice', 'faast-choice--switch', className), htmlFor: inputId, children: [_jsxs("span", { className: "faast-choice__text", children: [_jsx("span", { className: "faast-choice__label", id: labelId, children: label }), description && (_jsx("span", { className: "faast-choice__description", id: descriptionId, children: description }))] }), _jsx("input", { ref: ref, id: inputId, type: "checkbox", role: "switch", className: "faast-choice__input faast-switch", "aria-labelledby": labelId, "aria-describedby": [descriptionId, describedBy].filter(Boolean).join(' ') || undefined, ...rest })] }));
|
|
35
|
+
});
|
|
36
|
+
const RadioGroupContext = createContext(null);
|
|
37
|
+
export function RadioGroup({ legend, name, value, onChange, hint, error, disabled, inline = false, className, children, }) {
|
|
38
|
+
const auto = useId();
|
|
39
|
+
const groupName = name ?? `faast-radio-${auto}`;
|
|
40
|
+
const hintId = hint ? `${groupName}-hint` : undefined;
|
|
41
|
+
const errorId = error ? `${groupName}-error` : undefined;
|
|
42
|
+
return (_jsx(RadioGroupContext.Provider, { value: { name: groupName, value, onChange, disabled }, children: _jsxs("fieldset", { className: cx('faast-fieldset', error ? 'faast-field--invalid' : undefined, className), "aria-describedby": [hintId, errorId].filter(Boolean).join(' ') || undefined, disabled: disabled, children: [_jsx("legend", { className: "faast-field__label", children: legend }), _jsx("div", { className: cx('faast-radio-group', inline && 'faast-radio-group--inline'), children: children }), hint && (_jsx("p", { className: "faast-field__hint", id: hintId, children: hint })), _jsx("p", { className: "faast-field__error", id: `${groupName}-error`, "aria-live": "polite", children: error })] }) }));
|
|
43
|
+
}
|
|
44
|
+
export const Radio = forwardRef(function Radio({ label, description, id, className, value, onChange, 'aria-describedby': describedBy, ...rest }, ref) {
|
|
45
|
+
const group = useContext(RadioGroupContext);
|
|
46
|
+
const { inputId, labelId, descriptionId } = useChoiceIds(id, description);
|
|
47
|
+
const controlled = group?.value !== undefined ? { checked: group.value === value } : {};
|
|
48
|
+
return (_jsxs("label", { className: cx('faast-choice', className), htmlFor: inputId, children: [_jsx("input", { ref: ref, id: inputId, type: "radio", className: "faast-choice__input faast-radio", name: group?.name, value: value, "aria-labelledby": labelId, "aria-describedby": [descriptionId, describedBy].filter(Boolean).join(' ') || undefined, onChange: (event) => {
|
|
49
|
+
onChange?.(event);
|
|
50
|
+
if (event.target.checked)
|
|
51
|
+
group?.onChange?.(value);
|
|
52
|
+
}, ...controlled, ...rest }), _jsxs("span", { className: "faast-choice__text", children: [_jsx("span", { className: "faast-choice__label", id: labelId, children: label }), description && (_jsx("span", { className: "faast-choice__description", id: descriptionId, children: description }))] })] }));
|
|
53
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import type { Status } from './Badge.js';
|
|
3
|
+
import { type IconName } from './Icon.js';
|
|
4
|
+
export type DialogCloseReason = 'escape' | 'backdrop' | 'close-button';
|
|
5
|
+
export interface DialogProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
/** Called when the user asks to close; set `open` to false in response. */
|
|
8
|
+
onClose: (reason: DialogCloseReason) => void;
|
|
9
|
+
title: ReactNode;
|
|
10
|
+
description?: ReactNode;
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
/** Actions, primary last ("Cancelar", "Guardar Cambios"). */
|
|
13
|
+
footer?: ReactNode;
|
|
14
|
+
/** Desktop width: sm 24rem, md 32rem, lg 48rem, xl 64rem (60rem as a drawer). Default `md`. */
|
|
15
|
+
size?: 'sm' | 'md' | 'lg' | 'xl';
|
|
16
|
+
/**
|
|
17
|
+
* `center` (default) is a centred modal. `end` is a drawer docked to the inline end edge
|
|
18
|
+
* with full height; on phones it is a bottom sheet like any other dialog.
|
|
19
|
+
*/
|
|
20
|
+
placement?: 'center' | 'end';
|
|
21
|
+
/** Icon tile before the title (40px), e.g. the outcome of an operation. */
|
|
22
|
+
icon?: IconName;
|
|
23
|
+
/** Colour of the icon tile. Default `neutral`. */
|
|
24
|
+
tone?: Status;
|
|
25
|
+
/** Phone presentation: bottom sheet (default) or full screen. */
|
|
26
|
+
mobile?: 'sheet' | 'fullscreen';
|
|
27
|
+
/** Close when the backdrop is clicked. Default `true`. */
|
|
28
|
+
closeOnBackdrop?: boolean;
|
|
29
|
+
/** Accessible name of the close button. Default "Cerrar". */
|
|
30
|
+
closeLabel?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Element to focus when the dialog opens (first field, "Cancelar"...). By default the
|
|
33
|
+
* browser focuses the first focusable element, which is the close button. Ignored when the
|
|
34
|
+
* ref is empty or points to something disabled.
|
|
35
|
+
*/
|
|
36
|
+
initialFocusRef?: RefObject<HTMLElement | null>;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Modal dialog on the native `<dialog>` element: `showModal()` provides the focus trap,
|
|
41
|
+
* inert background and Esc handling; focus returns to the element that opened it.
|
|
42
|
+
* Below the md breakpoint it opens as a bottom sheet or full screen.
|
|
43
|
+
*/
|
|
44
|
+
export declare function Dialog({ open, onClose, title, description, children, footer, size, placement, icon, tone, mobile, closeOnBackdrop, closeLabel, initialFocusRef, className, }: DialogProps): import("react").JSX.Element;
|