@kapiuara/ui 0.15.3 → 0.17.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/LICENSE +19 -15
- package/README.md +505 -13
- package/dist/components/chat/KapiChatThread.js +4 -4
- package/dist/components/chat/KapiComposer.js +8 -8
- package/dist/components/data/KapiDataTable.d.ts +1 -1
- package/dist/components/data/KapiDataTable.js +25 -25
- package/dist/components/data/KapiPaginationFooter.js +1 -1
- package/dist/components/data/KapiSheet.d.ts +105 -0
- package/dist/components/data/KapiSheet.js +75 -0
- package/dist/components/data/KapiSparkline.d.ts +2 -1
- package/dist/components/data/KapiSparkline.js +29 -26
- package/dist/components/data/KapiTable.d.ts +2 -2
- package/dist/components/data/KapiTable.js +347 -329
- package/dist/components/data/KapiTableFilter.js +6 -6
- package/dist/components/data/KapiTableFooter.d.ts +22 -0
- package/dist/components/data/KapiTableFooter.js +55 -0
- package/dist/components/data/KapiTableRow.js +53 -52
- package/dist/components/data/KapiTableToolbar.d.ts +4 -2
- package/dist/components/data/KapiTableToolbar.js +71 -69
- package/dist/components/data/index.d.ts +3 -1
- package/dist/components/data/tableCells.d.ts +17 -5
- package/dist/components/data/tableCells.js +52 -53
- package/dist/components/data/tableLogic.d.ts +2 -0
- package/dist/components/data/tableLogic.js +66 -66
- package/dist/components/data/tableSlots.d.ts +9 -0
- package/dist/components/data/tableSlots.js +12 -0
- package/dist/components/data/tableSpanLogic.d.ts +35 -0
- package/dist/components/data/tableSpanLogic.js +47 -0
- package/dist/components/data/tableTypes.d.ts +54 -1
- package/dist/components/data/useTableSelection.d.ts +4 -2
- package/dist/components/data/useTableSelection.js +29 -25
- package/dist/components/display/KapiAnchor.d.ts +36 -0
- package/dist/components/display/KapiAnchor.js +36 -0
- package/dist/components/display/KapiAnnotation.js +68 -63
- package/dist/components/display/KapiAvatar.d.ts +6 -4
- package/dist/components/display/KapiAvatar.js +33 -28
- package/dist/components/display/KapiBadge.d.ts +6 -5
- package/dist/components/display/KapiBadge.js +25 -19
- package/dist/components/display/KapiCodeBlock.d.ts +48 -0
- package/dist/components/display/KapiCodeBlock.js +44 -0
- package/dist/components/display/KapiCommentComposer.js +6 -6
- package/dist/components/display/KapiDiff.d.ts +62 -0
- package/dist/components/display/KapiDiff.js +118 -0
- package/dist/components/display/KapiHighlight.d.ts +27 -0
- package/dist/components/display/KapiHighlight.js +21 -0
- package/dist/components/display/KapiIconTile.d.ts +2 -1
- package/dist/components/display/KapiIconTile.js +23 -21
- package/dist/components/display/KapiStat.d.ts +3 -2
- package/dist/components/display/KapiStat.js +32 -26
- package/dist/components/display/KapiTag.d.ts +4 -3
- package/dist/components/display/KapiTag.js +29 -24
- package/dist/components/display/KapiText.d.ts +43 -0
- package/dist/components/display/KapiText.js +33 -0
- package/dist/components/display/KapiTimeline.d.ts +5 -2
- package/dist/components/display/KapiTimeline.js +31 -23
- package/dist/components/display/KapiTitle.d.ts +33 -0
- package/dist/components/display/KapiTitle.js +29 -0
- package/dist/components/display/annotationLogic.d.ts +2 -1
- package/dist/components/display/annotationLogic.js +7 -6
- package/dist/components/display/codeBlockSlots.d.ts +10 -0
- package/dist/components/display/codeBlockSlots.js +13 -0
- package/dist/components/display/diffLogic.d.ts +58 -0
- package/dist/components/display/diffLogic.js +96 -0
- package/dist/components/display/diffSlots.d.ts +14 -0
- package/dist/components/display/diffSlots.js +17 -0
- package/dist/components/display/highlightLogic.d.ts +18 -0
- package/dist/components/display/highlightLogic.js +26 -0
- package/dist/components/display/highlightSlots.d.ts +5 -0
- package/dist/components/display/highlightSlots.js +8 -0
- package/dist/components/display/iconTileLogic.d.ts +2 -2
- package/dist/components/display/iconTileLogic.js +7 -6
- package/dist/components/display/index.d.ts +15 -0
- package/dist/components/display/statLogic.d.ts +2 -1
- package/dist/components/display/statLogic.js +7 -6
- package/dist/components/display/tagLogic.d.ts +2 -1
- package/dist/components/display/tagLogic.js +7 -6
- package/dist/components/display/textLogic.d.ts +32 -0
- package/dist/components/display/textLogic.js +19 -0
- package/dist/components/display/timelineLogic.d.ts +20 -2
- package/dist/components/display/timelineLogic.js +10 -2
- package/dist/components/feedback/KapiAlert.d.ts +8 -4
- package/dist/components/feedback/KapiAlert.js +39 -34
- package/dist/components/feedback/KapiFab.js +108 -108
- package/dist/components/feedback/KapiProgress.js +63 -54
- package/dist/components/feedback/KapiToastContainer.js +9 -9
- package/dist/components/feedback/KapiTour.js +12 -12
- package/dist/components/feedback/progressLogic.d.ts +2 -1
- package/dist/components/feedback/progressLogic.js +9 -8
- package/dist/components/inputs/KapiAutocomplete.d.ts +6 -0
- package/dist/components/inputs/KapiAutocomplete.js +86 -85
- package/dist/components/inputs/KapiButton.d.ts +7 -4
- package/dist/components/inputs/KapiButton.js +47 -42
- package/dist/components/inputs/KapiChecklist.d.ts +7 -1
- package/dist/components/inputs/KapiChecklist.js +53 -52
- package/dist/components/inputs/KapiCopyButton.d.ts +40 -0
- package/dist/components/inputs/KapiCopyButton.js +35 -0
- package/dist/components/inputs/KapiDatePicker.d.ts +7 -1
- package/dist/components/inputs/KapiDatePicker.js +118 -116
- package/dist/components/inputs/KapiDateRangePicker.d.ts +7 -1
- package/dist/components/inputs/KapiDateRangePicker.js +136 -135
- package/dist/components/inputs/KapiFacetedSearch.js +5 -5
- package/dist/components/inputs/KapiField.d.ts +9 -1
- package/dist/components/inputs/KapiField.js +43 -42
- package/dist/components/inputs/KapiFileUpload.js +6 -6
- package/dist/components/inputs/KapiInput.d.ts +29 -1
- package/dist/components/inputs/KapiInput.js +74 -51
- package/dist/components/inputs/KapiMaskedInput.js +26 -26
- package/dist/components/inputs/KapiNumberStepper.d.ts +7 -1
- package/dist/components/inputs/KapiNumberStepper.js +24 -23
- package/dist/components/inputs/KapiPinInput.d.ts +72 -0
- package/dist/components/inputs/KapiPinInput.js +75 -0
- package/dist/components/inputs/KapiPropsForm.d.ts +34 -0
- package/dist/components/inputs/KapiPropsForm.js +78 -0
- package/dist/components/inputs/KapiRating.d.ts +7 -1
- package/dist/components/inputs/KapiRating.js +39 -38
- package/dist/components/inputs/KapiSearchChip.js +5 -5
- package/dist/components/inputs/KapiSegmented.d.ts +13 -5
- package/dist/components/inputs/KapiSegmented.js +81 -77
- package/dist/components/inputs/KapiSelect.d.ts +21 -1
- package/dist/components/inputs/KapiSelect.js +251 -245
- package/dist/components/inputs/KapiSelectMenu.d.ts +4 -2
- package/dist/components/inputs/KapiSelectMenu.js +131 -133
- package/dist/components/inputs/KapiSlider.d.ts +10 -3
- package/dist/components/inputs/KapiSlider.js +67 -63
- package/dist/components/inputs/KapiTagInput.d.ts +7 -1
- package/dist/components/inputs/KapiTagInput.js +70 -69
- package/dist/components/inputs/KapiTextarea.d.ts +7 -1
- package/dist/components/inputs/KapiTextarea.js +51 -50
- package/dist/components/inputs/copyLogic.d.ts +1 -0
- package/dist/components/inputs/copyLogic.js +12 -0
- package/dist/components/inputs/fieldLogic.d.ts +21 -1
- package/dist/components/inputs/fieldLogic.js +18 -11
- package/dist/components/inputs/index.d.ts +9 -1
- package/dist/components/inputs/inputLogic.d.ts +16 -1
- package/dist/components/inputs/inputLogic.js +3 -3
- package/dist/components/inputs/ownField.d.ts +3 -1
- package/dist/components/inputs/ownField.js +28 -27
- package/dist/components/inputs/pinInputLogic.d.ts +34 -0
- package/dist/components/inputs/pinInputLogic.js +37 -0
- package/dist/components/inputs/propsFormLogic.d.ts +53 -0
- package/dist/components/inputs/propsFormLogic.js +11 -0
- package/dist/components/inputs/segmentedLogic.d.ts +7 -0
- package/dist/components/inputs/segmentedLogic.js +2 -2
- package/dist/components/inputs/selectSlots.d.ts +24 -0
- package/dist/components/inputs/selectSlots.js +27 -0
- package/dist/components/layout/KapiAccessCard.d.ts +5 -1
- package/dist/components/layout/KapiAccessCard.js +43 -39
- package/dist/components/layout/KapiAccountMenu.js +7 -7
- package/dist/components/layout/KapiBox.d.ts +31 -0
- package/dist/components/layout/KapiBox.js +26 -0
- package/dist/components/layout/KapiCard.d.ts +16 -4
- package/dist/components/layout/KapiCard.js +46 -34
- package/dist/components/layout/KapiCenter.d.ts +13 -0
- package/dist/components/layout/KapiCenter.js +23 -0
- package/dist/components/layout/KapiCol.d.ts +22 -0
- package/dist/components/layout/KapiCol.js +23 -0
- package/dist/components/layout/KapiCollapse.d.ts +39 -0
- package/dist/components/layout/KapiCollapse.js +20 -0
- package/dist/components/layout/KapiContextSlot.js +4 -4
- package/dist/components/layout/KapiDivider.d.ts +11 -2
- package/dist/components/layout/KapiDivider.js +30 -24
- package/dist/components/layout/KapiGrid.d.ts +29 -3
- package/dist/components/layout/KapiGrid.js +39 -17
- package/dist/components/layout/KapiNotificationBell.js +10 -10
- package/dist/components/layout/KapiPageHeader.d.ts +10 -1
- package/dist/components/layout/KapiPageHeader.js +94 -92
- package/dist/components/layout/KapiPanelParts.d.ts +11 -2
- package/dist/components/layout/KapiPanelParts.js +73 -56
- package/dist/components/layout/KapiRail.d.ts +10 -1
- package/dist/components/layout/KapiRail.js +125 -122
- package/dist/components/layout/KapiRoot.d.ts +55 -5
- package/dist/components/layout/KapiRoot.js +57 -38
- package/dist/components/layout/KapiShell.d.ts +44 -3
- package/dist/components/layout/KapiShell.js +54 -50
- package/dist/components/layout/accessCardLogic.d.ts +8 -1
- package/dist/components/layout/accessCardLogic.js +11 -7
- package/dist/components/layout/cardSlots.d.ts +9 -0
- package/dist/components/layout/cardSlots.js +12 -0
- package/dist/components/layout/gridSpanLogic.d.ts +46 -0
- package/dist/components/layout/gridSpanLogic.js +39 -0
- package/dist/components/layout/index.d.ts +13 -4
- package/dist/components/layout/layoutPrimitives.d.ts +11 -0
- package/dist/components/layout/layoutPrimitives.js +12 -1
- package/dist/components/layout/pageHeaderSlots.d.ts +12 -0
- package/dist/components/layout/pageHeaderSlots.js +15 -0
- package/dist/components/layout/railLogic.d.ts +16 -3
- package/dist/components/layout/railSlots.d.ts +12 -0
- package/dist/components/layout/railSlots.js +15 -0
- package/dist/components/layout/shellSlots.d.ts +6 -0
- package/dist/components/layout/shellSlots.js +9 -0
- package/dist/components/layout/useGridBreakpoint.d.ts +12 -0
- package/dist/components/layout/useGridBreakpoint.js +35 -0
- package/dist/components/locale/labelRegistry.d.ts +10 -0
- package/dist/components/navigation/KapiAccordion.js +9 -9
- package/dist/components/navigation/KapiBreadcrumb.d.ts +18 -2
- package/dist/components/navigation/KapiBreadcrumb.js +23 -16
- package/dist/components/navigation/KapiContextPanel.d.ts +17 -4
- package/dist/components/navigation/KapiContextPanel.js +152 -136
- package/dist/components/navigation/KapiNavBadge.d.ts +6 -3
- package/dist/components/navigation/KapiNavBadge.js +26 -22
- package/dist/components/navigation/KapiPanelGroup.d.ts +16 -4
- package/dist/components/navigation/KapiPanelGroup.js +66 -65
- package/dist/components/navigation/KapiTabs.d.ts +12 -0
- package/dist/components/navigation/KapiTabs.js +87 -71
- package/dist/components/navigation/KapiToc.d.ts +48 -0
- package/dist/components/navigation/KapiToc.js +66 -0
- package/dist/components/navigation/KapiTree.js +10 -10
- package/dist/components/navigation/MiniNavItem.d.ts +7 -2
- package/dist/components/navigation/MiniNavItem.js +41 -36
- package/dist/components/navigation/breadcrumbLogic.d.ts +4 -2
- package/dist/components/navigation/breadcrumbLogic.js +1 -1
- package/dist/components/navigation/index.d.ts +3 -0
- package/dist/components/navigation/navLink.d.ts +21 -0
- package/dist/components/navigation/navLink.js +26 -0
- package/dist/components/navigation/navLinkLogic.d.ts +18 -0
- package/dist/components/navigation/navLinkLogic.js +22 -0
- package/dist/components/navigation/tocLogic.d.ts +35 -0
- package/dist/components/navigation/tocLogic.js +11 -0
- package/dist/components/navigation/tocSlots.d.ts +8 -0
- package/dist/components/navigation/tocSlots.js +11 -0
- package/dist/components/overlays/KapiCommandPalette.js +6 -6
- package/dist/components/overlays/KapiContextMenu.d.ts +8 -0
- package/dist/components/overlays/KapiContextMenu.js +5 -5
- package/dist/components/overlays/KapiMenuButton.js +7 -7
- package/dist/components/overlays/KapiModal.d.ts +9 -0
- package/dist/components/overlays/KapiModal.js +79 -77
- package/dist/components/overlays/KapiOffcanvas.js +24 -24
- package/dist/components/overlays/KapiPhotoView.js +10 -10
- package/dist/components/overlays/KapiPopover.js +6 -6
- package/dist/components/overlays/KapiShapeSheet.js +4 -4
- package/dist/components/overlays/KapiTooltip.js +18 -18
- package/dist/components/overlays/index.d.ts +1 -1
- package/dist/components/overlays/menuList.js +127 -117
- package/dist/components/overlays/modalSlots.d.ts +11 -0
- package/dist/components/overlays/modalSlots.js +14 -0
- package/dist/components/slotCatalog.d.ts +123 -0
- package/dist/components/slotCatalog.js +27 -0
- package/dist/components/slotsLogic.d.ts +34 -0
- package/dist/components/slotsLogic.js +18 -0
- package/dist/components/tone.d.ts +26 -0
- package/dist/components/tone.js +15 -14
- package/dist/css/base.css +1 -1
- package/dist/css/components/data/KapiEventCalendar.css +1 -1
- package/dist/css/components/data/KapiTable.css +1 -1
- package/dist/css/components/display/KapiAnnotation.css +1 -1
- package/dist/css/components/display/KapiCodeBlock.css +1 -0
- package/dist/css/components/display/KapiDiff.css +1 -0
- package/dist/css/components/display/display.css +1 -1
- package/dist/css/components/display/typography.css +1 -0
- package/dist/css/components/feedback/feedback.css +1 -1
- package/dist/css/components/inputs/KapiButton.css +1 -1
- package/dist/css/components/inputs/KapiDatePicker.css +1 -1
- package/dist/css/components/inputs/KapiPinInput.css +1 -0
- package/dist/css/components/inputs/KapiSelect.css +1 -1
- package/dist/css/components/inputs/inputsExtra.css +1 -1
- package/dist/css/components/layout/KapiAccessCard.css +1 -1
- package/dist/css/components/layout/KapiBox.css +1 -0
- package/dist/css/components/layout/KapiCollapse.css +1 -0
- package/dist/css/components/layout/KapiDivider.css +1 -1
- package/dist/css/components/layout/KapiRail.css +1 -1
- package/dist/css/components/layout/gridSpan.css +1 -0
- package/dist/css/components/navigation/KapiToc.css +1 -0
- package/dist/css/components/navigation/navigation.css +1 -1
- package/dist/hooks/asyncResourceLogic.d.ts +11 -0
- package/dist/hooks/asyncResourceLogic.js +4 -0
- package/dist/hooks/densityLogic.d.ts +15 -0
- package/dist/hooks/densityLogic.js +4 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/themeColorsLogic.d.ts +19 -0
- package/dist/hooks/themeColorsLogic.js +4 -2
- package/dist/hooks/themeDeriveLogic.d.ts +16 -0
- package/dist/hooks/themeDeriveLogic.js +27 -17
- package/dist/hooks/toneFamilyLogic.d.ts +146 -0
- package/dist/hooks/toneFamilyLogic.js +164 -0
- package/dist/hooks/useAsyncResource.d.ts +45 -0
- package/dist/hooks/useAsyncResource.js +24 -0
- package/dist/hooks/useKapiTheme.d.ts +16 -3
- package/dist/hooks/useKapiTheme.js +130 -117
- package/dist/hooks/useToneFamilies.d.ts +40 -0
- package/dist/hooks/useToneFamilies.js +50 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +227 -204
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/dist/logic.d.ts +41 -0
- package/dist/logic.js +42 -0
- package/dist/styles/rawHeights.d.ts +8 -0
- package/package.json +14 -3
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/inputs/inputsExtra.css";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
4
|
+
import { hasAdornments as t, hasValue as n, inputBoxClasses as r, present as i, tipoDeCampo as ee } from "./inputLogic.js";
|
|
5
|
+
import { fieldControlProps as te, joinIds as a, resolveFieldMessage as o } from "./fieldLogic.js";
|
|
6
|
+
import { useOwnField as s } from "./ownField.js";
|
|
7
|
+
import { resolveGroupSize as c } from "./inputGroupLogic.js";
|
|
8
|
+
import { useKapiInputGroup as ne } from "./KapiInputGroup.js";
|
|
9
9
|
/* empty css */
|
|
10
|
-
import {
|
|
11
|
-
import { jsx as
|
|
12
|
-
import {
|
|
10
|
+
import { useEffect as re, useId as ie, useRef as l, useState as u } from "react";
|
|
11
|
+
import { jsx as d, jsxs as ae } from "react/jsx-runtime";
|
|
12
|
+
import { Eye as oe, EyeOff as f, X as p } from "lucide-react";
|
|
13
13
|
//#region src/components/inputs/KapiInput.tsx
|
|
14
|
-
var
|
|
14
|
+
var m = {
|
|
15
|
+
clear: "Limpiar",
|
|
16
|
+
show: "Mostrar la contraseña",
|
|
17
|
+
hide: "Ocultar la contraseña"
|
|
18
|
+
}, se = (e) => {
|
|
15
19
|
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set?.call(e, ""), e.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
16
20
|
}, h = ({ size: e = "md", status: t, num: n = !1, className: r = "" } = {}) => [
|
|
17
21
|
"kapi-input",
|
|
@@ -20,104 +24,123 @@ var p = { clear: "Limpiar" }, m = (e) => {
|
|
|
20
24
|
t && `kapi-input--${t}`,
|
|
21
25
|
r
|
|
22
26
|
].filter(Boolean).join(" "), g = (g) => {
|
|
23
|
-
let { size:
|
|
27
|
+
let { size: _, invalid: v, status: y, num: ce, label: le, required: b, help: x, error: S, fieldClassName: C, className: w, multiline: T, id: ue, startIcon: E, endIcon: D, prefix: O, suffix: k, clearable: A, onClear: de, reveal: j, shortcut: M, labels: N, ref: P, ...F } = g, I = P, { invalid: L, status: R } = o(S, x, v, y), z = e("input", m, N), B = c(_, ne()?.size), V = !T && t({
|
|
24
28
|
startIcon: E,
|
|
25
29
|
endIcon: D,
|
|
26
30
|
prefix: O,
|
|
27
31
|
suffix: k,
|
|
28
32
|
clearable: A,
|
|
33
|
+
reveal: j,
|
|
29
34
|
shortcut: M
|
|
30
|
-
}), H
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
}), [H, U] = u(!1), W = l(null), G = F;
|
|
36
|
+
re(() => {
|
|
37
|
+
G.disabled && U(!1);
|
|
38
|
+
}, [G.disabled]);
|
|
39
|
+
let K = ee({
|
|
40
|
+
reveal: j,
|
|
41
|
+
revealed: H,
|
|
42
|
+
disabled: G.disabled
|
|
43
|
+
}), [fe, q] = u(() => n(G.defaultValue)), J = s({
|
|
44
|
+
id: ue,
|
|
45
|
+
label: le,
|
|
46
|
+
help: x,
|
|
47
|
+
error: S,
|
|
48
|
+
required: b,
|
|
49
|
+
invalid: v,
|
|
50
|
+
status: y,
|
|
37
51
|
fieldClassName: C
|
|
38
|
-
}), { controlId:
|
|
39
|
-
...
|
|
40
|
-
id:
|
|
41
|
-
describedBy:
|
|
52
|
+
}), { controlId: pe, helpId: me } = J, Y = ie(), X = V && i(O) ? `${Y}-prefix` : void 0, Z = V && i(k) ? `${Y}-suffix` : void 0, Q = {
|
|
53
|
+
...te(J.outer, {
|
|
54
|
+
id: pe,
|
|
55
|
+
describedBy: a(me, F["aria-describedby"], X, Z),
|
|
42
56
|
invalid: L
|
|
43
57
|
}),
|
|
44
|
-
required:
|
|
58
|
+
required: b,
|
|
45
59
|
className: V ? "kapi-inputbox__control" : h({
|
|
46
60
|
size: B,
|
|
47
61
|
status: R,
|
|
48
|
-
num:
|
|
62
|
+
num: ce,
|
|
49
63
|
className: w
|
|
50
64
|
})
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
}, $ =
|
|
54
|
-
let e =
|
|
55
|
-
e && (
|
|
56
|
-
},
|
|
65
|
+
}, he = (e) => {
|
|
66
|
+
W.current = e, typeof I == "function" ? I(e) : I && (I.current = e);
|
|
67
|
+
}, $ = G.value === void 0 ? fe : n(G.value), ge = () => {
|
|
68
|
+
let e = W.current;
|
|
69
|
+
e && (se(e), q(!1), e.focus(), de?.());
|
|
70
|
+
}, _e = T ? /* @__PURE__ */ d("textarea", {
|
|
57
71
|
ref: I,
|
|
58
72
|
...F,
|
|
59
73
|
...Q
|
|
60
|
-
}) : V ? /* @__PURE__ */
|
|
61
|
-
className:
|
|
74
|
+
}) : V ? /* @__PURE__ */ ae("div", {
|
|
75
|
+
className: r({
|
|
62
76
|
size: B,
|
|
63
77
|
status: R,
|
|
64
|
-
disabled:
|
|
78
|
+
disabled: G.disabled,
|
|
65
79
|
className: w
|
|
66
80
|
}),
|
|
67
81
|
onMouseDown: (e) => {
|
|
68
|
-
e.target ===
|
|
82
|
+
e.target === W.current || G.disabled || (e.preventDefault(), W.current?.focus());
|
|
69
83
|
},
|
|
70
84
|
children: [
|
|
71
|
-
|
|
85
|
+
i(E) && /* @__PURE__ */ d("span", {
|
|
72
86
|
className: "kapi-inputbox__icon",
|
|
73
87
|
"aria-hidden": "true",
|
|
74
88
|
children: E
|
|
75
89
|
}),
|
|
76
|
-
|
|
90
|
+
i(O) && /* @__PURE__ */ d("span", {
|
|
77
91
|
id: X,
|
|
78
92
|
className: "kapi-inputbox__affix",
|
|
79
93
|
children: O
|
|
80
94
|
}),
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
ref:
|
|
83
|
-
...
|
|
95
|
+
/* @__PURE__ */ d("input", {
|
|
96
|
+
ref: he,
|
|
97
|
+
...G,
|
|
84
98
|
...Q,
|
|
85
|
-
|
|
99
|
+
...K ? { type: K } : {},
|
|
100
|
+
"aria-keyshortcuts": G["aria-keyshortcuts"] ?? (M || void 0),
|
|
86
101
|
onChange: (e) => {
|
|
87
|
-
|
|
102
|
+
q(n(e.target.value)), G.onChange?.(e);
|
|
88
103
|
}
|
|
89
104
|
}),
|
|
90
|
-
|
|
105
|
+
i(k) && /* @__PURE__ */ d("span", {
|
|
91
106
|
id: Z,
|
|
92
107
|
className: "kapi-inputbox__affix",
|
|
93
108
|
children: k
|
|
94
109
|
}),
|
|
95
|
-
|
|
110
|
+
j && !G.disabled && /* @__PURE__ */ d("button", {
|
|
111
|
+
type: "button",
|
|
112
|
+
className: "kapi-inputbox__reveal",
|
|
113
|
+
"aria-label": H ? z.hide : z.show,
|
|
114
|
+
"aria-pressed": H,
|
|
115
|
+
onClick: () => U((e) => !e),
|
|
116
|
+
children: d(H ? f : oe, { "aria-hidden": "true" })
|
|
117
|
+
}),
|
|
118
|
+
A && $ && !G.disabled && !G.readOnly && /* @__PURE__ */ d("button", {
|
|
96
119
|
type: "button",
|
|
97
120
|
tabIndex: -1,
|
|
98
121
|
className: "kapi-inputbox__clear",
|
|
99
122
|
"aria-label": z.clear,
|
|
100
|
-
onClick:
|
|
101
|
-
children: /* @__PURE__ */
|
|
123
|
+
onClick: ge,
|
|
124
|
+
children: /* @__PURE__ */ d(p, { "aria-hidden": "true" })
|
|
102
125
|
}),
|
|
103
|
-
M && !$ && /* @__PURE__ */
|
|
126
|
+
M && !$ && /* @__PURE__ */ d("kbd", {
|
|
104
127
|
className: "kapi-inputbox__kbd",
|
|
105
128
|
"aria-hidden": "true",
|
|
106
129
|
children: M
|
|
107
130
|
}),
|
|
108
|
-
|
|
131
|
+
i(D) && /* @__PURE__ */ d("span", {
|
|
109
132
|
className: "kapi-inputbox__icon",
|
|
110
133
|
"aria-hidden": "true",
|
|
111
134
|
children: D
|
|
112
135
|
})
|
|
113
136
|
]
|
|
114
|
-
}) : /* @__PURE__ */
|
|
137
|
+
}) : /* @__PURE__ */ d("input", {
|
|
115
138
|
ref: I,
|
|
116
|
-
...
|
|
139
|
+
...G,
|
|
117
140
|
...Q
|
|
118
141
|
});
|
|
119
|
-
return
|
|
142
|
+
return J.wrap(_e);
|
|
120
143
|
};
|
|
121
144
|
g.displayName = "KapiInput";
|
|
122
145
|
//#endregion
|
|
123
|
-
export {
|
|
146
|
+
export { m as DEFAULT_INPUT_LABELS, g as KapiInput, h as inputClasses };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
3
|
+
import { activeElementOf as t } from "../../hooks/ownerDocument.js";
|
|
4
|
+
import { assignRef as n } from "./fieldLogic.js";
|
|
5
|
+
import { KapiInput as r } from "./KapiInput.js";
|
|
6
|
+
import { useControllableState as i } from "../../hooks/useControllableState.js";
|
|
7
7
|
import { useFormReset as a } from "../../hooks/useFormReset.js";
|
|
8
8
|
import { caretForSignificant as o, countSignificant as s, formatCuit as c, formatCurrency as l, formatDni as u, isValidCuit as d, maskCurrencyInput as f, onlyDigits as p, parseCurrency as m } from "./maskLogic.js";
|
|
9
9
|
import { useCallback as h, useRef as g, useState as _ } from "react";
|
|
@@ -14,26 +14,26 @@ var x = (e, t, n) => e ? /* @__PURE__ */ y("input", {
|
|
|
14
14
|
name: e,
|
|
15
15
|
value: t,
|
|
16
16
|
disabled: n
|
|
17
|
-
}) : null, S = (
|
|
18
|
-
setRef: h((
|
|
19
|
-
|
|
20
|
-
}, [
|
|
21
|
-
apply: (
|
|
22
|
-
let a =
|
|
23
|
-
if (
|
|
24
|
-
let e = Math.max(0, c - (a.value.length -
|
|
25
|
-
return a.value =
|
|
17
|
+
}) : null, S = (e, r, i, a) => ({
|
|
18
|
+
setRef: h((e) => {
|
|
19
|
+
n(r, e), a?.(e);
|
|
20
|
+
}, [r, a]),
|
|
21
|
+
apply: (n, r) => {
|
|
22
|
+
let a = n.target, c = a.selectionStart ?? a.value.length;
|
|
23
|
+
if (i !== void 0 && p(a.value).length > i) {
|
|
24
|
+
let e = Math.max(0, c - (a.value.length - r.length));
|
|
25
|
+
return a.value = r, a.setSelectionRange(e, e), r;
|
|
26
26
|
}
|
|
27
|
-
let l = s(a.value, c), u =
|
|
28
|
-
if (a.value = u,
|
|
27
|
+
let l = s(a.value, c), u = e(a.value);
|
|
28
|
+
if (a.value = u, t(a) === a) {
|
|
29
29
|
let e = o(u, l);
|
|
30
30
|
a.setSelectionRange(e, e);
|
|
31
31
|
}
|
|
32
32
|
return u;
|
|
33
33
|
}
|
|
34
|
-
}), C = ({ value: e, defaultValue: t = "", onValueChange:
|
|
35
|
-
let [m, h, , g] =
|
|
36
|
-
return /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(
|
|
34
|
+
}), C = ({ value: e, defaultValue: t = "", onValueChange: n, onChange: o, ref: s, name: c, disabled: l, placeholder: d = "12.345.678", ...f }) => {
|
|
35
|
+
let [m, h, , g] = i(e, () => p(t, 8), n), _ = p(m, 8), { setRef: C, apply: w } = S(u, s, 8, a(g));
|
|
36
|
+
return /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(r, {
|
|
37
37
|
...f,
|
|
38
38
|
ref: C,
|
|
39
39
|
disabled: l,
|
|
@@ -46,9 +46,9 @@ var x = (e, t, n) => e ? /* @__PURE__ */ y("input", {
|
|
|
46
46
|
t !== _ && h(t), o?.(e);
|
|
47
47
|
}
|
|
48
48
|
}), x(c, _, l)] });
|
|
49
|
-
}, w = { invalid: "CUIT inválido: revisa el dígito verificador" }, T = ({ value:
|
|
50
|
-
let D =
|
|
51
|
-
return /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(
|
|
49
|
+
}, w = { invalid: "CUIT inválido: revisa el dígito verificador" }, T = ({ value: t, defaultValue: n = "", onValueChange: o, onChange: s, invalidMessage: l, invalid: u, status: f, help: m, label: h, ref: g, name: _, disabled: C, placeholder: T = "20-12345678-9", ...E }) => {
|
|
50
|
+
let D = e("cuitInput", w), [O, k, , A] = i(t, () => p(n, 11), o && ((e) => o(e, d(e)))), j = p(O, 11), M = a(A), N = j.length === 11 && !d(j), P = u !== void 0 || f !== void 0, F = h != null || !!m, { setRef: I, apply: L } = S(c, g, 11, M);
|
|
51
|
+
return /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(r, {
|
|
52
52
|
...E,
|
|
53
53
|
ref: I,
|
|
54
54
|
disabled: C,
|
|
@@ -65,13 +65,13 @@ var x = (e, t, n) => e ? /* @__PURE__ */ y("input", {
|
|
|
65
65
|
t !== j && k(t), s?.(e);
|
|
66
66
|
}
|
|
67
67
|
}), x(_, j, C)] });
|
|
68
|
-
}, E = ({ value: e, defaultValue: t = null, onValueChange:
|
|
68
|
+
}, E = ({ value: e, defaultValue: t = null, onValueChange: n, onChange: i, onBlur: o, ref: s, name: c, disabled: u, placeholder: d = "$ 0,00", ...p }) => {
|
|
69
69
|
let [h, C] = _(() => l(e === void 0 ? t : e)), w = g(m(h)), T = g(h), [E, D] = _(e);
|
|
70
70
|
e !== void 0 && e !== E && (D(e), e !== m(h) && (C(l(e)), w.current = e));
|
|
71
71
|
let O = a(() => {
|
|
72
72
|
e === void 0 && (C(T.current), w.current = m(T.current));
|
|
73
73
|
}), { setRef: k, apply: A } = S(f, s, void 0, O), j = m(h);
|
|
74
|
-
return /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(
|
|
74
|
+
return /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(r, {
|
|
75
75
|
...p,
|
|
76
76
|
ref: k,
|
|
77
77
|
disabled: u,
|
|
@@ -82,8 +82,8 @@ var x = (e, t, n) => e ? /* @__PURE__ */ y("input", {
|
|
|
82
82
|
onChange: (e) => {
|
|
83
83
|
let t = A(e, h);
|
|
84
84
|
C(t);
|
|
85
|
-
let
|
|
86
|
-
|
|
85
|
+
let r = m(t);
|
|
86
|
+
r !== w.current && (w.current = r, n?.(r)), i?.(e);
|
|
87
87
|
},
|
|
88
88
|
onBlur: (e) => {
|
|
89
89
|
C(l(m(h))), o?.(e);
|
|
@@ -29,6 +29,12 @@ export type KapiNumberStepperProps = Omit<InputHTMLAttributes<HTMLInputElement>,
|
|
|
29
29
|
label?: ReactNode;
|
|
30
30
|
/** Texto de ayuda o error bajo el control. */
|
|
31
31
|
help?: ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* El motivo por el que el campo está mal. Reemplaza a `help` y lo marca inválido (rojo, ícono y
|
|
34
|
+
* `role="alert"`). Es lo que entregan las librerías de formularios: un mensaje, no un booleano.
|
|
35
|
+
* Un error que React no pinta (`true`, `""`, `null`) no marca nada. Gana sobre `invalid` y `status`.
|
|
36
|
+
*/
|
|
37
|
+
error?: ReactNode | undefined;
|
|
32
38
|
/** Clase del contenedor del control (`.kapi-stepper`, botones + input). `className` va al `<input>`. */
|
|
33
39
|
fieldClassName?: string | undefined;
|
|
34
40
|
/**
|
|
@@ -53,4 +59,4 @@ export type KapiNumberStepperLabels = {
|
|
|
53
59
|
increase: string;
|
|
54
60
|
};
|
|
55
61
|
export declare const DEFAULT_NUMBER_STEPPER_LABELS: KapiNumberStepperLabels;
|
|
56
|
-
export declare const KapiNumberStepper: ({ value: valueProp, defaultValue, onChange, min, max, step, size, invalid: invalidProp, status: statusProp, required, label, help, fieldClassName, wrapperClassName, labels, className, disabled, readOnly: readOnlyProp, id, ...rest }: KapiNumberStepperProps) => ReactNode;
|
|
62
|
+
export declare const KapiNumberStepper: ({ value: valueProp, defaultValue, onChange, min, max, step, size, invalid: invalidProp, status: statusProp, required, label, help, error, fieldClassName, wrapperClassName, labels, className, disabled, readOnly: readOnlyProp, id, ...rest }: KapiNumberStepperProps) => ReactNode;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/inputs/inputsExtra.css";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
4
|
+
import { fieldControlProps as t, joinIds as n, resolveFieldClassName as r, resolveFieldMessage as i, resolveReadOnly as a } from "./fieldLogic.js";
|
|
5
|
+
import { useOwnField as o } from "./ownField.js";
|
|
6
6
|
/* empty css */
|
|
7
|
-
import { inputClasses as
|
|
8
|
-
import { useControllableState as
|
|
9
|
-
import { canDecrement as
|
|
10
|
-
import { useEffect as
|
|
7
|
+
import { inputClasses as s } from "./KapiInput.js";
|
|
8
|
+
import { useControllableState as ee } from "../../hooks/useControllableState.js";
|
|
9
|
+
import { canDecrement as c, canIncrement as te, clampNumber as l, parseTypedNumber as u, snapToStep as d, stepValue as ne } from "./numberStepLogic.js";
|
|
10
|
+
import { useEffect as f, useState as p } from "react";
|
|
11
11
|
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
12
12
|
import { Minus as g, Plus as re } from "lucide-react";
|
|
13
13
|
//#region src/components/inputs/KapiNumberStepper.tsx
|
|
@@ -18,25 +18,26 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
18
18
|
].filter(Boolean).join(" "), v = {
|
|
19
19
|
decrease: "Disminuir",
|
|
20
20
|
increase: "Aumentar"
|
|
21
|
-
}, y = ({ value: y, defaultValue: b, onChange: x, min: S, max: C, step: w = 1, size: T = "md", invalid: E, status: D, required: O, label:
|
|
22
|
-
let z =
|
|
21
|
+
}, y = ({ value: y, defaultValue: b, onChange: x, min: S, max: C, step: w = 1, size: T = "md", invalid: E, status: D, required: O, label: ie, help: k, error: A, fieldClassName: j, wrapperClassName: M, labels: N, className: P, disabled: F, readOnly: I, id: L, ...R }) => {
|
|
22
|
+
let z = e("numberStepper", v, N), [B, V] = ee(y, () => l(b ?? 0, {
|
|
23
23
|
min: S,
|
|
24
24
|
max: C,
|
|
25
25
|
step: w
|
|
26
|
-
}), x), { invalid: H, status: U } =
|
|
26
|
+
}), x), { invalid: H, status: U } = i(A, k, E, D), W = o({
|
|
27
27
|
id: L,
|
|
28
|
-
label:
|
|
29
|
-
help:
|
|
28
|
+
label: ie,
|
|
29
|
+
help: k,
|
|
30
|
+
error: A,
|
|
30
31
|
required: O,
|
|
31
32
|
invalid: E,
|
|
32
33
|
status: D,
|
|
33
34
|
readOnly: I
|
|
34
|
-
}), G = W.controlId ?? W.autoId, { helpId: K } = W, q =
|
|
35
|
+
}), G = W.controlId ?? W.autoId, { helpId: K } = W, q = a(I, W.field), J = {
|
|
35
36
|
min: S,
|
|
36
37
|
max: C,
|
|
37
38
|
step: w
|
|
38
39
|
}, [Y, X] = p(null);
|
|
39
|
-
|
|
40
|
+
f(() => X(null), [B]);
|
|
40
41
|
let Z = (e) => {
|
|
41
42
|
let t = l(e, J);
|
|
42
43
|
t !== B && V(t), X(null);
|
|
@@ -47,11 +48,11 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
47
48
|
}, $ = (e) => {
|
|
48
49
|
if (q) return;
|
|
49
50
|
let t = Y === null ? null : u(Y), n = t === null ? B : d(t, J);
|
|
50
|
-
Z(
|
|
51
|
-
},
|
|
51
|
+
Z(ne(n, e, J));
|
|
52
|
+
}, ae = /* @__PURE__ */ h("div", {
|
|
52
53
|
className: _({
|
|
53
54
|
size: T,
|
|
54
|
-
className:
|
|
55
|
+
className: r(j, M)
|
|
55
56
|
}),
|
|
56
57
|
children: [
|
|
57
58
|
/* @__PURE__ */ m("button", {
|
|
@@ -59,7 +60,7 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
59
60
|
className: "kapi-stepper__btn",
|
|
60
61
|
"aria-label": z.decrease,
|
|
61
62
|
tabIndex: -1,
|
|
62
|
-
disabled: F || q || !
|
|
63
|
+
disabled: F || q || !c(B, J),
|
|
63
64
|
onClick: () => $(-1),
|
|
64
65
|
children: /* @__PURE__ */ m(g, {
|
|
65
66
|
size: 15,
|
|
@@ -68,9 +69,9 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
68
69
|
}),
|
|
69
70
|
/* @__PURE__ */ m("input", {
|
|
70
71
|
...R,
|
|
71
|
-
...
|
|
72
|
+
...t(W.outer, {
|
|
72
73
|
id: G,
|
|
73
|
-
describedBy:
|
|
74
|
+
describedBy: n(K, R["aria-describedby"]),
|
|
74
75
|
invalid: H
|
|
75
76
|
}),
|
|
76
77
|
required: O,
|
|
@@ -81,7 +82,7 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
81
82
|
"aria-valuenow": B,
|
|
82
83
|
"aria-valuemin": S,
|
|
83
84
|
"aria-valuemax": C,
|
|
84
|
-
className:
|
|
85
|
+
className: s({
|
|
85
86
|
size: T,
|
|
86
87
|
status: U,
|
|
87
88
|
num: !0,
|
|
@@ -100,7 +101,7 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
100
101
|
className: "kapi-stepper__btn",
|
|
101
102
|
"aria-label": z.increase,
|
|
102
103
|
tabIndex: -1,
|
|
103
|
-
disabled: F || q || !
|
|
104
|
+
disabled: F || q || !te(B, J),
|
|
104
105
|
onClick: () => $(1),
|
|
105
106
|
children: /* @__PURE__ */ m(re, {
|
|
106
107
|
size: 15,
|
|
@@ -109,7 +110,7 @@ var _ = ({ size: e = "md", className: t = "" } = {}) => [
|
|
|
109
110
|
})
|
|
110
111
|
]
|
|
111
112
|
});
|
|
112
|
-
return W.wrap(
|
|
113
|
+
return W.wrap(ae);
|
|
113
114
|
};
|
|
114
115
|
//#endregion
|
|
115
116
|
export { v as DEFAULT_NUMBER_STEPPER_LABELS, y as KapiNumberStepper, _ as stepperClasses };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type FocusEvent, type HTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic.js";
|
|
3
|
+
import { type KapiFieldStatus } from "./fieldLogic.js";
|
|
4
|
+
import { type KapiPinInputType } from "./pinInputLogic.js";
|
|
5
|
+
export type KapiPinInputLabels = {
|
|
6
|
+
/** Nombre de cada caja. `{n}` es el número de caja y `{total}`, cuántas hay. */
|
|
7
|
+
digit: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const DEFAULT_PIN_INPUT_LABELS: KapiPinInputLabels;
|
|
10
|
+
export type KapiPinInputProps = Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "onBlur" | "defaultValue" | "children"> & {
|
|
11
|
+
/** `ref` a la PRIMERA caja, que es la que enfoca el campo. */
|
|
12
|
+
ref?: Ref<HTMLInputElement> | undefined;
|
|
13
|
+
/** Cuántas cajas. @default 6 */
|
|
14
|
+
length?: number | undefined;
|
|
15
|
+
/** Qué acepta cada caja. @default "numeric" */
|
|
16
|
+
type?: KapiPinInputType | undefined;
|
|
17
|
+
/** El código. Controlado. */
|
|
18
|
+
value?: string | undefined;
|
|
19
|
+
/** El código inicial, sin controlar. */
|
|
20
|
+
defaultValue?: string | undefined;
|
|
21
|
+
/** Avisa el código completo (las cajas unidas, sin los huecos). */
|
|
22
|
+
onChange?: ((value: string) => void) | undefined;
|
|
23
|
+
/** Avisa cuando se llenaron todas las cajas: el momento de enviar sin que aprieten un botón. */
|
|
24
|
+
onComplete?: ((value: string) => void) | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Oculta los caracteres, como una contraseña. Para un código que llega por SMS no va: verlo es
|
|
27
|
+
* parte de poder tipearlo bien.
|
|
28
|
+
*/
|
|
29
|
+
mask?: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Deja que el teléfono ofrezca el código del SMS (`autocomplete="one-time-code"`). Va en la
|
|
32
|
+
* PRIMERA caja nada más, que es como lo espera el navegador; el reparto a las demás lo hace solo.
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
oneTimeCode?: boolean | undefined;
|
|
36
|
+
/** Etiqueta del grupo. Con `label` o `help` se envuelve solo en un `KapiField`. */
|
|
37
|
+
label?: ReactNode | undefined;
|
|
38
|
+
/** Pista bajo las cajas. */
|
|
39
|
+
help?: ReactNode | undefined;
|
|
40
|
+
/** El motivo por el que está mal: reemplaza a `help` y lo marca inválido. Ver `KapiFieldProps`. */
|
|
41
|
+
error?: ReactNode | undefined;
|
|
42
|
+
/** Marca el grupo inválido. Sin esto, lo toma del `KapiField` que lo envuelve. */
|
|
43
|
+
invalid?: boolean | undefined;
|
|
44
|
+
/** Validación que no es error: `ok` o `pending`. */
|
|
45
|
+
status?: KapiFieldStatus | undefined;
|
|
46
|
+
/** Obligatorio. */
|
|
47
|
+
required?: boolean | undefined;
|
|
48
|
+
/** No se edita, pero se lee y se copia. */
|
|
49
|
+
readOnly?: boolean | undefined;
|
|
50
|
+
/** Deshabilitado. */
|
|
51
|
+
disabled?: boolean | undefined;
|
|
52
|
+
/** Enfoca la primera caja al montar. */
|
|
53
|
+
autoFocus?: boolean | undefined;
|
|
54
|
+
/** Para el envío nativo del `<form>`: emite un `<input type="hidden">` con el código. */
|
|
55
|
+
name?: string | undefined;
|
|
56
|
+
/** Se llama cuando el foco sale del grupo entero (moverse entre cajas no cuenta). */
|
|
57
|
+
onBlur?: ((event: FocusEvent<HTMLDivElement>) => void) | undefined;
|
|
58
|
+
/** Clase del contenedor del campo. */
|
|
59
|
+
fieldClassName?: string | undefined;
|
|
60
|
+
/** Textos propios. */
|
|
61
|
+
labels?: KapiLabelsOverride<KapiPinInputLabels> | undefined;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Un código en cajas, una por carácter: el segundo factor, el código del SMS, un PIN.
|
|
65
|
+
*
|
|
66
|
+
* NOMBRA CADA CAJA, y es el motivo por el que existe en vez de componerse a mano: seis `<input>`
|
|
67
|
+
* seguidos se anuncian como seis campos idénticos, así que cada uno lleva «Dígito 3 de 6» y el
|
|
68
|
+
* grupo entero lleva la etiqueta. Eso, el pegado desde cualquier caja y el Backspace que retrocede
|
|
69
|
+
* son justamente lo que cada app termina reescribiendo —y a veces olvidando— cuando compone esto
|
|
70
|
+
* con inputs sueltos.
|
|
71
|
+
*/
|
|
72
|
+
export declare function KapiPinInput({ ref, length, type, value: valueProp, defaultValue, onChange, onComplete, mask, oneTimeCode, label, help, error, invalid, status, required, readOnly, disabled, autoFocus, name, onBlur, fieldClassName, className, id, labels, ...rest }: KapiPinInputProps): ReactNode;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "#kapi-css/components/inputs/KapiPinInput.css";
|
|
3
|
+
import { joinClasses as e } from "../rootProps.js";
|
|
4
|
+
import { useMergedRefs as t } from "../../hooks/mergeRefs.js";
|
|
5
|
+
import { useLabels as n } from "../locale/KapiLocaleProvider.js";
|
|
6
|
+
import { fieldControlProps as r } from "./fieldLogic.js";
|
|
7
|
+
import { useOwnField as i } from "./ownField.js";
|
|
8
|
+
import { useControllableState as a } from "../../hooks/useControllableState.js";
|
|
9
|
+
import { joinPin as o, pinAfterBackspace as s, pinAfterInput as c, pinAfterPaste as l, splitPin as u } from "./pinInputLogic.js";
|
|
10
|
+
/* empty css */
|
|
11
|
+
import { useRef as d } from "react";
|
|
12
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
13
|
+
//#region src/components/inputs/KapiPinInput.tsx
|
|
14
|
+
var m = { digit: "Dígito {n} de {total}" };
|
|
15
|
+
function h({ ref: h, length: g = 6, type: _ = "numeric", value: v, defaultValue: y, onChange: b, onComplete: x, mask: S, oneTimeCode: C = !0, label: w, help: T, error: E, invalid: D, status: O, required: k, readOnly: A, disabled: j, autoFocus: M, name: N, onBlur: P, fieldClassName: F, className: I, id: L, labels: R, ...z }) {
|
|
16
|
+
let B = n("pinInput", m, R), V = i({
|
|
17
|
+
id: L,
|
|
18
|
+
label: w,
|
|
19
|
+
help: T,
|
|
20
|
+
error: E,
|
|
21
|
+
required: k,
|
|
22
|
+
invalid: D,
|
|
23
|
+
status: O,
|
|
24
|
+
readOnly: A,
|
|
25
|
+
fieldClassName: F
|
|
26
|
+
}), [H, U] = a(v, y ?? "", b), W = d([]), G = t(h, (e) => {
|
|
27
|
+
W.current[0] = e;
|
|
28
|
+
}), K = u(H, g), q = ({ boxes: e, focus: t }) => {
|
|
29
|
+
let n = o(e);
|
|
30
|
+
U(n), W.current[t]?.focus(), W.current[t]?.select(), n.length === g && x?.(n);
|
|
31
|
+
}, J = (e) => (t) => {
|
|
32
|
+
A || j || (t.key === "Backspace" ? (t.preventDefault(), q(s(K, e))) : t.key === "ArrowLeft" && e > 0 ? (t.preventDefault(), W.current[e - 1]?.focus()) : t.key === "ArrowRight" && e < g - 1 && (t.preventDefault(), W.current[e + 1]?.focus()));
|
|
33
|
+
}, Y = (e) => (t) => {
|
|
34
|
+
A || j || (t.preventDefault(), q(l(K, e, t.clipboardData.getData("text"), _)));
|
|
35
|
+
}, X = r(V.field, {
|
|
36
|
+
id: L,
|
|
37
|
+
required: k,
|
|
38
|
+
invalid: D,
|
|
39
|
+
labelable: !1
|
|
40
|
+
});
|
|
41
|
+
return V.wrap(/* @__PURE__ */ p("div", {
|
|
42
|
+
...z,
|
|
43
|
+
className: e("kapi-pin", I),
|
|
44
|
+
role: "group",
|
|
45
|
+
onBlur: (e) => {
|
|
46
|
+
e.currentTarget.contains(e.relatedTarget) || P?.(e);
|
|
47
|
+
},
|
|
48
|
+
...X,
|
|
49
|
+
children: [K.map((e, t) => /* @__PURE__ */ f("input", {
|
|
50
|
+
ref: t === 0 ? G : (e) => {
|
|
51
|
+
W.current[t] = e;
|
|
52
|
+
},
|
|
53
|
+
className: "kapi-pin__box",
|
|
54
|
+
type: S ? "password" : "text",
|
|
55
|
+
inputMode: _ === "numeric" ? "numeric" : "text",
|
|
56
|
+
autoComplete: C && t === 0 ? "one-time-code" : "off",
|
|
57
|
+
"aria-label": B.digit.replace("{n}", String(t + 1)).replace("{total}", String(g)),
|
|
58
|
+
"aria-invalid": X["aria-invalid"],
|
|
59
|
+
value: e,
|
|
60
|
+
readOnly: A,
|
|
61
|
+
disabled: j,
|
|
62
|
+
autoFocus: M && t === 0,
|
|
63
|
+
onPaste: Y(t),
|
|
64
|
+
onKeyDown: J(t),
|
|
65
|
+
onChange: (e) => q(c(K, t, e.target.value, _)),
|
|
66
|
+
onFocus: (e) => e.currentTarget.select()
|
|
67
|
+
}, t)), N && /* @__PURE__ */ f("input", {
|
|
68
|
+
type: "hidden",
|
|
69
|
+
name: N,
|
|
70
|
+
value: j ? "" : H
|
|
71
|
+
})]
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { m as DEFAULT_PIN_INPUT_LABELS, h as KapiPinInput };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HTMLAttributes, Ref } from "react";
|
|
2
|
+
import { type KapiPropsFormField, type KapiPropsFormValues } from "./propsFormLogic.js";
|
|
3
|
+
export type { KapiPropsFormField, KapiPropsFormValue, KapiPropsFormValues } from "./propsFormLogic.js";
|
|
4
|
+
/** Atributos nativos (`id`, `style`, `data-*`…) van al `<div>` raíz. */
|
|
5
|
+
export type KapiPropsFormProps = Omit<HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & {
|
|
6
|
+
/** Ref al `<div>` raíz. */
|
|
7
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
8
|
+
/** El esquema: qué campos hay y de qué tipo. Puede cambiar en vivo. */
|
|
9
|
+
fields: readonly KapiPropsFormField[];
|
|
10
|
+
/** Valores controlados, por nombre de campo. */
|
|
11
|
+
values?: KapiPropsFormValues | undefined;
|
|
12
|
+
/** Valores iniciales cuando el componente los maneja solo. */
|
|
13
|
+
defaultValues?: KapiPropsFormValues | undefined;
|
|
14
|
+
/** Avisa con TODOS los valores cada vez que uno cambia. */
|
|
15
|
+
onChange?: ((values: KapiPropsFormValues) => void) | undefined;
|
|
16
|
+
/** Marca en rojo los obligatorios vacíos. La app decide cuándo (al intentar guardar). */
|
|
17
|
+
showErrors?: boolean | undefined;
|
|
18
|
+
/** Deshabilita el formulario entero. @default false */
|
|
19
|
+
disabled?: boolean | undefined;
|
|
20
|
+
/** Ancho mínimo de cada campo, en px: debajo de eso la grilla pasa a una columna. @default 220 */
|
|
21
|
+
min?: number | undefined;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Formulario generado desde un esquema: el diálogo de "insertar bloque" de una wiki, la pantalla
|
|
25
|
+
* de configuración de un plugin, cualquier formulario que no se conoce al compilar.
|
|
26
|
+
*
|
|
27
|
+
* **El esquema puede cambiar en vivo** —viene del servidor, o de un tipo de bloque elegido en un
|
|
28
|
+
* menú— y los valores se acomodan solos: los campos que el esquema nuevo no declara se descartan y
|
|
29
|
+
* los que agrega entran con su inicial. Sin eso, cambiar de bloque manda campos del anterior.
|
|
30
|
+
*
|
|
31
|
+
* **`required` no valida: marca.** Quién decide si se puede guardar es la app, con
|
|
32
|
+
* `missingPropsFormFields`. La librería no tiene motor de validación y esto no lo cambia.
|
|
33
|
+
*/
|
|
34
|
+
export declare function KapiPropsForm({ fields, values, defaultValues, onChange, showErrors, disabled, min, className, ...rest }: KapiPropsFormProps): import("react").JSX.Element;
|