@forgedevstack/bear 1.2.6 → 1.2.7
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 +6 -2
- package/dist/components/AppBar/AppBar.cjs +1 -1
- package/dist/components/AppBar/AppBar.js +37 -36
- package/dist/components/Autocomplete/Autocomplete.cjs +1 -1
- package/dist/components/Autocomplete/Autocomplete.js +32 -32
- package/dist/components/Backdrop/Backdrop.cjs +1 -1
- package/dist/components/Backdrop/Backdrop.const.cjs +1 -1
- package/dist/components/Backdrop/Backdrop.const.d.ts +2 -1
- package/dist/components/Backdrop/Backdrop.const.js +4 -3
- package/dist/components/Backdrop/Backdrop.js +36 -29
- package/dist/components/Backdrop/Backdrop.types.d.ts +2 -0
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.js +48 -48
- package/dist/components/Chip/Chip.cjs +1 -1
- package/dist/components/Chip/Chip.const.cjs +1 -1
- package/dist/components/Chip/Chip.const.d.ts +10 -0
- package/dist/components/Chip/Chip.const.js +11 -1
- package/dist/components/Chip/Chip.js +24 -22
- package/dist/components/ChipGroup/ChipGroup.cjs +1 -1
- package/dist/components/ChipGroup/ChipGroup.const.cjs +1 -1
- package/dist/components/ChipGroup/ChipGroup.const.d.ts +6 -3
- package/dist/components/ChipGroup/ChipGroup.const.js +6 -3
- package/dist/components/ChipGroup/ChipGroup.js +83 -29
- package/dist/components/ChipGroup/ChipGroup.types.d.ts +5 -0
- package/dist/components/Drawer/Drawer.cjs +1 -1
- package/dist/components/Drawer/Drawer.js +57 -54
- package/dist/components/EmptyState/EmptyState.cjs +1 -1
- package/dist/components/EmptyState/EmptyState.const.cjs +1 -0
- package/dist/components/EmptyState/EmptyState.const.d.ts +26 -1
- package/dist/components/EmptyState/EmptyState.const.js +29 -0
- package/dist/components/EmptyState/EmptyState.js +49 -31
- package/dist/components/Input/Input.cjs +1 -1
- package/dist/components/Input/Input.const.cjs +1 -1
- package/dist/components/Input/Input.const.d.ts +10 -0
- package/dist/components/Input/Input.const.js +16 -6
- package/dist/components/Input/Input.js +96 -96
- package/dist/components/MessageList/MessageList.cjs +1 -1
- package/dist/components/MessageList/MessageList.js +98 -92
- package/dist/components/MessageList/MessageList.types.d.ts +2 -0
- package/dist/components/Modal/Modal.cjs +1 -1
- package/dist/components/Modal/Modal.const.cjs +1 -1
- package/dist/components/Modal/Modal.const.js +7 -8
- package/dist/components/Modal/Modal.js +60 -55
- package/dist/components/PageHeader/PageHeader.cjs +1 -0
- package/dist/components/PageHeader/PageHeader.const.cjs +1 -0
- package/dist/components/PageHeader/PageHeader.const.d.ts +6 -0
- package/dist/components/PageHeader/PageHeader.const.js +9 -0
- package/dist/components/PageHeader/PageHeader.d.ts +3 -0
- package/dist/components/PageHeader/PageHeader.js +57 -0
- package/dist/components/PageHeader/PageHeader.types.d.ts +10 -0
- package/dist/components/PageHeader/index.d.ts +2 -0
- package/dist/components/Select/Select.cjs +1 -1
- package/dist/components/Select/Select.js +108 -99
- package/dist/components/Select/Select.types.d.ts +3 -1
- package/dist/components/Snackbar/Snackbar.cjs +1 -1
- package/dist/components/Snackbar/Snackbar.js +62 -60
- package/dist/components/Snackbar/Snackbar.types.d.ts +2 -0
- package/dist/components/Tabs/Tabs.cjs +1 -1
- package/dist/components/Tabs/Tabs.const.cjs +1 -0
- package/dist/components/Tabs/Tabs.const.d.ts +2 -0
- package/dist/components/Tabs/Tabs.const.js +5 -0
- package/dist/components/Tabs/Tabs.js +40 -35
- package/dist/components/Tabs/Tabs.types.d.ts +1 -0
- package/dist/components/Toast/Toast.cjs +1 -1
- package/dist/components/Toast/Toast.const.cjs +1 -1
- package/dist/components/Toast/Toast.const.js +7 -15
- package/dist/components/Toast/Toast.js +99 -95
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +267 -265
- package/dist/context/BearProvider.js +1 -1
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +45 -41
- package/dist/hooks/useBreakpoint/index.d.ts +4 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.cjs +1 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.const.cjs +1 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.const.d.ts +8 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.const.js +10 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.d.ts +2 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.js +26 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.types.d.ts +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +446 -431
- package/dist/styles.css +0 -4
- package/dist/utils/generateBearId.const.cjs +1 -1
- package/dist/utils/generateBearId.const.d.ts +4 -2
- package/dist/utils/generateBearId.const.js +6 -4
- package/dist/utils/generateBearId.utils.cjs +1 -1
- package/dist/utils/generateBearId.utils.js +33 -21
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.js +27 -18
- package/dist/utils/liveRegion.const.cjs +1 -0
- package/dist/utils/liveRegion.const.d.ts +5 -0
- package/dist/utils/liveRegion.const.js +17 -0
- package/dist/utils/liveRegion.utils.cjs +1 -0
- package/dist/utils/liveRegion.utils.d.ts +7 -0
- package/dist/utils/liveRegion.utils.js +10 -0
- package/dist/utils/useBearId.cjs +1 -1
- package/dist/utils/useBearId.js +5 -4
- package/package.json +1 -1
|
@@ -1,120 +1,120 @@
|
|
|
1
1
|
import { jsxs as g, jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { cn as
|
|
4
|
-
import { resolveBearId as
|
|
5
|
-
import { useBearId as
|
|
6
|
-
import { BearContext as
|
|
7
|
-
import { ClearIcon as
|
|
8
|
-
import { applyAutoFormat as
|
|
9
|
-
import { validateFieldValue as
|
|
10
|
-
import { INPUT_TEXT_CLASSES as
|
|
11
|
-
const
|
|
2
|
+
import { forwardRef as ve, useContext as we, useState as Ne, useRef as Be, useCallback as C, useEffect as Ce } from "react";
|
|
3
|
+
import { cn as c } from "../../utils/cn.js";
|
|
4
|
+
import { resolveBearId as Te } from "../../utils/generateBearId.utils.js";
|
|
5
|
+
import { useBearId as Ee } from "../../utils/useBearId.js";
|
|
6
|
+
import { useBearDensityOptional as Se, BearContext as Ae, useBearDirectionOptional as ke } from "../../context/BearProvider.js";
|
|
7
|
+
import { ClearIcon as Le } from "./components/ClearIcon/ClearIcon.js";
|
|
8
|
+
import { applyAutoFormat as Ue } from "./Input.utils.js";
|
|
9
|
+
import { validateFieldValue as Oe } from "../Form/Form.utils.js";
|
|
10
|
+
import { INPUT_TEXT_COMPACT_CLASSES as Me, INPUT_TEXT_CLASSES as He, INPUT_MULTILINE_MIN_ROWS as Re, INPUT_MULTILINE_DEFAULT_ROWS as We, INPUT_WRAPPER_HEIGHT_COMPACT_CLASSES as je, INPUT_WRAPPER_HEIGHT_CLASSES as De, INPUT_ROOT_CLASS as Ge } from "./Input.const.js";
|
|
11
|
+
const Pe = ve(
|
|
12
12
|
({
|
|
13
|
-
label:
|
|
13
|
+
label: T,
|
|
14
14
|
helperText: K,
|
|
15
15
|
error: y,
|
|
16
|
-
success:
|
|
17
|
-
size:
|
|
18
|
-
variant:
|
|
19
|
-
radius:
|
|
16
|
+
success: E,
|
|
17
|
+
size: S = "md",
|
|
18
|
+
variant: Xe,
|
|
19
|
+
radius: $e,
|
|
20
20
|
InputProps: i,
|
|
21
21
|
leftAddon: Q,
|
|
22
22
|
rightAddon: V,
|
|
23
|
-
prefix:
|
|
24
|
-
suffix:
|
|
23
|
+
prefix: Fe,
|
|
24
|
+
suffix: qe,
|
|
25
25
|
fullWidth: Y = !1,
|
|
26
26
|
clearable: Z = !1,
|
|
27
|
-
onClear:
|
|
28
|
-
showCharCount:
|
|
29
|
-
charCountMax:
|
|
30
|
-
autoFormat:
|
|
27
|
+
onClear: ee,
|
|
28
|
+
showCharCount: A = !1,
|
|
29
|
+
charCountMax: re,
|
|
30
|
+
autoFormat: I,
|
|
31
31
|
validation: t,
|
|
32
|
-
validateOnBlur:
|
|
33
|
-
validateOnChange:
|
|
34
|
-
loading:
|
|
35
|
-
copyable:
|
|
36
|
-
onCopy:
|
|
37
|
-
floatingLabel:
|
|
32
|
+
validateOnBlur: ae,
|
|
33
|
+
validateOnChange: k = !1,
|
|
34
|
+
loading: ze,
|
|
35
|
+
copyable: Je,
|
|
36
|
+
onCopy: Ke,
|
|
37
|
+
floatingLabel: Qe,
|
|
38
38
|
multiline: l = !1,
|
|
39
|
-
rows:
|
|
40
|
-
minRows:
|
|
41
|
-
maxRows:
|
|
42
|
-
readOnly:
|
|
39
|
+
rows: te,
|
|
40
|
+
minRows: se = Re,
|
|
41
|
+
maxRows: Ve,
|
|
42
|
+
readOnly: L,
|
|
43
43
|
inputRef: s,
|
|
44
44
|
inputProps: U,
|
|
45
|
-
id:
|
|
46
|
-
testId:
|
|
47
|
-
className:
|
|
48
|
-
disabled:
|
|
45
|
+
id: oe,
|
|
46
|
+
testId: ne,
|
|
47
|
+
className: ie,
|
|
48
|
+
disabled: b,
|
|
49
49
|
value: d,
|
|
50
50
|
defaultValue: f,
|
|
51
|
-
maxLength:
|
|
51
|
+
maxLength: v,
|
|
52
52
|
onChange: u,
|
|
53
53
|
onBlur: _,
|
|
54
|
-
...
|
|
54
|
+
...O
|
|
55
55
|
}, o) => {
|
|
56
56
|
var J;
|
|
57
|
-
const
|
|
57
|
+
const le = Ee("Input"), w = Te(oe, le), { density: ce } = Se(), M = ce === "compact", N = we(Ae), r = (J = N == null ? void 0 : N.components) == null ? void 0 : J.Input, be = r == null ? void 0 : r.root, de = r == null ? void 0 : r.input, fe = r == null ? void 0 : r.label, ue = r == null ? void 0 : r.helper, _e = r == null ? void 0 : r.prefix, pe = r == null ? void 0 : r.suffix, [me, H] = Ne(null), R = Be(!1), xe = M ? Me : He, he = M ? je : De, W = t ? ae ?? !0 : !1, j = y || me, n = !!j, p = !!E && !n, m = re ?? v, B = typeof d == "string" ? d.length : typeof f == "string" ? f.length : 0, D = m != null && B > m, ge = Z && !b && B > 0, { direction: ye } = ke(), G = (i == null ? void 0 : i.startAdornment) ?? Q, P = (i == null ? void 0 : i.endAdornment) ?? V, X = j || E || K, x = C(async (e) => {
|
|
58
58
|
if (!t) return;
|
|
59
|
-
|
|
60
|
-
const h = await
|
|
61
|
-
|
|
59
|
+
R.current = !0;
|
|
60
|
+
const h = await Oe(e, t);
|
|
61
|
+
R.current = !1, H(h);
|
|
62
62
|
}, [t]);
|
|
63
|
-
|
|
64
|
-
y &&
|
|
63
|
+
Ce(() => {
|
|
64
|
+
y && H(null);
|
|
65
65
|
}, [y]);
|
|
66
|
-
const
|
|
66
|
+
const $ = C(
|
|
67
67
|
(e) => {
|
|
68
|
-
if (
|
|
69
|
-
const h =
|
|
68
|
+
if (I && !l) {
|
|
69
|
+
const h = Ue(e.target.value, I);
|
|
70
70
|
h !== e.target.value && (e.target.value = h);
|
|
71
71
|
}
|
|
72
|
-
u == null || u(e),
|
|
72
|
+
u == null || u(e), k && t && x(e.target.value);
|
|
73
73
|
},
|
|
74
|
-
[
|
|
75
|
-
),
|
|
74
|
+
[I, l, u, k, t, x]
|
|
75
|
+
), F = C(
|
|
76
76
|
(e) => {
|
|
77
|
-
_ == null || _(e),
|
|
77
|
+
_ == null || _(e), W && t && x(e.target.value);
|
|
78
78
|
},
|
|
79
|
-
[_,
|
|
80
|
-
), q =
|
|
79
|
+
[_, W, t, x]
|
|
80
|
+
), q = c(
|
|
81
81
|
"Bear-Input__field",
|
|
82
82
|
"bear-flex-1 bear-min-w-0 bear-border-0 bear-outline-none bear-bg-transparent",
|
|
83
83
|
"placeholder:opacity-100 placeholder:[color:var(--bear-text-muted)]",
|
|
84
|
-
|
|
84
|
+
xe[S],
|
|
85
85
|
l && "bear-resize-y bear-py-2 bear-min-h-0 bear-h-auto",
|
|
86
|
-
|
|
86
|
+
ie
|
|
87
87
|
), z = {
|
|
88
88
|
color: "var(--bear-text-primary)",
|
|
89
|
-
...
|
|
90
|
-
},
|
|
89
|
+
...de
|
|
90
|
+
}, Ie = te ?? se ?? We;
|
|
91
91
|
return /* @__PURE__ */ g(
|
|
92
92
|
"div",
|
|
93
93
|
{
|
|
94
94
|
id: w,
|
|
95
|
-
"data-testid":
|
|
96
|
-
className:
|
|
97
|
-
style:
|
|
95
|
+
"data-testid": ne,
|
|
96
|
+
className: c(Ge, "bear-flex bear-flex-col bear-gap-1.5", Y && "bear-w-full"),
|
|
97
|
+
style: be,
|
|
98
98
|
children: [
|
|
99
|
-
|
|
99
|
+
T && /* @__PURE__ */ a("label", { className: "Bear-Input__label bear-text-sm bear-font-medium", style: { color: "var(--bear-text-secondary)", ...fe }, children: T }),
|
|
100
100
|
/* @__PURE__ */ g(
|
|
101
101
|
"div",
|
|
102
102
|
{
|
|
103
|
-
className:
|
|
103
|
+
className: c(
|
|
104
104
|
"Bear-Input__wrapper bear-flex bear-items-center bear-rounded-lg bear-border bear-overflow-hidden bear-transition-all bear-duration-200",
|
|
105
105
|
"focus-within:bear-ring-2 focus-within:bear-ring-offset-2",
|
|
106
106
|
"focus-within:bear-ring-offset-[var(--bear-bg-primary)]",
|
|
107
107
|
n ? "Bear-Input__wrapper--error bear-border-red-500 focus-within:bear-ring-red-500" : p ? "Bear-Input__wrapper--success bear-border-green-500 focus-within:bear-ring-green-500" : "focus-within:bear-border-bear-500 focus-within:bear-ring-bear-500 dark:focus-within:bear-border-bear-500 dark:focus-within:bear-ring-bear-500",
|
|
108
|
-
|
|
109
|
-
!l &&
|
|
108
|
+
b && "bear-opacity-50 bear-cursor-not-allowed",
|
|
109
|
+
!l && he[S]
|
|
110
110
|
),
|
|
111
|
-
dir:
|
|
111
|
+
dir: ye,
|
|
112
112
|
style: {
|
|
113
113
|
backgroundColor: "var(--bear-bg-primary)",
|
|
114
114
|
borderColor: n || p ? void 0 : "var(--bear-border-default)"
|
|
115
115
|
},
|
|
116
116
|
children: [
|
|
117
|
-
|
|
117
|
+
G && /* @__PURE__ */ a(
|
|
118
118
|
"div",
|
|
119
119
|
{
|
|
120
120
|
className: "Bear-Input__addon Bear-Input__addon--left bear-flex bear-items-center bear-self-stretch bear-shrink-0 bear-px-3 bear-text-sm bear-font-medium bear-select-none bear-pointer-events-none",
|
|
@@ -122,9 +122,9 @@ const He = ye(
|
|
|
122
122
|
backgroundColor: "var(--bear-bg-tertiary)",
|
|
123
123
|
borderInlineEnd: "1px solid var(--bear-border-default)",
|
|
124
124
|
color: "var(--bear-text-secondary)",
|
|
125
|
-
...
|
|
125
|
+
..._e
|
|
126
126
|
},
|
|
127
|
-
children:
|
|
127
|
+
children: G
|
|
128
128
|
}
|
|
129
129
|
),
|
|
130
130
|
l ? /* @__PURE__ */ a(
|
|
@@ -134,19 +134,19 @@ const He = ye(
|
|
|
134
134
|
typeof o == "function" ? o(e) : o && (o.current = e), typeof s == "function" ? s(e) : s && (s.current = e);
|
|
135
135
|
},
|
|
136
136
|
id: `${w}-field`,
|
|
137
|
-
disabled:
|
|
138
|
-
readOnly:
|
|
137
|
+
disabled: b,
|
|
138
|
+
readOnly: L,
|
|
139
139
|
value: d,
|
|
140
140
|
defaultValue: f,
|
|
141
|
-
maxLength:
|
|
142
|
-
rows:
|
|
141
|
+
maxLength: v,
|
|
142
|
+
rows: Ie,
|
|
143
143
|
"aria-invalid": n || void 0,
|
|
144
144
|
className: q,
|
|
145
145
|
style: z,
|
|
146
146
|
...U,
|
|
147
|
-
...
|
|
148
|
-
onChange: (e) =>
|
|
149
|
-
onBlur: (e) =>
|
|
147
|
+
...O,
|
|
148
|
+
onChange: (e) => $(e),
|
|
149
|
+
onBlur: (e) => F(e)
|
|
150
150
|
}
|
|
151
151
|
) : /* @__PURE__ */ a(
|
|
152
152
|
"input",
|
|
@@ -155,29 +155,29 @@ const He = ye(
|
|
|
155
155
|
typeof o == "function" ? o(e) : o && (o.current = e), typeof s == "function" ? s(e) : s && (s.current = e);
|
|
156
156
|
},
|
|
157
157
|
id: `${w}-field`,
|
|
158
|
-
disabled:
|
|
159
|
-
readOnly:
|
|
158
|
+
disabled: b,
|
|
159
|
+
readOnly: L,
|
|
160
160
|
value: d,
|
|
161
161
|
defaultValue: f,
|
|
162
|
-
maxLength:
|
|
162
|
+
maxLength: v,
|
|
163
163
|
"aria-invalid": n || void 0,
|
|
164
|
-
onChange:
|
|
165
|
-
onBlur:
|
|
164
|
+
onChange: $,
|
|
165
|
+
onBlur: F,
|
|
166
166
|
className: q,
|
|
167
167
|
style: z,
|
|
168
168
|
...U,
|
|
169
|
-
...
|
|
169
|
+
...O
|
|
170
170
|
}
|
|
171
171
|
),
|
|
172
|
-
|
|
172
|
+
ge && /* @__PURE__ */ a(
|
|
173
173
|
"div",
|
|
174
174
|
{
|
|
175
175
|
className: "Bear-Input__clear bear-flex bear-items-center bear-self-stretch bear-shrink-0 bear-px-2 bear-cursor-pointer",
|
|
176
176
|
style: { color: "var(--bear-text-muted)" },
|
|
177
|
-
children: /* @__PURE__ */ a(
|
|
177
|
+
children: /* @__PURE__ */ a(Le, { onClick: ee })
|
|
178
178
|
}
|
|
179
179
|
),
|
|
180
|
-
|
|
180
|
+
P && /* @__PURE__ */ a(
|
|
181
181
|
"div",
|
|
182
182
|
{
|
|
183
183
|
className: "Bear-Input__addon Bear-Input__addon--right bear-flex bear-items-center bear-self-stretch bear-shrink-0 bear-px-3 bear-gap-1.5",
|
|
@@ -185,42 +185,42 @@ const He = ye(
|
|
|
185
185
|
backgroundColor: "var(--bear-bg-tertiary)",
|
|
186
186
|
borderInlineStart: "1px solid var(--bear-border-default)",
|
|
187
187
|
color: "var(--bear-text-secondary)",
|
|
188
|
-
...
|
|
188
|
+
...pe
|
|
189
189
|
},
|
|
190
|
-
children:
|
|
190
|
+
children: P
|
|
191
191
|
}
|
|
192
192
|
)
|
|
193
193
|
]
|
|
194
194
|
}
|
|
195
195
|
),
|
|
196
196
|
/* @__PURE__ */ g("div", { className: "Bear-Input__footer bear-flex bear-items-center bear-justify-between bear-gap-2", children: [
|
|
197
|
-
|
|
197
|
+
X ? /* @__PURE__ */ a(
|
|
198
198
|
"p",
|
|
199
199
|
{
|
|
200
|
-
className:
|
|
200
|
+
className: c(
|
|
201
201
|
"Bear-Input__helper bear-text-sm bear-flex-1",
|
|
202
202
|
n && "Bear-Input__helper--error bear-text-red-500",
|
|
203
203
|
p && "Bear-Input__helper--success bear-text-green-500"
|
|
204
204
|
),
|
|
205
205
|
style: {
|
|
206
206
|
...n || p ? {} : { color: "var(--bear-text-muted)" },
|
|
207
|
-
...
|
|
207
|
+
...ue
|
|
208
208
|
},
|
|
209
|
-
children:
|
|
209
|
+
children: X
|
|
210
210
|
}
|
|
211
|
-
) :
|
|
212
|
-
|
|
211
|
+
) : A ? /* @__PURE__ */ a("span", {}) : null,
|
|
212
|
+
A && m != null && /* @__PURE__ */ g(
|
|
213
213
|
"span",
|
|
214
214
|
{
|
|
215
|
-
className:
|
|
215
|
+
className: c(
|
|
216
216
|
"Bear-Input__char-count bear-text-xs bear-tabular-nums bear-shrink-0",
|
|
217
217
|
D && "bear-text-red-500"
|
|
218
218
|
),
|
|
219
219
|
style: D ? void 0 : { color: "var(--bear-text-muted)" },
|
|
220
220
|
children: [
|
|
221
|
-
|
|
221
|
+
B,
|
|
222
222
|
"/",
|
|
223
|
-
|
|
223
|
+
m
|
|
224
224
|
]
|
|
225
225
|
}
|
|
226
226
|
)
|
|
@@ -230,7 +230,7 @@ const He = ye(
|
|
|
230
230
|
);
|
|
231
231
|
}
|
|
232
232
|
);
|
|
233
|
-
|
|
233
|
+
Pe.displayName = "Input";
|
|
234
234
|
export {
|
|
235
|
-
|
|
235
|
+
Pe as Input
|
|
236
236
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),_=require("react"),eS=require("../Avatar/Avatar.cjs"),a=require("../Typography/Typography.cjs"),e=require("./MessageList.const.cjs"),A=require("./MessageList.utils.cjs"),n=require("../../utils/cn.cjs"),tS=require("../../utils/generateBearId.utils.cjs"),sS=require("../../utils/useBearId.cjs"),nS=({id:H,testId:B,messages:c,currentUserId:b,groupWindowMs:$=e.MESSAGE_LIST_GROUP_WINDOW_MS,showDaySeparators:g=!0,showAvatars:w=!0,showTimestamps:h=!0,autoScroll:p=!0,virtualized:P,overscan:U=e.MESSAGE_LIST_OVERSCAN,height:E=e.MESSAGE_LIST_DEFAULT_HEIGHT,renderMessage:L,emptyState:D,formatDayLabel:T,formatTimestamp:u,translations:q,onNewMessagesClick:d,className:Y})=>{const W=sS.useBearId("MessageList"),F=tS.resolveBearId(H,W),l=_.useRef(null),C=_.useRef(!0),I=_.useRef(null),O=_.useRef(null),M=_.useRef(null),[V,G]=_.useState(!1),[k,m]=_.useState(0),[z,f]=_.useState(typeof E=="number"?E:e.MESSAGE_LIST_DEFAULT_HEIGHT),R={...e.MESSAGE_LIST_DEFAULT_TRANSLATIONS,...q},o=A.buildMessageListItems(c,b,$,g),X=S=>(T==null?void 0:T(S))??A.getDefaultDayLabel(S,R),y=S=>(u==null?void 0:u(S))??A.getDefaultTimestamp(S),v=P??c.length>=e.MESSAGE_LIST_VIRTUALIZE_THRESHOLD,N=S=>{const s=l.current;s&&s.scrollTo({top:s.scrollHeight,behavior:S?"smooth":"auto"})},Z=()=>{const S=l.current;if(!S)return;m(S.scrollTop),f(S.clientHeight);const r=S.scrollHeight-S.scrollTop-S.clientHeight<=e.MESSAGE_LIST_BOTTOM_THRESHOLD_PX;C.current=r,r&&G(!1)};_.useEffect(()=>{const S=l.current;S&&f(S.clientHeight)},[E]),_.useEffect(()=>{const S=c.length>0?c[0].id:null,s=c.length>0?c[c.length-1].id:null,r=I.current===null,Q=S!==null&&O.current!==null&&S!==O.current,SS=s!==null&&s!==I.current;if(Q&&l.current&&(M.current=l.current.scrollHeight),O.current=S,I.current=s,!!SS){if(r||p&&C.current){N(!r);return}G(!0)}},[c,p]),_.useLayoutEffect(()=>{const S=l.current,s=M.current;if(!S||s===null)return;const r=S.scrollHeight-s;r>0&&(S.scrollTop+=r,m(S.scrollTop)),M.current=null},[c]);const J=()=>{N(!0),G(!1),d==null||d()},K=S=>t.jsxs("div",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__group`,e.MESSAGE_LIST_GROUP_CLASSES,S.isOwn&&e.MESSAGE_LIST_GROUP_OWN_CLASSES),children:[w&&!S.isOwn&&t.jsx(eS.Avatar,{src:S.author.avatar,initials:S.author.name[0],size:"sm",className:"bear-flex-shrink-0"}),t.jsxs("div",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__group-body`,e.MESSAGE_LIST_GROUP_BODY_CLASSES,S.isOwn&&e.MESSAGE_LIST_GROUP_BODY_OWN_CLASSES),children:[!S.isOwn&&t.jsxs("div",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__meta`,e.MESSAGE_LIST_META_CLASSES),children:[t.jsx(a.Typography,{variant:"caption",component:"span",className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__author`,e.MESSAGE_LIST_AUTHOR_CLASSES),children:S.author.name}),h&&t.jsx(a.Typography,{variant:"caption",component:"span",className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__timestamp`,e.MESSAGE_LIST_TIMESTAMP_CLASSES),children:y(S.messages[0].timestamp)})]}),S.messages.map(s=>t.jsx("div",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__bubble`,e.MESSAGE_LIST_BUBBLE_CLASSES,S.isOwn&&`${e.MESSAGE_LIST_ROOT_CLASS}__bubble--own`,S.isOwn&&e.MESSAGE_LIST_BUBBLE_OWN_CLASSES),children:(L==null?void 0:L(s))??s.content},s.id)),S.isOwn&&h&&t.jsx(a.Typography,{variant:"caption",component:"span",className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__timestamp`,e.MESSAGE_LIST_TIMESTAMP_CLASSES),children:y(S.messages[S.messages.length-1].timestamp)})]})]},S.key),x=S=>S.kind==="day"?t.jsxs("div",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__day-separator`,e.MESSAGE_LIST_DAY_SEPARATOR_CLASSES),children:[t.jsx("span",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__day-line`,e.MESSAGE_LIST_DAY_LINE_CLASSES)}),t.jsx("span",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__day-label`,e.MESSAGE_LIST_DAY_LABEL_CLASSES),children:X(S.date)}),t.jsx("span",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__day-line`,e.MESSAGE_LIST_DAY_LINE_CLASSES)})]},S.key):K(S),i=v?A.getMessageListWindow(o,k,z,U):null,j=i===null?o:o.slice(i.startIndex,i.endIndex+1);return t.jsxs("div",{id:F,"data-testid":B,className:n.cn(e.MESSAGE_LIST_ROOT_CLASS,e.MESSAGE_LIST_BASE_CLASSES,Y),style:{height:typeof E=="number"?`${E}px`:E},children:[t.jsxs("div",{ref:l,onScroll:Z,className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__scroller`,e.MESSAGE_LIST_SCROLLER_CLASSES),role:"log","aria-live":"polite",children:[o.length===0&&t.jsx("div",{className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__empty`,e.MESSAGE_LIST_EMPTY_CLASSES),children:D??t.jsx(a.Typography,{variant:"body2",component:"span",children:R.emptyLabel})}),v&&i?t.jsx("div",{className:`${e.MESSAGE_LIST_ROOT_CLASS}__virtual`,style:{height:i.totalHeight,position:"relative"},children:t.jsx("div",{style:{transform:`translateY(${i.offsetTop}px)`},children:j.map(S=>x(S))})}):j.map(S=>x(S))]}),V&&t.jsx("button",{type:"button",onClick:J,className:n.cn(`${e.MESSAGE_LIST_ROOT_CLASS}__new-messages`,e.MESSAGE_LIST_NEW_MESSAGES_CLASSES),children:R.newMessages})]})};exports.MessageList=nS;
|