@skiddph/prui 0.13.0 → 0.13.1
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/dist/core/tag-input.d.ts +6 -4
- package/dist/core/tag-input.js +56 -49
- package/package.json +1 -1
package/dist/core/tag-input.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ import { PropsMeta } from './props-meta';
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
/**
|
|
5
5
|
* TagInput: comma-separated entry as removable chips (tags, email
|
|
6
|
-
* recipients, keywords). Text commits
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* recipients, keywords). Text commits the moment a separator arrives — by
|
|
7
|
+
* keydown, or through the input value itself (IME, virtual keyboards,
|
|
8
|
+
* autofill, multi-char separators like " and ") — plus Enter, multi-value
|
|
9
|
+
* paste, or blur; Backspace on an empty field removes the last tag. The
|
|
10
|
+
* chip and the value are separate concerns: labelFor decides what the chip
|
|
11
|
+
* displays while onChange keeps emitting the original strings, and
|
|
10
12
|
* renderTag takes over the chip entirely.
|
|
11
13
|
*/
|
|
12
14
|
export type TagInputSize = "sm" | "md" | "lg";
|
package/dist/core/tag-input.js
CHANGED
|
@@ -1,81 +1,88 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import { X as
|
|
4
|
-
import { resolveSurface as
|
|
5
|
-
import { cn as
|
|
6
|
-
import { usePruiI18n as
|
|
7
|
-
const
|
|
1
|
+
import { jsxs as D, jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import * as d from "react";
|
|
3
|
+
import { X as Q } from "lucide-react";
|
|
4
|
+
import { resolveSurface as W, withSurface as Y } from "./surface.js";
|
|
5
|
+
import { cn as Z } from "./cn.js";
|
|
6
|
+
import { usePruiI18n as ee } from "../i18n.js";
|
|
7
|
+
const te = (h) => h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), ne = {
|
|
8
8
|
sm: "min-h-8 text-sm",
|
|
9
9
|
md: "min-h-9 text-sm",
|
|
10
10
|
lg: "min-h-11 text-base"
|
|
11
|
-
},
|
|
11
|
+
}, re = d.forwardRef(function({
|
|
12
12
|
className: j,
|
|
13
13
|
style: k,
|
|
14
14
|
size: R = "md",
|
|
15
15
|
variant: T = "default",
|
|
16
|
-
value:
|
|
16
|
+
value: v,
|
|
17
17
|
defaultValue: B,
|
|
18
|
-
onChange:
|
|
19
|
-
separators:
|
|
20
|
-
commitOnBlur:
|
|
21
|
-
parseInput:
|
|
22
|
-
validate:
|
|
18
|
+
onChange: m,
|
|
19
|
+
separators: a = [","],
|
|
20
|
+
commitOnBlur: C = !0,
|
|
21
|
+
parseInput: P,
|
|
22
|
+
validate: b,
|
|
23
23
|
maxTags: y,
|
|
24
|
-
allowDuplicates:
|
|
24
|
+
allowDuplicates: S = !1,
|
|
25
25
|
labelFor: x,
|
|
26
26
|
renderTag: w,
|
|
27
|
-
disabled:
|
|
27
|
+
disabled: f,
|
|
28
28
|
bg: z,
|
|
29
29
|
fg: E,
|
|
30
30
|
radius: F,
|
|
31
31
|
texture: K,
|
|
32
32
|
textureColor: A,
|
|
33
33
|
elevation: M,
|
|
34
|
-
...
|
|
34
|
+
...r
|
|
35
35
|
}, O) {
|
|
36
|
-
const { t: U } =
|
|
37
|
-
N || X(e),
|
|
38
|
-
},
|
|
36
|
+
const { t: U } = ee(), N = v !== void 0, [V, X] = d.useState(B ?? []), o = N ? v : V, [l, p] = d.useState(""), _ = P ?? ((e) => e.split(new RegExp(a.map(te).join("|"))).map((t) => t.trim()).filter(Boolean)), I = (e) => {
|
|
37
|
+
N || X(e), m == null || m(e);
|
|
38
|
+
}, c = (e) => {
|
|
39
39
|
const t = _(e);
|
|
40
40
|
if (!t.length) {
|
|
41
|
-
|
|
41
|
+
p("");
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const n = [...o], i = [];
|
|
45
45
|
for (const s of t)
|
|
46
|
-
y !== void 0 &&
|
|
47
|
-
|
|
48
|
-
}, g = (e) =>
|
|
46
|
+
y !== void 0 && n.length >= y ? i.push(s) : !S && n.includes(s) || (b && !b(s) ? i.push(s) : n.push(s));
|
|
47
|
+
p(i.join(a[0] ?? ", ")), n.length !== o.length && I(n);
|
|
48
|
+
}, g = (e) => I(o.filter((t, n) => n !== e)), q = (e) => {
|
|
49
49
|
var t;
|
|
50
|
-
e.key === "Enter" ||
|
|
50
|
+
e.key === "Enter" || a.includes(e.key) ? (e.preventDefault(), c(l)) : e.key === "Backspace" && !l && o.length && (e.preventDefault(), g(o.length - 1)), (t = r.onKeyDown) == null || t.call(r, e);
|
|
51
51
|
}, G = (e) => {
|
|
52
|
-
var
|
|
52
|
+
var n;
|
|
53
53
|
const t = e.clipboardData.getData("text");
|
|
54
|
-
if (t &&
|
|
55
|
-
e.preventDefault(),
|
|
54
|
+
if (t && a.some((i) => t.includes(i))) {
|
|
55
|
+
e.preventDefault(), c(l ? `${l}${a[0] ?? ","}${t}` : t);
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
(
|
|
58
|
+
(n = r.onPaste) == null || n.call(r, e);
|
|
59
59
|
}, H = (e) => {
|
|
60
60
|
var t;
|
|
61
|
-
|
|
62
|
-
}, J =
|
|
63
|
-
|
|
61
|
+
C && c(l), (t = r.onBlur) == null || t.call(r, e);
|
|
62
|
+
}, J = (e) => {
|
|
63
|
+
const t = e.target.value;
|
|
64
|
+
if (a.some((n) => t.includes(n))) {
|
|
65
|
+
c(t);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
p(t);
|
|
69
|
+
}, L = W({ bg: z, fg: E, radius: F, texture: K, textureColor: A, elevation: M }), $ = Y(
|
|
70
|
+
Z(
|
|
64
71
|
"prui-f-control prui-taginput flex w-full flex-wrap items-center gap-1 px-1.5 py-1",
|
|
65
72
|
"border border-[var(--prui-line)] rounded-[var(--prui-s-radius,var(--prui-radius))]",
|
|
66
73
|
"bg-[var(--prui-s-bg,var(--prui-background))] text-[var(--prui-s-fg,var(--prui-fg))] placeholder:text-[var(--prui-dim)]",
|
|
67
74
|
"outline-none transition-colors focus-within:border-[var(--prui-brand)] focus-within:ring-2 focus-within:ring-[var(--prui-brand)]/30",
|
|
68
|
-
|
|
75
|
+
ne[R],
|
|
69
76
|
T === "filled" && "bg-[var(--prui-s-bg,var(--prui-raise))] border-transparent",
|
|
70
|
-
|
|
77
|
+
f && "opacity-50 cursor-not-allowed",
|
|
71
78
|
j
|
|
72
79
|
),
|
|
73
80
|
k,
|
|
74
|
-
|
|
81
|
+
L
|
|
75
82
|
);
|
|
76
|
-
return /* @__PURE__ */
|
|
77
|
-
|
|
78
|
-
(e, t) => w ? /* @__PURE__ */ u(
|
|
83
|
+
return /* @__PURE__ */ D("div", { className: $.className, style: $.style, children: [
|
|
84
|
+
o.map(
|
|
85
|
+
(e, t) => w ? /* @__PURE__ */ u(d.Fragment, { children: w(e, { remove: () => g(t) }) }, `${e}-${t}`) : /* @__PURE__ */ D(
|
|
79
86
|
"span",
|
|
80
87
|
{
|
|
81
88
|
className: "inline-flex max-w-full items-center gap-1 rounded-[var(--prui-radius-full)] border border-[var(--prui-line)] bg-[var(--prui-raise)] py-0.5 pl-2 pr-1 text-xs text-[var(--prui-fg)]",
|
|
@@ -86,10 +93,10 @@ const ee = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), te = {
|
|
|
86
93
|
{
|
|
87
94
|
type: "button",
|
|
88
95
|
"aria-label": U.removeTag.replace("{label}", e),
|
|
89
|
-
disabled:
|
|
96
|
+
disabled: f,
|
|
90
97
|
onClick: () => g(t),
|
|
91
98
|
className: "flex h-4 w-4 cursor-pointer items-center justify-center rounded-full text-[var(--prui-dim)] hover:bg-[var(--prui-line)] hover:text-[var(--prui-fg)] disabled:cursor-not-allowed",
|
|
92
|
-
children: /* @__PURE__ */ u(
|
|
99
|
+
children: /* @__PURE__ */ u(Q, { className: "h-3 w-3", "aria-hidden": !0 })
|
|
93
100
|
}
|
|
94
101
|
)
|
|
95
102
|
]
|
|
@@ -101,20 +108,20 @@ const ee = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), te = {
|
|
|
101
108
|
"input",
|
|
102
109
|
{
|
|
103
110
|
ref: O,
|
|
104
|
-
value:
|
|
105
|
-
onChange:
|
|
111
|
+
value: l,
|
|
112
|
+
onChange: J,
|
|
106
113
|
onKeyDown: q,
|
|
107
114
|
onPaste: G,
|
|
108
115
|
onBlur: H,
|
|
109
|
-
disabled:
|
|
110
|
-
...
|
|
116
|
+
disabled: f,
|
|
117
|
+
...r,
|
|
111
118
|
className: "h-7 min-w-16 flex-1 bg-transparent text-sm outline-none placeholder:text-[var(--prui-dim)] disabled:cursor-not-allowed"
|
|
112
119
|
}
|
|
113
120
|
)
|
|
114
121
|
] });
|
|
115
122
|
});
|
|
116
|
-
|
|
117
|
-
const
|
|
123
|
+
re.displayName = "TagInput";
|
|
124
|
+
const ue = {
|
|
118
125
|
name: "TagInput",
|
|
119
126
|
props: [
|
|
120
127
|
{ name: "value", type: "string[]", default: "uncontrolled", control: "none" },
|
|
@@ -135,6 +142,6 @@ const se = {
|
|
|
135
142
|
]
|
|
136
143
|
};
|
|
137
144
|
export {
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
re as TagInput,
|
|
146
|
+
ue as tagInputPropsMeta
|
|
140
147
|
};
|