@kapiuara/ui 0.16.0 → 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/README.md +171 -11
- package/dist/components/chat/KapiChatThread.js +4 -4
- package/dist/components/chat/KapiComposer.js +8 -8
- package/dist/components/data/KapiDataTable.js +4 -4
- package/dist/components/data/KapiSparkline.d.ts +2 -1
- package/dist/components/data/KapiSparkline.js +29 -26
- package/dist/components/data/KapiTableFilter.js +6 -6
- package/dist/components/data/tableCells.d.ts +12 -1
- package/dist/components/data/tableCells.js +49 -51
- package/dist/components/data/useTableSelection.js +3 -3
- 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/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/KapiTimeline.d.ts +5 -2
- package/dist/components/display/KapiTimeline.js +31 -23
- 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 +8 -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/timelineLogic.d.ts +20 -2
- package/dist/components/display/timelineLogic.js +10 -2
- 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/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 +9 -1
- package/dist/components/inputs/KapiSelect.js +236 -233
- 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 +23 -3
- package/dist/components/inputs/fieldLogic.js +18 -11
- package/dist/components/inputs/index.d.ts +8 -0
- 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/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/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.js +2 -2
- package/dist/components/layout/KapiNotificationBell.js +10 -10
- package/dist/components/layout/KapiPageHeader.js +22 -22
- package/dist/components/layout/KapiRail.js +4 -4
- package/dist/components/layout/KapiRoot.d.ts +22 -2
- package/dist/components/layout/KapiRoot.js +33 -29
- package/dist/components/layout/KapiShell.d.ts +9 -1
- package/dist/components/layout/KapiShell.js +28 -27
- package/dist/components/layout/accessCardLogic.d.ts +8 -1
- package/dist/components/layout/accessCardLogic.js +11 -7
- package/dist/components/layout/index.d.ts +2 -0
- package/dist/components/locale/labelRegistry.d.ts +10 -0
- package/dist/components/navigation/KapiAccordion.js +9 -9
- package/dist/components/navigation/KapiContextPanel.js +12 -12
- package/dist/components/navigation/KapiNavBadge.d.ts +6 -3
- package/dist/components/navigation/KapiNavBadge.js +26 -22
- package/dist/components/navigation/KapiTabs.js +9 -9
- 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/index.d.ts +3 -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.js +5 -5
- package/dist/components/overlays/KapiMenuButton.js +7 -7
- package/dist/components/overlays/KapiModal.js +3 -3
- 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/menuList.js +22 -22
- package/dist/components/slotCatalog.d.ts +33 -0
- package/dist/components/slotCatalog.js +18 -10
- package/dist/css/base.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/feedback/feedback.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/KapiCollapse.css +1 -0
- package/dist/css/components/layout/KapiDivider.css +1 -1
- package/dist/css/components/navigation/KapiToc.css +1 -0
- package/dist/hooks/asyncResourceLogic.d.ts +11 -0
- package/dist/hooks/asyncResourceLogic.js +4 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/toneFamilyLogic.d.ts +26 -2
- package/dist/hooks/toneFamilyLogic.js +19 -6
- package/dist/hooks/useAsyncResource.d.ts +45 -0
- package/dist/hooks/useAsyncResource.js +24 -0
- package/dist/hooks/useKapiTheme.d.ts +8 -1
- package/dist/hooks/useKapiTheme.js +57 -57
- package/dist/hooks/useToneFamilies.d.ts +14 -4
- package/dist/hooks/useToneFamilies.js +27 -23
- package/dist/index.js +221 -207
- 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/package.json +13 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InputHTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
|
+
import { type KapiFamilyTone } from "../tone.js";
|
|
2
3
|
export type KapiSliderTone = "primary" | "success" | "warning" | "danger";
|
|
3
4
|
export type KapiSliderProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "size" | "value" | "defaultValue" | "onChange" | "min" | "max" | "step"> & {
|
|
4
5
|
/** Valor actual; con él, el control es controlado. */
|
|
@@ -14,7 +15,7 @@ export type KapiSliderProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type"
|
|
|
14
15
|
/** Paso entre valores. */
|
|
15
16
|
step?: number | undefined;
|
|
16
17
|
/** Color of the filled track and the thumb. */
|
|
17
|
-
tone?: KapiSliderTone | undefined;
|
|
18
|
+
tone?: KapiSliderTone | KapiFamilyTone | undefined;
|
|
18
19
|
/**
|
|
19
20
|
* Etiqueta arriba del slider, en la misma fila que `showValue` (por eso no es el `<label>` de un
|
|
20
21
|
* `KapiField`: el valor va a su derecha). Lo nombra con `for`.
|
|
@@ -22,6 +23,12 @@ export type KapiSliderProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type"
|
|
|
22
23
|
label?: ReactNode;
|
|
23
24
|
/** Ayuda / mensaje de error bajo el slider (lo envuelve en un `KapiField` sin etiqueta). */
|
|
24
25
|
help?: ReactNode | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* El motivo por el que el campo está mal. Reemplaza a `help` y lo marca inválido (rojo, ícono y
|
|
28
|
+
* `role="alert"`). Es lo que entregan las librerías de formularios: un mensaje, no un booleano.
|
|
29
|
+
* Un error que React no pinta (`true`, `""`, `null`) no marca nada. Gana sobre `invalid` y `status`.
|
|
30
|
+
*/
|
|
31
|
+
error?: ReactNode | undefined;
|
|
25
32
|
/**
|
|
26
33
|
* Solo lectura: se enfoca y muestra el valor, pero no se mueve (`aria-readonly`). Sin la prop, lo
|
|
27
34
|
* toma del `KapiField`.
|
|
@@ -45,7 +52,7 @@ export type KapiSliderProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type"
|
|
|
45
52
|
};
|
|
46
53
|
/** Wrapper classes. Pure and exported. */
|
|
47
54
|
export declare const sliderClasses: ({ tone, disabled, readOnly, className }?: {
|
|
48
|
-
tone?: KapiSliderTone | undefined;
|
|
55
|
+
tone?: KapiSliderTone | KapiFamilyTone | undefined;
|
|
49
56
|
disabled?: boolean | undefined;
|
|
50
57
|
readOnly?: boolean | undefined;
|
|
51
58
|
className?: string | undefined;
|
|
@@ -57,4 +64,4 @@ export declare const sliderClasses: ({ tone, disabled, readOnly, className }?: {
|
|
|
57
64
|
* `name` goes to the native range, so a native `<form>` submits the number. Inside a `KapiField`
|
|
58
65
|
* (and without its own `label`) it takes the field id, help, `aria-invalid` and `aria-required`.
|
|
59
66
|
*/
|
|
60
|
-
export declare const KapiSlider: ({ value: valueProp, defaultValue, onChange, min, max, step, tone, label, help, readOnly: readOnlyProp, showValue, formatValue, fieldClassName, wrapperClassName, className, style: styleProp, disabled, id, ref, invalid, required, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, ...rest }: KapiSliderProps) => ReactNode;
|
|
67
|
+
export declare const KapiSlider: ({ value: valueProp, defaultValue, onChange, min, max, step, tone, label, help, error, readOnly: readOnlyProp, showValue, formatValue, fieldClassName, wrapperClassName, className, style: styleProp, disabled, id, ref, invalid, required, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, ...rest }: KapiSliderProps) => ReactNode;
|
|
@@ -1,83 +1,87 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/inputs/inputsExtra.css";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useToneLook as e } from "../../hooks/useToneFamilies.js";
|
|
4
|
+
import { isFamilyTone as t } from "../tone.js";
|
|
5
|
+
import { nativeFieldProps as n, resolveFieldClassName as r, resolveReadOnly as i } from "./fieldLogic.js";
|
|
6
|
+
import { useOwnField as a } from "./ownField.js";
|
|
5
7
|
/* empty css */
|
|
6
|
-
import { useControllableState as
|
|
7
|
-
import { clampToStep as
|
|
8
|
+
import { useControllableState as o } from "../../hooks/useControllableState.js";
|
|
9
|
+
import { clampToStep as s, percentOf as c } from "./sliderLogic.js";
|
|
8
10
|
import "react";
|
|
9
|
-
import { jsx as
|
|
11
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
10
12
|
//#region src/components/inputs/KapiSlider.tsx
|
|
11
|
-
var
|
|
13
|
+
var d = ({ tone: e = "primary", disabled: n = !1, readOnly: r = !1, className: i = "" } = {}) => [
|
|
12
14
|
"kapi-slider",
|
|
13
|
-
e !== "primary" && `kapi-slider--${e}`,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
].filter(Boolean).join(" "),
|
|
18
|
-
let
|
|
19
|
-
id:
|
|
20
|
-
help:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
t(e) ? "kapi-slider--family" : e !== "primary" && `kapi-slider--${e}`,
|
|
16
|
+
n && "kapi-slider--disabled",
|
|
17
|
+
r && "kapi-slider--readonly",
|
|
18
|
+
i
|
|
19
|
+
].filter(Boolean).join(" "), f = ({ value: t, defaultValue: f, onChange: p, min: m = 0, max: h = 100, step: g = 1, tone: _, label: v, help: y, error: b, readOnly: x, showValue: S, formatValue: C, fieldClassName: w, wrapperClassName: T, className: E, style: D, disabled: O, id: k, ref: A, invalid: j, required: M, "aria-describedby": N, "aria-invalid": P, "aria-required": F, ...I }) => {
|
|
20
|
+
let L = a({
|
|
21
|
+
id: k,
|
|
22
|
+
help: y,
|
|
23
|
+
error: b,
|
|
24
|
+
required: M,
|
|
25
|
+
invalid: j,
|
|
26
|
+
readOnly: x
|
|
27
|
+
}), R = L.autoId, z = i(x, L.field), [B, V] = o(t, f ?? m, p), H = n(L.wraps || v == null ? L.field : null, {
|
|
28
|
+
id: k,
|
|
29
|
+
describedBy: N,
|
|
30
|
+
invalid: j,
|
|
31
|
+
required: M,
|
|
32
|
+
ariaInvalid: P,
|
|
33
|
+
ariaRequired: F
|
|
34
|
+
}), U = H.id ?? R, W = s(B, {
|
|
35
|
+
min: m,
|
|
36
|
+
max: h,
|
|
37
|
+
step: g
|
|
38
|
+
}), G = e("KapiSlider", _), K = { "--kapi-slider-pct": `${c(W, m, h)}%` }, q = v != null || S, J = C ? C(W) : void 0;
|
|
39
|
+
return L.wrap(/* @__PURE__ */ u("div", {
|
|
40
|
+
className: d({
|
|
41
|
+
tone: G.tone,
|
|
42
|
+
disabled: O,
|
|
43
|
+
readOnly: z,
|
|
44
|
+
className: r(w, T)
|
|
42
45
|
}),
|
|
43
|
-
children: [
|
|
46
|
+
children: [q && /* @__PURE__ */ u("div", {
|
|
44
47
|
className: "kapi-slider__head",
|
|
45
|
-
children: [
|
|
46
|
-
htmlFor:
|
|
47
|
-
children:
|
|
48
|
-
}),
|
|
49
|
-
htmlFor:
|
|
48
|
+
children: [v != null && /* @__PURE__ */ l("label", {
|
|
49
|
+
htmlFor: U,
|
|
50
|
+
children: v
|
|
51
|
+
}), S && /* @__PURE__ */ l("output", {
|
|
52
|
+
htmlFor: U,
|
|
50
53
|
className: "kapi-slider__value",
|
|
51
|
-
children:
|
|
54
|
+
children: J ?? W
|
|
52
55
|
})]
|
|
53
|
-
}), /* @__PURE__ */
|
|
54
|
-
...
|
|
55
|
-
...
|
|
56
|
-
ref:
|
|
57
|
-
id:
|
|
58
|
-
required:
|
|
56
|
+
}), /* @__PURE__ */ l("input", {
|
|
57
|
+
...I,
|
|
58
|
+
...H,
|
|
59
|
+
ref: A,
|
|
60
|
+
id: U,
|
|
61
|
+
required: M,
|
|
59
62
|
type: "range",
|
|
60
|
-
className: ["kapi-slider__input",
|
|
61
|
-
min:
|
|
62
|
-
max:
|
|
63
|
-
step:
|
|
64
|
-
value:
|
|
65
|
-
"aria-valuetext":
|
|
66
|
-
"aria-readonly":
|
|
67
|
-
disabled:
|
|
63
|
+
className: ["kapi-slider__input", E].filter(Boolean).join(" "),
|
|
64
|
+
min: m,
|
|
65
|
+
max: h,
|
|
66
|
+
step: g,
|
|
67
|
+
value: W,
|
|
68
|
+
"aria-valuetext": J,
|
|
69
|
+
"aria-readonly": z || void 0,
|
|
70
|
+
disabled: O,
|
|
68
71
|
style: {
|
|
69
|
-
...
|
|
70
|
-
...
|
|
72
|
+
...G.style,
|
|
73
|
+
...D,
|
|
74
|
+
...K
|
|
71
75
|
},
|
|
72
76
|
onChange: (e) => {
|
|
73
|
-
|
|
74
|
-
min:
|
|
75
|
-
max:
|
|
76
|
-
step:
|
|
77
|
+
z || V(s(Number(e.target.value), {
|
|
78
|
+
min: m,
|
|
79
|
+
max: h,
|
|
80
|
+
step: g
|
|
77
81
|
}));
|
|
78
82
|
}
|
|
79
83
|
})]
|
|
80
84
|
}));
|
|
81
85
|
};
|
|
82
86
|
//#endregion
|
|
83
|
-
export {
|
|
87
|
+
export { f as KapiSlider, d as sliderClasses };
|
|
@@ -52,6 +52,12 @@ export type KapiTagInputProps = Omit<HTMLAttributes<HTMLDivElement>, "children"
|
|
|
52
52
|
label?: ReactNode | undefined;
|
|
53
53
|
/** Ayuda / mensaje de error bajo el control (lo envuelve en un `KapiField`). */
|
|
54
54
|
help?: ReactNode | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* El motivo por el que el campo está mal. Reemplaza a `help` y lo marca inválido (rojo, ícono y
|
|
57
|
+
* `role="alert"`). Es lo que entregan las librerías de formularios: un mensaje, no un booleano.
|
|
58
|
+
* Un error que React no pinta (`true`, `""`, `null`) no marca nada. Gana sobre `invalid` y `status`.
|
|
59
|
+
*/
|
|
60
|
+
error?: ReactNode | undefined;
|
|
55
61
|
/** Clase del `KapiField` propio (con `label` o `help`). `className` va al contenedor. */
|
|
56
62
|
fieldClassName?: string | undefined;
|
|
57
63
|
/**
|
|
@@ -86,5 +92,5 @@ export declare const tagInputClasses: ({ size, invalid, disabled, readOnly, clas
|
|
|
86
92
|
* texto vacío quita la última. `validate`, `maxTags` y los duplicados rechazan con un mensaje y dejan el
|
|
87
93
|
* texto para corregirlo.
|
|
88
94
|
*/
|
|
89
|
-
export declare function KapiTagInput({ value, defaultValue, onChange, validate, maxTags, allowDuplicates, caseSensitive, placeholder, disabled, size, name, id, invalid, required, label, help, fieldClassName, readOnly: readOnlyProp, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onBlur, ref, labels, className, onClick, ...rest }: KapiTagInputProps): ReactNode;
|
|
95
|
+
export declare function KapiTagInput({ value, defaultValue, onChange, validate, maxTags, allowDuplicates, caseSensitive, placeholder, disabled, size, name, id, invalid, required, label, help, error: errorProp, fieldClassName, readOnly: readOnlyProp, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onBlur, ref, labels, className, onClick, ...rest }: KapiTagInputProps): ReactNode;
|
|
90
96
|
export {};
|
|
@@ -1,122 +1,123 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/inputs/KapiTagInput.css";
|
|
3
3
|
import { joinClasses as e } from "../rootProps.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
4
|
+
import { useMergedRefs as t } from "../../hooks/mergeRefs.js";
|
|
5
|
+
import { useLabels as n } from "../locale/KapiLocaleProvider.js";
|
|
6
|
+
import { assignRef as r, fieldControlProps as i, focusLeaves as a, joinIds as o, resolveReadOnly as ee } from "./fieldLogic.js";
|
|
7
|
+
import { useOwnField as s } from "./ownField.js";
|
|
8
|
+
import { useControllableState as te } from "../../hooks/useControllableState.js";
|
|
9
|
+
import { useFormReset as ne } from "../../hooks/useFormReset.js";
|
|
10
10
|
/* empty css */
|
|
11
|
-
import { addTags as re, hasSeparator as c, removeTagAt as l, spliceText as
|
|
12
|
-
import { KapiTag as
|
|
13
|
-
import { useCallback as
|
|
14
|
-
import { jsx as
|
|
11
|
+
import { addTags as re, hasSeparator as c, removeTagAt as l, spliceText as ie, splitDraft as ae, splitTags as u } from "./tagInputLogic.js";
|
|
12
|
+
import { KapiTag as oe } from "../display/KapiTag.js";
|
|
13
|
+
import { useCallback as d, useId as se, useRef as f, useState as p } from "react";
|
|
14
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
15
15
|
//#region src/components/inputs/KapiTagInput.tsx
|
|
16
|
-
var
|
|
16
|
+
var g = {
|
|
17
17
|
remove: "Quitar",
|
|
18
18
|
duplicate: "Ya está en la lista:",
|
|
19
19
|
max: "Llegaste al máximo de"
|
|
20
|
-
},
|
|
21
|
-
function
|
|
22
|
-
let
|
|
20
|
+
}, _ = ({ size: t = "md", invalid: n, disabled: r, readOnly: i, className: a }) => e("kapi-taginput", t !== "md" && `kapi-taginput--${t}`, n && "kapi-taginput--err", r && "kapi-taginput--disabled", i && "kapi-taginput--readonly", a);
|
|
21
|
+
function v({ value: e, defaultValue: v = [], onChange: ce, validate: y, maxTags: b, allowDuplicates: le, caseSensitive: ue, placeholder: x, disabled: S = !1, size: C = "md", name: w, id: T, invalid: E, required: D, label: de, help: fe, error: pe, fieldClassName: O, readOnly: k, "aria-label": A, "aria-labelledby": j, "aria-describedby": M, onBlur: N, ref: P, labels: F, className: I, onClick: L, ...R }) {
|
|
22
|
+
let z = n("tagInput", g, F), B = s({
|
|
23
23
|
id: T,
|
|
24
24
|
label: de,
|
|
25
25
|
help: fe,
|
|
26
|
+
error: pe,
|
|
26
27
|
required: D,
|
|
27
28
|
invalid: E,
|
|
28
|
-
readOnly:
|
|
29
|
-
fieldClassName:
|
|
30
|
-
}),
|
|
31
|
-
|
|
32
|
-
}, [
|
|
33
|
-
let { values: n, rejected: r } = re(
|
|
34
|
-
validate:
|
|
35
|
-
maxTags:
|
|
36
|
-
allowDuplicates:
|
|
37
|
-
caseSensitive:
|
|
29
|
+
readOnly: k,
|
|
30
|
+
fieldClassName: O
|
|
31
|
+
}), V = B.field, H = ee(k, V), U = se(), [W, G, , me] = te(e, v, ce), [K, q] = p(""), [J, Y] = p(null), X = f(null), he = t(X, ne(me)), Z = f(null), ge = d((e) => {
|
|
32
|
+
Z.current = e, r(P, e);
|
|
33
|
+
}, [P]), _e = (e) => e.reason === "invalid" ? e.message : e.reason === "duplicate" ? `${z.duplicate} ${e.tag}` : `${z.max} ${b}`, Q = (e, t = "") => {
|
|
34
|
+
let { values: n, rejected: r } = re(W, e, {
|
|
35
|
+
validate: y,
|
|
36
|
+
maxTags: b,
|
|
37
|
+
allowDuplicates: le,
|
|
38
|
+
caseSensitive: ue
|
|
38
39
|
});
|
|
39
|
-
n.length !==
|
|
40
|
-
},
|
|
40
|
+
n.length !== W.length && G(n), Y(r[0] ? _e(r[0]) : null), q([...r.map((e) => e.tag), t].filter(Boolean).join(", "));
|
|
41
|
+
}, ve = (e) => {
|
|
41
42
|
let t = e.target.value;
|
|
42
|
-
if (
|
|
43
|
-
|
|
43
|
+
if (Y(null), !c(t)) {
|
|
44
|
+
q(t);
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
|
-
let { complete: n, tail: r } =
|
|
47
|
-
|
|
48
|
-
}, ve = (e) => {
|
|
49
|
-
S || V || (e.key === "Enter" && G.trim() ? (e.preventDefault(), Z(f(G))) : e.key === "Backspace" && G === "" && U.length > 0 && (e.preventDefault(), J(null), W(l(U, U.length - 1))));
|
|
47
|
+
let { complete: n, tail: r } = ae(t);
|
|
48
|
+
Q(n, r);
|
|
50
49
|
}, ye = (e) => {
|
|
51
|
-
|
|
50
|
+
S || H || (e.key === "Enter" && K.trim() ? (e.preventDefault(), Q(u(K))) : e.key === "Backspace" && K === "" && W.length > 0 && (e.preventDefault(), Y(null), G(l(W, W.length - 1))));
|
|
51
|
+
}, be = (e) => {
|
|
52
|
+
if (H) return;
|
|
52
53
|
let t = e.clipboardData.getData("text");
|
|
53
54
|
if (!c(t)) return;
|
|
54
55
|
e.preventDefault();
|
|
55
|
-
let n = e.currentTarget, r =
|
|
56
|
-
|
|
57
|
-
}, be = (e) => {
|
|
58
|
-
r(e.relatedTarget, Y.current) && (G.trim() && !V && Z(f(G)), M?.(e));
|
|
56
|
+
let n = e.currentTarget, r = ie(K, n.selectionStart ?? K.length, n.selectionEnd ?? K.length, t);
|
|
57
|
+
Q(u(r));
|
|
59
58
|
}, xe = (e) => {
|
|
60
|
-
|
|
59
|
+
a(e.relatedTarget, X.current) && (K.trim() && !H && Q(u(K)), N?.(e));
|
|
61
60
|
}, Se = (e) => {
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
L?.(e), !(e.defaultPrevented || S) && (e.target.closest("button, input") || Z.current?.focus());
|
|
62
|
+
}, Ce = (e) => {
|
|
63
|
+
Y(null), G(l(W, e)), Z.current?.focus();
|
|
64
|
+
}, $ = J !== null || (E ?? V?.invalid ?? !1);
|
|
65
|
+
return B.wrap(/* @__PURE__ */ h("div", {
|
|
66
|
+
...R,
|
|
66
67
|
ref: he,
|
|
67
|
-
className:
|
|
68
|
+
className: _({
|
|
68
69
|
size: C,
|
|
69
70
|
invalid: $,
|
|
70
71
|
disabled: S,
|
|
71
|
-
readOnly:
|
|
72
|
-
className:
|
|
72
|
+
readOnly: H,
|
|
73
|
+
className: I
|
|
73
74
|
}),
|
|
74
|
-
onClick:
|
|
75
|
-
onBlur:
|
|
75
|
+
onClick: Se,
|
|
76
|
+
onBlur: xe,
|
|
76
77
|
children: [
|
|
77
|
-
/* @__PURE__ */
|
|
78
|
+
/* @__PURE__ */ h("div", {
|
|
78
79
|
className: "kapi-taginput__box",
|
|
79
|
-
children: [
|
|
80
|
+
children: [W.length > 0 && /* @__PURE__ */ m("ul", {
|
|
80
81
|
className: "kapi-taginput__tags",
|
|
81
|
-
children:
|
|
82
|
+
children: W.map((e, t) => /* @__PURE__ */ m("li", {
|
|
82
83
|
className: "kapi-taginput__item",
|
|
83
|
-
children: /* @__PURE__ */
|
|
84
|
+
children: /* @__PURE__ */ m(oe, {
|
|
84
85
|
tone: "primary",
|
|
85
86
|
size: C === "sm" ? "sm" : "md",
|
|
86
|
-
onRemove: S ||
|
|
87
|
-
removeLabel: `${
|
|
87
|
+
onRemove: S || H ? void 0 : () => Ce(t),
|
|
88
|
+
removeLabel: `${z.remove} ${e}`,
|
|
88
89
|
children: e
|
|
89
90
|
})
|
|
90
91
|
}, `${t}-${e}`))
|
|
91
|
-
}), /* @__PURE__ */
|
|
92
|
+
}), /* @__PURE__ */ m("input", {
|
|
92
93
|
ref: ge,
|
|
93
94
|
type: "text",
|
|
94
95
|
className: "kapi-taginput__input",
|
|
95
|
-
...
|
|
96
|
+
...i(V, {
|
|
96
97
|
id: T,
|
|
97
|
-
describedBy:
|
|
98
|
+
describedBy: o(J !== null && U, M),
|
|
98
99
|
invalid: $,
|
|
99
100
|
required: D
|
|
100
101
|
}),
|
|
101
|
-
"aria-label":
|
|
102
|
-
"aria-labelledby":
|
|
103
|
-
placeholder:
|
|
104
|
-
value:
|
|
102
|
+
"aria-label": A,
|
|
103
|
+
"aria-labelledby": j,
|
|
104
|
+
placeholder: W.length ? void 0 : x,
|
|
105
|
+
value: K,
|
|
105
106
|
disabled: S,
|
|
106
|
-
readOnly:
|
|
107
|
+
readOnly: H || void 0,
|
|
107
108
|
enterKeyHint: "enter",
|
|
108
|
-
onChange:
|
|
109
|
-
onKeyDown:
|
|
110
|
-
onPaste:
|
|
109
|
+
onChange: ve,
|
|
110
|
+
onKeyDown: ye,
|
|
111
|
+
onPaste: be
|
|
111
112
|
})]
|
|
112
113
|
}),
|
|
113
|
-
|
|
114
|
-
id:
|
|
114
|
+
J !== null && /* @__PURE__ */ m("span", {
|
|
115
|
+
id: U,
|
|
115
116
|
className: "kapi-taginput__error",
|
|
116
117
|
role: "alert",
|
|
117
|
-
children:
|
|
118
|
+
children: J
|
|
118
119
|
}),
|
|
119
|
-
w &&
|
|
120
|
+
w && W.map((e, t) => /* @__PURE__ */ m("input", {
|
|
120
121
|
type: "hidden",
|
|
121
122
|
name: w,
|
|
122
123
|
value: e
|
|
@@ -125,4 +126,4 @@ function y({ value: e, defaultValue: y = [], onChange: b, validate: se, maxTags:
|
|
|
125
126
|
}));
|
|
126
127
|
}
|
|
127
128
|
//#endregion
|
|
128
|
-
export {
|
|
129
|
+
export { g as DEFAULT_TAG_INPUT_LABELS, v as KapiTagInput, _ as tagInputClasses };
|
|
@@ -11,6 +11,12 @@ export type KapiTextareaFieldProps = TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
|
11
11
|
required?: boolean | undefined;
|
|
12
12
|
/** Help / error message below the control (takes the color of `invalid` or `status`). */
|
|
13
13
|
help?: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Why the field is wrong. Replaces `help` and marks the field invalid (red, icon and `role="alert"`).
|
|
16
|
+
* This is what form libraries hand you: a message, not a boolean. An error React does not paint
|
|
17
|
+
* (`true`, `""`, `null`) marks nothing. Wins over `invalid` and `status`.
|
|
18
|
+
*/
|
|
19
|
+
error?: ReactNode | undefined;
|
|
14
20
|
/** Class of the wrapping `KapiField` (if any). `className` goes to the control. */
|
|
15
21
|
fieldClassName?: string | undefined;
|
|
16
22
|
/** Grow with the content instead of showing a scrollbar. */
|
|
@@ -30,4 +36,4 @@ export declare const textareaClasses: ({ status, autosize, className }?: {
|
|
|
30
36
|
* Multiline text field of the design system (`.kapi-input` + `.kapi-textarea`). Works controlled or not.
|
|
31
37
|
* With `autosize` it grows with its content, optionally up to `maxRows`.
|
|
32
38
|
*/
|
|
33
|
-
export declare const KapiTextarea: ({ invalid: invalidProp, status: statusProp, label, required, help, fieldClassName, autosize, maxRows, className, id, rows, onInput, ref, ...rest }: KapiTextareaFieldProps) => ReactNode;
|
|
39
|
+
export declare const KapiTextarea: ({ invalid: invalidProp, status: statusProp, label, required, help, error, fieldClassName, autosize, maxRows, className, id, rows, onInput, ref, ...rest }: KapiTextareaFieldProps) => ReactNode;
|
|
@@ -1,89 +1,90 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "#kapi-css/components/inputs/inputsExtra.css";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { computedStyleOf as e } from "../../hooks/ownerDocument.js";
|
|
4
|
+
import { fieldControlProps as t, joinIds as n, resolveFieldMessage as r } from "./fieldLogic.js";
|
|
5
|
+
import { useOwnField as i } from "./ownField.js";
|
|
5
6
|
/* empty css */
|
|
6
|
-
import { inputClasses as
|
|
7
|
-
import { computedStyleOf as a } from "../../hooks/ownerDocument.js";
|
|
7
|
+
import { inputClasses as a } from "./KapiInput.js";
|
|
8
8
|
import { rafThrottle as o } from "../../hooks/rafThrottle.js";
|
|
9
9
|
import { autosizeHeight as s, rowsToHeight as c } from "./textareaLogic.js";
|
|
10
10
|
import { useCallback as l, useEffect as u, useLayoutEffect as d, useRef as f } from "react";
|
|
11
11
|
import { jsx as p } from "react/jsx-runtime";
|
|
12
12
|
//#region src/components/inputs/KapiTextarea.tsx
|
|
13
|
-
var m = ({ status: e, autosize: t = !1, className: n = "" } = {}) =>
|
|
13
|
+
var m = ({ status: e, autosize: t = !1, className: n = "" } = {}) => a({
|
|
14
14
|
status: e,
|
|
15
15
|
className: [
|
|
16
16
|
"kapi-textarea",
|
|
17
17
|
t && "kapi-textarea--auto",
|
|
18
18
|
n
|
|
19
19
|
].filter(Boolean).join(" ")
|
|
20
|
-
}), h = ({ invalid:
|
|
21
|
-
let { invalid:
|
|
22
|
-
id:
|
|
20
|
+
}), h = ({ invalid: a, status: h, label: g, required: _, help: v, error: y, fieldClassName: b, autosize: x, maxRows: S, className: C, id: w, rows: T = 3, onInput: E, ref: D, ...O }) => {
|
|
21
|
+
let { invalid: k, status: A } = r(y, v, a, h), j = i({
|
|
22
|
+
id: w,
|
|
23
23
|
label: g,
|
|
24
24
|
help: v,
|
|
25
|
+
error: y,
|
|
25
26
|
required: _,
|
|
26
|
-
invalid:
|
|
27
|
+
invalid: a,
|
|
27
28
|
status: h,
|
|
28
|
-
fieldClassName:
|
|
29
|
-
}), { controlId:
|
|
30
|
-
|
|
31
|
-
}, [
|
|
32
|
-
let
|
|
33
|
-
if (!
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
let { height: l, overflowing: u } = s(
|
|
39
|
-
minHeight: c(
|
|
40
|
-
maxHeight:
|
|
29
|
+
fieldClassName: b
|
|
30
|
+
}), { controlId: M, helpId: N } = j, P = f(null), F = l((e) => {
|
|
31
|
+
P.current = e, typeof D == "function" ? D(e) : D && (D.current = e);
|
|
32
|
+
}, [D]), I = f(null), L = l(() => {
|
|
33
|
+
let t = P.current;
|
|
34
|
+
if (!t || !x) return;
|
|
35
|
+
let n = e(t), r = (e) => parseFloat(e) || 0;
|
|
36
|
+
I.current = Math.max(0, t.clientWidth - r(n.paddingLeft) - r(n.paddingRight));
|
|
37
|
+
let i = r(n.lineHeight) || r(n.fontSize) * 1.5, a = r(n.borderTopWidth) + r(n.borderBottomWidth), o = r(n.paddingTop) + r(n.paddingBottom) + a;
|
|
38
|
+
t.style.height = "auto";
|
|
39
|
+
let { height: l, overflowing: u } = s(t.scrollHeight + a, {
|
|
40
|
+
minHeight: c(T, i, o),
|
|
41
|
+
maxHeight: S ? c(S, i, o) : void 0
|
|
41
42
|
});
|
|
42
|
-
|
|
43
|
+
t.style.height = `${l}px`, t.style.overflowY = u ? "auto" : "hidden";
|
|
43
44
|
}, [
|
|
44
|
-
b,
|
|
45
45
|
x,
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
S,
|
|
47
|
+
T
|
|
48
|
+
]), R = O.value;
|
|
48
49
|
d(() => {
|
|
49
|
-
|
|
50
|
-
}, [
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
let e =
|
|
54
|
-
if (!e || !
|
|
55
|
-
let t = null, n = o(() =>
|
|
50
|
+
L();
|
|
51
|
+
}, [L, R]);
|
|
52
|
+
let z = f(L);
|
|
53
|
+
z.current = L, u(() => {
|
|
54
|
+
let e = P.current;
|
|
55
|
+
if (!e || !x || typeof ResizeObserver > "u") return;
|
|
56
|
+
let t = null, n = o(() => z.current()), r = new ResizeObserver((e) => {
|
|
56
57
|
let r = e[e.length - 1]?.contentRect.width;
|
|
57
58
|
if (r === void 0 || r === t) return;
|
|
58
59
|
let i = t === null;
|
|
59
60
|
t = r;
|
|
60
|
-
let a =
|
|
61
|
+
let a = I.current;
|
|
61
62
|
i && a !== null && Math.abs(r - a) < 1 || n();
|
|
62
63
|
});
|
|
63
64
|
return r.observe(e), () => {
|
|
64
65
|
r.disconnect(), n.cancel();
|
|
65
66
|
};
|
|
66
|
-
}, [
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
...
|
|
71
|
-
ref:
|
|
72
|
-
...
|
|
73
|
-
id:
|
|
74
|
-
describedBy:
|
|
75
|
-
invalid:
|
|
67
|
+
}, [x]);
|
|
68
|
+
let B = (e) => {
|
|
69
|
+
L(), E?.(e);
|
|
70
|
+
}, V = /* @__PURE__ */ p("textarea", {
|
|
71
|
+
...O,
|
|
72
|
+
ref: F,
|
|
73
|
+
...t(j.outer, {
|
|
74
|
+
id: M,
|
|
75
|
+
describedBy: n(N, O["aria-describedby"]),
|
|
76
|
+
invalid: k
|
|
76
77
|
}),
|
|
77
|
-
rows:
|
|
78
|
+
rows: T,
|
|
78
79
|
required: _,
|
|
79
80
|
className: m({
|
|
80
|
-
status:
|
|
81
|
-
autosize:
|
|
82
|
-
className:
|
|
81
|
+
status: A,
|
|
82
|
+
autosize: x,
|
|
83
|
+
className: C
|
|
83
84
|
}),
|
|
84
|
-
onInput:
|
|
85
|
+
onInput: B
|
|
85
86
|
});
|
|
86
|
-
return
|
|
87
|
+
return j.wrap(V);
|
|
87
88
|
};
|
|
88
89
|
//#endregion
|
|
89
90
|
export { h as KapiTextarea, m as textareaClasses };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const copyText: (value: string, from?: Element | null) => Promise<boolean>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { winOf as e } from "../../hooks/ownerDocument.js";
|
|
2
|
+
//#region src/components/inputs/copyLogic.ts
|
|
3
|
+
var t = async (t, n) => {
|
|
4
|
+
try {
|
|
5
|
+
let r = (n ? e(n) : globalThis.window)?.navigator?.clipboard;
|
|
6
|
+
return r?.writeText ? (await r.writeText(t), !0) : !1;
|
|
7
|
+
} catch {
|
|
8
|
+
return !1;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { t as copyText };
|