mimir-ui-kit 1.49.2 → 1.50.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.
@@ -0,0 +1,255 @@
1
+ import { jsxs as k, jsx as u } from "react/jsx-runtime";
2
+ import { c as f } from "../../index-DIxK0V-G.js";
3
+ import { memo as L, forwardRef as R, useId as b, useRef as I, useState as q, useEffect as tt, useCallback as x } from "react";
4
+ import { ETextAreaSize as g, ETextAreaVariant as et } from "./constants.js";
5
+ import { getCurrentText as D, setEditableText as V, placeCaretAtEnd as B, clampByMaxLength as rt, getMaxHeightStyle as at } from "./utils.js";
6
+ import { useMergeRefs as nt } from "../../hooks/useMergeRefs/useMergeRefs.js";
7
+ import { Icon as st } from "../../icons/Icon.js";
8
+ import { MiniButton as ot } from "../MiniButton/MiniButton.js";
9
+ import '../../assets/TextArea2.css';const ct = "_textarea_1sytk_2", lt = "_disabled_1sytk_68", ut = "_clear_1sytk_112", it = "_label_1sytk_128", dt = "_message_1sytk_184", _t = "_error_1sytk_188", ft = "_success_1sytk_219", mt = "_alarm_1sytk_226", pt = "_s_1sytk_219", xt = "_m_1sytk_184", yt = "_l_1sytk_128", e = {
10
+ "textarea-wrapper": "_textarea-wrapper_1sytk_2",
11
+ textarea: ct,
12
+ disabled: lt,
13
+ "with-value": "_with-value_1sytk_73",
14
+ clear: ut,
15
+ "has-left-addon": "_has-left-addon_1sytk_115",
16
+ "has-clear": "_has-clear_1sytk_119",
17
+ "is-required": "_is-required_1sytk_123",
18
+ label: it,
19
+ "is-focused": "_is-focused_1sytk_148",
20
+ "textarea-right-addon": "_textarea-right-addon_1sytk_152",
21
+ "textarea-left-addon": "_textarea-left-addon_1sytk_153",
22
+ "required-mark": "_required-mark_1sytk_169",
23
+ "addon-icon": "_addon-icon_1sytk_179",
24
+ message: dt,
25
+ error: _t,
26
+ "right-addons-content": "_right-addons-content_1sytk_192",
27
+ "default-gray": "_default-gray_1sytk_201",
28
+ "default-white": "_default-white_1sytk_210",
29
+ success: ft,
30
+ alarm: mt,
31
+ s: pt,
32
+ m: xt,
33
+ l: yt
34
+ }, kt = (i, c) => {
35
+ if (!i)
36
+ return null;
37
+ switch (i.addonType) {
38
+ case "icon": {
39
+ const d = c === g.L, h = c === g.M, r = c === g.S;
40
+ return /* @__PURE__ */ u(
41
+ st,
42
+ {
43
+ style: {
44
+ "--icon-size": f({
45
+ "16px": h || r,
46
+ "24px": d
47
+ })
48
+ },
49
+ className: e["addon-icon"],
50
+ iconName: i.addonContent
51
+ }
52
+ );
53
+ }
54
+ case "text":
55
+ return i.addonContent;
56
+ default:
57
+ return null;
58
+ }
59
+ }, gt = L(
60
+ R(
61
+ ({
62
+ className: i,
63
+ label: c,
64
+ required: d,
65
+ leftAddon: h,
66
+ disabled: r,
67
+ autofocus: F,
68
+ withClearButton: C,
69
+ value: S,
70
+ onChange: y,
71
+ maxLength: _,
72
+ maxRows: $,
73
+ message: A,
74
+ size: m = g.M,
75
+ status: M,
76
+ variant: j = et.DefaultGray,
77
+ containerClassName: H,
78
+ wrapperClassName: K
79
+ }, P) => {
80
+ const w = b(), N = kt(h, m), a = I(null), v = I(!1), W = nt(P, a), [p, E] = q(
81
+ F
82
+ ), [G, U] = q(""), T = S !== void 0, n = T ? S ?? "" : G, z = at(m, $);
83
+ tt(() => {
84
+ const t = a.current;
85
+ if (t) {
86
+ if (v.current) {
87
+ v.current = !1;
88
+ return;
89
+ }
90
+ D(t) !== n && (V(n, t), B(t));
91
+ }
92
+ }, [n]);
93
+ const l = x(
94
+ (t, o = !1) => {
95
+ const s = rt(t, _);
96
+ T ? y == null || y(s) : U(s), o && (v.current = !0, V(s, a == null ? void 0 : a.current), B(a == null ? void 0 : a.current));
97
+ },
98
+ [T, y, _]
99
+ ), J = x(() => {
100
+ if (r) return;
101
+ const t = D(a == null ? void 0 : a.current);
102
+ typeof _ == "number" && _ >= 0 && t.length > _ ? l(t, !0) : t.length === 0 ? l("", !0) : l(t);
103
+ }, [l, _, r]), O = x(
104
+ (t) => {
105
+ if (r)
106
+ return;
107
+ t.preventDefault();
108
+ const o = (t.clipboardData.getData("text/plain") || "").replace(/\r\n|\r/g, `
109
+ `), s = window.getSelection();
110
+ s != null && s.rangeCount && (s.deleteFromDocument(), s.getRangeAt(0).insertNode(document.createTextNode(o)), s.collapseToEnd());
111
+ const Z = D(a == null ? void 0 : a.current);
112
+ l(Z, !0);
113
+ },
114
+ [l, r]
115
+ ), Q = x(
116
+ (t) => {
117
+ r && t.preventDefault();
118
+ },
119
+ [r]
120
+ ), X = x(() => {
121
+ var t;
122
+ l("", !0), (t = a.current) == null || t.focus();
123
+ }, [l]), Y = f(
124
+ e["textarea-wrapper"],
125
+ e[j],
126
+ e[m],
127
+ e[M ?? ""],
128
+ d && e.required,
129
+ r && e.disabled,
130
+ !!n && e["with-value"],
131
+ N && e["has-left-addon"],
132
+ C && !!n && e["has-clear"],
133
+ d && !p && e["is-required"],
134
+ K
135
+ );
136
+ return /* @__PURE__ */ k(
137
+ "div",
138
+ {
139
+ id: `textarea-container-${w}`,
140
+ className: f(e["textarea-container"], H),
141
+ children: [
142
+ /* @__PURE__ */ k(
143
+ "div",
144
+ {
145
+ "data-testid": "textarea-wrapper",
146
+ id: `textarea-wrapper-${w}`,
147
+ tabIndex: r ? -1 : 0,
148
+ className: Y,
149
+ onMouseDown: (t) => {
150
+ var o;
151
+ r || t.target === t.currentTarget && (t.preventDefault(), (o = a.current) == null || o.focus());
152
+ },
153
+ onFocusCapture: (t) => {
154
+ var o;
155
+ r || (t.target === t.currentTarget && ((o = a.current) == null || o.focus()), t.currentTarget.contains(t.relatedTarget) || E(!0));
156
+ },
157
+ onBlurCapture: (t) => {
158
+ r || t.currentTarget.contains(t.relatedTarget) || E(!1);
159
+ },
160
+ children: [
161
+ N && /* @__PURE__ */ u(
162
+ "div",
163
+ {
164
+ "data-testid": "left-addon",
165
+ className: e["textarea-left-addon"],
166
+ children: N
167
+ }
168
+ ),
169
+ c && /* @__PURE__ */ k(
170
+ "span",
171
+ {
172
+ className: f(e.label, {
173
+ [e["is-focused"]]: !!n || p
174
+ }),
175
+ children: [
176
+ c,
177
+ d && (!!n || p) && /* @__PURE__ */ u(
178
+ "span",
179
+ {
180
+ className: e["required-mark"],
181
+ "data-testid": "required-mark"
182
+ }
183
+ )
184
+ ]
185
+ }
186
+ ),
187
+ /* @__PURE__ */ u(
188
+ "div",
189
+ {
190
+ id: `textarea-${w}`,
191
+ className: f(
192
+ e.textarea,
193
+ i,
194
+ r && e.disabled,
195
+ {
196
+ [e["with-value"]]: !!n
197
+ }
198
+ ),
199
+ role: "textbox",
200
+ "aria-multiline": !0,
201
+ "aria-label": c,
202
+ "aria-disabled": r,
203
+ onInput: J,
204
+ onKeyDown: Q,
205
+ onBeforeInput: (t) => {
206
+ r && t.preventDefault();
207
+ },
208
+ contentEditable: !0,
209
+ suppressContentEditableWarning: !0,
210
+ onPaste: O,
211
+ ref: W,
212
+ style: z,
213
+ tabIndex: -1,
214
+ "data-placeholder": n || p ? void 0 : c
215
+ }
216
+ ),
217
+ /* @__PURE__ */ k("div", { className: e["right-addons-content"], children: [
218
+ d && !n && !p && /* @__PURE__ */ u(
219
+ "span",
220
+ {
221
+ className: e["required-mark"],
222
+ "data-testid": "required-mark"
223
+ }
224
+ ),
225
+ C && !!n && /* @__PURE__ */ u(
226
+ ot,
227
+ {
228
+ className: e.clear,
229
+ iconName: m === "l" ? "Close16px" : "Close12px",
230
+ size: m === "l" ? "l" : "m-s",
231
+ variant: "transparent",
232
+ disabled: r,
233
+ "data-testid": "clear-button",
234
+ "data-minibutton": !0,
235
+ onMouseDown: (t) => {
236
+ t.preventDefault();
237
+ },
238
+ onClick: X
239
+ }
240
+ )
241
+ ] })
242
+ ]
243
+ }
244
+ ),
245
+ A && /* @__PURE__ */ u("div", { className: f(e.message, e[M ?? ""]), children: A })
246
+ ]
247
+ }
248
+ );
249
+ }
250
+ )
251
+ );
252
+ gt.displayName = "TextArea";
253
+ export {
254
+ gt as TextArea
255
+ };
@@ -0,0 +1,16 @@
1
+ export declare const enum ETextAreaSize {
2
+ S = "s",
3
+ M = "m",
4
+ L = "l"
5
+ }
6
+ export declare const enum ETextAreaStatus {
7
+ Alarm = "alarm",
8
+ Success = "success",
9
+ Error = "error"
10
+ }
11
+ export declare enum ETextAreaVariant {
12
+ DefaultGray = "default-gray",
13
+ DefaultWhite = "default-white"
14
+ }
15
+ export declare const LINE_HEIGHTS_MAP: Record<ETextAreaSize, number>;
16
+ export declare const PADDINGS_MAP: Record<ETextAreaSize, number>;
@@ -0,0 +1,17 @@
1
+ var l = /* @__PURE__ */ ((r) => (r.S = "s", r.M = "m", r.L = "l", r))(l || {}), s = /* @__PURE__ */ ((r) => (r.Alarm = "alarm", r.Success = "success", r.Error = "error", r))(s || {}), u = /* @__PURE__ */ ((r) => (r.DefaultGray = "default-gray", r.DefaultWhite = "default-white", r))(u || {});
2
+ const c = {
3
+ s: 1.5,
4
+ m: 1.2,
5
+ l: 1.4
6
+ }, m = {
7
+ s: 14,
8
+ m: 14,
9
+ l: 18
10
+ };
11
+ export {
12
+ l as ETextAreaSize,
13
+ s as ETextAreaStatus,
14
+ u as ETextAreaVariant,
15
+ c as LINE_HEIGHTS_MAP,
16
+ m as PADDINGS_MAP
17
+ };
@@ -0,0 +1,3 @@
1
+ export { TextArea } from './TextArea';
2
+ export type { TProps as TextAreaV2Props } from './types';
3
+ export { ETextAreaSize, ETextAreaStatus, ETextAreaVariant } from './constants';
@@ -0,0 +1,8 @@
1
+ import { TextArea as t } from "./TextArea.js";
2
+ import { ETextAreaSize as x, ETextAreaStatus as o, ETextAreaVariant as A } from "./constants.js";
3
+ export {
4
+ x as ETextAreaSize,
5
+ o as ETextAreaStatus,
6
+ A as ETextAreaVariant,
7
+ t as TextArea
8
+ };
@@ -0,0 +1,88 @@
1
+ import { ReactNode } from 'react';
2
+ import { ETextAreaSize, ETextAreaStatus, ETextAreaVariant } from './constants';
3
+ import { TIcon } from '../../icons';
4
+
5
+ type TTextAddon = {
6
+ addonType?: 'text';
7
+ addonContent: string;
8
+ };
9
+ export type TIconAddon = {
10
+ addonType?: 'icon';
11
+ addonContent: TIcon;
12
+ };
13
+ export type TReactNodeAddon = {
14
+ addonType?: 'react-node';
15
+ addonContent: ReactNode;
16
+ };
17
+ export type TTextAreaV2Addon = TTextAddon | TIconAddon | TReactNodeAddon;
18
+ export type TProps = {
19
+ /**
20
+ * Дополнительный класс.
21
+ */
22
+ className?: string;
23
+ /**
24
+ * Дополнительный класс для обертки текстового поля.
25
+ */
26
+ wrapperClassName?: string;
27
+ /**
28
+ * Дополнительный класс для контейнера текстового поля.
29
+ */
30
+ containerClassName?: string;
31
+ /**
32
+ * Текстовое описание поля ввода.
33
+ */
34
+ label?: string;
35
+ /**
36
+ * Варианты отображения ввода. Может быть 'alert', 'success', 'default', 'default-gray', 'default-white'.
37
+ */
38
+ variant?: ETextAreaVariant | `${ETextAreaVariant}`;
39
+ /**
40
+ * Статус ввода. Может быть 'alarm', 'success', 'error'.
41
+ */
42
+ status?: ETextAreaStatus | `${ETextAreaStatus}`;
43
+ /**
44
+ * Размер текстового поля.
45
+ */
46
+ size?: ETextAreaSize | `${ETextAreaSize}`;
47
+ /**
48
+ * Флаг, опредляющий, что поле ввода обязательно для заполнения.
49
+ */
50
+ required?: boolean;
51
+ /**
52
+ * Флаг, опредляющий, что поле ввода недоступно для заполнения и манипуляций.
53
+ */
54
+ disabled?: boolean;
55
+ /**
56
+ * Флаг, опредляющий, что при первом рендере будет установлен фокус.
57
+ */
58
+ autofocus?: boolean;
59
+ /**
60
+ * Флаг, опредляющий показ кнопки для очистки текстового поля.
61
+ */
62
+ withClearButton?: boolean;
63
+ /**
64
+ * Информационное сообщение под текстовым полем.
65
+ */
66
+ message?: ReactNode;
67
+ /**
68
+ * Значение текстового поля (контролируемый режим)
69
+ */
70
+ value?: string;
71
+ /**
72
+ * Колбэк изменения значения (контролируемый режим)
73
+ */
74
+ onChange?: (value: string) => void;
75
+ /**
76
+ * Максимальное количество символов
77
+ */
78
+ maxLength?: number;
79
+ /**
80
+ * Максимальное количество строк (ограничение по высоте)
81
+ */
82
+ maxRows?: number;
83
+ /**
84
+ * Дополнительный слот слева.
85
+ */
86
+ leftAddon?: TIconAddon;
87
+ };
88
+ export {};
@@ -0,0 +1,10 @@
1
+ import { ETextAreaSize } from './constants';
2
+
3
+ export declare const escapeHtml: (str: string) => string;
4
+ export declare const clampByMaxLength: (text: string, maxLength?: number) => string;
5
+ export declare const placeCaretAtEnd: (editableNode?: HTMLDivElement | null) => void;
6
+ export declare const getMaxHeightStyle: (size: ETextAreaSize | `${ETextAreaSize}`, maxRows?: number) => {
7
+ readonly maxHeight: `calc(${number}em + ${number}px)`;
8
+ } | undefined;
9
+ export declare const getCurrentText: (editableNode?: HTMLDivElement | null) => string;
10
+ export declare const setEditableText: (next: string, editableNode?: HTMLDivElement | null) => void;
@@ -0,0 +1,36 @@
1
+ import { LINE_HEIGHTS_MAP as c, PADDINGS_MAP as l } from "./constants.js";
2
+ const g = (n) => n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"), o = (n, e) => typeof e == "number" && e >= 0 ? n.slice(0, e) : n, s = (n) => {
3
+ if (!n) return;
4
+ const e = document.createRange();
5
+ e.selectNodeContents(n), e.collapse(!1);
6
+ const r = window.getSelection();
7
+ r && (r.removeAllRanges(), r.addRange(e));
8
+ }, i = (n, e) => {
9
+ if (!e) return;
10
+ const r = c[n], t = l[n];
11
+ return {
12
+ maxHeight: `calc(${e * r}em + ${t}px)`
13
+ };
14
+ }, p = (n) => {
15
+ if (!n) return "";
16
+ let e = (n.innerText || "").replace(/\r\n|\r/g, `
17
+ `);
18
+ return (e === `
19
+ ` || n.innerHTML === "<br>") && (e = ""), e;
20
+ }, u = (n, e) => {
21
+ if (!e) return;
22
+ if (n.length === 0) {
23
+ e.innerHTML = "";
24
+ return;
25
+ }
26
+ const r = g(n).replace(/\n/g, "<br>");
27
+ e.innerHTML = r;
28
+ };
29
+ export {
30
+ o as clampByMaxLength,
31
+ g as escapeHtml,
32
+ p as getCurrentText,
33
+ i as getMaxHeightStyle,
34
+ s as placeCaretAtEnd,
35
+ u as setEditableText
36
+ };
@@ -80,3 +80,8 @@ export { CardTrail } from './CardTrail';
80
80
  export { ClearButton } from './InputClearButton';
81
81
  export { CopyText } from './CopyText';
82
82
  export type { TCopyTextProps } from './CopyText';
83
+ export { TextArea as TextAreaV2 } from './TextAreaV2';
84
+ export type { ETextAreaSize, ETextAreaStatus, ETextAreaVariant, TextAreaV2Props } from './TextAreaV2';
85
+ export { MiniButton } from './MiniButton';
86
+ export { EMiniButtonSize, EMiniButtonVariant } from './MiniButton';
87
+ export type { TMiniButton } from './MiniButton';