@sito/dashboard 0.0.72 → 0.0.74
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 +27 -3
- package/dist/{FiltersProvider-DVMj0LV0.cjs → FiltersProvider-CnrF3xWV.cjs} +1 -1
- package/dist/{FiltersProvider-BV023mmu.js → FiltersProvider-iOkSYSFZ.js} +1 -1
- package/dist/FiltersProvider.cjs +1 -1
- package/dist/FiltersProvider.js +1 -1
- package/dist/Form.cjs +1 -1
- package/dist/Form.js +1 -1
- package/dist/SelectInput-Dm7gv03Z.js +521 -0
- package/dist/SelectInput-dYjrdopP.cjs +1 -0
- package/dist/{Table-DYcrwEM-.cjs → Table-C03frnWb.cjs} +1 -1
- package/dist/{Table-ehiZ_7Qa.js → Table-DO7FFraQ.js} +3 -3
- package/dist/Table.cjs +1 -1
- package/dist/Table.js +1 -1
- package/dist/TableOptions.cjs +1 -1
- package/dist/TableOptions.js +1 -1
- package/dist/TableOptionsProvider-Dzq4dOu8.js +157 -0
- package/dist/TableOptionsProvider-bPNtpa4V.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/providers/TableOptions/TableOptionsProvider.d.ts +2 -2
- package/dist/providers/TableOptions/types.d.ts +9 -0
- package/dist/providers/TableOptions/utils.d.ts +60 -0
- package/package.json +1 -1
- package/dist/SelectInput-B9EEu-h1.cjs +0 -1
- package/dist/SelectInput-H421nC22.js +0 -525
- package/dist/TableOptionsProvider-BgnISoXx.js +0 -120
- package/dist/TableOptionsProvider-i4uVLLwH.cjs +0 -1
package/README.md
CHANGED
|
@@ -94,11 +94,33 @@ export function UsersTable() {
|
|
|
94
94
|
- `CheckInput` is controlled with `checked` (not `value`).
|
|
95
95
|
- `FileInput` `onChange` receives the native input event; read files from `e.currentTarget.files`.
|
|
96
96
|
|
|
97
|
+
## `TableOptionsProvider` Initial State
|
|
98
|
+
|
|
99
|
+
`TableOptionsProvider` supports optional `initialState` configuration:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { SortOrder, TableOptionsProvider } from "@sito/dashboard";
|
|
103
|
+
|
|
104
|
+
<TableOptionsProvider
|
|
105
|
+
defaultHiddenColumns={["email"]}
|
|
106
|
+
initialState={{
|
|
107
|
+
currentPage: 0,
|
|
108
|
+
pageSize: 50,
|
|
109
|
+
pageSizes: [25, 50, 100],
|
|
110
|
+
sortingBy: "createdAt",
|
|
111
|
+
sortingOrder: SortOrder.ASC,
|
|
112
|
+
filters: { status: "active" },
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<UsersTable />
|
|
116
|
+
</TableOptionsProvider>;
|
|
117
|
+
```
|
|
118
|
+
|
|
97
119
|
## Core `Table` Props
|
|
98
120
|
|
|
99
121
|
| Prop | Type | Required | Description |
|
|
100
122
|
| --------------------------- | ----------------------------------------------------------------- | -------- | --------------------------------------------------------------------------- |
|
|
101
|
-
| `entity` | `string` |
|
|
123
|
+
| `entity` | `string` | No | Optional logical entity identifier. |
|
|
102
124
|
| `data` | `TRow[]` | Yes | Rows to render. `TRow` must extend `BaseDto` and include `id`. |
|
|
103
125
|
| `columns` | `ColumnType<TRow>[]` | No | Column definitions. |
|
|
104
126
|
| `actions` | `(row: TRow) => ActionType<TRow>[]` | No | Per-row action factory. |
|
|
@@ -106,6 +128,8 @@ export function UsersTable() {
|
|
|
106
128
|
| `toolbar` | `ReactNode` | No | Extra content rendered in the table header. |
|
|
107
129
|
| `isLoading` | `boolean` | No | Loading state for table UI. |
|
|
108
130
|
| `filterOptions` | `FilterOptions` | No | Extra options passed to filter behavior/components. |
|
|
131
|
+
| `canHideColumns` | `boolean` | No | Shows column visibility menu in the header. |
|
|
132
|
+
| `canReset` | `boolean` | No | Shows table reset button in the header. |
|
|
109
133
|
| `onSort` | `(prop: string, sortOrder: SortOrder) => void` | No | Sort callback when a sortable column is toggled. |
|
|
110
134
|
| `onRowSelect` | `(row: TRow, selected: boolean) => void` | No | Row selection callback. |
|
|
111
135
|
| `onSelectedRowsChange` | `(rows: TRow[]) => void` | No | Callback with selected rows. |
|
|
@@ -121,8 +145,8 @@ export function UsersTable() {
|
|
|
121
145
|
|
|
122
146
|
Main package exports include:
|
|
123
147
|
|
|
124
|
-
- Components: `Action`, `Actions`, `ActionsDropdown`, `Badge`, `Button`, `Chip`, `Dropdown`, `
|
|
125
|
-
- Providers: `FiltersProvider`, `TableOptionsProvider`, `TranslationProvider` and related hooks/types.
|
|
148
|
+
- Components: `Action`, `Actions`, `ActionsDropdown`, `Badge`, `Button`, `Chip`, `Dropdown`, `IconButton`, `Loading`, `SvgIcons`, `Table`, `Tooltip`, `TextInput`, `SelectInput`, `AutocompleteInput`, `CheckInput`, `FileInput`.
|
|
149
|
+
- Providers: `FiltersProvider`, `TableOptionsProvider`, `TranslationProvider` and related hooks/types (`useFilters`, `useTableOptions`, `useTranslation`).
|
|
126
150
|
- Utilities and models: `FilterTypes`, `SortOrder`, `BaseDto`, and query/filter helpers from `lib`.
|
|
127
151
|
|
|
128
152
|
## Development Setup
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const p=require("react/jsx-runtime"),i=require("react"),f=require("./TableOptionsProvider-
|
|
1
|
+
"use strict";const p=require("react/jsx-runtime"),i=require("react"),f=require("./TableOptionsProvider-bPNtpa4V.cjs");var n=(e=>(e[e.update=0]="update",e[e.reset=1]="reset",e))(n||{});const o=e=>{if(e){const t={};return Object.keys(e)?.forEach(r=>{t[r]={value:e[r]}}),t}return{}};function a(e,t){const{type:s}=t;switch(s){case n.reset:return{};case n.update:{const{toUpdate:r}=t;return{...e,...r}}default:return e}}const d=i.createContext(void 0),v=e=>{const{children:t}=e,{filters:s}=f.useTableOptions(),[r,u]=i.useReducer(a,o(s));i.useEffect(()=>{u({type:n.reset});const c=o(s);Object.keys(c).length&&u({type:n.update,toUpdate:c})},[s]);const l=i.useMemo(()=>({currentFilters:r,setCurrentFilters:u}),[r]);return p.jsx(d.Provider,{value:l,children:t})},x=()=>{const e=i.useContext(d);if(!e)throw new Error("filtersContext must be used within a Provider");return e};exports.FiltersActions=n;exports.FiltersProvider=v;exports.filtersReducer=a;exports.initializer=o;exports.useFilters=x;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import { useReducer as p, useEffect as f, useMemo as l, createContext as m, useContext as v } from "react";
|
|
3
|
-
import { u as x } from "./TableOptionsProvider-
|
|
3
|
+
import { u as x } from "./TableOptionsProvider-Dzq4dOu8.js";
|
|
4
4
|
var n = /* @__PURE__ */ ((e) => (e[e.update = 0] = "update", e[e.reset = 1] = "reset", e))(n || {});
|
|
5
5
|
const a = (e) => {
|
|
6
6
|
if (e) {
|
package/dist/FiltersProvider.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./FiltersProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./FiltersProvider-CnrF3xWV.cjs");exports.FiltersActions=e.FiltersActions;exports.FiltersProvider=e.FiltersProvider;exports.filtersReducer=e.filtersReducer;exports.initializer=e.initializer;exports.useFilters=e.useFilters;
|
package/dist/FiltersProvider.js
CHANGED
package/dist/Form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./SelectInput-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./SelectInput-dYjrdopP.cjs"),t=require("./FileInput-CqzVk1gQ.cjs");exports.AutocompleteInput=e.AutocompleteInput;exports.CheckInput=e.CheckInput;exports.SelectInput=e.SelectInput;exports.State=e.State;exports.TextInput=e.TextInput;exports.helperTextStateClassName=e.helperTextStateClassName;exports.inputStateClassName=e.inputStateClassName;exports.labelStateClassName=e.labelStateClassName;exports.FileInput=t.FileInput;
|
package/dist/Form.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as e, C as s, S as l, a as p, T as u, h as m, i as n, l as o } from "./SelectInput-
|
|
1
|
+
import { A as e, C as s, S as l, a as p, T as u, h as m, i as n, l as o } from "./SelectInput-Dm7gv03Z.js";
|
|
2
2
|
import { F as r } from "./FileInput-Cr4TxWUg.js";
|
|
3
3
|
export {
|
|
4
4
|
e as AutocompleteInput,
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import "./SelectInput.css";
|
|
2
|
+
import { jsxs as E, jsx as a, Fragment as Y } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef as W, useState as F, useEffect as H, useMemo as j, useRef as U, useCallback as k, useLayoutEffect as Z } from "react";
|
|
4
|
+
import { C as M } from "./Chip-C5ogKbFn.js";
|
|
5
|
+
import { I as ee } from "./IconButton-BpsTEj0z.js";
|
|
6
|
+
import { C as te } from "./Close-rKC9AcNX.js";
|
|
7
|
+
const oe = W(function(l, p) {
|
|
8
|
+
const {
|
|
9
|
+
state: m,
|
|
10
|
+
value: t,
|
|
11
|
+
onChange: r,
|
|
12
|
+
options: x = [],
|
|
13
|
+
name: $ = "",
|
|
14
|
+
id: w = "",
|
|
15
|
+
label: y = "",
|
|
16
|
+
containerClassName: A = "",
|
|
17
|
+
inputContainerClassName: N = "",
|
|
18
|
+
helperText: S = "",
|
|
19
|
+
placeholder: T = "",
|
|
20
|
+
multiple: d = !1,
|
|
21
|
+
...D
|
|
22
|
+
} = l, [i, f] = F("");
|
|
23
|
+
H(() => {
|
|
24
|
+
if (!d && t && !Array.isArray(t)) {
|
|
25
|
+
f(String(t.value ?? t.name ?? ""));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
f("");
|
|
29
|
+
}, [d, t]);
|
|
30
|
+
const [g, C] = F(!1), [b, v] = F(-1), s = j(
|
|
31
|
+
() => x.filter((e) => {
|
|
32
|
+
const n = String(e.value ?? e.name).toLowerCase().includes(i?.toLowerCase());
|
|
33
|
+
return Array.isArray(t) && t.length ? n && !t.some((c) => c.id === e.id) : t && !Array.isArray(t) ? n && t.id !== e.id : n;
|
|
34
|
+
}),
|
|
35
|
+
[x, t, i]
|
|
36
|
+
);
|
|
37
|
+
H(() => {
|
|
38
|
+
if (!g || !s.length) {
|
|
39
|
+
v(-1);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
v(0);
|
|
43
|
+
}, [g, s]);
|
|
44
|
+
const o = U(null), h = U(null), [O, I] = F(!1), u = U(null);
|
|
45
|
+
H(() => {
|
|
46
|
+
const e = (c) => {
|
|
47
|
+
o.current && !o.current.contains(c.target) && C(!1);
|
|
48
|
+
}, n = (c) => {
|
|
49
|
+
c.key === "Escape" && C(!1);
|
|
50
|
+
};
|
|
51
|
+
return document.addEventListener("mousedown", e), document.addEventListener("keydown", n), () => {
|
|
52
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", n);
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
const P = k((e) => {
|
|
56
|
+
f(e.target.value);
|
|
57
|
+
}, []), L = k(
|
|
58
|
+
(e) => {
|
|
59
|
+
e ? d ? (f(""), Array.isArray(t) && t.length ? r([...t, e]) : r([e])) : (f(String(e.name ?? e.value ?? "")), r(e)) : r(null), C(!1);
|
|
60
|
+
},
|
|
61
|
+
[d, r, t]
|
|
62
|
+
), K = k(
|
|
63
|
+
(e) => {
|
|
64
|
+
if (!s.length) {
|
|
65
|
+
e.key === "Escape" && C(!1);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
69
|
+
if (e.preventDefault(), !g) {
|
|
70
|
+
C(!0), v(0);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
v((n) => {
|
|
74
|
+
const c = n >= 0 ? n : 0;
|
|
75
|
+
return e.key === "ArrowDown" ? (c + 1 + s.length) % s.length : (c - 1 + s.length) % s.length;
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (e.key === "Enter" && g) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
const n = b >= 0 ? b : 0;
|
|
82
|
+
L(s[n]);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
e.key === "Escape" && g && (e.preventDefault(), C(!1));
|
|
86
|
+
},
|
|
87
|
+
[
|
|
88
|
+
L,
|
|
89
|
+
b,
|
|
90
|
+
g,
|
|
91
|
+
s
|
|
92
|
+
]
|
|
93
|
+
), R = k(
|
|
94
|
+
(e) => {
|
|
95
|
+
if (!Array.isArray(t)) {
|
|
96
|
+
r(null);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const n = t.filter((c, z) => z !== e);
|
|
100
|
+
n.length ? r(n) : r(null);
|
|
101
|
+
},
|
|
102
|
+
[r, t]
|
|
103
|
+
), V = k(() => {
|
|
104
|
+
Array.isArray(t) && r([t[0]]);
|
|
105
|
+
}, [r, t]);
|
|
106
|
+
return Z(() => {
|
|
107
|
+
const e = u.current?.offsetWidth ?? 0, n = o.current?.offsetWidth ?? 0;
|
|
108
|
+
I(e > n * 0.4);
|
|
109
|
+
}, [t]), /* @__PURE__ */ E(
|
|
110
|
+
"div",
|
|
111
|
+
{
|
|
112
|
+
className: `autocomplete-input-container ${A}`,
|
|
113
|
+
ref: o,
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ E("div", { className: "autocomplete-value-input-container", children: [
|
|
116
|
+
/* @__PURE__ */ a(
|
|
117
|
+
Q,
|
|
118
|
+
{
|
|
119
|
+
state: m,
|
|
120
|
+
name: $,
|
|
121
|
+
id: w,
|
|
122
|
+
value: i,
|
|
123
|
+
onChange: P,
|
|
124
|
+
placeholder: T,
|
|
125
|
+
helperText: S,
|
|
126
|
+
onFocus: () => C(!0),
|
|
127
|
+
onKeyDown: K,
|
|
128
|
+
label: y,
|
|
129
|
+
containerClassName: `autocomplete-text-input ${N}`,
|
|
130
|
+
ref: p ?? h,
|
|
131
|
+
...D,
|
|
132
|
+
children: !d && t && !Array.isArray(t) && (t.value || t.name) && /* @__PURE__ */ a(
|
|
133
|
+
ee,
|
|
134
|
+
{
|
|
135
|
+
icon: /* @__PURE__ */ a(te, {}),
|
|
136
|
+
className: "autocomplete-delete-button",
|
|
137
|
+
onClick: (e) => {
|
|
138
|
+
L(), e.stopPropagation();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
d && Array.isArray(t) && t.length ? /* @__PURE__ */ a("ul", { ref: u, className: "autocomplete-value-container", children: O ? /* @__PURE__ */ E(Y, { children: [
|
|
145
|
+
/* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
|
|
146
|
+
M,
|
|
147
|
+
{
|
|
148
|
+
text: t[0]?.value ?? t[0]?.name,
|
|
149
|
+
onDelete: (e) => {
|
|
150
|
+
R(0), e.stopPropagation();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
) }),
|
|
154
|
+
t.length > 1 && /* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
|
|
155
|
+
M,
|
|
156
|
+
{
|
|
157
|
+
text: `+${t.length - 1}`,
|
|
158
|
+
onDelete: (e) => {
|
|
159
|
+
V(), e.stopPropagation();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
) })
|
|
163
|
+
] }) : t.map((e, n) => /* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
|
|
164
|
+
M,
|
|
165
|
+
{
|
|
166
|
+
text: String(e.value ?? e.name),
|
|
167
|
+
onDelete: (c) => {
|
|
168
|
+
R(n), c.stopPropagation();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
) }, e.id ?? e.value ?? e.name)) }) : null
|
|
172
|
+
] }),
|
|
173
|
+
g && /* @__PURE__ */ a(
|
|
174
|
+
"ul",
|
|
175
|
+
{
|
|
176
|
+
className: "autocomplete-suggestions-container",
|
|
177
|
+
style: { width: o.current?.offsetWidth },
|
|
178
|
+
children: s.map((e) => /* @__PURE__ */ a(
|
|
179
|
+
"li",
|
|
180
|
+
{
|
|
181
|
+
className: `autocomplete-suggestion-item ${e.id === s[b]?.id ? "highlighted" : ""}`,
|
|
182
|
+
onMouseEnter: () => v(
|
|
183
|
+
s.findIndex((n) => n.id === e.id)
|
|
184
|
+
),
|
|
185
|
+
onClick: (n) => {
|
|
186
|
+
L(e), n.stopPropagation();
|
|
187
|
+
},
|
|
188
|
+
children: e.value ?? e.name
|
|
189
|
+
},
|
|
190
|
+
e.id ?? e.value ?? e.name
|
|
191
|
+
))
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
var B = /* @__PURE__ */ ((l) => (l.error = "error", l.good = "good", l.default = "default", l))(B || {});
|
|
199
|
+
const q = (l) => {
|
|
200
|
+
switch (l) {
|
|
201
|
+
case "error":
|
|
202
|
+
return "input-error";
|
|
203
|
+
case "good":
|
|
204
|
+
return "input-good";
|
|
205
|
+
default:
|
|
206
|
+
return "input-normal";
|
|
207
|
+
}
|
|
208
|
+
}, _ = (l) => {
|
|
209
|
+
switch (l) {
|
|
210
|
+
case "error":
|
|
211
|
+
return "input-label-error";
|
|
212
|
+
case "good":
|
|
213
|
+
return "input-label-good";
|
|
214
|
+
default:
|
|
215
|
+
return "input-label-normal";
|
|
216
|
+
}
|
|
217
|
+
}, J = (l) => {
|
|
218
|
+
switch (l) {
|
|
219
|
+
case "error":
|
|
220
|
+
return "input-helper-text-error";
|
|
221
|
+
case "good":
|
|
222
|
+
return "input-helper-text-good";
|
|
223
|
+
default:
|
|
224
|
+
return "input-helper-text-normal";
|
|
225
|
+
}
|
|
226
|
+
}, ce = W(function(l, p) {
|
|
227
|
+
const {
|
|
228
|
+
checked: m,
|
|
229
|
+
onChange: t,
|
|
230
|
+
name: r = "",
|
|
231
|
+
id: x = "",
|
|
232
|
+
label: $ = "",
|
|
233
|
+
state: w = B.default,
|
|
234
|
+
containerClassName: y = "",
|
|
235
|
+
inputClassName: A = "",
|
|
236
|
+
labelClassName: N = "",
|
|
237
|
+
...S
|
|
238
|
+
} = l;
|
|
239
|
+
return /* @__PURE__ */ E("label", { className: `input-check-container ${y}`, children: [
|
|
240
|
+
/* @__PURE__ */ a(
|
|
241
|
+
"input",
|
|
242
|
+
{
|
|
243
|
+
id: x,
|
|
244
|
+
ref: p,
|
|
245
|
+
name: r,
|
|
246
|
+
type: "checkbox",
|
|
247
|
+
checked: m,
|
|
248
|
+
onChange: t,
|
|
249
|
+
className: `input-check ${q(w)} ${A}`,
|
|
250
|
+
...S
|
|
251
|
+
}
|
|
252
|
+
),
|
|
253
|
+
/* @__PURE__ */ a(
|
|
254
|
+
"span",
|
|
255
|
+
{
|
|
256
|
+
className: `input-check-label ${_(w)} ${N}`,
|
|
257
|
+
children: $
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
] });
|
|
261
|
+
}), G = (l) => l == null ? !1 : Array.isArray(l) ? l.length > 0 : `${l}`.length > 0, Q = W(function(l, p) {
|
|
262
|
+
const {
|
|
263
|
+
children: m,
|
|
264
|
+
state: t = B.default,
|
|
265
|
+
label: r = "",
|
|
266
|
+
containerClassName: x = "",
|
|
267
|
+
inputClassName: $ = "",
|
|
268
|
+
labelClassName: w = "",
|
|
269
|
+
helperText: y = "",
|
|
270
|
+
helperTextClassName: A = "",
|
|
271
|
+
value: N,
|
|
272
|
+
defaultValue: S,
|
|
273
|
+
onChange: T,
|
|
274
|
+
onFocus: d,
|
|
275
|
+
onBlur: D,
|
|
276
|
+
...i
|
|
277
|
+
} = l, f = N !== void 0, [g, C] = F(
|
|
278
|
+
() => G(S)
|
|
279
|
+
), b = f ? G(N) : g, v = i.type === "date", s = !!i.placeholder || v, o = (h) => {
|
|
280
|
+
f || C(h.currentTarget.value.length > 0), T?.(h);
|
|
281
|
+
};
|
|
282
|
+
return /* @__PURE__ */ E("div", { className: `text-input-container ${x}`, children: [
|
|
283
|
+
/* @__PURE__ */ a(
|
|
284
|
+
"input",
|
|
285
|
+
{
|
|
286
|
+
ref: p,
|
|
287
|
+
defaultValue: S,
|
|
288
|
+
onChange: o,
|
|
289
|
+
onFocus: d,
|
|
290
|
+
onBlur: D,
|
|
291
|
+
...f ? { value: N } : {},
|
|
292
|
+
className: `text-input ${q(t)} ${$} ${b ? "has-value" : ""} ${i.placeholder ? "has-placeholder" : ""} ${s ? "keep-label-up" : ""}`,
|
|
293
|
+
...i
|
|
294
|
+
}
|
|
295
|
+
),
|
|
296
|
+
!!r && /* @__PURE__ */ E(
|
|
297
|
+
"label",
|
|
298
|
+
{
|
|
299
|
+
htmlFor: i.id,
|
|
300
|
+
className: `text-input-label ${_(t)} ${w}`,
|
|
301
|
+
children: [
|
|
302
|
+
r,
|
|
303
|
+
i.required ? " *" : ""
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
),
|
|
307
|
+
m,
|
|
308
|
+
!!y && /* @__PURE__ */ a(
|
|
309
|
+
"p",
|
|
310
|
+
{
|
|
311
|
+
className: `text-input-helper-text ${J(t)} ${A}`,
|
|
312
|
+
children: y
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
] });
|
|
316
|
+
}), ue = W(function(l, p) {
|
|
317
|
+
const {
|
|
318
|
+
value: m,
|
|
319
|
+
onChange: t,
|
|
320
|
+
options: r,
|
|
321
|
+
containerClassName: x = "",
|
|
322
|
+
inputClassName: $ = "",
|
|
323
|
+
labelClassName: w = "",
|
|
324
|
+
helperText: y = "",
|
|
325
|
+
helperTextClassName: A = "",
|
|
326
|
+
label: N = "",
|
|
327
|
+
placeholder: S = "",
|
|
328
|
+
name: T = "",
|
|
329
|
+
id: d = "",
|
|
330
|
+
state: D = B.default,
|
|
331
|
+
native: i = !0,
|
|
332
|
+
disabled: f,
|
|
333
|
+
required: g,
|
|
334
|
+
autoFocus: C,
|
|
335
|
+
children: b,
|
|
336
|
+
...v
|
|
337
|
+
} = l, s = U(null), [o, h] = F(!1), [O, I] = F(-1), u = j(
|
|
338
|
+
() => r.findIndex(
|
|
339
|
+
(e) => String(e.id) === String(m ?? r[0]?.id ?? "")
|
|
340
|
+
),
|
|
341
|
+
[r, m]
|
|
342
|
+
), P = j(
|
|
343
|
+
() => u >= 0 ? r[u] : void 0,
|
|
344
|
+
[r, u]
|
|
345
|
+
);
|
|
346
|
+
H(() => {
|
|
347
|
+
if (!(i || !o)) {
|
|
348
|
+
if (!r.length) {
|
|
349
|
+
I(-1);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
I(u >= 0 ? u : 0);
|
|
353
|
+
}
|
|
354
|
+
}, [i, r.length, u, o]), H(() => {
|
|
355
|
+
if (i) return;
|
|
356
|
+
const e = (n) => {
|
|
357
|
+
s.current && !s.current.contains(n.target) && h(!1);
|
|
358
|
+
};
|
|
359
|
+
return document.addEventListener("mousedown", e), () => {
|
|
360
|
+
document.removeEventListener("mousedown", e);
|
|
361
|
+
};
|
|
362
|
+
}, [i]);
|
|
363
|
+
const L = k(
|
|
364
|
+
(e) => {
|
|
365
|
+
p && (typeof p == "function" ? p(e) : p.current = e);
|
|
366
|
+
},
|
|
367
|
+
[p]
|
|
368
|
+
), K = k(
|
|
369
|
+
(e) => {
|
|
370
|
+
if (!t) return;
|
|
371
|
+
const n = {
|
|
372
|
+
target: { value: String(e) },
|
|
373
|
+
currentTarget: { value: String(e) }
|
|
374
|
+
};
|
|
375
|
+
t(n);
|
|
376
|
+
},
|
|
377
|
+
[t]
|
|
378
|
+
), R = k(
|
|
379
|
+
(e) => {
|
|
380
|
+
const n = r[e];
|
|
381
|
+
n && (K(n.id), h(!1));
|
|
382
|
+
},
|
|
383
|
+
[K, r]
|
|
384
|
+
), V = k(
|
|
385
|
+
(e) => {
|
|
386
|
+
if (r.length) {
|
|
387
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
388
|
+
if (e.preventDefault(), !o) {
|
|
389
|
+
h(!0);
|
|
390
|
+
const n = u >= 0 ? u : 0;
|
|
391
|
+
I(n);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
I((n) => {
|
|
395
|
+
const c = n >= 0 ? n : u;
|
|
396
|
+
return e.key === "ArrowDown" ? (c + 1 + r.length) % r.length : (c - 1 + r.length) % r.length;
|
|
397
|
+
});
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (e.key === "Enter") {
|
|
401
|
+
if (!o) {
|
|
402
|
+
e.preventDefault(), h(!0), I(u >= 0 ? u : 0);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
e.preventDefault(), R(O >= 0 ? O : 0);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
e.key === "Escape" && o && (e.preventDefault(), h(!1));
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
[O, r, R, u, o]
|
|
412
|
+
);
|
|
413
|
+
return i ? /* @__PURE__ */ E("div", { className: `select-input-container ${x}`, children: [
|
|
414
|
+
/* @__PURE__ */ a(
|
|
415
|
+
"select",
|
|
416
|
+
{
|
|
417
|
+
...v,
|
|
418
|
+
id: d,
|
|
419
|
+
ref: L,
|
|
420
|
+
name: T,
|
|
421
|
+
value: m,
|
|
422
|
+
onChange: t,
|
|
423
|
+
className: `select-input ${q(D)} peer ${$}`,
|
|
424
|
+
children: r?.map((e) => /* @__PURE__ */ a("option", { value: e.id, children: e.value ?? e.name ?? e.id }, e.id))
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
/* @__PURE__ */ a(
|
|
428
|
+
"label",
|
|
429
|
+
{
|
|
430
|
+
htmlFor: d,
|
|
431
|
+
className: `select-input-label ${_(D)} ${w}`,
|
|
432
|
+
children: N
|
|
433
|
+
}
|
|
434
|
+
),
|
|
435
|
+
b,
|
|
436
|
+
y && /* @__PURE__ */ a(
|
|
437
|
+
"p",
|
|
438
|
+
{
|
|
439
|
+
className: `select-input-helper-text ${J(D)} ${A}`,
|
|
440
|
+
children: y
|
|
441
|
+
}
|
|
442
|
+
)
|
|
443
|
+
] }) : /* @__PURE__ */ E(
|
|
444
|
+
"div",
|
|
445
|
+
{
|
|
446
|
+
ref: s,
|
|
447
|
+
className: `select-input-container ${x}`,
|
|
448
|
+
children: [
|
|
449
|
+
/* @__PURE__ */ a(
|
|
450
|
+
"select",
|
|
451
|
+
{
|
|
452
|
+
...v,
|
|
453
|
+
ref: L,
|
|
454
|
+
name: T,
|
|
455
|
+
id: d,
|
|
456
|
+
value: m,
|
|
457
|
+
onChange: t,
|
|
458
|
+
className: "select-input-native-hidden",
|
|
459
|
+
tabIndex: -1,
|
|
460
|
+
"aria-hidden": !0,
|
|
461
|
+
children: r?.map((e) => /* @__PURE__ */ a("option", { value: e.id, children: e.value ?? e.name ?? e.id }, e.id))
|
|
462
|
+
}
|
|
463
|
+
),
|
|
464
|
+
/* @__PURE__ */ a(
|
|
465
|
+
Q,
|
|
466
|
+
{
|
|
467
|
+
id: d,
|
|
468
|
+
name: T,
|
|
469
|
+
state: D,
|
|
470
|
+
value: String(P?.value ?? P?.name ?? ""),
|
|
471
|
+
readOnly: !0,
|
|
472
|
+
label: N,
|
|
473
|
+
helperText: y,
|
|
474
|
+
containerClassName: "select-input-text-container",
|
|
475
|
+
inputClassName: `select-input-text ${$}`,
|
|
476
|
+
labelClassName: w,
|
|
477
|
+
helperTextClassName: A,
|
|
478
|
+
placeholder: S,
|
|
479
|
+
disabled: f,
|
|
480
|
+
required: g,
|
|
481
|
+
autoFocus: C,
|
|
482
|
+
onClick: () => h((e) => !e),
|
|
483
|
+
onKeyDown: V,
|
|
484
|
+
onFocus: () => h(!0),
|
|
485
|
+
role: "combobox",
|
|
486
|
+
"aria-expanded": o,
|
|
487
|
+
"aria-haspopup": "listbox",
|
|
488
|
+
children: b
|
|
489
|
+
}
|
|
490
|
+
),
|
|
491
|
+
o && /* @__PURE__ */ a("ul", { className: "select-input-options-container", role: "listbox", children: r.map((e, n) => {
|
|
492
|
+
const c = String(e.id) === String(m);
|
|
493
|
+
return /* @__PURE__ */ a(
|
|
494
|
+
"li",
|
|
495
|
+
{
|
|
496
|
+
role: "option",
|
|
497
|
+
"aria-selected": c,
|
|
498
|
+
className: `select-input-option-item ${n === O ? "highlighted" : ""}`,
|
|
499
|
+
onMouseEnter: () => I(n),
|
|
500
|
+
onClick: (X) => {
|
|
501
|
+
R(n), X.stopPropagation();
|
|
502
|
+
},
|
|
503
|
+
children: e.value ?? e.name ?? e.id
|
|
504
|
+
},
|
|
505
|
+
e.id
|
|
506
|
+
);
|
|
507
|
+
}) })
|
|
508
|
+
]
|
|
509
|
+
}
|
|
510
|
+
);
|
|
511
|
+
});
|
|
512
|
+
export {
|
|
513
|
+
oe as A,
|
|
514
|
+
ce as C,
|
|
515
|
+
ue as S,
|
|
516
|
+
Q as T,
|
|
517
|
+
B as a,
|
|
518
|
+
J as h,
|
|
519
|
+
q as i,
|
|
520
|
+
_ as l
|
|
521
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var X=require("./SelectInput.css");const r=require("react/jsx-runtime"),l=require("react"),K=require("./Chip-D17UJHW6.cjs"),_=require("./IconButton-CVnmT2E9.cjs"),z=require("./Close-O9P7wJGf.cjs"),G=l.forwardRef(function(s,f){const{state:m,value:t,onChange:a,options:k=[],name:j="",id:v="",label:y="",containerClassName:S="",inputContainerClassName:N="",helperText:$="",placeholder:D="",multiple:h=!1,...A}=s,[o,g]=l.useState("");l.useEffect(()=>{if(!h&&t&&!Array.isArray(t)){g(String(t.value??t.name??""));return}g("")},[h,t]);const[x,C]=l.useState(!1),[w,b]=l.useState(-1),i=l.useMemo(()=>k.filter(e=>{const n=String(e.value??e.name).toLowerCase().includes(o?.toLowerCase());return Array.isArray(t)&&t.length?n&&!t.some(c=>c.id===e.id):t&&!Array.isArray(t)?n&&t.id!==e.id:n}),[k,t,o]);l.useEffect(()=>{if(!x||!i.length){b(-1);return}b(0)},[x,i]);const u=l.useRef(null),p=l.useRef(null),[T,I]=l.useState(!1),d=l.useRef(null);l.useEffect(()=>{const e=c=>{u.current&&!u.current.contains(c.target)&&C(!1)},n=c=>{c.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}},[]);const F=l.useCallback(e=>{g(e.target.value)},[]),E=l.useCallback(e=>{e?h?(g(""),Array.isArray(t)&&t.length?a([...t,e]):a([e])):(g(String(e.name??e.value??"")),a(e)):a(null),C(!1)},[h,a,t]),q=l.useCallback(e=>{if(!i.length){e.key==="Escape"&&C(!1);return}if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!x){C(!0),b(0);return}b(n=>{const c=n>=0?n:0;return e.key==="ArrowDown"?(c+1+i.length)%i.length:(c-1+i.length)%i.length});return}if(e.key==="Enter"&&x){e.preventDefault();const n=w>=0?w:0;E(i[n]);return}e.key==="Escape"&&x&&(e.preventDefault(),C(!1))},[E,w,x,i]),R=l.useCallback(e=>{if(!Array.isArray(t)){a(null);return}const n=t.filter((c,H)=>H!==e);n.length?a(n):a(null)},[a,t]),B=l.useCallback(()=>{Array.isArray(t)&&a([t[0]])},[a,t]);return l.useLayoutEffect(()=>{const e=d.current?.offsetWidth??0,n=u.current?.offsetWidth??0;I(e>n*.4)},[t]),r.jsxs("div",{className:`autocomplete-input-container ${S}`,ref:u,children:[r.jsxs("div",{className:"autocomplete-value-input-container",children:[r.jsx(U,{state:m,name:j,id:v,value:o,onChange:F,placeholder:D,helperText:$,onFocus:()=>C(!0),onKeyDown:q,label:y,containerClassName:`autocomplete-text-input ${N}`,ref:f??p,...A,children:!h&&t&&!Array.isArray(t)&&(t.value||t.name)&&r.jsx(_.IconButton,{icon:r.jsx(z.Close,{}),className:"autocomplete-delete-button",onClick:e=>{E(),e.stopPropagation()}})}),h&&Array.isArray(t)&&t.length?r.jsx("ul",{ref:d,className:"autocomplete-value-container",children:T?r.jsxs(r.Fragment,{children:[r.jsx("li",{children:r.jsx(K.Chip,{text:t[0]?.value??t[0]?.name,onDelete:e=>{R(0),e.stopPropagation()}})}),t.length>1&&r.jsx("li",{children:r.jsx(K.Chip,{text:`+${t.length-1}`,onDelete:e=>{B(),e.stopPropagation()}})})]}):t.map((e,n)=>r.jsx("li",{children:r.jsx(K.Chip,{text:String(e.value??e.name),onDelete:c=>{R(n),c.stopPropagation()}})},e.id??e.value??e.name))}):null]}),x&&r.jsx("ul",{className:"autocomplete-suggestions-container",style:{width:u.current?.offsetWidth},children:i.map(e=>r.jsx("li",{className:`autocomplete-suggestion-item ${e.id===i[w]?.id?"highlighted":""}`,onMouseEnter:()=>b(i.findIndex(n=>n.id===e.id)),onClick:n=>{E(e),n.stopPropagation()},children:e.value??e.name},e.id??e.value??e.name))})]})});var L=(s=>(s.error="error",s.good="good",s.default="default",s))(L||{});const O=s=>{switch(s){case"error":return"input-error";case"good":return"input-good";default:return"input-normal"}},P=s=>{switch(s){case"error":return"input-label-error";case"good":return"input-label-good";default:return"input-label-normal"}},M=s=>{switch(s){case"error":return"input-helper-text-error";case"good":return"input-helper-text-good";default:return"input-helper-text-normal"}},J=l.forwardRef(function(s,f){const{checked:m,onChange:t,name:a="",id:k="",label:j="",state:v=L.default,containerClassName:y="",inputClassName:S="",labelClassName:N="",...$}=s;return r.jsxs("label",{className:`input-check-container ${y}`,children:[r.jsx("input",{id:k,ref:f,name:a,type:"checkbox",checked:m,onChange:t,className:`input-check ${O(v)} ${S}`,...$}),r.jsx("span",{className:`input-check-label ${P(v)} ${N}`,children:j})]})}),W=s=>s==null?!1:Array.isArray(s)?s.length>0:`${s}`.length>0,U=l.forwardRef(function(s,f){const{children:m,state:t=L.default,label:a="",containerClassName:k="",inputClassName:j="",labelClassName:v="",helperText:y="",helperTextClassName:S="",value:N,defaultValue:$,onChange:D,onFocus:h,onBlur:A,...o}=s,g=N!==void 0,[x,C]=l.useState(()=>W($)),w=g?W(N):x,b=o.type==="date",i=!!o.placeholder||b,u=p=>{g||C(p.currentTarget.value.length>0),D?.(p)};return r.jsxs("div",{className:`text-input-container ${k}`,children:[r.jsx("input",{ref:f,defaultValue:$,onChange:u,onFocus:h,onBlur:A,...g?{value:N}:{},className:`text-input ${O(t)} ${j} ${w?"has-value":""} ${o.placeholder?"has-placeholder":""} ${i?"keep-label-up":""}`,...o}),!!a&&r.jsxs("label",{htmlFor:o.id,className:`text-input-label ${P(t)} ${v}`,children:[a,o.required?" *":""]}),m,!!y&&r.jsx("p",{className:`text-input-helper-text ${M(t)} ${S}`,children:y})]})}),Q=l.forwardRef(function(s,f){const{value:m,onChange:t,options:a,containerClassName:k="",inputClassName:j="",labelClassName:v="",helperText:y="",helperTextClassName:S="",label:N="",placeholder:$="",name:D="",id:h="",state:A=L.default,native:o=!0,disabled:g,required:x,autoFocus:C,children:w,...b}=s,i=l.useRef(null),[u,p]=l.useState(!1),[T,I]=l.useState(-1),d=l.useMemo(()=>a.findIndex(e=>String(e.id)===String(m??a[0]?.id??"")),[a,m]),F=l.useMemo(()=>d>=0?a[d]:void 0,[a,d]);l.useEffect(()=>{if(!(o||!u)){if(!a.length){I(-1);return}I(d>=0?d:0)}},[o,a.length,d,u]),l.useEffect(()=>{if(o)return;const e=n=>{i.current&&!i.current.contains(n.target)&&p(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[o]);const E=l.useCallback(e=>{f&&(typeof f=="function"?f(e):f.current=e)},[f]),q=l.useCallback(e=>{if(!t)return;const n={target:{value:String(e)},currentTarget:{value:String(e)}};t(n)},[t]),R=l.useCallback(e=>{const n=a[e];n&&(q(n.id),p(!1))},[q,a]),B=l.useCallback(e=>{if(a.length){if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!u){p(!0);const n=d>=0?d:0;I(n);return}I(n=>{const c=n>=0?n:d;return e.key==="ArrowDown"?(c+1+a.length)%a.length:(c-1+a.length)%a.length});return}if(e.key==="Enter"){if(!u){e.preventDefault(),p(!0),I(d>=0?d:0);return}e.preventDefault(),R(T>=0?T:0);return}e.key==="Escape"&&u&&(e.preventDefault(),p(!1))}},[T,a,R,d,u]);return o?r.jsxs("div",{className:`select-input-container ${k}`,children:[r.jsx("select",{...b,id:h,ref:E,name:D,value:m,onChange:t,className:`select-input ${O(A)} peer ${j}`,children:a?.map(e=>r.jsx("option",{value:e.id,children:e.value??e.name??e.id},e.id))}),r.jsx("label",{htmlFor:h,className:`select-input-label ${P(A)} ${v}`,children:N}),w,y&&r.jsx("p",{className:`select-input-helper-text ${M(A)} ${S}`,children:y})]}):r.jsxs("div",{ref:i,className:`select-input-container ${k}`,children:[r.jsx("select",{...b,ref:E,name:D,id:h,value:m,onChange:t,className:"select-input-native-hidden",tabIndex:-1,"aria-hidden":!0,children:a?.map(e=>r.jsx("option",{value:e.id,children:e.value??e.name??e.id},e.id))}),r.jsx(U,{id:h,name:D,state:A,value:String(F?.value??F?.name??""),readOnly:!0,label:N,helperText:y,containerClassName:"select-input-text-container",inputClassName:`select-input-text ${j}`,labelClassName:v,helperTextClassName:S,placeholder:$,disabled:g,required:x,autoFocus:C,onClick:()=>p(e=>!e),onKeyDown:B,onFocus:()=>p(!0),role:"combobox","aria-expanded":u,"aria-haspopup":"listbox",children:w}),u&&r.jsx("ul",{className:"select-input-options-container",role:"listbox",children:a.map((e,n)=>{const c=String(e.id)===String(m),H=n===T;return r.jsx("li",{role:"option","aria-selected":c,className:`select-input-option-item ${H?"highlighted":""}`,onMouseEnter:()=>I(n),onClick:V=>{R(n),V.stopPropagation()},children:e.value??e.name??e.id},e.id)})})]})});exports.AutocompleteInput=G;exports.CheckInput=J;exports.SelectInput=Q;exports.State=L;exports.TextInput=U;exports.helperTextStateClassName=M;exports.inputStateClassName=O;exports.labelStateClassName=P;
|