@situaction/traq-ui-ste 1.2.1 → 1.2.3
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.
|
@@ -32,8 +32,11 @@ export interface SelectProps {
|
|
|
32
32
|
};
|
|
33
33
|
/** Text displayed when no item is selected */
|
|
34
34
|
placeholder?: string;
|
|
35
|
+
searchPlaceholder?: string;
|
|
35
36
|
/** Condition to close the modal */
|
|
36
37
|
autoCloseCondition: boolean;
|
|
38
|
+
/** Enable a search input inside the select modal to filter options */
|
|
39
|
+
searchable?: boolean;
|
|
37
40
|
fullWidth?: boolean;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
@@ -41,4 +44,4 @@ export interface SelectProps {
|
|
|
41
44
|
* It supports three display modes: 'all' (icon + text), 'icon' (only icon), and 'text' (only text).
|
|
42
45
|
* The selected value is displayed in a button, and a modal opens to show the list of options.
|
|
43
46
|
*/
|
|
44
|
-
export declare const Select: ({ selected, size, listItem, modeDisplay, onSelect, positionOverride, placeholder, autoCloseCondition, fullWidth }: SelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export declare const Select: ({ selected, size, listItem, modeDisplay, onSelect, positionOverride, placeholder, searchPlaceholder, autoCloseCondition, searchable, fullWidth }: SelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,181 +1,207 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { Button as
|
|
4
|
-
import {
|
|
1
|
+
import { jsxs as w, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { useState as b, useRef as m, useEffect as p } from "react";
|
|
3
|
+
import { Button as W } from "../button/Button.js";
|
|
4
|
+
import { Input as H } from "../input/Input.js";
|
|
5
|
+
import { IconButton as I } from "../icon-button/IconButton.js";
|
|
5
6
|
import { Icon as _ } from "../icon/Icon.js";
|
|
6
|
-
import { Modal as
|
|
7
|
+
import { Modal as J } from "../modal/Modal.js";
|
|
7
8
|
import "../theme/ThemeContext.js";
|
|
8
9
|
import '../../styles/Size.css';import '../../styles/Select.css';/* empty css */
|
|
9
|
-
const
|
|
10
|
-
selectContainer:
|
|
11
|
-
selected:
|
|
12
|
-
children:
|
|
13
|
-
active:
|
|
14
|
-
selectList:
|
|
15
|
-
modal:
|
|
16
|
-
dropdownFadeIn:
|
|
17
|
-
itemLabel:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
const O = "_selectContainer_133eb_54", Q = "_selected_133eb_57", X = "_children_133eb_61", Y = "_active_133eb_78", Z = "_selectList_133eb_82", ee = "_modal_133eb_91", te = "_dropdownFadeIn_133eb_1", ne = "_itemLabel_133eb_98", re = "_searchWrapper_133eb_103", oe = "_noResults_133eb_109", u = {
|
|
11
|
+
selectContainer: O,
|
|
12
|
+
selected: Q,
|
|
13
|
+
children: X,
|
|
14
|
+
active: Y,
|
|
15
|
+
selectList: Z,
|
|
16
|
+
modal: ee,
|
|
17
|
+
dropdownFadeIn: te,
|
|
18
|
+
itemLabel: ne,
|
|
19
|
+
searchWrapper: re,
|
|
20
|
+
noResults: oe
|
|
21
|
+
}, me = ({
|
|
22
|
+
selected: L,
|
|
23
|
+
size: C = "m",
|
|
21
24
|
listItem: s,
|
|
22
|
-
modeDisplay:
|
|
25
|
+
modeDisplay: x = "all",
|
|
23
26
|
onSelect: B,
|
|
24
|
-
positionOverride:
|
|
25
|
-
placeholder:
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
positionOverride: y,
|
|
28
|
+
placeholder: F = "Sélectionner",
|
|
29
|
+
searchPlaceholder: U,
|
|
30
|
+
autoCloseCondition: V,
|
|
31
|
+
searchable: z = !1,
|
|
32
|
+
fullWidth: S = !1
|
|
28
33
|
}) => {
|
|
29
|
-
const [
|
|
34
|
+
const [t, f] = b(!1), A = m(null), [M, P] = b({
|
|
30
35
|
top: "calc(100% + 6px)",
|
|
31
36
|
left: "0px"
|
|
32
|
-
}), [c,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}, [
|
|
36
|
-
|
|
37
|
-
}, [
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
const e = c == null ? void 0 : c.icon, o = (c == null ? void 0 : c.label) ||
|
|
42
|
-
return
|
|
43
|
-
|
|
37
|
+
}), [c, k] = b(L ?? null), [$, q] = b("");
|
|
38
|
+
p(() => {
|
|
39
|
+
L ? k(L) : s.length > 0 ? k(s[0]) : k(null);
|
|
40
|
+
}, [L, s]), p(() => {
|
|
41
|
+
y && P(y);
|
|
42
|
+
}, [y]);
|
|
43
|
+
const D = (e) => {
|
|
44
|
+
k(e), f(!1), B && B(e);
|
|
45
|
+
}, G = () => {
|
|
46
|
+
const e = c == null ? void 0 : c.icon, o = (c == null ? void 0 : c.label) || F || "Sélectionner";
|
|
47
|
+
return x === "icon" && e ? /* @__PURE__ */ r(I, { ref: d, mode: "tertiary", size: C, onClick: () => f(!t), children: /* @__PURE__ */ r(_, { icon: c.icon }) }) : x === "text" ? /* @__PURE__ */ r(
|
|
48
|
+
W,
|
|
44
49
|
{
|
|
45
50
|
ref: d,
|
|
46
51
|
mode: "tertiary",
|
|
47
52
|
label: o,
|
|
48
|
-
childrenRight: /* @__PURE__ */ r(_, { icon:
|
|
49
|
-
size:
|
|
50
|
-
fullWidth:
|
|
51
|
-
onClick: () =>
|
|
53
|
+
childrenRight: /* @__PURE__ */ r(_, { icon: t ? "CaretUp" : "CaretDown", size: 14, weight: "bold" }),
|
|
54
|
+
size: C,
|
|
55
|
+
fullWidth: S,
|
|
56
|
+
onClick: () => f(!t)
|
|
52
57
|
}
|
|
53
|
-
) :
|
|
54
|
-
|
|
58
|
+
) : x === "all" ? /* @__PURE__ */ r(
|
|
59
|
+
W,
|
|
55
60
|
{
|
|
56
61
|
ref: d,
|
|
57
62
|
mode: "tertiary",
|
|
58
63
|
label: o,
|
|
59
|
-
size:
|
|
60
|
-
fullWidth:
|
|
64
|
+
size: C,
|
|
65
|
+
fullWidth: S,
|
|
61
66
|
childrenLeft: e && /* @__PURE__ */ r(_, { icon: c.icon }),
|
|
62
|
-
childrenRight: /* @__PURE__ */ r(_, { icon:
|
|
63
|
-
onClick: () =>
|
|
67
|
+
childrenRight: /* @__PURE__ */ r(_, { icon: t ? "CaretUp" : "CaretDown", size: 14, weight: "bold" }),
|
|
68
|
+
onClick: () => f(!t)
|
|
64
69
|
}
|
|
65
70
|
) : /* @__PURE__ */ r(
|
|
66
|
-
|
|
71
|
+
W,
|
|
67
72
|
{
|
|
68
73
|
ref: d,
|
|
69
74
|
mode: "tertiary",
|
|
70
|
-
fullWidth:
|
|
71
|
-
label:
|
|
72
|
-
size:
|
|
73
|
-
onClick: () =>
|
|
75
|
+
fullWidth: S,
|
|
76
|
+
label: F ?? "Sélectionner",
|
|
77
|
+
size: C,
|
|
78
|
+
onClick: () => f(!t)
|
|
74
79
|
}
|
|
75
80
|
);
|
|
76
|
-
}, E =
|
|
77
|
-
|
|
81
|
+
}, E = m(null), g = m({}), [R, v] = b(""), h = m(null), K = m({}), j = s.filter(
|
|
82
|
+
(e) => (e.label ?? "").toLowerCase().includes($.toLowerCase())
|
|
83
|
+
), N = (e) => {
|
|
84
|
+
if (!t) return;
|
|
78
85
|
const o = e.key.length === 1 ? e.key.toLowerCase() : "";
|
|
79
86
|
if (!o) return;
|
|
80
|
-
const a =
|
|
87
|
+
const a = R + o;
|
|
81
88
|
v(a);
|
|
82
|
-
const i = s.find((
|
|
89
|
+
const i = s.find((n) => {
|
|
83
90
|
var l;
|
|
84
|
-
return (l =
|
|
91
|
+
return (l = n.label) == null ? void 0 : l.toLowerCase().startsWith(a);
|
|
85
92
|
});
|
|
86
93
|
if (i) {
|
|
87
|
-
const
|
|
88
|
-
|
|
94
|
+
const n = g.current[i.value];
|
|
95
|
+
n == null || n.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
89
96
|
}
|
|
90
|
-
|
|
97
|
+
h.current && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
91
98
|
v("");
|
|
92
99
|
}, 500);
|
|
93
100
|
};
|
|
94
|
-
|
|
95
|
-
window.removeEventListener("keydown",
|
|
96
|
-
}), [
|
|
101
|
+
p(() => (t ? window.addEventListener("keydown", N) : (window.removeEventListener("keydown", N), v("")), () => {
|
|
102
|
+
window.removeEventListener("keydown", N);
|
|
103
|
+
}), [t, R, s]), p(() => {
|
|
97
104
|
const e = (o) => {
|
|
98
|
-
if (!
|
|
105
|
+
if (!t) return;
|
|
99
106
|
const a = o.key.length === 1 ? o.key.toLowerCase() : "";
|
|
100
107
|
if (!a) return;
|
|
101
|
-
const i =
|
|
108
|
+
const i = R + a;
|
|
102
109
|
v(i);
|
|
103
|
-
const
|
|
110
|
+
const n = s.find(
|
|
104
111
|
(l) => {
|
|
105
|
-
var
|
|
106
|
-
return (
|
|
112
|
+
var T;
|
|
113
|
+
return (T = l.label) == null ? void 0 : T.toLowerCase().startsWith(i);
|
|
107
114
|
}
|
|
108
115
|
);
|
|
109
|
-
if (
|
|
110
|
-
const l = E.current,
|
|
116
|
+
if (n && E.current && n.value in g.current && g.current[n.value]) {
|
|
117
|
+
const l = E.current, T = g.current[n.value];
|
|
111
118
|
l.scrollTo({
|
|
112
|
-
top:
|
|
119
|
+
top: T.offsetTop - l.offsetTop,
|
|
113
120
|
behavior: "smooth"
|
|
114
121
|
});
|
|
115
122
|
}
|
|
116
|
-
|
|
123
|
+
h.current && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
117
124
|
v("");
|
|
118
125
|
}, 700);
|
|
119
126
|
};
|
|
120
127
|
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
121
|
-
}, [
|
|
122
|
-
if (!
|
|
128
|
+
}, [t, s, R]), p(() => {
|
|
129
|
+
if (!t) return;
|
|
123
130
|
const e = (o) => {
|
|
124
131
|
const a = o.key.toLowerCase();
|
|
125
132
|
if (a.length === 1) {
|
|
126
133
|
const i = s.find(
|
|
127
|
-
(
|
|
134
|
+
(n) => {
|
|
128
135
|
var l;
|
|
129
|
-
return (l =
|
|
136
|
+
return (l = n.label) == null ? void 0 : l.toLowerCase().startsWith(a);
|
|
130
137
|
}
|
|
131
138
|
);
|
|
132
139
|
if (i) {
|
|
133
|
-
const
|
|
134
|
-
|
|
140
|
+
const n = K.current[i.value];
|
|
141
|
+
n && n.scrollIntoView({ block: "start", behavior: "smooth" });
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
};
|
|
138
145
|
return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
|
|
139
|
-
}, [
|
|
140
|
-
const d =
|
|
141
|
-
return
|
|
142
|
-
if (
|
|
146
|
+
}, [t, s]);
|
|
147
|
+
const d = m(null);
|
|
148
|
+
return p(() => {
|
|
149
|
+
if (t && d.current) {
|
|
143
150
|
const e = d.current.getBoundingClientRect().height;
|
|
144
|
-
|
|
151
|
+
P(y || {
|
|
145
152
|
top: `${e + 6}px`,
|
|
146
153
|
left: "0px"
|
|
147
154
|
});
|
|
148
155
|
}
|
|
149
|
-
}, [
|
|
150
|
-
|
|
156
|
+
}, [t]), /* @__PURE__ */ w("div", { className: u.selectContainer, children: [
|
|
157
|
+
G(),
|
|
151
158
|
/* @__PURE__ */ r(
|
|
152
|
-
|
|
159
|
+
J,
|
|
153
160
|
{
|
|
154
|
-
ref:
|
|
161
|
+
ref: A,
|
|
155
162
|
anchorRef: d,
|
|
156
|
-
open:
|
|
157
|
-
onClose: () =>
|
|
158
|
-
position:
|
|
163
|
+
open: t,
|
|
164
|
+
onClose: () => f(!1),
|
|
165
|
+
position: M,
|
|
159
166
|
disableOverlay: !0,
|
|
160
|
-
className:
|
|
161
|
-
autoCloseCondition:
|
|
162
|
-
children: /* @__PURE__ */
|
|
163
|
-
"div",
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
className: u.modal,
|
|
168
|
+
autoCloseCondition: V,
|
|
169
|
+
children: /* @__PURE__ */ w("div", { children: [
|
|
170
|
+
z && /* @__PURE__ */ w("div", { children: [
|
|
171
|
+
/* @__PURE__ */ r(
|
|
172
|
+
H,
|
|
173
|
+
{
|
|
174
|
+
type: "text",
|
|
175
|
+
placeholder: U,
|
|
176
|
+
status: "ghost",
|
|
177
|
+
sizeStyle: "s",
|
|
178
|
+
value: $,
|
|
179
|
+
onChange: (e) => q(e.target.value)
|
|
180
|
+
}
|
|
181
|
+
),
|
|
182
|
+
/* @__PURE__ */ r("div", { className: u.searchWrapper })
|
|
183
|
+
] }),
|
|
184
|
+
/* @__PURE__ */ w("div", { className: u.selectList, ref: E, children: [
|
|
185
|
+
j.map((e) => /* @__PURE__ */ w(
|
|
186
|
+
"div",
|
|
187
|
+
{
|
|
188
|
+
ref: (o) => K.current[e.value] = o,
|
|
189
|
+
className: `${u.children} ${(c == null ? void 0 : c.value) === e.value ? u.active : ""}`,
|
|
190
|
+
onClick: () => D(e),
|
|
191
|
+
children: [
|
|
192
|
+
e.icon && /* @__PURE__ */ r(_, { icon: e.icon, size: 16 }),
|
|
193
|
+
e.label && /* @__PURE__ */ r("div", { className: u.itemLabel, children: e.label })
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
e.value
|
|
197
|
+
)),
|
|
198
|
+
j.length === 0 && /* @__PURE__ */ r("div", { className: `${u.noResults} textSmall`, children: "Aucun résultat" })
|
|
199
|
+
] })
|
|
200
|
+
] })
|
|
175
201
|
}
|
|
176
202
|
)
|
|
177
203
|
] });
|
|
178
204
|
};
|
|
179
205
|
export {
|
|
180
|
-
|
|
206
|
+
me as Select
|
|
181
207
|
};
|
package/dist/styles/Select.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._selectContainer_133eb_54{position:relative}._selectContainer_133eb_54 ._selected_133eb_57{background:var(--button-tertiary-pressed-background);border-radius:var(--spacing-xs-6)}._selectContainer_133eb_54 ._children_133eb_61{padding:var(--spacing-xs-6) var(--spacing-xs-5);box-sizing:border-box;width:100%;gap:.5rem;cursor:pointer;font-style:normal;line-height:1.25rem;display:flex;justify-content:flex-start;align-items:center;flex-direction:row}._selectContainer_133eb_54 ._children_133eb_61:hover{background:var(--dropdown-line-background-hover);border-radius:var(--spacing-xs-6)}._selectContainer_133eb_54 ._children_133eb_61._active_133eb_78{background:var(--button-tertiary-pressed-background);border-radius:var(--spacing-xs-6)}._selectContainer_133eb_54 ._selectList_133eb_82{max-height:200px;overflow-y:auto;gap:.125rem;display:flex;justify-content:flex-start;align-items:stretch;flex-direction:column}._selectContainer_133eb_54 ._modal_133eb_91{box-shadow:0 4px 4px 0 var(--shadow-color-lowest);border-radius:4px;padding:.25rem;animation:_dropdownFadeIn_133eb_1 .2s ease-out;transform-origin:top left}._selectContainer_133eb_54 ._itemLabel_133eb_98{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}._selectContainer_133eb_54 ._searchWrapper_133eb_103{background-color:var(--general-border-window);height:1px;width:100%;margin-bottom:.25rem}._selectContainer_133eb_54 ._noResults_133eb_109{text-align:center;padding:.5rem 0}@keyframes _dropdownFadeIn_133eb_1{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}
|