@kapiuara/ui 0.17.0 → 0.18.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 +259 -9
- package/dist/components/data/KapiScatterChart.d.ts +56 -0
- package/dist/components/data/KapiScatterChart.js +90 -0
- package/dist/components/data/chartFrame.d.ts +20 -2
- package/dist/components/data/chartFrame.js +33 -24
- package/dist/components/data/index.d.ts +4 -0
- package/dist/components/data/scatterLogic.d.ts +56 -0
- package/dist/components/data/scatterLogic.js +43 -0
- package/dist/components/display/KapiAvatarGroup.d.ts +14 -2
- package/dist/components/display/KapiAvatarGroup.js +25 -23
- package/dist/components/display/KapiTimeline.d.ts +14 -0
- package/dist/components/display/KapiTimeline.js +28 -21
- package/dist/components/display/avatarGroupSlots.d.ts +6 -0
- package/dist/components/display/avatarGroupSlots.js +9 -0
- package/dist/components/display/index.d.ts +1 -1
- package/dist/components/feedback/KapiAlert.d.ts +6 -1
- package/dist/components/feedback/KapiAlert.js +45 -44
- package/dist/components/feedback/KapiCountdown.d.ts +12 -1
- package/dist/components/feedback/KapiCountdown.js +34 -31
- package/dist/components/feedback/KapiEmpty.d.ts +6 -1
- package/dist/components/feedback/KapiEmpty.js +20 -18
- package/dist/components/feedback/KapiProgress.js +1 -1
- package/dist/components/feedback/KapiSpinner.d.ts +48 -0
- package/dist/components/feedback/KapiSpinner.js +27 -0
- package/dist/components/feedback/KapiToastContainer.js +1 -1
- package/dist/components/feedback/KapiTour.js +1 -1
- package/dist/components/feedback/alertSlots.d.ts +9 -0
- package/dist/components/feedback/alertSlots.js +12 -0
- package/dist/components/feedback/countdownSlots.d.ts +6 -0
- package/dist/components/feedback/countdownSlots.js +9 -0
- package/dist/components/feedback/emptySlots.d.ts +8 -0
- package/dist/components/feedback/emptySlots.js +11 -0
- package/dist/components/feedback/index.d.ts +5 -3
- package/dist/components/inputs/KapiFileUpload.d.ts +14 -1
- package/dist/components/inputs/KapiFileUpload.js +80 -67
- package/dist/components/inputs/formBridgeLogic.d.ts +104 -0
- package/dist/components/inputs/formBridgeLogic.js +25 -0
- package/dist/components/inputs/index.d.ts +2 -0
- package/dist/components/locale/labelRegistry.d.ts +8 -0
- package/dist/components/navigation/KapiSteps.d.ts +26 -5
- package/dist/components/navigation/KapiSteps.js +55 -43
- package/dist/components/overlays/KapiImageViewer.d.ts +63 -0
- package/dist/components/overlays/KapiImageViewer.js +106 -0
- package/dist/components/overlays/KapiShortcutsHelp.d.ts +53 -0
- package/dist/components/overlays/KapiShortcutsHelp.js +55 -0
- package/dist/components/overlays/KapiTooltip.d.ts +49 -10
- package/dist/components/overlays/KapiTooltip.js +110 -58
- package/dist/components/overlays/KapiViewport.d.ts +63 -0
- package/dist/components/overlays/KapiViewport.js +195 -0
- package/dist/components/overlays/index.d.ts +8 -0
- package/dist/components/overlays/shortcutsHelpSlots.d.ts +9 -0
- package/dist/components/overlays/shortcutsHelpSlots.js +12 -0
- package/dist/components/overlays/viewportLogic.d.ts +73 -0
- package/dist/components/overlays/viewportLogic.js +54 -0
- package/dist/components/slotCatalog.d.ts +33 -0
- package/dist/components/slotCatalog.js +30 -20
- package/dist/css/base.css +1 -1
- package/dist/css/components/data/KapiScatterChart.css +1 -0
- package/dist/css/components/display/display.css +1 -1
- package/dist/css/components/inputs/KapiFileUpload.css +1 -1
- package/dist/css/components/navigation/KapiSteps.css +1 -1
- package/dist/css/components/overlays/KapiViewport.css +1 -0
- package/dist/css/components/overlays/overlays.css +1 -1
- package/dist/hooks/elementSizeLogic.d.ts +15 -0
- package/dist/hooks/elementSizeLogic.js +7 -0
- package/dist/hooks/hotkeyLogic.d.ts +9 -0
- package/dist/hooks/hotkeyLogic.js +16 -15
- package/dist/hooks/hotkeyRegistry.d.ts +44 -0
- package/dist/hooks/hotkeyRegistry.js +32 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/useDebouncedValue.d.ts +30 -0
- package/dist/hooks/useDebouncedValue.js +26 -0
- package/dist/hooks/useDisclosure.d.ts +39 -0
- package/dist/hooks/useDisclosure.js +35 -0
- package/dist/hooks/useElementSize.d.ts +27 -0
- package/dist/hooks/useElementSize.js +29 -0
- package/dist/hooks/useHotkey.d.ts +8 -0
- package/dist/hooks/useHotkey.js +27 -15
- package/dist/index.js +201 -188
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/dist/logic.d.ts +4 -0
- package/dist/logic.js +33 -29
- package/package.json +1 -1
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/feedback/feedback.css";
|
|
3
|
+
import { slot as e } from "../slotsLogic.js";
|
|
3
4
|
/* empty css */
|
|
4
|
-
import {
|
|
5
|
+
import { EMPTY_SLOTS as t } from "./emptySlots.js";
|
|
6
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
5
7
|
//#region src/components/feedback/KapiEmpty.tsx
|
|
6
|
-
function
|
|
7
|
-
return /* @__PURE__ */
|
|
8
|
-
|
|
9
|
-
...
|
|
8
|
+
function i({ icon: i, title: a, description: o, action: s, className: c, classNames: l, ...u }) {
|
|
9
|
+
return /* @__PURE__ */ r("div", {
|
|
10
|
+
...u,
|
|
11
|
+
...e(t, "root", l, c),
|
|
10
12
|
children: [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
i != null && /* @__PURE__ */ n("div", {
|
|
14
|
+
...e(t, "icon", l),
|
|
13
15
|
"aria-hidden": !0,
|
|
14
|
-
children: n
|
|
15
|
-
}),
|
|
16
|
-
/* @__PURE__ */ e("div", {
|
|
17
|
-
className: "kapi-empty__title",
|
|
18
|
-
children: r
|
|
19
|
-
}),
|
|
20
|
-
i != null && /* @__PURE__ */ e("div", {
|
|
21
|
-
className: "kapi-empty__desc",
|
|
22
16
|
children: i
|
|
23
17
|
}),
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
/* @__PURE__ */ n("div", {
|
|
19
|
+
...e(t, "title", l),
|
|
26
20
|
children: a
|
|
21
|
+
}),
|
|
22
|
+
o != null && /* @__PURE__ */ n("div", {
|
|
23
|
+
...e(t, "description", l),
|
|
24
|
+
children: o
|
|
25
|
+
}),
|
|
26
|
+
s != null && /* @__PURE__ */ n("div", {
|
|
27
|
+
...e(t, "action", l),
|
|
28
|
+
children: s
|
|
27
29
|
})
|
|
28
30
|
]
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
//#endregion
|
|
32
|
-
export {
|
|
34
|
+
export { i as KapiEmpty };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/feedback/feedback.css";
|
|
3
3
|
import { useToneLook as e } from "../../hooks/useToneFamilies.js";
|
|
4
|
-
/* empty css */
|
|
5
4
|
import { circleDash as t, clampPercent as n, formatPercent as r, progressClasses as i } from "./progressLogic.js";
|
|
5
|
+
/* empty css */
|
|
6
6
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
7
|
//#region src/components/feedback/KapiProgress.tsx
|
|
8
8
|
var s = {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { HTMLAttributes, Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic.js";
|
|
3
|
+
/** Textos de `KapiSpinner`. */
|
|
4
|
+
export type KapiSpinnerLabels = {
|
|
5
|
+
/** Nombre accesible (y texto visible con `labelVisible`). */
|
|
6
|
+
loading: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const DEFAULT_SPINNER_LABELS: KapiSpinnerLabels;
|
|
9
|
+
/** Tamaños de `KapiSpinner`: los dos que dibuja la hoja base. */
|
|
10
|
+
export type KapiSpinnerSize = "sm" | "md";
|
|
11
|
+
/** Atributos nativos (`id`, `style`, `data-*`…) van al contenedor. */
|
|
12
|
+
export type KapiSpinnerProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
13
|
+
/** Ref al `<div>` raíz. */
|
|
14
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* `sm` mide 20px y entra al lado de un texto; `md` mide 46px y es el de una zona que carga entera.
|
|
17
|
+
* @default "md"
|
|
18
|
+
*/
|
|
19
|
+
size?: KapiSpinnerSize | undefined;
|
|
20
|
+
/** Nombre accesible propio. Sin él, el del locale (`Cargando`). */
|
|
21
|
+
label?: string | undefined;
|
|
22
|
+
/** Además de nombrarlo, muestra el texto debajo del disco. */
|
|
23
|
+
labelVisible?: boolean | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Lo saca del árbol de accesibilidad. Para cuando el estado de carga **ya lo anuncia otra cosa**
|
|
26
|
+
* (un `KapiButton loading`, una tabla con `aria-busy`): dos anuncios del mismo hecho son ruido
|
|
27
|
+
* para quien usa un lector de pantalla.
|
|
28
|
+
*/
|
|
29
|
+
decorative?: boolean | undefined;
|
|
30
|
+
/** Textos fijos (el nombre accesible). */
|
|
31
|
+
labels?: KapiLabelsOverride<KapiSpinnerLabels> | undefined;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Indicador de carga en línea.
|
|
35
|
+
*
|
|
36
|
+
* Existe porque hasta ahora había dos extremos y nada en el medio: `.kapi-spinner` es **sólo una
|
|
37
|
+
* clase** —cada pantalla escribía el `<span>` a mano y casi siempre sin anunciar nada— y
|
|
38
|
+
* `KapiLoading` es un **overlay** que tapa la pantalla entera. Esto es el disco solo, con el
|
|
39
|
+
* anuncio hecho bien: `role="status"` y un nombre accesible, o nada en absoluto con `decorative`.
|
|
40
|
+
* **No lleva `aria-busy`**, y es a propósito: sobre una región viva le diría al lector que espere y
|
|
41
|
+
* se perdería el anuncio, que es justo lo que este componente existe para hacer. El motivo completo
|
|
42
|
+
* está en el comentario de la raíz, al lado del `role`.
|
|
43
|
+
*
|
|
44
|
+
* No trae CSS propio: usa las clases que la hoja base ya dibuja, así que el gate de movimiento lo
|
|
45
|
+
* sigue tratando como loop de carga (gira lento en vez de congelarse con `data-motion="reduced"`,
|
|
46
|
+
* porque un spinner congelado parece colgado).
|
|
47
|
+
*/
|
|
48
|
+
export declare const KapiSpinner: ({ size, label, labelVisible, decorative, labels, className, ...rest }: KapiSpinnerProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { joinClasses as e } from "../rootProps.js";
|
|
3
|
+
import { useLabels as t } from "../locale/KapiLocaleProvider.js";
|
|
4
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/feedback/KapiSpinner.tsx
|
|
6
|
+
var i = { loading: "Cargando" }, a = ({ size: a = "md", label: o, labelVisible: s, decorative: c, labels: l, className: u, ...d }) => {
|
|
7
|
+
let f = t("spinner", i, l), p = o ?? f.loading, m = /* @__PURE__ */ n("div", {
|
|
8
|
+
className: e("kapi-spinner", a === "sm" && "kapi-spinner--sm"),
|
|
9
|
+
"aria-hidden": "true"
|
|
10
|
+
});
|
|
11
|
+
return c ? /* @__PURE__ */ n("div", {
|
|
12
|
+
...d,
|
|
13
|
+
className: u,
|
|
14
|
+
"aria-hidden": "true",
|
|
15
|
+
children: m
|
|
16
|
+
}) : /* @__PURE__ */ r("div", {
|
|
17
|
+
...d,
|
|
18
|
+
className: u,
|
|
19
|
+
role: "status",
|
|
20
|
+
children: [m, /* @__PURE__ */ n("span", {
|
|
21
|
+
className: s ? void 0 : "kapi-sr-only",
|
|
22
|
+
children: p
|
|
23
|
+
})]
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { i as DEFAULT_SPINNER_LABELS, a as KapiSpinner };
|
|
@@ -6,8 +6,8 @@ import { useLabels as n } from "../locale/KapiLocaleProvider.js";
|
|
|
6
6
|
import { activeElementOf as r, docOf as i } from "../../hooks/ownerDocument.js";
|
|
7
7
|
import { usePortalRootOverride as a } from "../../hooks/portalRoot.js";
|
|
8
8
|
import { modalStack as o } from "../overlays/modalStack.js";
|
|
9
|
-
import { getPortalRoot as s } from "../overlays/useNativeDialog.js";
|
|
10
9
|
/* empty css */
|
|
10
|
+
import { getPortalRoot as s } from "../overlays/useNativeDialog.js";
|
|
11
11
|
import { moveNode as c, raisePopover as l } from "./toastLayer.js";
|
|
12
12
|
import { toastStore as u } from "./toastStore.js";
|
|
13
13
|
import { useEffect as d, useLayoutEffect as f, useRef as p, useState as m, useSyncExternalStore as h } from "react";
|
|
@@ -9,8 +9,8 @@ import { useKapiRoot as s } from "../../hooks/kapiRoot.js";
|
|
|
9
9
|
import { onViewportChange as c } from "../../hooks/rafThrottle.js";
|
|
10
10
|
import { usePlacement as l } from "../../hooks/usePlacement.js";
|
|
11
11
|
import { useDismiss as u } from "../../hooks/useDismiss.js";
|
|
12
|
-
import { trapTabKey as d } from "../../hooks/focusLogic.js";
|
|
13
12
|
/* empty css */
|
|
13
|
+
import { trapTabKey as d } from "../../hooks/focusLogic.js";
|
|
14
14
|
import { TOUR_PLACEMENT as f, filterAvailableSteps as p, highlightBox as m, markTourSeen as h } from "./tourLogic.js";
|
|
15
15
|
import { useCallback as g, useEffect as _, useId as v, useLayoutEffect as y, useRef as b, useState as x } from "react";
|
|
16
16
|
import { jsx as S, jsxs as C } from "react/jsx-runtime";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Partes de `alert` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
|
|
2
|
+
export declare const ALERT_SLOTS: import("../slotsLogic.js").SlotTable<"alert", {
|
|
3
|
+
readonly root: "kapi-alert";
|
|
4
|
+
readonly icon: "kapi-alert__ico";
|
|
5
|
+
readonly body: "kapi-alert__body";
|
|
6
|
+
readonly title: "kapi-alert__title";
|
|
7
|
+
readonly message: "kapi-alert__msg";
|
|
8
|
+
readonly close: "kapi-alert__close";
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineSlots as e } from "../slotsLogic.js";
|
|
2
|
+
//#region src/components/feedback/alertSlots.ts
|
|
3
|
+
var t = e("alert", {
|
|
4
|
+
root: "kapi-alert",
|
|
5
|
+
icon: "kapi-alert__ico",
|
|
6
|
+
body: "kapi-alert__body",
|
|
7
|
+
title: "kapi-alert__title",
|
|
8
|
+
message: "kapi-alert__msg",
|
|
9
|
+
close: "kapi-alert__close"
|
|
10
|
+
});
|
|
11
|
+
//#endregion
|
|
12
|
+
export { t as ALERT_SLOTS };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Partes de `countdown` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
|
|
2
|
+
export declare const COUNTDOWN_SLOTS: import("../slotsLogic.js").SlotTable<"countdown", {
|
|
3
|
+
readonly root: "kapi-countdown";
|
|
4
|
+
readonly prefix: "kapi-countdown__prefix";
|
|
5
|
+
readonly time: "kapi-countdown__time";
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineSlots as e } from "../slotsLogic.js";
|
|
2
|
+
//#region src/components/feedback/countdownSlots.ts
|
|
3
|
+
var t = e("countdown", {
|
|
4
|
+
root: "kapi-countdown",
|
|
5
|
+
prefix: "kapi-countdown__prefix",
|
|
6
|
+
time: "kapi-countdown__time"
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as COUNTDOWN_SLOTS };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Partes de `empty` (ver `slotCatalog.ts` para el contrato). Vive junto al componente para que su CSS lo siga. */
|
|
2
|
+
export declare const EMPTY_SLOTS: import("../slotsLogic.js").SlotTable<"empty", {
|
|
3
|
+
readonly root: "kapi-empty";
|
|
4
|
+
readonly icon: "kapi-empty__icon";
|
|
5
|
+
readonly title: "kapi-empty__title";
|
|
6
|
+
readonly description: "kapi-empty__desc";
|
|
7
|
+
readonly action: "kapi-empty__action";
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineSlots as e } from "../slotsLogic.js";
|
|
2
|
+
//#region src/components/feedback/emptySlots.ts
|
|
3
|
+
var t = e("empty", {
|
|
4
|
+
root: "kapi-empty",
|
|
5
|
+
icon: "kapi-empty__icon",
|
|
6
|
+
title: "kapi-empty__title",
|
|
7
|
+
description: "kapi-empty__desc",
|
|
8
|
+
action: "kapi-empty__action"
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
export { t as EMPTY_SLOTS };
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
export { KapiAlert,
|
|
2
2
|
/** @deprecated Interno, se quita en 1.0. */
|
|
3
3
|
alertRole, DEFAULT_ALERT_LABELS } from "./KapiAlert.js";
|
|
4
|
-
export type { KapiAlertLabels, KapiAlertProps, KapiAlertRole, KapiAlertTone, KapiAlertVariant } from "./KapiAlert.js";
|
|
4
|
+
export type { KapiAlertLabels, KapiAlertClassNames, KapiAlertProps, KapiAlertRole, KapiAlertTone, KapiAlertVariant } from "./KapiAlert.js";
|
|
5
5
|
export { KapiToastContainer, DEFAULT_TOAST_LABELS } from "./KapiToastContainer.js";
|
|
6
6
|
export type { KapiToastContainerProps, KapiToastLabels } from "./KapiToastContainer.js";
|
|
7
7
|
export { kapiToast, toastStore,
|
|
8
8
|
/** @deprecated Interno, se quita en 1.0. */
|
|
9
9
|
createToastStore, TOAST_ACTION_DURATION, TOAST_DEFAULT_DURATION } from "./toastStore.js";
|
|
10
10
|
export type { KapiToastAction, KapiToastItem, KapiToastMessage, KapiToastOptions, KapiToastPromiseMessages, KapiToastShowOptions, KapiToastStore, KapiToastStoreOptions, KapiToastTone, KapiToastUpdate, KapiToastVariant } from "./toastStore.js";
|
|
11
|
+
export { KapiSpinner, DEFAULT_SPINNER_LABELS } from "./KapiSpinner.js";
|
|
12
|
+
export type { KapiSpinnerProps, KapiSpinnerLabels, KapiSpinnerSize } from "./KapiSpinner.js";
|
|
11
13
|
export { KapiSkeleton } from "./KapiSkeleton.js";
|
|
12
14
|
export type { KapiSkeletonProps } from "./KapiSkeleton.js";
|
|
13
15
|
export { KapiFab, DEFAULT_FAB_LABELS } from "./KapiFab.js";
|
|
@@ -27,9 +29,9 @@ clampPercent, formatPercent,
|
|
|
27
29
|
progressClasses } from "./progressLogic.js";
|
|
28
30
|
export type { KapiProgressTone } from "./progressLogic.js";
|
|
29
31
|
export { KapiEmpty } from "./KapiEmpty.js";
|
|
30
|
-
export type { KapiEmptyProps } from "./KapiEmpty.js";
|
|
32
|
+
export type { KapiEmptyClassNames, KapiEmptyProps } from "./KapiEmpty.js";
|
|
31
33
|
export { KapiCountdown } from "./KapiCountdown.js";
|
|
32
|
-
export type { KapiCountdownProps } from "./KapiCountdown.js";
|
|
34
|
+
export type { KapiCountdownClassNames, KapiCountdownProps } from "./KapiCountdown.js";
|
|
33
35
|
export { KapiUnsavedBar, DEFAULT_UNSAVED_BAR_LABELS } from "./KapiUnsavedBar.js";
|
|
34
36
|
export type { KapiUnsavedBarProps, KapiUnsavedBarLabels } from "./KapiUnsavedBar.js";
|
|
35
37
|
export { KapiBulkBar, DEFAULT_BULK_BAR_LABELS } from "./KapiBulkBar.js";
|
|
@@ -32,6 +32,17 @@ export type KapiFileUploadProps = {
|
|
|
32
32
|
onBlur?: ((event: FocusEvent<HTMLDivElement>) => void) | undefined;
|
|
33
33
|
/** Marca la zona como inválida (`aria-invalid`). Sin la prop, lo toma del `KapiField` (`invalid`). */
|
|
34
34
|
invalid?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Progreso de subida de cada archivo, 0–100. Devolver `undefined` para un archivo es no mostrarle
|
|
37
|
+
* barra (todavía no empezó, o ya terminó). Es una **función y no un mapa por nombre** porque la
|
|
38
|
+
* lista admite dos archivos con el mismo nombre y un mapa se los pisaría entre sí.
|
|
39
|
+
*/
|
|
40
|
+
progress?: ((file: File, index: number) => number | undefined) | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Permite pegar archivos del portapapeles con Ctrl/Cmd+V cuando la zona tiene el foco (una captura
|
|
43
|
+
* de pantalla, por ejemplo). Respeta `accept` y `multiple`, igual que arrastrar.
|
|
44
|
+
*/
|
|
45
|
+
paste?: boolean | undefined;
|
|
35
46
|
/** `id`s extra para `aria-describedby` (se suman a la ayuda del campo y al hint). */
|
|
36
47
|
"aria-describedby"?: string | undefined;
|
|
37
48
|
/** Ref a la zona (el elemento enfocable, `role="button"`). */
|
|
@@ -46,6 +57,8 @@ export type KapiFileUploadLabels = {
|
|
|
46
57
|
remove: string;
|
|
47
58
|
/** Ayuda bajo el título (sin `hint`). */
|
|
48
59
|
hint: string;
|
|
60
|
+
/** Prefijo del nombre accesible de la barra de progreso ("Subiendo informe.pdf"). */
|
|
61
|
+
uploading: string;
|
|
49
62
|
};
|
|
50
63
|
export declare const DEFAULT_FILE_UPLOAD_LABELS: KapiFileUploadLabels;
|
|
51
64
|
/**
|
|
@@ -54,4 +67,4 @@ export declare const DEFAULT_FILE_UPLOAD_LABELS: KapiFileUploadLabels;
|
|
|
54
67
|
* Dentro de un `KapiField` la zona toma id, nombre (label del campo + texto de la zona), ayuda y `aria-invalid`.
|
|
55
68
|
* No lleva `aria-required` (no es válido en `role="button"`): el obligatorio se ve en el asterisco del label.
|
|
56
69
|
*/
|
|
57
|
-
export declare const KapiFileUpload: ({ multiple, accept, hint: hintProp, onChange, disabled, className, style, labels, name, id, onBlur, invalid, "aria-describedby": describedBy, ref }: KapiFileUploadProps) => import("react").JSX.Element;
|
|
70
|
+
export declare const KapiFileUpload: ({ multiple, accept, hint: hintProp, onChange, disabled, className, style, labels, name, id, onBlur, invalid, progress, paste, "aria-describedby": describedBy, ref }: KapiFileUploadProps) => import("react").JSX.Element;
|
|
@@ -6,124 +6,137 @@ import { fieldControlProps as n, joinIds as r } from "./fieldLogic.js";
|
|
|
6
6
|
import { useKapiField as i } from "./KapiField.js";
|
|
7
7
|
import { formatFileSize as a, isActivationKey as o, matchesAccept as s, mergeFiles as c, removeFileAt as l } from "./fileUploadLogic.js";
|
|
8
8
|
/* empty css */
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { KapiProgress as u } from "../feedback/KapiProgress.js";
|
|
10
|
+
import { useEffect as d, useId as f, useRef as p, useState as m } from "react";
|
|
11
|
+
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
12
|
+
import { FileText as _, UploadCloud as v, X as y } from "lucide-react";
|
|
12
13
|
//#region src/components/inputs/KapiFileUpload.tsx
|
|
13
|
-
var
|
|
14
|
+
var b = {
|
|
14
15
|
drop: "Arrastra archivos o",
|
|
15
16
|
choose: "elige",
|
|
16
17
|
remove: "Quitar",
|
|
17
|
-
hint: "PDF, JPG, PNG · hasta 10MB"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
hint: "PDF, JPG, PNG · hasta 10MB",
|
|
19
|
+
uploading: "Subiendo"
|
|
20
|
+
}, x = ({ multiple: x = !0, accept: S, hint: C, onChange: w, disabled: T = !1, className: E, style: D, labels: O, name: k, id: A, onBlur: j, invalid: M, progress: N, paste: P = !1, "aria-describedby": F, ref: I }) => {
|
|
21
|
+
let L = t("fileUpload", b, O), R = C ?? L.hint, z = i(), [B, V] = m([]), [H, U] = m(!1), W = p(null), G = f(), K = `${G}-title`, q = `${G}-hint`, J = !!z?.labelId, Y = n(z, {
|
|
22
|
+
id: A,
|
|
23
|
+
describedBy: r(J && q, F),
|
|
24
|
+
invalid: M
|
|
23
25
|
});
|
|
24
|
-
|
|
25
|
-
let e =
|
|
26
|
-
if (!
|
|
26
|
+
d(() => {
|
|
27
|
+
let e = W.current;
|
|
28
|
+
if (!k || !e || typeof DataTransfer > "u" || B.length === 0 && !e.files?.length) return;
|
|
27
29
|
let t = new DataTransfer();
|
|
28
|
-
|
|
29
|
-
}, [
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
},
|
|
30
|
+
B.forEach((e) => t.items.add(e)), e.files = t.files;
|
|
31
|
+
}, [B, k]);
|
|
32
|
+
let X = (e) => {
|
|
33
|
+
V(e), w?.(e);
|
|
34
|
+
}, Z = (e) => {
|
|
33
35
|
let t = Array.from(e ?? []);
|
|
34
|
-
t.length !== 0 &&
|
|
35
|
-
},
|
|
36
|
-
return /* @__PURE__ */
|
|
37
|
-
className: e("kapi-upload-wrap",
|
|
38
|
-
style:
|
|
36
|
+
t.length !== 0 && X(c(B, t, x));
|
|
37
|
+
}, Q = () => W.current?.click();
|
|
38
|
+
return /* @__PURE__ */ g("div", {
|
|
39
|
+
className: e("kapi-upload-wrap", E),
|
|
40
|
+
style: D,
|
|
39
41
|
children: [
|
|
40
|
-
/* @__PURE__ */
|
|
41
|
-
ref:
|
|
42
|
-
id:
|
|
43
|
-
"aria-describedby":
|
|
44
|
-
"aria-invalid":
|
|
45
|
-
"aria-labelledby":
|
|
46
|
-
onBlur:
|
|
47
|
-
className: `kapi-upload${
|
|
48
|
-
onClick:
|
|
42
|
+
/* @__PURE__ */ g("div", {
|
|
43
|
+
ref: I,
|
|
44
|
+
id: Y.id,
|
|
45
|
+
"aria-describedby": Y["aria-describedby"],
|
|
46
|
+
"aria-invalid": Y["aria-invalid"],
|
|
47
|
+
"aria-labelledby": J ? r(z?.labelId, K) : void 0,
|
|
48
|
+
onBlur: j,
|
|
49
|
+
className: `kapi-upload${H ? " is-over" : ""}`,
|
|
50
|
+
onClick: Q,
|
|
49
51
|
onKeyDown: (e) => {
|
|
50
|
-
o(e.key) && (e.preventDefault(),
|
|
52
|
+
o(e.key) && (e.preventDefault(), Q());
|
|
51
53
|
},
|
|
52
54
|
onDragOver: (e) => {
|
|
53
|
-
e.preventDefault(),
|
|
55
|
+
e.preventDefault(), T || U(!0);
|
|
54
56
|
},
|
|
55
|
-
onDragLeave: () =>
|
|
57
|
+
onDragLeave: () => U(!1),
|
|
56
58
|
onDrop: (e) => {
|
|
57
|
-
if (e.preventDefault(),
|
|
58
|
-
let t = Array.from(e.dataTransfer.files).filter((e) => s(e,
|
|
59
|
-
t.length !== 0 &&
|
|
59
|
+
if (e.preventDefault(), U(!1), T) return;
|
|
60
|
+
let t = Array.from(e.dataTransfer.files).filter((e) => s(e, S));
|
|
61
|
+
t.length !== 0 && X(c(B, t, x));
|
|
62
|
+
},
|
|
63
|
+
onPaste: (e) => {
|
|
64
|
+
if (!P || T) return;
|
|
65
|
+
let t = Array.from(e.clipboardData?.files ?? []).filter((e) => s(e, S));
|
|
66
|
+
t.length !== 0 && (e.preventDefault(), X(c(B, t, x)));
|
|
60
67
|
},
|
|
61
68
|
role: "button",
|
|
62
|
-
tabIndex:
|
|
63
|
-
"aria-disabled":
|
|
64
|
-
children: [/* @__PURE__ */
|
|
69
|
+
tabIndex: T ? -1 : 0,
|
|
70
|
+
"aria-disabled": T || void 0,
|
|
71
|
+
children: [/* @__PURE__ */ h("span", {
|
|
65
72
|
className: "kapi-upload__ico",
|
|
66
|
-
children: /* @__PURE__ */
|
|
73
|
+
children: /* @__PURE__ */ h(v, {
|
|
67
74
|
size: 22,
|
|
68
75
|
strokeWidth: 1.9
|
|
69
76
|
})
|
|
70
|
-
}), /* @__PURE__ */
|
|
77
|
+
}), /* @__PURE__ */ g("div", {
|
|
71
78
|
className: "kapi-upload__body",
|
|
72
|
-
children: [/* @__PURE__ */
|
|
73
|
-
id:
|
|
79
|
+
children: [/* @__PURE__ */ g("div", {
|
|
80
|
+
id: K,
|
|
74
81
|
className: "kapi-upload__t",
|
|
75
82
|
children: [
|
|
76
|
-
|
|
83
|
+
L.drop,
|
|
77
84
|
" ",
|
|
78
|
-
/* @__PURE__ */
|
|
85
|
+
/* @__PURE__ */ h("b", { children: L.choose })
|
|
79
86
|
]
|
|
80
|
-
}), /* @__PURE__ */
|
|
81
|
-
id:
|
|
87
|
+
}), /* @__PURE__ */ h("div", {
|
|
88
|
+
id: q,
|
|
82
89
|
className: "kapi-upload__s",
|
|
83
|
-
children:
|
|
90
|
+
children: R
|
|
84
91
|
})]
|
|
85
92
|
})]
|
|
86
93
|
}),
|
|
87
|
-
/* @__PURE__ */
|
|
88
|
-
ref:
|
|
94
|
+
/* @__PURE__ */ h("input", {
|
|
95
|
+
ref: W,
|
|
89
96
|
className: "kapi-upload__input",
|
|
90
97
|
type: "file",
|
|
91
98
|
hidden: !0,
|
|
92
|
-
name:
|
|
93
|
-
multiple:
|
|
94
|
-
accept:
|
|
95
|
-
disabled:
|
|
99
|
+
name: k,
|
|
100
|
+
multiple: x,
|
|
101
|
+
accept: S,
|
|
102
|
+
disabled: T,
|
|
96
103
|
tabIndex: -1,
|
|
97
104
|
onChange: (e) => {
|
|
98
|
-
|
|
105
|
+
Z(e.target.files), e.target.value = "";
|
|
99
106
|
}
|
|
100
107
|
}),
|
|
101
|
-
|
|
108
|
+
B.length > 0 && /* @__PURE__ */ h("div", {
|
|
102
109
|
className: "kapi-upload__list",
|
|
103
|
-
children:
|
|
110
|
+
children: B.map((e, t) => /* @__PURE__ */ g("div", {
|
|
104
111
|
className: "kapi-upload__file",
|
|
105
112
|
children: [
|
|
106
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ h(_, {
|
|
107
114
|
className: "kapi-upload__fileico",
|
|
108
115
|
size: 16,
|
|
109
116
|
strokeWidth: 1.9
|
|
110
117
|
}),
|
|
111
|
-
/* @__PURE__ */
|
|
118
|
+
/* @__PURE__ */ h("span", {
|
|
112
119
|
className: "kapi-upload__name",
|
|
113
120
|
children: e.name
|
|
114
121
|
}),
|
|
115
|
-
/* @__PURE__ */
|
|
122
|
+
/* @__PURE__ */ h("span", {
|
|
116
123
|
className: "kapi-upload__size",
|
|
117
124
|
children: a(e.size)
|
|
118
125
|
}),
|
|
119
|
-
/* @__PURE__ */
|
|
126
|
+
/* @__PURE__ */ h("button", {
|
|
120
127
|
type: "button",
|
|
121
|
-
"aria-label": `${
|
|
122
|
-
onClick: () =>
|
|
123
|
-
children: /* @__PURE__ */
|
|
128
|
+
"aria-label": `${L.remove} ${e.name}`,
|
|
129
|
+
onClick: () => X(l(B, t)),
|
|
130
|
+
children: /* @__PURE__ */ h(y, {
|
|
124
131
|
size: 15,
|
|
125
132
|
strokeWidth: 2.2
|
|
126
133
|
})
|
|
134
|
+
}),
|
|
135
|
+
N?.(e, t) !== void 0 && /* @__PURE__ */ h(u, {
|
|
136
|
+
className: "kapi-upload__progress",
|
|
137
|
+
value: N(e, t) ?? 0,
|
|
138
|
+
size: "sm",
|
|
139
|
+
label: `${L.uploading} ${e.name}`
|
|
127
140
|
})
|
|
128
141
|
]
|
|
129
142
|
}, `${e.name}-${t}`))
|
|
@@ -132,4 +145,4 @@ var y = {
|
|
|
132
145
|
});
|
|
133
146
|
};
|
|
134
147
|
//#endregion
|
|
135
|
-
export {
|
|
148
|
+
export { b as DEFAULT_FILE_UPLOAD_LABELS, x as KapiFileUpload };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ChangeEvent, FocusEvent, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Lo que entrega el `getInputProps(path)` de una librería de formularios (`@mantine/form`,
|
|
4
|
+
* `react-hook-form` vía `register`, Formik…). Se describe por su FORMA, no importando la librería:
|
|
5
|
+
* el paquete no tiene dependencias de runtime y el contrato que importa es público.
|
|
6
|
+
*
|
|
7
|
+
* El `onChange` se escribe `(payload: never) => void` **a propósito, y es lo único raro del tipo**.
|
|
8
|
+
* Es el único tipo de parámetro que acepta un handler de cualquier aridad de un argumento: por
|
|
9
|
+
* contravarianza, el parámetro del destino tiene que ser asignable al del origen, y `never` lo es a
|
|
10
|
+
* todo. Con `unknown` no compilaría un `(e: ChangeEvent) => void`, y con `any` se apagaría el
|
|
11
|
+
* chequeo en vez de resolverlo.
|
|
12
|
+
*/
|
|
13
|
+
export type KapiFieldSource<V = unknown> = {
|
|
14
|
+
/** Valor actual del campo (modo controlado). */
|
|
15
|
+
value?: V | undefined;
|
|
16
|
+
/** Valor inicial (modo no controlado de la librería). Se reenvía sólo si no vino `value`. */
|
|
17
|
+
defaultValue?: V | undefined;
|
|
18
|
+
/** Estado del campo cuando la librería lo pidió con `type: "checkbox"`. */
|
|
19
|
+
checked?: boolean | undefined;
|
|
20
|
+
/** Estado inicial de la marca (modo no controlado de la librería). Se reenvía sólo si no vino `checked`. */
|
|
21
|
+
defaultChecked?: boolean | undefined;
|
|
22
|
+
/** Handler de la librería; acepta un evento del DOM o un valor pelado. */
|
|
23
|
+
onChange?: ((payload: never) => void) | undefined;
|
|
24
|
+
/** Handler de salida de foco, para marcar el campo como tocado. */
|
|
25
|
+
onBlur?: ((event: never) => void) | undefined;
|
|
26
|
+
/** Handler de entrada de foco, para marcar el campo como tocado. */
|
|
27
|
+
onFocus?: ((event: never) => void) | undefined;
|
|
28
|
+
/** Motivo por el que el campo está mal, tal como lo entrega la librería. */
|
|
29
|
+
error?: ReactNode;
|
|
30
|
+
/** Nombre del campo, si la librería lo entrega. */
|
|
31
|
+
name?: string | undefined;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Qué clase de control recibe el resultado, porque de eso depende la firma de su `onChange`:
|
|
35
|
+
* `event` para los wrappers de un control nativo (`KapiInput`, `KapiTextarea`), `value` para los
|
|
36
|
+
* que eligen un valor (`KapiSelect`, `KapiDatePicker`, `KapiRating`…) y `checked` para los que son
|
|
37
|
+
* una casilla (`KapiCheckbox`, `KapiSwitch`).
|
|
38
|
+
*/
|
|
39
|
+
export type KapiFieldMode = "event" | "value" | "checked";
|
|
40
|
+
/** Props para un control que avisa con el evento del DOM (`KapiInput`, `KapiTextarea`). */
|
|
41
|
+
export type KapiEventFieldProps<V = string> = {
|
|
42
|
+
name?: string | undefined;
|
|
43
|
+
value?: V | undefined;
|
|
44
|
+
defaultValue?: V | undefined;
|
|
45
|
+
onChange?: ((event: ChangeEvent<HTMLInputElement & HTMLTextAreaElement>) => void) | undefined;
|
|
46
|
+
onBlur?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
|
|
47
|
+
onFocus?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
|
|
48
|
+
error?: ReactNode;
|
|
49
|
+
};
|
|
50
|
+
/** Props para un control que avisa con el valor ya tipado (`KapiSelect`, `KapiDatePicker`). */
|
|
51
|
+
export type KapiValueFieldProps<V> = {
|
|
52
|
+
name?: string | undefined;
|
|
53
|
+
value?: V | undefined;
|
|
54
|
+
defaultValue?: V | undefined;
|
|
55
|
+
onChange?: ((value: V) => void) | undefined;
|
|
56
|
+
onBlur?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
|
|
57
|
+
onFocus?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
|
|
58
|
+
error?: ReactNode;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Props para una casilla (`KapiCheckbox`, `KapiSwitch`). Lleva `invalid` y **no** `error`: esos dos
|
|
62
|
+
* controles no dibujan mensaje, así que mandarles el texto lo perdería en silencio. El mensaje va
|
|
63
|
+
* al `KapiField` que los envuelve.
|
|
64
|
+
*/
|
|
65
|
+
export type KapiCheckedFieldProps = {
|
|
66
|
+
name?: string | undefined;
|
|
67
|
+
checked?: boolean | undefined;
|
|
68
|
+
defaultChecked?: boolean | undefined;
|
|
69
|
+
onChange?: ((event: ChangeEvent<HTMLInputElement>) => void) | undefined;
|
|
70
|
+
onBlur?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
|
|
71
|
+
onFocus?: ((event: FocusEvent<HTMLElement>) => void) | undefined;
|
|
72
|
+
invalid: boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Ata un campo de una librería de formularios a un control de Kapi.
|
|
76
|
+
*
|
|
77
|
+
* **Para la mayoría de los campos no hace falta**, y conviene decirlo antes que venderlo: el
|
|
78
|
+
* `onChange` que devuelve `getInputProps` ya absorbe tanto un evento del DOM como un valor pelado
|
|
79
|
+
* —por eso el mismo spread anda en el `TextInput` y en el `Select` de la propia Mantine—, así que
|
|
80
|
+
* un `{...form.getInputProps("x")}` sobre un `KapiInput` funciona en runtime. Lo que esta función
|
|
81
|
+
* resuelve son las tres cosas que ese spread sí rompe:
|
|
82
|
+
*
|
|
83
|
+
* 1. **Los tipos.** El `onChange` de la librería no tiene la firma del control de destino, y el
|
|
84
|
+
* `mode` obliga a declarar qué clase de control lo recibe, así que `tsc` caza el cruce (un
|
|
85
|
+
* `"value"` spreadeado sobre un `KapiInput` no compila).
|
|
86
|
+
* 2. **`value` + `defaultValue` juntos.** El modo no controlado devuelve los dos y React avisa que
|
|
87
|
+
* el control pasó de no controlado a controlado. Acá se reenvía uno solo.
|
|
88
|
+
* 3. **Las props de más.** `enhanceGetInputProps` deja claves que el control de Kapi no declara y
|
|
89
|
+
* que ponen `tsc` en rojo al spreadearlas; se descartan.
|
|
90
|
+
*
|
|
91
|
+
* Más `error` → `invalid` en las casillas, que no dibujan mensaje.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <KapiInput label="Correo" {...bindField(form.getInputProps("correo"))} />
|
|
96
|
+
* <KapiSelect label="Área" options={areas} {...bindField<string | null>(form.getInputProps("area"), "value")} />
|
|
97
|
+
* <KapiField label="Términos" error={form.errors.ok}>
|
|
98
|
+
* <KapiCheckbox {...bindField(form.getInputProps("ok", { type: "checkbox" }), "checked")} />
|
|
99
|
+
* </KapiField>
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function bindField<V = string>(source: KapiFieldSource<V>, mode?: "event"): KapiEventFieldProps<V>;
|
|
103
|
+
export declare function bindField<V>(source: KapiFieldSource<V>, mode: "value"): KapiValueFieldProps<V>;
|
|
104
|
+
export declare function bindField<V = unknown>(source: KapiFieldSource<V>, mode: "checked"): KapiCheckedFieldProps;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { present as e } from "./inputLogic.js";
|
|
2
|
+
//#region src/components/inputs/formBridgeLogic.ts
|
|
3
|
+
var t = (e, t) => t === void 0 ? {} : { [e]: t };
|
|
4
|
+
function n(n, r = "event") {
|
|
5
|
+
let i = n.onChange, a = {
|
|
6
|
+
...t("onBlur", n.onBlur),
|
|
7
|
+
...t("onFocus", n.onFocus),
|
|
8
|
+
...t("name", n.name)
|
|
9
|
+
};
|
|
10
|
+
if (r === "checked") return {
|
|
11
|
+
...a,
|
|
12
|
+
...n.checked === void 0 ? t("defaultChecked", n.defaultChecked) : t("checked", n.checked),
|
|
13
|
+
...t("onChange", i),
|
|
14
|
+
invalid: e(n.error)
|
|
15
|
+
};
|
|
16
|
+
let o = n.value === void 0 ? t("defaultValue", n.defaultValue) : t("value", n.value);
|
|
17
|
+
return {
|
|
18
|
+
...a,
|
|
19
|
+
...o,
|
|
20
|
+
...t("onChange", i),
|
|
21
|
+
...t("error", n.error)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { n as bindField };
|
|
@@ -124,3 +124,5 @@ export type { KapiFacet, KapiFacetChip, KapiFacetKind, KapiFacetOption, KapiFace
|
|
|
124
124
|
export { KapiPropsForm } from "./KapiPropsForm.js";
|
|
125
125
|
export type { KapiPropsFormField, KapiPropsFormProps, KapiPropsFormValue, KapiPropsFormValues } from "./KapiPropsForm.js";
|
|
126
126
|
export { initialPropsFormValues, isPropsFormFieldEmpty, missingPropsFormFields, reconcilePropsFormValues } from "./propsFormLogic.js";
|
|
127
|
+
export { bindField } from "./formBridgeLogic.js";
|
|
128
|
+
export type { KapiCheckedFieldProps, KapiEventFieldProps, KapiFieldMode, KapiFieldSource, KapiValueFieldProps } from "./formBridgeLogic.js";
|