@faast-app/ui 0.0.0-stage → 0.8.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 +16 -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/kit/catalogo.html +5281 -0
- package/dist/kit/faast-kit.css +5129 -0
- package/dist/kit/markup.json +127 -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 +53 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useId, useRef } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { useModalDialog } from '../utils/useModalDialog.js';
|
|
5
|
+
import { IconButton } from './Button.js';
|
|
6
|
+
import { Icon } from './Icon.js';
|
|
7
|
+
function dialogContains(dialog, target) {
|
|
8
|
+
return !!dialog && dialog.contains(target);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Modal dialog on the native `<dialog>` element: `showModal()` provides the focus trap,
|
|
12
|
+
* inert background and Esc handling; focus returns to the element that opened it.
|
|
13
|
+
* Below the md breakpoint it opens as a bottom sheet or full screen.
|
|
14
|
+
*/
|
|
15
|
+
export function Dialog({ open, onClose, title, description, children, footer, size = 'md', placement = 'center', icon, tone = 'neutral', mobile = 'sheet', closeOnBackdrop = true, closeLabel = 'Cerrar', initialFocusRef, className, }) {
|
|
16
|
+
const ref = useRef(null);
|
|
17
|
+
const onCloseRef = useRef(onClose);
|
|
18
|
+
const id = useId();
|
|
19
|
+
const titleId = `${id}-title`;
|
|
20
|
+
const descriptionId = description ? `${id}-description` : undefined;
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onCloseRef.current = onClose;
|
|
23
|
+
});
|
|
24
|
+
const initialFocusRefRef = useRef(initialFocusRef);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
initialFocusRefRef.current = initialFocusRef;
|
|
27
|
+
});
|
|
28
|
+
const focusInitial = useCallback(() => {
|
|
29
|
+
const target = initialFocusRefRef.current?.current;
|
|
30
|
+
if (target && dialogContains(ref.current, target))
|
|
31
|
+
target.focus();
|
|
32
|
+
}, []);
|
|
33
|
+
useModalDialog(ref, open, focusInitial);
|
|
34
|
+
// Backdrop clicks land on the <dialog> itself (the panel fills its box).
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const dialog = ref.current;
|
|
37
|
+
if (!dialog || !closeOnBackdrop)
|
|
38
|
+
return;
|
|
39
|
+
const onClick = (event) => {
|
|
40
|
+
if (event.target === dialog)
|
|
41
|
+
onCloseRef.current('backdrop');
|
|
42
|
+
};
|
|
43
|
+
dialog.addEventListener('click', onClick);
|
|
44
|
+
return () => dialog.removeEventListener('click', onClick);
|
|
45
|
+
}, [closeOnBackdrop]);
|
|
46
|
+
return (_jsx("dialog", { ref: ref, className: cx('faast-dialog', `faast-dialog--${size}`, placement === 'end' && 'faast-dialog--end', `faast-dialog--mobile-${mobile}`, className), "aria-modal": "true", "aria-labelledby": titleId, "aria-describedby": descriptionId, onCancel: (event) => {
|
|
47
|
+
// Keep React in control: Esc asks the owner to close.
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
onCloseRef.current('escape');
|
|
50
|
+
}, children: open && (_jsxs("div", { className: "faast-dialog__panel", children: [_jsxs("div", { className: "faast-dialog__header", children: [icon && (_jsx("span", { className: cx('faast-dialog__icon', `faast-dialog__icon--${tone}`), "aria-hidden": "true", children: _jsx(Icon, { name: icon, size: 20 }) })), _jsxs("div", { children: [_jsx("h2", { className: "faast-dialog__title", id: titleId, children: title }), description && (_jsx("p", { className: "faast-dialog__description", id: descriptionId, children: description }))] }), _jsx(IconButton, { label: closeLabel, icon: _jsx(Icon, { name: "x", size: 16 }), onClick: () => onCloseRef.current('close-button') })] }), children && _jsx("div", { className: "faast-dialog__body", children: children }), footer && _jsx("div", { className: "faast-dialog__footer", children: footer })] })) }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
export interface EmptyStateProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
4
|
+
/** What is empty, in plain words ("Aún no hay operaciones."). */
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
/** The next step. */
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
/** Decorative icon in a tile above the title ("search-x" for no results). Optional. */
|
|
9
|
+
icon?: IconName;
|
|
10
|
+
/** The first action, where the data will appear. */
|
|
11
|
+
action?: ReactNode;
|
|
12
|
+
/** Heading level when the title should be a heading. Default: a paragraph. */
|
|
13
|
+
level?: 2 | 3 | 4;
|
|
14
|
+
}
|
|
15
|
+
/** Empty block that keeps its frame and offers the next step. No illustration. */
|
|
16
|
+
export declare function EmptyState({ title, description, icon, action, level, className, ...rest }: EmptyStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
/** Empty block that keeps its frame and offers the next step. No illustration. */
|
|
5
|
+
export function EmptyState({ title, description, icon, action, level, className, ...rest }) {
|
|
6
|
+
const Title = level ? `h${level}` : 'p';
|
|
7
|
+
return (_jsxs("div", { className: cx('faast-empty-state', icon && 'faast-empty-state--icon', className), ...rest, children: [icon && (_jsx("span", { className: "faast-empty-state__icon", children: _jsx(Icon, { name: icon, size: 24 }) })), _jsx(Title, { className: "faast-empty-state__title", children: title }), description && _jsx("p", { className: "faast-empty-state__description", children: description }), action && _jsx("div", { className: "faast-empty-state__action", children: action })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type DragEvent, type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
export interface UseFileDropOptions {
|
|
4
|
+
/** Receives the dropped files (never empty). */
|
|
5
|
+
onFiles: (files: File[]) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface FileDropProps {
|
|
9
|
+
onDragEnter: (event: DragEvent<HTMLElement>) => void;
|
|
10
|
+
onDragOver: (event: DragEvent<HTMLElement>) => void;
|
|
11
|
+
onDragLeave: (event: DragEvent<HTMLElement>) => void;
|
|
12
|
+
onDrop: (event: DragEvent<HTMLElement>) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Drag-and-drop of files onto any element. Spread `dropProps` on the drop target (e.g. a whole
|
|
16
|
+
* card) and use `dragging` to style it. Only drags that carry files react; dragging text or
|
|
17
|
+
* links over the target does nothing. Dropping is a convenience: always offer a button.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useFileDrop({ onFiles, disabled }: UseFileDropOptions): {
|
|
20
|
+
dragging: boolean;
|
|
21
|
+
dropProps: FileDropProps;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Stops the browser from opening a file that is dropped outside the drop target (it would
|
|
25
|
+
* navigate away from the page). Call it once in the screen that owns a drop target.
|
|
26
|
+
* Drops that land inside an element marked `data-file-drop` or handled with `preventDefault`
|
|
27
|
+
* by the target itself are unaffected.
|
|
28
|
+
*/
|
|
29
|
+
export declare function usePreventWindowFileDrop(enabled?: boolean): void;
|
|
30
|
+
export interface FileDropAreaProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'onDrop'> {
|
|
31
|
+
/**
|
|
32
|
+
* `empty`: large dashed area with icon, title, description and actions (nothing uploaded
|
|
33
|
+
* yet). `strip`: one compact line (icon and sentence) shown above existing content.
|
|
34
|
+
* Default `empty`.
|
|
35
|
+
*/
|
|
36
|
+
variant?: 'empty' | 'strip';
|
|
37
|
+
/** Default `file-up` for `empty` and `files` for `strip`. */
|
|
38
|
+
icon?: IconName;
|
|
39
|
+
title?: ReactNode;
|
|
40
|
+
/** Heading level of the title in the `empty` variant. Default 3. */
|
|
41
|
+
titleLevel?: 2 | 3 | 4;
|
|
42
|
+
description?: ReactNode;
|
|
43
|
+
/** Buttons that do the same as dropping (choose files). Rendered after the description. */
|
|
44
|
+
actions?: ReactNode;
|
|
45
|
+
/** Called with the dropped files. */
|
|
46
|
+
onFiles: (files: File[]) => void;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Controlled drag-over state, for a parent that is the real drop target through
|
|
50
|
+
* `useFileDrop` (e.g. the whole card). When set (true or false) this area does not listen
|
|
51
|
+
* for drops itself, so a drop is never handled twice; `onFiles` is then unused.
|
|
52
|
+
*/
|
|
53
|
+
dragging?: boolean;
|
|
54
|
+
/** Announced to assistive technology while files are dragged over. Default Spanish. */
|
|
55
|
+
dragLabel?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Drop zone for files. Dashed and sunken when empty; accent outline and accent-subtle
|
|
59
|
+
* background while a file is dragged over (light and dark). The area itself is not focusable:
|
|
60
|
+
* the `actions` buttons are the keyboard and touch path.
|
|
61
|
+
*/
|
|
62
|
+
export declare function FileDropArea({ variant, icon, title, titleLevel, description, actions, onFiles, disabled, dragging: draggingProp, dragLabel, className, children, ...rest }: FileDropAreaProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { Icon } from './Icon.js';
|
|
5
|
+
function hasFiles(event) {
|
|
6
|
+
return Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Drag-and-drop of files onto any element. Spread `dropProps` on the drop target (e.g. a whole
|
|
10
|
+
* card) and use `dragging` to style it. Only drags that carry files react; dragging text or
|
|
11
|
+
* links over the target does nothing. Dropping is a convenience: always offer a button.
|
|
12
|
+
*/
|
|
13
|
+
export function useFileDrop({ onFiles, disabled = false }) {
|
|
14
|
+
const [dragging, setDragging] = useState(false);
|
|
15
|
+
// dragenter/dragleave fire for every child; a counter tells when the drag really left.
|
|
16
|
+
const depth = useRef(0);
|
|
17
|
+
const reset = useCallback(() => {
|
|
18
|
+
depth.current = 0;
|
|
19
|
+
setDragging(false);
|
|
20
|
+
}, []);
|
|
21
|
+
const dropProps = {
|
|
22
|
+
onDragEnter: (event) => {
|
|
23
|
+
if (disabled || !hasFiles(event))
|
|
24
|
+
return;
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
if (!dragging)
|
|
27
|
+
depth.current = 0;
|
|
28
|
+
depth.current += 1;
|
|
29
|
+
setDragging(true);
|
|
30
|
+
},
|
|
31
|
+
onDragOver: (event) => {
|
|
32
|
+
if (disabled || !hasFiles(event))
|
|
33
|
+
return;
|
|
34
|
+
// Required for the element to accept the drop.
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
37
|
+
},
|
|
38
|
+
onDragLeave: (event) => {
|
|
39
|
+
if (disabled || !hasFiles(event))
|
|
40
|
+
return;
|
|
41
|
+
depth.current = Math.max(0, depth.current - 1);
|
|
42
|
+
if (depth.current === 0)
|
|
43
|
+
setDragging(false);
|
|
44
|
+
},
|
|
45
|
+
onDrop: (event) => {
|
|
46
|
+
if (disabled || !hasFiles(event))
|
|
47
|
+
return;
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
reset();
|
|
50
|
+
const files = Array.from(event.dataTransfer.files);
|
|
51
|
+
if (files.length > 0)
|
|
52
|
+
onFiles(files);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return { dragging: dragging && !disabled, dropProps };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stops the browser from opening a file that is dropped outside the drop target (it would
|
|
59
|
+
* navigate away from the page). Call it once in the screen that owns a drop target.
|
|
60
|
+
* Drops that land inside an element marked `data-file-drop` or handled with `preventDefault`
|
|
61
|
+
* by the target itself are unaffected.
|
|
62
|
+
*/
|
|
63
|
+
export function usePreventWindowFileDrop(enabled = true) {
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!enabled)
|
|
66
|
+
return;
|
|
67
|
+
const stop = (event) => {
|
|
68
|
+
if (Array.from(event.dataTransfer?.types ?? []).includes('Files'))
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
};
|
|
71
|
+
window.addEventListener('dragover', stop);
|
|
72
|
+
window.addEventListener('drop', stop);
|
|
73
|
+
return () => {
|
|
74
|
+
window.removeEventListener('dragover', stop);
|
|
75
|
+
window.removeEventListener('drop', stop);
|
|
76
|
+
};
|
|
77
|
+
}, [enabled]);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Drop zone for files. Dashed and sunken when empty; accent outline and accent-subtle
|
|
81
|
+
* background while a file is dragged over (light and dark). The area itself is not focusable:
|
|
82
|
+
* the `actions` buttons are the keyboard and touch path.
|
|
83
|
+
*/
|
|
84
|
+
export function FileDropArea({ variant = 'empty', icon, title, titleLevel = 3, description, actions, onFiles, disabled = false, dragging: draggingProp, dragLabel = 'Suelta los archivos para cargarlos', className, children, ...rest }) {
|
|
85
|
+
const own = useFileDrop({ onFiles, disabled });
|
|
86
|
+
const dragging = draggingProp ?? own.dragging;
|
|
87
|
+
const Heading = `h${titleLevel}`;
|
|
88
|
+
const iconName = icon ?? (variant === 'strip' ? 'files' : 'file-up');
|
|
89
|
+
return (_jsxs("div", { "data-file-drop": "", className: cx('faast-drop', `faast-drop--${variant}`, dragging && 'faast-drop--dragging', disabled && 'faast-drop--disabled', className), ...(draggingProp === undefined ? own.dropProps : undefined), ...rest, children: [_jsx(Icon, { name: iconName, size: variant === 'strip' ? 18 : 28, className: "faast-drop__icon" }), variant === 'empty' ? (_jsxs(_Fragment, { children: [title && _jsx(Heading, { className: "faast-drop__title", children: title }), description && _jsx("p", { className: "faast-drop__description", children: description }), children, actions && _jsx("div", { className: "faast-drop__actions", children: actions })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: "faast-drop__description", children: description ?? title }), children, actions && _jsx("div", { className: "faast-drop__actions", children: actions })] })), _jsx("span", { className: "faast-sr-only", role: "status", "aria-live": "polite", children: dragging ? dragLabel : '' })] }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface FormFieldContextValue {
|
|
3
|
+
controlId: string;
|
|
4
|
+
hintId: string | undefined;
|
|
5
|
+
errorId: string | undefined;
|
|
6
|
+
/** Space-separated ids for `aria-describedby` (hint first, then error). */
|
|
7
|
+
describedBy: string | undefined;
|
|
8
|
+
invalid: boolean;
|
|
9
|
+
required: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Field wiring for custom controls. Returns `null` outside a FormField. */
|
|
12
|
+
export declare function useFormField(): FormFieldContextValue | null;
|
|
13
|
+
/** Merges the field's describedby ids with any the control already has. */
|
|
14
|
+
export declare function mergeDescribedBy(...ids: Array<string | undefined>): string | undefined;
|
|
15
|
+
export interface FormFieldProps {
|
|
16
|
+
/** Visible label (always shown above the control; never a placeholder substitute). */
|
|
17
|
+
label: ReactNode;
|
|
18
|
+
/** Help text: what the field accepts. Linked with `aria-describedby`. */
|
|
19
|
+
hint?: ReactNode;
|
|
20
|
+
/** Error message. Sets `aria-invalid` on the control and is linked with `aria-describedby`. */
|
|
21
|
+
error?: ReactNode;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
/** Text after the label for required fields. Default "(obligatorio)". */
|
|
24
|
+
requiredLabel?: string;
|
|
25
|
+
/** Use your own id for the control. */
|
|
26
|
+
id?: string;
|
|
27
|
+
className?: string;
|
|
28
|
+
/** One control: Input, Select, Textarea, or a custom control using `useFormField()`. */
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Label, hint and error wiring for one control. Controls from this library read the
|
|
33
|
+
* context automatically (id, `aria-describedby`, `aria-invalid`, `required`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function FormField({ label, hint, error, required, requiredLabel, id, className, children, }: FormFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useId } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
const FormFieldContext = createContext(null);
|
|
5
|
+
/** Field wiring for custom controls. Returns `null` outside a FormField. */
|
|
6
|
+
export function useFormField() {
|
|
7
|
+
return useContext(FormFieldContext);
|
|
8
|
+
}
|
|
9
|
+
/** Merges the field's describedby ids with any the control already has. */
|
|
10
|
+
export function mergeDescribedBy(...ids) {
|
|
11
|
+
const merged = ids.filter(Boolean).join(' ');
|
|
12
|
+
return merged || undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Label, hint and error wiring for one control. Controls from this library read the
|
|
16
|
+
* context automatically (id, `aria-describedby`, `aria-invalid`, `required`).
|
|
17
|
+
*/
|
|
18
|
+
export function FormField({ label, hint, error, required = false, requiredLabel = '(obligatorio)', id, className, children, }) {
|
|
19
|
+
const autoId = useId();
|
|
20
|
+
const controlId = id ?? `faast-field-${autoId}`;
|
|
21
|
+
const hintId = hint ? `${controlId}-hint` : undefined;
|
|
22
|
+
const errorId = error ? `${controlId}-error` : undefined;
|
|
23
|
+
const value = {
|
|
24
|
+
controlId,
|
|
25
|
+
hintId,
|
|
26
|
+
errorId,
|
|
27
|
+
describedBy: mergeDescribedBy(hintId, errorId),
|
|
28
|
+
invalid: Boolean(error),
|
|
29
|
+
required,
|
|
30
|
+
};
|
|
31
|
+
return (_jsx(FormFieldContext.Provider, { value: value, children: _jsxs("div", { className: cx('faast-field', Boolean(error) && 'faast-field--invalid', className), children: [_jsxs("label", { className: "faast-field__label", htmlFor: controlId, children: [label, required && _jsxs("span", { className: "faast-field__required", children: [" ", requiredLabel] })] }), children, hint && (_jsx("p", { className: "faast-field__hint", id: hintId, children: hint })), _jsx("p", { className: "faast-field__error", id: `${controlId}-error`, "aria-live": "polite", children: error })] }) }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface HelpMenuLabels {
|
|
3
|
+
/** Accessible name of the trigger ("Ayuda y recorridos"). */
|
|
4
|
+
trigger: string;
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
/** Accessible name of the close button. */
|
|
8
|
+
close: string;
|
|
9
|
+
/** Small line at the bottom ("Esc para cerrar un recorrido"). */
|
|
10
|
+
footer?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface HelpMenuProps {
|
|
13
|
+
labels: HelpMenuLabels;
|
|
14
|
+
/** Controlled open state. Omit to let the menu manage itself. */
|
|
15
|
+
open?: boolean;
|
|
16
|
+
onOpenChange?: (open: boolean) => void;
|
|
17
|
+
/** Hooks for the application (tour anchor, test id) on the trigger button. */
|
|
18
|
+
triggerProps?: {
|
|
19
|
+
'data-tour'?: string;
|
|
20
|
+
'data-testid'?: string;
|
|
21
|
+
};
|
|
22
|
+
/** `HelpMenuItem`s. */
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Help button for the top bar and the panel it opens: a non-modal dialog under the button
|
|
28
|
+
* with the guided tours of the portal. Opening focuses the first action; Esc closes and
|
|
29
|
+
* returns focus to the button; a press outside closes it without moving focus. It is rendered
|
|
30
|
+
* next to the trigger (fixed position, set through the CSSOM) so the tab order stays natural.
|
|
31
|
+
*/
|
|
32
|
+
export declare function HelpMenu({ labels, open: openProp, onOpenChange, triggerProps, children, className, }: HelpMenuProps): import("react").JSX.Element;
|
|
33
|
+
export interface HelpMenuItemProps {
|
|
34
|
+
title: string;
|
|
35
|
+
/** Secondary line ("9 pasos · 2 min"). */
|
|
36
|
+
meta: string;
|
|
37
|
+
status: {
|
|
38
|
+
tone: 'info' | 'warning' | 'success';
|
|
39
|
+
label: string;
|
|
40
|
+
};
|
|
41
|
+
/** Buttons: primary first ("Empezar", "Continuar"), then secondary or ghost. */
|
|
42
|
+
actions: ReactNode;
|
|
43
|
+
className?: string;
|
|
44
|
+
}
|
|
45
|
+
/** One tour in the help panel: title, meta, status badge and its actions. */
|
|
46
|
+
export declare function HelpMenuItem({ title, meta, status, actions, className }: HelpMenuItemProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { cx } from '../utils/cx.js';
|
|
4
|
+
import { StatusBadge } from './Badge.js';
|
|
5
|
+
import { IconButton } from './Button.js';
|
|
6
|
+
import { Icon } from './Icon.js';
|
|
7
|
+
/**
|
|
8
|
+
* Help button for the top bar and the panel it opens: a non-modal dialog under the button
|
|
9
|
+
* with the guided tours of the portal. Opening focuses the first action; Esc closes and
|
|
10
|
+
* returns focus to the button; a press outside closes it without moving focus. It is rendered
|
|
11
|
+
* next to the trigger (fixed position, set through the CSSOM) so the tab order stays natural.
|
|
12
|
+
*/
|
|
13
|
+
export function HelpMenu({ labels, open: openProp, onOpenChange, triggerProps, children, className, }) {
|
|
14
|
+
const [openState, setOpenState] = useState(false);
|
|
15
|
+
const open = openProp ?? openState;
|
|
16
|
+
const triggerRef = useRef(null);
|
|
17
|
+
const panelRef = useRef(null);
|
|
18
|
+
const id = useId();
|
|
19
|
+
const panelId = `${id}-panel`;
|
|
20
|
+
const titleId = `${id}-title`;
|
|
21
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
onOpenChangeRef.current = onOpenChange;
|
|
24
|
+
});
|
|
25
|
+
const openRef = useRef(open);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
openRef.current = open;
|
|
28
|
+
});
|
|
29
|
+
const setOpen = (next) => {
|
|
30
|
+
if (openProp === undefined)
|
|
31
|
+
setOpenState(next);
|
|
32
|
+
onOpenChange?.(next);
|
|
33
|
+
};
|
|
34
|
+
// Under the trigger, at the end edge (right is in the stylesheet).
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
if (!open)
|
|
37
|
+
return;
|
|
38
|
+
const place = () => {
|
|
39
|
+
const trigger = triggerRef.current;
|
|
40
|
+
const panel = panelRef.current;
|
|
41
|
+
if (!trigger || !panel)
|
|
42
|
+
return;
|
|
43
|
+
panel.style.top = `${String(trigger.getBoundingClientRect().bottom + 8)}px`;
|
|
44
|
+
};
|
|
45
|
+
place();
|
|
46
|
+
window.addEventListener('resize', place);
|
|
47
|
+
window.addEventListener('scroll', place, { capture: true, passive: true });
|
|
48
|
+
return () => {
|
|
49
|
+
window.removeEventListener('resize', place);
|
|
50
|
+
window.removeEventListener('scroll', place, { capture: true });
|
|
51
|
+
};
|
|
52
|
+
}, [open]);
|
|
53
|
+
// Opening moves focus to the first action of the panel.
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!open)
|
|
56
|
+
return;
|
|
57
|
+
const panel = panelRef.current;
|
|
58
|
+
if (!panel)
|
|
59
|
+
return;
|
|
60
|
+
const first = panel.querySelector('.faast-button');
|
|
61
|
+
(first ?? panel).focus({ preventScroll: true });
|
|
62
|
+
}, [open]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!open)
|
|
65
|
+
return;
|
|
66
|
+
const close = (returnFocus) => {
|
|
67
|
+
if (!openRef.current)
|
|
68
|
+
return;
|
|
69
|
+
if (openProp === undefined)
|
|
70
|
+
setOpenState(false);
|
|
71
|
+
onOpenChangeRef.current?.(false);
|
|
72
|
+
if (returnFocus)
|
|
73
|
+
triggerRef.current?.focus();
|
|
74
|
+
};
|
|
75
|
+
const onKeyDown = (event) => {
|
|
76
|
+
if (event.key === 'Escape' && !event.defaultPrevented) {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
close(true);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const onPointerDown = (event) => {
|
|
82
|
+
const target = event.target;
|
|
83
|
+
if (!(target instanceof Node))
|
|
84
|
+
return;
|
|
85
|
+
if (panelRef.current?.contains(target) || triggerRef.current?.contains(target))
|
|
86
|
+
return;
|
|
87
|
+
close(false);
|
|
88
|
+
};
|
|
89
|
+
document.addEventListener('keydown', onKeyDown);
|
|
90
|
+
document.addEventListener('pointerdown', onPointerDown, true);
|
|
91
|
+
return () => {
|
|
92
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
93
|
+
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
94
|
+
};
|
|
95
|
+
}, [open, openProp]);
|
|
96
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconButton, { ref: triggerRef, label: labels.trigger, icon: _jsx(Icon, { name: "circle-help" }), "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? panelId : undefined, onClick: () => setOpen(!open), ...triggerProps }), open && (_jsxs("div", { ref: panelRef, id: panelId, className: cx('faast-help-menu', className), role: "dialog", "aria-modal": "false", "aria-labelledby": titleId, tabIndex: -1, children: [_jsxs("div", { className: "faast-help-menu__head", children: [_jsxs("div", { children: [_jsx("h2", { className: "faast-help-menu__title", id: titleId, children: labels.title }), _jsx("p", { className: "faast-help-menu__description", children: labels.description })] }), _jsx(IconButton, { label: labels.close, icon: _jsx(Icon, { name: "x", size: 16 }), onClick: () => {
|
|
97
|
+
setOpen(false);
|
|
98
|
+
triggerRef.current?.focus();
|
|
99
|
+
} })] }), _jsx("ul", { className: "faast-help-menu__list", children: children }), labels.footer && (_jsx("div", { className: "faast-help-menu__footer", children: _jsx("span", { children: labels.footer }) }))] }))] }));
|
|
100
|
+
}
|
|
101
|
+
/** One tour in the help panel: title, meta, status badge and its actions. */
|
|
102
|
+
export function HelpMenuItem({ title, meta, status, actions, className }) {
|
|
103
|
+
return (_jsxs("li", { className: cx('faast-help-item', className), children: [_jsx("b", { className: "faast-help-item__title", children: title }), _jsx(StatusBadge, { status: status.tone, className: "faast-help-item__status", children: status.label }), _jsx("span", { className: "faast-help-item__meta", children: meta }), _jsx("div", { className: "faast-help-item__actions", children: actions })] }));
|
|
104
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SVGProps } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The closed set of icon names. Only these Lucide icons are imported, so a bundler keeps
|
|
4
|
+
* exactly this set. Applications validate backend icon ids with `isIconName` before
|
|
5
|
+
* rendering; an unknown id is a configuration error, never rendered.
|
|
6
|
+
*/
|
|
7
|
+
export declare const iconNames: readonly ["arrow-down", "arrow-left-right", "arrow-right", "arrow-up", "arrow-up-down", "ban", "bell", "bell-off", "book-open", "building-2", "calculator", "calendar", "calendar-cog", "check", "check-check", "check-circle-2", "chevron-down", "chevron-left", "chevron-right", "chevron-up", "chevrons-up-down", "circle-alert", "circle-check", "circle-help", "circle-x", "coins", "columns-3-cog", "download", "eraser", "eye", "eye-off", "file-check", "file-code-2", "file-plus", "file-spreadsheet", "file-text", "file-up", "file-warning", "file-x", "files", "fingerprint", "folder-clock", "globe", "history", "house", "image", "info", "key-round", "layout-dashboard", "list", "lock", "log-in", "log-out", "mail", "menu", "monitor", "moon", "palette", "panel-left", "paperclip", "pencil", "play", "plus", "refresh-cw", "repeat", "replace", "rotate-cw", "route", "search", "search-x", "send", "settings", "shield-alert", "shield-check", "sliders-horizontal", "sun", "timer", "trash-2", "triangle-alert", "undo-2", "upload", "user-round", "users", "x", "x-circle"];
|
|
8
|
+
export type IconName = (typeof iconNames)[number];
|
|
9
|
+
/** Type guard for icon ids that come from configuration (e.g. backend navigation). */
|
|
10
|
+
export declare function isIconName(value: unknown): value is IconName;
|
|
11
|
+
export interface IconProps extends Omit<SVGProps<SVGSVGElement>, 'ref' | 'name' | 'children' | 'width' | 'height'> {
|
|
12
|
+
name: IconName;
|
|
13
|
+
/** Rendered size in px (square). Default 20. */
|
|
14
|
+
size?: number;
|
|
15
|
+
/** Stroke width on the 24px grid. Default 1.75. */
|
|
16
|
+
strokeWidth?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Accessible name. When set the icon is exposed as `role="img"`; otherwise it is
|
|
19
|
+
* decorative and hidden from assistive technology (the default).
|
|
20
|
+
*/
|
|
21
|
+
label?: string;
|
|
22
|
+
}
|
|
23
|
+
/** One Lucide icon from the allowlist. Colour follows `currentColor`. */
|
|
24
|
+
export declare function Icon({ name, size, strokeWidth, label, className, ...rest }: IconProps): import("react").JSX.Element;
|