@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.
Files changed (181) hide show
  1. package/README.md +171 -11
  2. package/dist/components/chat/KapiChatThread.js +4 -4
  3. package/dist/components/chat/KapiComposer.js +8 -8
  4. package/dist/components/data/KapiDataTable.js +4 -4
  5. package/dist/components/data/KapiSparkline.d.ts +2 -1
  6. package/dist/components/data/KapiSparkline.js +29 -26
  7. package/dist/components/data/KapiTableFilter.js +6 -6
  8. package/dist/components/data/tableCells.d.ts +12 -1
  9. package/dist/components/data/tableCells.js +49 -51
  10. package/dist/components/data/useTableSelection.js +3 -3
  11. package/dist/components/display/KapiAnnotation.js +68 -63
  12. package/dist/components/display/KapiAvatar.d.ts +6 -4
  13. package/dist/components/display/KapiAvatar.js +33 -28
  14. package/dist/components/display/KapiCodeBlock.d.ts +48 -0
  15. package/dist/components/display/KapiCodeBlock.js +44 -0
  16. package/dist/components/display/KapiCommentComposer.js +6 -6
  17. package/dist/components/display/KapiDiff.d.ts +62 -0
  18. package/dist/components/display/KapiDiff.js +118 -0
  19. package/dist/components/display/KapiHighlight.d.ts +27 -0
  20. package/dist/components/display/KapiHighlight.js +21 -0
  21. package/dist/components/display/KapiIconTile.d.ts +2 -1
  22. package/dist/components/display/KapiIconTile.js +23 -21
  23. package/dist/components/display/KapiStat.d.ts +3 -2
  24. package/dist/components/display/KapiStat.js +32 -26
  25. package/dist/components/display/KapiTag.d.ts +4 -3
  26. package/dist/components/display/KapiTag.js +29 -24
  27. package/dist/components/display/KapiTimeline.d.ts +5 -2
  28. package/dist/components/display/KapiTimeline.js +31 -23
  29. package/dist/components/display/annotationLogic.d.ts +2 -1
  30. package/dist/components/display/annotationLogic.js +7 -6
  31. package/dist/components/display/codeBlockSlots.d.ts +10 -0
  32. package/dist/components/display/codeBlockSlots.js +13 -0
  33. package/dist/components/display/diffLogic.d.ts +58 -0
  34. package/dist/components/display/diffLogic.js +96 -0
  35. package/dist/components/display/diffSlots.d.ts +14 -0
  36. package/dist/components/display/diffSlots.js +17 -0
  37. package/dist/components/display/highlightLogic.d.ts +18 -0
  38. package/dist/components/display/highlightLogic.js +26 -0
  39. package/dist/components/display/highlightSlots.d.ts +5 -0
  40. package/dist/components/display/highlightSlots.js +8 -0
  41. package/dist/components/display/iconTileLogic.d.ts +2 -2
  42. package/dist/components/display/iconTileLogic.js +7 -6
  43. package/dist/components/display/index.d.ts +8 -0
  44. package/dist/components/display/statLogic.d.ts +2 -1
  45. package/dist/components/display/statLogic.js +7 -6
  46. package/dist/components/display/tagLogic.d.ts +2 -1
  47. package/dist/components/display/tagLogic.js +7 -6
  48. package/dist/components/display/timelineLogic.d.ts +20 -2
  49. package/dist/components/display/timelineLogic.js +10 -2
  50. package/dist/components/feedback/KapiFab.js +108 -108
  51. package/dist/components/feedback/KapiProgress.js +63 -54
  52. package/dist/components/feedback/KapiToastContainer.js +9 -9
  53. package/dist/components/feedback/KapiTour.js +12 -12
  54. package/dist/components/feedback/progressLogic.d.ts +2 -1
  55. package/dist/components/feedback/progressLogic.js +9 -8
  56. package/dist/components/inputs/KapiAutocomplete.d.ts +6 -0
  57. package/dist/components/inputs/KapiAutocomplete.js +86 -85
  58. package/dist/components/inputs/KapiChecklist.d.ts +7 -1
  59. package/dist/components/inputs/KapiChecklist.js +53 -52
  60. package/dist/components/inputs/KapiCopyButton.d.ts +40 -0
  61. package/dist/components/inputs/KapiCopyButton.js +35 -0
  62. package/dist/components/inputs/KapiDatePicker.d.ts +7 -1
  63. package/dist/components/inputs/KapiDatePicker.js +118 -116
  64. package/dist/components/inputs/KapiDateRangePicker.d.ts +7 -1
  65. package/dist/components/inputs/KapiDateRangePicker.js +136 -135
  66. package/dist/components/inputs/KapiFacetedSearch.js +5 -5
  67. package/dist/components/inputs/KapiField.d.ts +9 -1
  68. package/dist/components/inputs/KapiField.js +43 -42
  69. package/dist/components/inputs/KapiFileUpload.js +6 -6
  70. package/dist/components/inputs/KapiInput.d.ts +29 -1
  71. package/dist/components/inputs/KapiInput.js +74 -51
  72. package/dist/components/inputs/KapiMaskedInput.js +26 -26
  73. package/dist/components/inputs/KapiNumberStepper.d.ts +7 -1
  74. package/dist/components/inputs/KapiNumberStepper.js +24 -23
  75. package/dist/components/inputs/KapiPinInput.d.ts +72 -0
  76. package/dist/components/inputs/KapiPinInput.js +75 -0
  77. package/dist/components/inputs/KapiPropsForm.d.ts +34 -0
  78. package/dist/components/inputs/KapiPropsForm.js +78 -0
  79. package/dist/components/inputs/KapiRating.d.ts +7 -1
  80. package/dist/components/inputs/KapiRating.js +39 -38
  81. package/dist/components/inputs/KapiSearchChip.js +5 -5
  82. package/dist/components/inputs/KapiSegmented.d.ts +13 -5
  83. package/dist/components/inputs/KapiSegmented.js +81 -77
  84. package/dist/components/inputs/KapiSelect.d.ts +9 -1
  85. package/dist/components/inputs/KapiSelect.js +236 -233
  86. package/dist/components/inputs/KapiSlider.d.ts +10 -3
  87. package/dist/components/inputs/KapiSlider.js +67 -63
  88. package/dist/components/inputs/KapiTagInput.d.ts +7 -1
  89. package/dist/components/inputs/KapiTagInput.js +70 -69
  90. package/dist/components/inputs/KapiTextarea.d.ts +7 -1
  91. package/dist/components/inputs/KapiTextarea.js +51 -50
  92. package/dist/components/inputs/copyLogic.d.ts +1 -0
  93. package/dist/components/inputs/copyLogic.js +12 -0
  94. package/dist/components/inputs/fieldLogic.d.ts +23 -3
  95. package/dist/components/inputs/fieldLogic.js +18 -11
  96. package/dist/components/inputs/index.d.ts +8 -0
  97. package/dist/components/inputs/inputLogic.d.ts +16 -1
  98. package/dist/components/inputs/inputLogic.js +3 -3
  99. package/dist/components/inputs/ownField.d.ts +3 -1
  100. package/dist/components/inputs/ownField.js +28 -27
  101. package/dist/components/inputs/pinInputLogic.d.ts +34 -0
  102. package/dist/components/inputs/pinInputLogic.js +37 -0
  103. package/dist/components/inputs/propsFormLogic.d.ts +53 -0
  104. package/dist/components/inputs/propsFormLogic.js +11 -0
  105. package/dist/components/inputs/segmentedLogic.d.ts +7 -0
  106. package/dist/components/inputs/segmentedLogic.js +2 -2
  107. package/dist/components/layout/KapiAccessCard.d.ts +5 -1
  108. package/dist/components/layout/KapiAccessCard.js +43 -39
  109. package/dist/components/layout/KapiAccountMenu.js +7 -7
  110. package/dist/components/layout/KapiCollapse.d.ts +39 -0
  111. package/dist/components/layout/KapiCollapse.js +20 -0
  112. package/dist/components/layout/KapiContextSlot.js +4 -4
  113. package/dist/components/layout/KapiDivider.d.ts +11 -2
  114. package/dist/components/layout/KapiDivider.js +30 -24
  115. package/dist/components/layout/KapiGrid.js +2 -2
  116. package/dist/components/layout/KapiNotificationBell.js +10 -10
  117. package/dist/components/layout/KapiPageHeader.js +22 -22
  118. package/dist/components/layout/KapiRail.js +4 -4
  119. package/dist/components/layout/KapiRoot.d.ts +22 -2
  120. package/dist/components/layout/KapiRoot.js +33 -29
  121. package/dist/components/layout/KapiShell.d.ts +9 -1
  122. package/dist/components/layout/KapiShell.js +28 -27
  123. package/dist/components/layout/accessCardLogic.d.ts +8 -1
  124. package/dist/components/layout/accessCardLogic.js +11 -7
  125. package/dist/components/layout/index.d.ts +2 -0
  126. package/dist/components/locale/labelRegistry.d.ts +10 -0
  127. package/dist/components/navigation/KapiAccordion.js +9 -9
  128. package/dist/components/navigation/KapiContextPanel.js +12 -12
  129. package/dist/components/navigation/KapiNavBadge.d.ts +6 -3
  130. package/dist/components/navigation/KapiNavBadge.js +26 -22
  131. package/dist/components/navigation/KapiTabs.js +9 -9
  132. package/dist/components/navigation/KapiToc.d.ts +48 -0
  133. package/dist/components/navigation/KapiToc.js +66 -0
  134. package/dist/components/navigation/KapiTree.js +10 -10
  135. package/dist/components/navigation/index.d.ts +3 -0
  136. package/dist/components/navigation/tocLogic.d.ts +35 -0
  137. package/dist/components/navigation/tocLogic.js +11 -0
  138. package/dist/components/navigation/tocSlots.d.ts +8 -0
  139. package/dist/components/navigation/tocSlots.js +11 -0
  140. package/dist/components/overlays/KapiCommandPalette.js +6 -6
  141. package/dist/components/overlays/KapiContextMenu.js +5 -5
  142. package/dist/components/overlays/KapiMenuButton.js +7 -7
  143. package/dist/components/overlays/KapiModal.js +3 -3
  144. package/dist/components/overlays/KapiOffcanvas.js +24 -24
  145. package/dist/components/overlays/KapiPhotoView.js +10 -10
  146. package/dist/components/overlays/KapiPopover.js +6 -6
  147. package/dist/components/overlays/KapiShapeSheet.js +4 -4
  148. package/dist/components/overlays/KapiTooltip.js +18 -18
  149. package/dist/components/overlays/menuList.js +22 -22
  150. package/dist/components/slotCatalog.d.ts +33 -0
  151. package/dist/components/slotCatalog.js +18 -10
  152. package/dist/css/base.css +1 -1
  153. package/dist/css/components/display/KapiAnnotation.css +1 -1
  154. package/dist/css/components/display/KapiCodeBlock.css +1 -0
  155. package/dist/css/components/display/KapiDiff.css +1 -0
  156. package/dist/css/components/display/display.css +1 -1
  157. package/dist/css/components/feedback/feedback.css +1 -1
  158. package/dist/css/components/inputs/KapiPinInput.css +1 -0
  159. package/dist/css/components/inputs/KapiSelect.css +1 -1
  160. package/dist/css/components/inputs/inputsExtra.css +1 -1
  161. package/dist/css/components/layout/KapiAccessCard.css +1 -1
  162. package/dist/css/components/layout/KapiCollapse.css +1 -0
  163. package/dist/css/components/layout/KapiDivider.css +1 -1
  164. package/dist/css/components/navigation/KapiToc.css +1 -0
  165. package/dist/hooks/asyncResourceLogic.d.ts +11 -0
  166. package/dist/hooks/asyncResourceLogic.js +4 -0
  167. package/dist/hooks/index.d.ts +3 -0
  168. package/dist/hooks/toneFamilyLogic.d.ts +26 -2
  169. package/dist/hooks/toneFamilyLogic.js +19 -6
  170. package/dist/hooks/useAsyncResource.d.ts +45 -0
  171. package/dist/hooks/useAsyncResource.js +24 -0
  172. package/dist/hooks/useKapiTheme.d.ts +8 -1
  173. package/dist/hooks/useKapiTheme.js +57 -57
  174. package/dist/hooks/useToneFamilies.d.ts +14 -4
  175. package/dist/hooks/useToneFamilies.js +27 -23
  176. package/dist/index.js +221 -207
  177. package/dist/kapi.css +1 -1
  178. package/dist/kapi.layered.css +1 -1
  179. package/dist/logic.d.ts +41 -0
  180. package/dist/logic.js +42 -0
  181. 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 { nativeFieldProps as e, resolveFieldClassName as t, resolveReadOnly as n } from "./fieldLogic.js";
4
- import { useOwnField as r } from "./ownField.js";
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 i } from "../../hooks/useControllableState.js";
7
- import { clampToStep as a, percentOf as o } from "./sliderLogic.js";
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 s, jsxs as c } from "react/jsx-runtime";
11
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
10
12
  //#region src/components/inputs/KapiSlider.tsx
11
- var l = ({ tone: e = "primary", disabled: t = !1, readOnly: n = !1, className: r = "" } = {}) => [
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
- t && "kapi-slider--disabled",
15
- n && "kapi-slider--readonly",
16
- r
17
- ].filter(Boolean).join(" "), u = ({ value: u, defaultValue: d, onChange: f, min: p = 0, max: m = 100, step: h = 1, tone: g, label: _, help: v, readOnly: y, showValue: b, formatValue: x, fieldClassName: S, wrapperClassName: C, className: w, style: T, disabled: E, id: D, ref: O, invalid: k, required: A, "aria-describedby": j, "aria-invalid": M, "aria-required": N, ...P }) => {
18
- let F = r({
19
- id: D,
20
- help: v,
21
- required: A,
22
- invalid: k,
23
- readOnly: y
24
- }), I = F.autoId, L = n(y, F.field), [R, z] = i(u, d ?? p, f), B = e(F.wraps || _ == null ? F.field : null, {
25
- id: D,
26
- describedBy: j,
27
- invalid: k,
28
- required: A,
29
- ariaInvalid: M,
30
- ariaRequired: N
31
- }), V = B.id ?? I, H = a(R, {
32
- min: p,
33
- max: m,
34
- step: h
35
- }), U = { "--kapi-slider-pct": `${o(H, p, m)}%` }, W = _ != null || b, G = x ? x(H) : void 0;
36
- return F.wrap(/* @__PURE__ */ c("div", {
37
- className: l({
38
- tone: g,
39
- disabled: E,
40
- readOnly: L,
41
- className: t(S, C)
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: [W && /* @__PURE__ */ c("div", {
46
+ children: [q && /* @__PURE__ */ u("div", {
44
47
  className: "kapi-slider__head",
45
- children: [_ != null && /* @__PURE__ */ s("label", {
46
- htmlFor: V,
47
- children: _
48
- }), b && /* @__PURE__ */ s("output", {
49
- htmlFor: V,
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: G ?? H
54
+ children: J ?? W
52
55
  })]
53
- }), /* @__PURE__ */ s("input", {
54
- ...P,
55
- ...B,
56
- ref: O,
57
- id: V,
58
- required: A,
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", w].filter(Boolean).join(" "),
61
- min: p,
62
- max: m,
63
- step: h,
64
- value: H,
65
- "aria-valuetext": G,
66
- "aria-readonly": L || void 0,
67
- disabled: E,
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
- ...T,
70
- ...U
72
+ ...G.style,
73
+ ...D,
74
+ ...K
71
75
  },
72
76
  onChange: (e) => {
73
- L || z(a(Number(e.target.value), {
74
- min: p,
75
- max: m,
76
- step: h
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 { u as KapiSlider, l as sliderClasses };
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 { assignRef as t, fieldControlProps as n, focusLeaves as r, joinIds as i, resolveReadOnly as a } from "./fieldLogic.js";
5
- import { useOwnField as o } from "./ownField.js";
6
- import { useLabels as s } from "../locale/KapiLocaleProvider.js";
7
- import { useControllableState as ee } from "../../hooks/useControllableState.js";
8
- import { useFormReset as te } from "../../hooks/useFormReset.js";
9
- import { useMergedRefs as ne } from "../../hooks/mergeRefs.js";
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 u, splitDraft as d, splitTags as f } from "./tagInputLogic.js";
12
- import { KapiTag as ie } from "../display/KapiTag.js";
13
- import { useCallback as ae, useId as oe, useRef as p, useState as m } from "react";
14
- import { jsx as h, jsxs as g } from "react/jsx-runtime";
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
- }, v = ({ 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 y({ value: e, defaultValue: y = [], onChange: b, validate: se, maxTags: x, allowDuplicates: ce, caseSensitive: le, placeholder: ue, disabled: S = !1, size: C = "md", name: w, id: T, invalid: E, required: D, label: de, help: fe, fieldClassName: pe, readOnly: O, "aria-label": k, "aria-labelledby": A, "aria-describedby": j, onBlur: M, ref: N, labels: P, className: F, onClick: I, ...L }) {
22
- let R = s("tagInput", _, P), z = o({
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: O,
29
- fieldClassName: pe
30
- }), B = z.field, V = a(O, B), H = oe(), [U, W, , me] = ee(e, y, b), [G, K] = m(""), [q, J] = m(null), Y = p(null), he = ne(Y, te(me)), X = p(null), ge = ae((e) => {
31
- X.current = e, t(N, e);
32
- }, [N]), _e = (e) => e.reason === "invalid" ? e.message : e.reason === "duplicate" ? `${R.duplicate} ${e.tag}` : `${R.max} ${x}`, Z = (e, t = "") => {
33
- let { values: n, rejected: r } = re(U, e, {
34
- validate: se,
35
- maxTags: x,
36
- allowDuplicates: ce,
37
- caseSensitive: le
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 !== U.length && W(n), J(r[0] ? _e(r[0]) : null), K([...r.map((e) => e.tag), t].filter(Boolean).join(", "));
40
- }, Q = (e) => {
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 (J(null), !c(t)) {
43
- K(t);
43
+ if (Y(null), !c(t)) {
44
+ q(t);
44
45
  return;
45
46
  }
46
- let { complete: n, tail: r } = d(t);
47
- Z(n, r);
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
- if (V) return;
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 = u(G, n.selectionStart ?? G.length, n.selectionEnd ?? G.length, t);
56
- Z(f(r));
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
- I?.(e), !(e.defaultPrevented || S) && (e.target.closest("button, input") || X.current?.focus());
59
+ a(e.relatedTarget, X.current) && (K.trim() && !H && Q(u(K)), N?.(e));
61
60
  }, Se = (e) => {
62
- J(null), W(l(U, e)), X.current?.focus();
63
- }, $ = q !== null || (E ?? B?.invalid ?? !1);
64
- return z.wrap(/* @__PURE__ */ g("div", {
65
- ...L,
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: v({
68
+ className: _({
68
69
  size: C,
69
70
  invalid: $,
70
71
  disabled: S,
71
- readOnly: V,
72
- className: F
72
+ readOnly: H,
73
+ className: I
73
74
  }),
74
- onClick: xe,
75
- onBlur: be,
75
+ onClick: Se,
76
+ onBlur: xe,
76
77
  children: [
77
- /* @__PURE__ */ g("div", {
78
+ /* @__PURE__ */ h("div", {
78
79
  className: "kapi-taginput__box",
79
- children: [U.length > 0 && /* @__PURE__ */ h("ul", {
80
+ children: [W.length > 0 && /* @__PURE__ */ m("ul", {
80
81
  className: "kapi-taginput__tags",
81
- children: U.map((e, t) => /* @__PURE__ */ h("li", {
82
+ children: W.map((e, t) => /* @__PURE__ */ m("li", {
82
83
  className: "kapi-taginput__item",
83
- children: /* @__PURE__ */ h(ie, {
84
+ children: /* @__PURE__ */ m(oe, {
84
85
  tone: "primary",
85
86
  size: C === "sm" ? "sm" : "md",
86
- onRemove: S || V ? void 0 : () => Se(t),
87
- removeLabel: `${R.remove} ${e}`,
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__ */ h("input", {
92
+ }), /* @__PURE__ */ m("input", {
92
93
  ref: ge,
93
94
  type: "text",
94
95
  className: "kapi-taginput__input",
95
- ...n(B, {
96
+ ...i(V, {
96
97
  id: T,
97
- describedBy: i(q !== null && H, j),
98
+ describedBy: o(J !== null && U, M),
98
99
  invalid: $,
99
100
  required: D
100
101
  }),
101
- "aria-label": k,
102
- "aria-labelledby": A,
103
- placeholder: U.length ? void 0 : ue,
104
- value: G,
102
+ "aria-label": A,
103
+ "aria-labelledby": j,
104
+ placeholder: W.length ? void 0 : x,
105
+ value: K,
105
106
  disabled: S,
106
- readOnly: V || void 0,
107
+ readOnly: H || void 0,
107
108
  enterKeyHint: "enter",
108
- onChange: Q,
109
- onKeyDown: ve,
110
- onPaste: ye
109
+ onChange: ve,
110
+ onKeyDown: ye,
111
+ onPaste: be
111
112
  })]
112
113
  }),
113
- q !== null && /* @__PURE__ */ h("span", {
114
- id: H,
114
+ J !== null && /* @__PURE__ */ m("span", {
115
+ id: U,
115
116
  className: "kapi-taginput__error",
116
117
  role: "alert",
117
- children: q
118
+ children: J
118
119
  }),
119
- w && U.map((e, t) => /* @__PURE__ */ h("input", {
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 { _ as DEFAULT_TAG_INPUT_LABELS, y as KapiTagInput, v as tagInputClasses };
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 { fieldControlProps as e, joinIds as t, resolveValidation as n } from "./fieldLogic.js";
4
- import { useOwnField as r } from "./ownField.js";
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 i } from "./KapiInput.js";
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 = "" } = {}) => i({
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: i, status: h, label: g, required: _, help: v, fieldClassName: y, autosize: b, maxRows: x, className: S, id: C, rows: w = 3, onInput: T, ref: E, ...D }) => {
21
- let { invalid: O, status: k } = n(i, h), A = r({
22
- id: C,
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: i,
27
+ invalid: a,
27
28
  status: h,
28
- fieldClassName: y
29
- }), { controlId: j, helpId: M } = A, N = f(null), P = l((e) => {
30
- N.current = e, typeof E == "function" ? E(e) : E && (E.current = e);
31
- }, [E]), F = f(null), I = l(() => {
32
- let e = N.current;
33
- if (!e || !b) return;
34
- let t = a(e), n = (e) => parseFloat(e) || 0;
35
- F.current = Math.max(0, e.clientWidth - n(t.paddingLeft) - n(t.paddingRight));
36
- let r = n(t.lineHeight) || n(t.fontSize) * 1.5, i = n(t.borderTopWidth) + n(t.borderBottomWidth), o = n(t.paddingTop) + n(t.paddingBottom) + i;
37
- e.style.height = "auto";
38
- let { height: l, overflowing: u } = s(e.scrollHeight + i, {
39
- minHeight: c(w, r, o),
40
- maxHeight: x ? c(x, r, o) : void 0
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
- e.style.height = `${l}px`, e.style.overflowY = u ? "auto" : "hidden";
43
+ t.style.height = `${l}px`, t.style.overflowY = u ? "auto" : "hidden";
43
44
  }, [
44
- b,
45
45
  x,
46
- w
47
- ]), L = D.value;
46
+ S,
47
+ T
48
+ ]), R = O.value;
48
49
  d(() => {
49
- I();
50
- }, [I, L]);
51
- let R = f(I);
52
- R.current = I, u(() => {
53
- let e = N.current;
54
- if (!e || !b || typeof ResizeObserver > "u") return;
55
- let t = null, n = o(() => R.current()), r = new ResizeObserver((e) => {
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 = F.current;
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
- }, [b]);
67
- let z = (e) => {
68
- I(), T?.(e);
69
- }, B = /* @__PURE__ */ p("textarea", {
70
- ...D,
71
- ref: P,
72
- ...e(A.outer, {
73
- id: j,
74
- describedBy: t(M, D["aria-describedby"]),
75
- invalid: O
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: w,
78
+ rows: T,
78
79
  required: _,
79
80
  className: m({
80
- status: k,
81
- autosize: b,
82
- className: S
81
+ status: A,
82
+ autosize: x,
83
+ className: C
83
84
  }),
84
- onInput: z
85
+ onInput: B
85
86
  });
86
- return A.wrap(B);
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 };