allaw-ui 3.8.0 → 3.8.2
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/components/atoms/selects/Select.d.ts +2 -0
- package/dist/components/atoms/selects/Select.js +20 -15
- package/dist/components/atoms/selects/Select.module.css +22 -0
- package/dist/components/atoms/selects/Select.stories.d.ts +24 -7
- package/dist/components/atoms/selects/Select.stories.js +68 -0
- package/package.json +1 -1
|
@@ -13,6 +13,8 @@ export interface SelectProps<T extends string | string[]> {
|
|
|
13
13
|
showError?: boolean;
|
|
14
14
|
width?: number;
|
|
15
15
|
maxItems?: number;
|
|
16
|
+
requireAttention?: boolean;
|
|
17
|
+
disabledItems?: string[];
|
|
16
18
|
onChange?: (selected: T) => void;
|
|
17
19
|
onError?: (error: string) => void;
|
|
18
20
|
}
|
|
@@ -14,21 +14,21 @@ import "../../../styles/global.css";
|
|
|
14
14
|
import TinyInfo from "../typography/TinyInfo";
|
|
15
15
|
function Select(_a, ref) {
|
|
16
16
|
var _b;
|
|
17
|
-
var items = _a.items, selectedItem = _a.selectedItem, _c = _a.placeholder, placeholder = _c === void 0 ? "Choisir..." : _c, _d = _a.multiple, multiple = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, _f = _a.showError, showError = _f === void 0 ? false : _f, _g = _a.width, width = _g === void 0 ? 100 : _g, maxItems = _a.maxItems, onChange = _a.onChange, onError = _a.onError;
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
17
|
+
var items = _a.items, selectedItem = _a.selectedItem, _c = _a.placeholder, placeholder = _c === void 0 ? "Choisir..." : _c, _d = _a.multiple, multiple = _d === void 0 ? false : _d, _e = _a.isRequired, isRequired = _e === void 0 ? false : _e, _f = _a.showError, showError = _f === void 0 ? false : _f, _g = _a.width, width = _g === void 0 ? 100 : _g, maxItems = _a.maxItems, _h = _a.requireAttention, requireAttention = _h === void 0 ? false : _h, _j = _a.disabledItems, disabledItems = _j === void 0 ? [] : _j, onChange = _a.onChange, onError = _a.onError;
|
|
18
|
+
var _k = useState(false), isOpen = _k[0], setIsOpen = _k[1];
|
|
19
|
+
var _l = useState((multiple ? selectedItem || [] : selectedItem || "")), selected = _l[0], setSelected = _l[1];
|
|
20
|
+
var _m = useState(""), error = _m[0], setError = _m[1];
|
|
21
21
|
var selectRef = useRef(null);
|
|
22
22
|
var listRef = useRef(null);
|
|
23
23
|
var tagContainerRef = useRef(null);
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
24
|
+
var _o = useState([]), visibleTags = _o[0], setVisibleTags = _o[1];
|
|
25
|
+
var _p = useState(0), hiddenCount = _p[0], setHiddenCount = _p[1];
|
|
26
|
+
var _q = useState({
|
|
27
27
|
top: 0,
|
|
28
28
|
left: 0,
|
|
29
29
|
width: 0,
|
|
30
|
-
}), listPosition =
|
|
31
|
-
var
|
|
30
|
+
}), listPosition = _q[0], setListPosition = _q[1];
|
|
31
|
+
var _r = useState("bottom"), placement = _r[0], setPlacement = _r[1];
|
|
32
32
|
useEffect(function () {
|
|
33
33
|
setSelected((multiple ? selectedItem || [] : selectedItem || ""));
|
|
34
34
|
}, [selectedItem, multiple]);
|
|
@@ -207,11 +207,16 @@ function Select(_a, ref) {
|
|
|
207
207
|
left: "".concat(listPosition.left, "px"),
|
|
208
208
|
width: "".concat(listPosition.width, "px"),
|
|
209
209
|
margin: placement === "bottom" ? "4px 0 0 0" : "0 0 4px 0",
|
|
210
|
-
} }, items.map(function (item) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
} }, items.map(function (item) {
|
|
211
|
+
var isDisabled = disabledItems.includes(item.value);
|
|
212
|
+
var isSelected = Array.isArray(selected)
|
|
213
|
+
? selected.includes(item.value)
|
|
214
|
+
: item.value === selectedItem;
|
|
215
|
+
var isHighlighted = !multiple && item.value === selectedItem;
|
|
216
|
+
return (React.createElement("div", { key: item.value, "data-value": item.value, className: "".concat(styles.selectItem, " ").concat(isSelected ? styles.selected : "", " ").concat(isHighlighted ? styles.highlighted : "", " ").concat(!multiple ? styles.singleSelect : "", " ").concat(isDisabled ? styles.disabledItem : ""), onClick: function () { return !isDisabled && handleSelect(item); }, "aria-disabled": isDisabled },
|
|
217
|
+
multiple && React.createElement("span", { className: styles.selectItemIcon }),
|
|
218
|
+
React.createElement("span", { className: styles.selectItemText }, item.label)));
|
|
219
|
+
}))); };
|
|
215
220
|
var renderTags = function (selectedValues) {
|
|
216
221
|
if (!selectedValues.length)
|
|
217
222
|
return null;
|
|
@@ -226,7 +231,7 @@ function Select(_a, ref) {
|
|
|
226
231
|
validate: function () { return validateSelect(selected); },
|
|
227
232
|
}); });
|
|
228
233
|
return (React.createElement("div", { ref: selectRef, className: "".concat(styles.selectContainer, " ").concat(isOpen ? styles.selectPressed : ""), style: { width: "".concat(width, "%") } },
|
|
229
|
-
React.createElement("button", { type: "button", className: "".concat(styles.select, " ").concat(isOpen ? styles.selectPressed : styles.selectDefault, " ").concat(multiple ? styles.selectMultiple : styles.selectSingle), onClick: toggleOpen, style: { width: "100%" } },
|
|
234
|
+
React.createElement("button", { type: "button", className: "".concat(styles.select, " ").concat(isOpen ? styles.selectPressed : styles.selectDefault, " ").concat(multiple ? styles.selectMultiple : styles.selectSingle, " ").concat(requireAttention ? styles.selectRequireAttention : ""), onClick: toggleOpen, style: { width: "100%" } },
|
|
230
235
|
React.createElement("span", { className: styles.selectText }, Array.isArray(selected) && selected.length > 0
|
|
231
236
|
? renderTags(selected)
|
|
232
237
|
: !Array.isArray(selected) && selected
|
|
@@ -144,6 +144,16 @@
|
|
|
144
144
|
border-radius: 8px;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
.disabledItem {
|
|
148
|
+
color: var(--mid-grey) !important;
|
|
149
|
+
opacity: 0.5;
|
|
150
|
+
cursor: not-allowed;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.disabledItem:hover {
|
|
154
|
+
background: transparent !important;
|
|
155
|
+
}
|
|
156
|
+
|
|
147
157
|
.tagContainer {
|
|
148
158
|
display: flex;
|
|
149
159
|
flex-wrap: nowrap;
|
|
@@ -184,3 +194,15 @@
|
|
|
184
194
|
.selectSingle {
|
|
185
195
|
padding: 8px 16px;
|
|
186
196
|
}
|
|
197
|
+
|
|
198
|
+
.selectRequireAttention {
|
|
199
|
+
border-color: #25beeb !important;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.selectRequireAttention:hover {
|
|
203
|
+
border-color: #1d9cc9 !important;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.selectRequireAttention:focus {
|
|
207
|
+
border-color: #1d9cc9 !important;
|
|
208
|
+
}
|
|
@@ -32,35 +32,49 @@ declare namespace _default {
|
|
|
32
32
|
}
|
|
33
33
|
export { control_3 as control };
|
|
34
34
|
}
|
|
35
|
-
namespace
|
|
35
|
+
namespace requireAttention {
|
|
36
36
|
export namespace control_4 {
|
|
37
37
|
let type_4: string;
|
|
38
38
|
export { type_4 as type };
|
|
39
39
|
}
|
|
40
40
|
export { control_4 as control };
|
|
41
41
|
}
|
|
42
|
-
namespace
|
|
42
|
+
namespace selectedItem {
|
|
43
43
|
export namespace control_5 {
|
|
44
44
|
let type_5: string;
|
|
45
45
|
export { type_5 as type };
|
|
46
|
-
export let min: number;
|
|
47
46
|
}
|
|
48
47
|
export { control_5 as control };
|
|
49
48
|
}
|
|
49
|
+
namespace maxItems {
|
|
50
|
+
export namespace control_6 {
|
|
51
|
+
let type_6: string;
|
|
52
|
+
export { type_6 as type };
|
|
53
|
+
export let min: number;
|
|
54
|
+
}
|
|
55
|
+
export { control_6 as control };
|
|
56
|
+
}
|
|
57
|
+
namespace disabledItems {
|
|
58
|
+
export namespace control_7 {
|
|
59
|
+
let type_7: string;
|
|
60
|
+
export { type_7 as type };
|
|
61
|
+
}
|
|
62
|
+
export { control_7 as control };
|
|
63
|
+
}
|
|
50
64
|
namespace onChange {
|
|
51
65
|
namespace table {
|
|
52
66
|
let disable: boolean;
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
69
|
namespace width {
|
|
56
|
-
export namespace
|
|
57
|
-
let
|
|
58
|
-
export {
|
|
70
|
+
export namespace control_8 {
|
|
71
|
+
let type_8: string;
|
|
72
|
+
export { type_8 as type };
|
|
59
73
|
let min_1: number;
|
|
60
74
|
export { min_1 as min };
|
|
61
75
|
export let max: number;
|
|
62
76
|
}
|
|
63
|
-
export {
|
|
77
|
+
export { control_8 as control };
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
export namespace parameters {
|
|
@@ -92,4 +106,7 @@ export const Pressed: any;
|
|
|
92
106
|
export const Multiple: any;
|
|
93
107
|
export const Required: any;
|
|
94
108
|
export const CustomWidth: any;
|
|
109
|
+
export const RequireAttention: any;
|
|
110
|
+
export const WithDisabledItems: any;
|
|
111
|
+
export const MultipleWithDisabledItems: any;
|
|
95
112
|
import Select from "./Select";
|
|
@@ -40,6 +40,11 @@ export default {
|
|
|
40
40
|
type: "boolean",
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
|
+
requireAttention: {
|
|
44
|
+
control: {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
43
48
|
selectedItem: {
|
|
44
49
|
control: {
|
|
45
50
|
type: "text",
|
|
@@ -51,6 +56,11 @@ export default {
|
|
|
51
56
|
min: 1,
|
|
52
57
|
},
|
|
53
58
|
},
|
|
59
|
+
disabledItems: {
|
|
60
|
+
control: {
|
|
61
|
+
type: "array",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
54
64
|
onChange: {
|
|
55
65
|
table: {
|
|
56
66
|
disable: true,
|
|
@@ -109,6 +119,7 @@ Default.args = {
|
|
|
109
119
|
placeholder: "Select...",
|
|
110
120
|
multiple: false,
|
|
111
121
|
isRequired: false,
|
|
122
|
+
requireAttention: false,
|
|
112
123
|
width: 100,
|
|
113
124
|
};
|
|
114
125
|
export var Pressed = Template.bind({});
|
|
@@ -125,6 +136,7 @@ Pressed.args = {
|
|
|
125
136
|
placeholder: "Select...",
|
|
126
137
|
multiple: false,
|
|
127
138
|
isRequired: false,
|
|
139
|
+
requireAttention: false,
|
|
128
140
|
};
|
|
129
141
|
export var Multiple = Template.bind({});
|
|
130
142
|
Multiple.args = {
|
|
@@ -140,6 +152,7 @@ Multiple.args = {
|
|
|
140
152
|
placeholder: "Select...",
|
|
141
153
|
multiple: true,
|
|
142
154
|
isRequired: false,
|
|
155
|
+
requireAttention: false,
|
|
143
156
|
maxItems: 3,
|
|
144
157
|
};
|
|
145
158
|
export var Required = Template.bind({});
|
|
@@ -156,6 +169,61 @@ Required.args = {
|
|
|
156
169
|
placeholder: "Select...",
|
|
157
170
|
multiple: false,
|
|
158
171
|
isRequired: true,
|
|
172
|
+
requireAttention: false,
|
|
159
173
|
};
|
|
160
174
|
export var CustomWidth = Template.bind({});
|
|
161
175
|
CustomWidth.args = __assign(__assign({}, Default.args), { width: 50 });
|
|
176
|
+
export var RequireAttention = Template.bind({});
|
|
177
|
+
RequireAttention.args = {
|
|
178
|
+
items: [
|
|
179
|
+
{ label: "Lundi 12 août", value: "lundi-12-aout" },
|
|
180
|
+
{ label: "Mardi 13 août", value: "mardi-13-aout" },
|
|
181
|
+
{ label: "Mercredi 14 août", value: "mercredi-14-aout" },
|
|
182
|
+
{ label: "Jeudi 15 août", value: "jeudi-15-aout" },
|
|
183
|
+
{ label: "Vendredi 16 août", value: "vendredi-16-aout" },
|
|
184
|
+
{ label: "Samedi 17 août", value: "samedi-17-aout" },
|
|
185
|
+
],
|
|
186
|
+
selectedItem: "",
|
|
187
|
+
placeholder: "Choisir une date...",
|
|
188
|
+
multiple: false,
|
|
189
|
+
isRequired: false,
|
|
190
|
+
requireAttention: true,
|
|
191
|
+
width: 100,
|
|
192
|
+
};
|
|
193
|
+
export var WithDisabledItems = Template.bind({});
|
|
194
|
+
WithDisabledItems.args = {
|
|
195
|
+
items: [
|
|
196
|
+
{ label: "Lundi 12 août", value: "lundi-12-aout" },
|
|
197
|
+
{ label: "Mardi 13 août", value: "mardi-13-aout" },
|
|
198
|
+
{ label: "Mercredi 14 août", value: "mercredi-14-aout" },
|
|
199
|
+
{ label: "Jeudi 15 août", value: "jeudi-15-aout" },
|
|
200
|
+
{ label: "Vendredi 16 août", value: "vendredi-16-aout" },
|
|
201
|
+
{ label: "Samedi 17 août", value: "samedi-17-aout" },
|
|
202
|
+
],
|
|
203
|
+
selectedItem: "",
|
|
204
|
+
placeholder: "Sélectionner une option...",
|
|
205
|
+
multiple: false,
|
|
206
|
+
isRequired: false,
|
|
207
|
+
requireAttention: false,
|
|
208
|
+
disabledItems: ["mardi-13-aout", "jeudi-15-aout"],
|
|
209
|
+
width: 100,
|
|
210
|
+
};
|
|
211
|
+
export var MultipleWithDisabledItems = Template.bind({});
|
|
212
|
+
MultipleWithDisabledItems.args = {
|
|
213
|
+
items: [
|
|
214
|
+
{ label: "Lundi 12 août", value: "lundi-12-aout" },
|
|
215
|
+
{ label: "Mardi 13 août", value: "mardi-13-aout" },
|
|
216
|
+
{ label: "Mercredi 14 août", value: "mercredi-14-aout" },
|
|
217
|
+
{ label: "Jeudi 15 août", value: "jeudi-15-aout" },
|
|
218
|
+
{ label: "Vendredi 16 août", value: "vendredi-16-aout" },
|
|
219
|
+
{ label: "Samedi 17 août", value: "samedi-17-aout" },
|
|
220
|
+
],
|
|
221
|
+
selectedItem: [],
|
|
222
|
+
placeholder: "Sélectionner des options...",
|
|
223
|
+
multiple: true,
|
|
224
|
+
isRequired: false,
|
|
225
|
+
requireAttention: false,
|
|
226
|
+
disabledItems: ["mardi-13-aout", "vendredi-16-aout"],
|
|
227
|
+
maxItems: 4,
|
|
228
|
+
width: 100,
|
|
229
|
+
};
|