@1doc/1ds-react 0.0.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.
- package/README.md +34 -0
- package/dist/components/Alert/Alert.css +188 -0
- package/dist/components/Alert/Alert.d.ts +65 -0
- package/dist/components/Alert/Alert.js +56 -0
- package/dist/components/Avatar/Avatar.css +88 -0
- package/dist/components/Avatar/Avatar.d.ts +34 -0
- package/dist/components/Avatar/Avatar.js +16 -0
- package/dist/components/Avatar/AvatarGroup.d.ts +12 -0
- package/dist/components/Avatar/AvatarGroup.js +8 -0
- package/dist/components/Badge/Badge.css +155 -0
- package/dist/components/Badge/Badge.d.ts +46 -0
- package/dist/components/Badge/Badge.js +17 -0
- package/dist/components/Button/Button.css +199 -0
- package/dist/components/Button/Button.d.ts +23 -0
- package/dist/components/Button/Button.js +62 -0
- package/dist/components/Checkbox/Checkbox.css +122 -0
- package/dist/components/Checkbox/Checkbox.d.ts +21 -0
- package/dist/components/Checkbox/Checkbox.js +49 -0
- package/dist/components/Divider/Divider.css +81 -0
- package/dist/components/Divider/Divider.d.ts +18 -0
- package/dist/components/Divider/Divider.js +26 -0
- package/dist/components/Grid/Grid.css +154 -0
- package/dist/components/Grid/Grid.d.ts +21 -0
- package/dist/components/Grid/Grid.js +53 -0
- package/dist/components/Icon/Icon.css +41 -0
- package/dist/components/Icon/Icon.d.ts +12 -0
- package/dist/components/Icon/Icon.js +29 -0
- package/dist/components/Input/Input.css +190 -0
- package/dist/components/Input/Input.d.ts +32 -0
- package/dist/components/Input/Input.js +58 -0
- package/dist/components/Link/Link.css +76 -0
- package/dist/components/Link/Link.d.ts +15 -0
- package/dist/components/Link/Link.js +19 -0
- package/dist/components/Logo/Logo.css +32 -0
- package/dist/components/Logo/Logo.d.ts +10 -0
- package/dist/components/Logo/Logo.js +16 -0
- package/dist/components/Modal/Modal.css +155 -0
- package/dist/components/Modal/Modal.d.ts +36 -0
- package/dist/components/Modal/Modal.js +55 -0
- package/dist/components/Radio/Radio.css +114 -0
- package/dist/components/Radio/Radio.d.ts +19 -0
- package/dist/components/Radio/Radio.js +39 -0
- package/dist/components/Select/Select.css +291 -0
- package/dist/components/Select/Select.d.ts +38 -0
- package/dist/components/Select/Select.js +246 -0
- package/dist/components/Spinner/Spinner.css +60 -0
- package/dist/components/Spinner/Spinner.d.ts +16 -0
- package/dist/components/Spinner/Spinner.js +16 -0
- package/dist/components/Switch/Switch.css +127 -0
- package/dist/components/Switch/Switch.d.ts +18 -0
- package/dist/components/Switch/Switch.js +57 -0
- package/dist/components/Tabs/Tab.d.ts +19 -0
- package/dist/components/Tabs/Tab.js +76 -0
- package/dist/components/Tabs/TabContent.d.ts +15 -0
- package/dist/components/Tabs/TabContent.js +11 -0
- package/dist/components/Tabs/Tabs.css +124 -0
- package/dist/components/Tabs/Tabs.d.ts +20 -0
- package/dist/components/Tabs/Tabs.js +14 -0
- package/dist/components/Tabs/TabsContent.d.ts +16 -0
- package/dist/components/Tabs/TabsContent.js +12 -0
- package/dist/components/Tabs/tabs.context.d.ts +2 -0
- package/dist/components/Tabs/tabs.context.js +2 -0
- package/dist/components/Tag/Tag.css +140 -0
- package/dist/components/Tag/Tag.d.ts +63 -0
- package/dist/components/Tag/Tag.js +48 -0
- package/dist/components/Text/Text.css +1213 -0
- package/dist/components/Text/Text.d.ts +70 -0
- package/dist/components/Text/Text.js +89 -0
- package/dist/components/Textarea/Textarea.css +133 -0
- package/dist/components/Textarea/Textarea.d.ts +28 -0
- package/dist/components/Textarea/Textarea.js +72 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +27 -0
- package/dist/utils/theme.d.ts +30 -0
- package/dist/utils/theme.js +106 -0
- package/package.json +26 -0
- package/scripts/postbuild.js +21 -0
- package/src/index.ts +28 -0
- package/src/utils/theme.ts +136 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
.umds-select {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--umds-primitive-spacing-nano);
|
|
5
|
+
font-family: var(--umds-semantic-font-family-base);
|
|
6
|
+
width: 320px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.umds-select--full-width {
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.umds-select__label {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.umds-select__required {
|
|
19
|
+
color: var(--umds-semantic-color-feedback-negative-pure);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.umds-select__container {
|
|
23
|
+
position: relative;
|
|
24
|
+
width: 100%;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.umds-select__trigger {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: space-between;
|
|
31
|
+
background-color: var(--umds-semantic-color-background-white);
|
|
32
|
+
border: 1px solid var(--umds-semantic-color-neutral-dark-up);
|
|
33
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
34
|
+
padding: var(--umds-primitive-spacing-nano) var(--umds-primitive-spacing-xxxs);
|
|
35
|
+
min-height: 48px;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
transition: all 0.2s ease;
|
|
38
|
+
box-sizing: border-box;
|
|
39
|
+
width: 100%;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.umds-select--small .umds-select__trigger {
|
|
43
|
+
min-height: 32px;
|
|
44
|
+
padding: var(--umds-primitive-spacing-nano) var(--umds-primitive-spacing-nano);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.umds-select--large .umds-select__trigger {
|
|
48
|
+
min-height: 56px;
|
|
49
|
+
padding: var(--umds-primitive-spacing-nano) var(--umds-primitive-spacing-xxs);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.umds-select__trigger:hover {
|
|
53
|
+
border-color: var(--umds-semantic-color-neutral-dark-down);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.umds-select__trigger:focus {
|
|
57
|
+
outline: 2px solid var(--umds-semantic-color-neutral-dark-down);
|
|
58
|
+
outline-offset: 2px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.umds-select--open .umds-select__trigger {
|
|
62
|
+
border-color: var(--umds-semantic-color-primary-pure);
|
|
63
|
+
box-shadow: 0 0 0 1px var(--umds-semantic-color-primary-pure);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.umds-select--disabled .umds-select__trigger {
|
|
67
|
+
background-color: var(--umds-semantic-color-neutral-light-medium);
|
|
68
|
+
border-color: var(--umds-semantic-color-neutral-light-down);
|
|
69
|
+
cursor: not-allowed;
|
|
70
|
+
pointer-events: none;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.umds-select--invalid .umds-select__trigger {
|
|
74
|
+
border-color: var(--umds-semantic-color-feedback-negative-pure);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.umds-select__values {
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-wrap: wrap;
|
|
80
|
+
gap: 4px;
|
|
81
|
+
flex: 1;
|
|
82
|
+
overflow: hidden;
|
|
83
|
+
min-width: 0;
|
|
84
|
+
align-items: center;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.umds-select--has-tags .umds-select__values {
|
|
88
|
+
overflow: visible;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.umds-select__placeholder {
|
|
92
|
+
color: var(--umds-semantic-color-neutral-light-down);
|
|
93
|
+
white-space: nowrap;
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
text-overflow: ellipsis;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.umds-select__actions {
|
|
99
|
+
display: flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
gap: var(--umds-primitive-spacing-nano);
|
|
102
|
+
margin-left: 8px;
|
|
103
|
+
color: var(--umds-semantic-color-neutral-dark-up);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.umds-select__arrow {
|
|
107
|
+
display: flex;
|
|
108
|
+
transition: transform 0.2s ease;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.umds-select--open .umds-select__arrow {
|
|
112
|
+
transform: rotate(0deg);
|
|
113
|
+
/* handled by icon name chagne but keeping just in case */
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* Options Dropdown */
|
|
117
|
+
.umds-select__dropdown {
|
|
118
|
+
position: absolute;
|
|
119
|
+
top: calc(100% + 4px);
|
|
120
|
+
left: 0;
|
|
121
|
+
width: 100%;
|
|
122
|
+
background-color: var(--umds-semantic-color-background-white);
|
|
123
|
+
border: 1px solid var(--umds-semantic-color-neutral-dark-up);
|
|
124
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
125
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
126
|
+
z-index: 5000;
|
|
127
|
+
max-height: 300px;
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-direction: column;
|
|
130
|
+
overflow: hidden;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.umds-select__search-container {
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
padding: 8px 12px;
|
|
137
|
+
border-bottom: 1px solid var(--umds-semantic-color-neutral-light-medium);
|
|
138
|
+
gap: 8px;
|
|
139
|
+
background-color: var(--umds-semantic-color-background-white);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.umds-select__search-icon {
|
|
143
|
+
display: flex;
|
|
144
|
+
align-items: center;
|
|
145
|
+
color: var(--umds-semantic-color-neutral-dark-up);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.umds-select__search-input {
|
|
149
|
+
flex: 1;
|
|
150
|
+
border: none;
|
|
151
|
+
outline: none;
|
|
152
|
+
font-size: var(--umds-primitive-font-size-xxs);
|
|
153
|
+
color: var(--umds-semantic-color-neutral-pure);
|
|
154
|
+
background: transparent;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* Inline Search Variant Styles */
|
|
158
|
+
.umds-select--search-inline .umds-select__search-container {
|
|
159
|
+
padding: 0 12px;
|
|
160
|
+
height: 48px;
|
|
161
|
+
border-bottom: 1px solid var(--umds-semantic-color-neutral-light-medium);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.umds-select--search-inline.umds-select--small .umds-select__search-container {
|
|
165
|
+
height: 32px;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.umds-select--search-inline.umds-select--large .umds-select__search-container {
|
|
169
|
+
height: 56px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.umds-select__search-close {
|
|
173
|
+
cursor: pointer;
|
|
174
|
+
display: flex;
|
|
175
|
+
align-items: center;
|
|
176
|
+
color: var(--umds-semantic-color-neutral-dark-up);
|
|
177
|
+
opacity: 0.6;
|
|
178
|
+
transition: opacity 0.2s;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.umds-select__search-close:hover {
|
|
182
|
+
opacity: 1;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.umds-select__options {
|
|
186
|
+
overflow-y: auto;
|
|
187
|
+
flex: 1;
|
|
188
|
+
padding: 4px 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.umds-select__option {
|
|
192
|
+
display: flex;
|
|
193
|
+
align-items: center;
|
|
194
|
+
padding: 8px 12px;
|
|
195
|
+
cursor: pointer;
|
|
196
|
+
transition: background-color 0.1s ease;
|
|
197
|
+
gap: 8px;
|
|
198
|
+
color: var(--umds-semantic-color-neutral-pure);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.umds-select__option:hover {
|
|
202
|
+
background-color: var(--umds-semantic-color-neutral-light-medium);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.umds-select__option--selected {
|
|
206
|
+
background-color: var(--umds-semantic-color-primary-light);
|
|
207
|
+
color: var(--umds-semantic-color-neutral-pure);
|
|
208
|
+
font-weight: var(--umds-primitive-font-weight-semibold);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.umds-select__option--selected:hover {
|
|
212
|
+
background-color: var(--umds-semantic-color-primary-light);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.umds-select__option-check {
|
|
216
|
+
display: flex;
|
|
217
|
+
align-items: center;
|
|
218
|
+
color: var(--umds-semantic-color-primary-pure);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.umds-select__option-content {
|
|
222
|
+
flex: 1;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.umds-select__no-options {
|
|
226
|
+
padding: 16px;
|
|
227
|
+
text-align: center;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.umds-select__loading-more {
|
|
231
|
+
display: flex;
|
|
232
|
+
align-items: center;
|
|
233
|
+
justify-content: center;
|
|
234
|
+
gap: 8px;
|
|
235
|
+
padding: 8px;
|
|
236
|
+
border-top: 1px solid var(--umds-semantic-color-neutral-light-medium);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/* Tags */
|
|
240
|
+
.umds-select__tags {
|
|
241
|
+
display: flex;
|
|
242
|
+
flex-wrap: wrap;
|
|
243
|
+
gap: 4px;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.umds-select__tag {
|
|
247
|
+
display: flex;
|
|
248
|
+
align-items: center;
|
|
249
|
+
background-color: var(--umds-semantic-color-neutral-light-medium);
|
|
250
|
+
border-radius: var(--umds-primitive-border-radius-xs);
|
|
251
|
+
padding: 2px 4px 2px 8px;
|
|
252
|
+
gap: 4px;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.umds-select__tag-close {
|
|
256
|
+
cursor: pointer;
|
|
257
|
+
display: flex;
|
|
258
|
+
opacity: 0.6;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.umds-select__tag-close:hover {
|
|
262
|
+
opacity: 1;
|
|
263
|
+
color: var(--umds-semantic-color-feedback-negative-pure);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/* Selected List */
|
|
267
|
+
.umds-select__selected-list {
|
|
268
|
+
margin-top: 8px;
|
|
269
|
+
display: flex;
|
|
270
|
+
flex-direction: column;
|
|
271
|
+
gap: 4px;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.umds-select__selected-list-item {
|
|
275
|
+
display: flex;
|
|
276
|
+
align-items: center;
|
|
277
|
+
justify-content: space-between;
|
|
278
|
+
padding: 8px 12px;
|
|
279
|
+
background-color: var(--umds-semantic-color-background-light);
|
|
280
|
+
border: 1px solid var(--umds-semantic-color-neutral-light-medium);
|
|
281
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.umds-select__list-remove {
|
|
285
|
+
cursor: pointer;
|
|
286
|
+
color: var(--umds-semantic-color-neutral-dark-up);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.umds-select__list-remove:hover {
|
|
290
|
+
color: var(--umds-semantic-color-feedback-negative-pure);
|
|
291
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import './Select.css';
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
label: string;
|
|
4
|
+
value: any;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export interface SelectProps {
|
|
8
|
+
label?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
options?: SelectOption[];
|
|
12
|
+
value?: any | any[];
|
|
13
|
+
multiple?: boolean;
|
|
14
|
+
searchable?: boolean;
|
|
15
|
+
autoFocusSearch?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
invalid?: boolean;
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
errorMessage?: string;
|
|
20
|
+
fullWidth?: boolean;
|
|
21
|
+
size?: "small" | "medium" | "large";
|
|
22
|
+
pagination?: boolean;
|
|
23
|
+
hasMore?: boolean;
|
|
24
|
+
onLoadMore?: () => void;
|
|
25
|
+
onSearchChange?: (query: string) => void;
|
|
26
|
+
searchVariant?: "default" | "inline";
|
|
27
|
+
searchDebounce?: number;
|
|
28
|
+
cache?: boolean;
|
|
29
|
+
cacheKey?: string;
|
|
30
|
+
cacheTime?: number;
|
|
31
|
+
selectionDisplay?: "text" | "tags" | "list";
|
|
32
|
+
onChange?: (value: any | any[]) => void;
|
|
33
|
+
item?: any;
|
|
34
|
+
className?: string;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
declare function Select(props: SelectProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export default Select;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import './Select.css';
|
|
3
|
+
"use client";
|
|
4
|
+
import { useState, useRef, useEffect } from "react";
|
|
5
|
+
import Text from "../Text/Text";
|
|
6
|
+
import Icon from "../Icon/Icon";
|
|
7
|
+
import Spinner from "../Spinner/Spinner";
|
|
8
|
+
import Checkbox from "../Checkbox/Checkbox";
|
|
9
|
+
import Tag from "../Tag/Tag";
|
|
10
|
+
function Select(props) {
|
|
11
|
+
const selectRef = useRef(null);
|
|
12
|
+
const searchInputRef = useRef(null);
|
|
13
|
+
const [isOpen, setIsOpen] = useState(() => false);
|
|
14
|
+
const [searchTerm, setSearchTerm] = useState(() => "");
|
|
15
|
+
const [internalSelected, setInternalSelected] = useState(() => Array());
|
|
16
|
+
const [searchTimeout, setSearchTimeout] = useState(() => null);
|
|
17
|
+
const [shouldFocusSearch, setShouldFocusSearch] = useState(() => false);
|
|
18
|
+
function selectedOptionsList() {
|
|
19
|
+
const currentVal = props.value !== undefined
|
|
20
|
+
? Array.isArray(props.value)
|
|
21
|
+
? props.value
|
|
22
|
+
: props.value === null
|
|
23
|
+
? []
|
|
24
|
+
: [props.value]
|
|
25
|
+
: internalSelected || [];
|
|
26
|
+
if (props.options && props.options.length > 0) {
|
|
27
|
+
return currentVal.map((v) => {
|
|
28
|
+
const found = props.options?.find((opt) => opt.value === v);
|
|
29
|
+
return (found || {
|
|
30
|
+
label: String(v),
|
|
31
|
+
value: v,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return (currentVal || []).map((v) => ({
|
|
36
|
+
label: String(v),
|
|
37
|
+
value: v,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
function displayLabelText() {
|
|
41
|
+
const currentVal = props.value !== undefined
|
|
42
|
+
? Array.isArray(props.value)
|
|
43
|
+
? props.value
|
|
44
|
+
: props.value === null
|
|
45
|
+
? []
|
|
46
|
+
: [props.value]
|
|
47
|
+
: internalSelected || [];
|
|
48
|
+
if (currentVal.length === 0)
|
|
49
|
+
return props.placeholder || "Selecione...";
|
|
50
|
+
if (props.multiple) {
|
|
51
|
+
if (props.selectionDisplay === "tags")
|
|
52
|
+
return "";
|
|
53
|
+
if (currentVal.length === 1) {
|
|
54
|
+
const found = props.options?.find((opt) => opt.value === currentVal[0]);
|
|
55
|
+
return found ? found.label : String(currentVal[0]);
|
|
56
|
+
}
|
|
57
|
+
return `${currentVal.length} selecionado(s)`;
|
|
58
|
+
}
|
|
59
|
+
// For single select, find label
|
|
60
|
+
if (props.options) {
|
|
61
|
+
const found = props.options.find((opt) => opt.value === currentVal[0]);
|
|
62
|
+
if (found)
|
|
63
|
+
return found.label;
|
|
64
|
+
}
|
|
65
|
+
return String(currentVal[0]);
|
|
66
|
+
}
|
|
67
|
+
function isPlaceholder() {
|
|
68
|
+
const currentVal = props.value !== undefined
|
|
69
|
+
? Array.isArray(props.value)
|
|
70
|
+
? props.value
|
|
71
|
+
: props.value === null
|
|
72
|
+
? []
|
|
73
|
+
: [props.value]
|
|
74
|
+
: internalSelected || [];
|
|
75
|
+
return currentVal.length === 0;
|
|
76
|
+
}
|
|
77
|
+
function filteredOptionsList() {
|
|
78
|
+
if (!props.options)
|
|
79
|
+
return [];
|
|
80
|
+
// If it's remote search (onSearchChange provided), we don't filter locally
|
|
81
|
+
if (!props.searchable || !searchTerm || props.onSearchChange)
|
|
82
|
+
return props.options;
|
|
83
|
+
const term = searchTerm.toLowerCase();
|
|
84
|
+
return props.options.filter((opt) => opt.label.toLowerCase().includes(term));
|
|
85
|
+
}
|
|
86
|
+
function wrapperClassesList() {
|
|
87
|
+
return [
|
|
88
|
+
"umds-select",
|
|
89
|
+
`umds-select--${props.size || "medium"}`,
|
|
90
|
+
props.fullWidth ? "umds-select--full-width" : "",
|
|
91
|
+
props.disabled ? "umds-select--disabled" : "",
|
|
92
|
+
props.invalid ? "umds-select--invalid" : "",
|
|
93
|
+
isOpen ? "umds-select--open" : "",
|
|
94
|
+
props.searchVariant === "inline" ? "umds-select--search-inline" : "",
|
|
95
|
+
props.multiple &&
|
|
96
|
+
props.selectionDisplay === "tags" &&
|
|
97
|
+
selectedOptionsList().length > 0
|
|
98
|
+
? "umds-select--has-tags"
|
|
99
|
+
: "",
|
|
100
|
+
props.className,
|
|
101
|
+
]
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
.join(" ");
|
|
104
|
+
}
|
|
105
|
+
function toggle() {
|
|
106
|
+
if (props.disabled)
|
|
107
|
+
return;
|
|
108
|
+
setIsOpen(!isOpen);
|
|
109
|
+
if (isOpen &&
|
|
110
|
+
props.searchable &&
|
|
111
|
+
(props.autoFocusSearch || props.searchVariant === "inline")) {
|
|
112
|
+
setShouldFocusSearch(true);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function handleSearch(event) {
|
|
116
|
+
const val = event.target.value;
|
|
117
|
+
setSearchTerm(val);
|
|
118
|
+
if (props.onSearchChange) {
|
|
119
|
+
if (searchTimeout) {
|
|
120
|
+
clearTimeout(searchTimeout);
|
|
121
|
+
}
|
|
122
|
+
const debounceTime = props.searchDebounce ?? 300;
|
|
123
|
+
setSearchTimeout(setTimeout(() => {
|
|
124
|
+
props.onSearchChange(val);
|
|
125
|
+
}, debounceTime));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function clearSearch() {
|
|
129
|
+
setSearchTerm("");
|
|
130
|
+
if (props.onSearchChange) {
|
|
131
|
+
props.onSearchChange("");
|
|
132
|
+
}
|
|
133
|
+
if (searchInputRef.current) {
|
|
134
|
+
searchInputRef.current.focus();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function closeSearch() {
|
|
138
|
+
setIsOpen(false);
|
|
139
|
+
setSearchTerm("");
|
|
140
|
+
if (props.onSearchChange) {
|
|
141
|
+
props.onSearchChange("");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function selectOption(option) {
|
|
145
|
+
if (props.disabled)
|
|
146
|
+
return;
|
|
147
|
+
let newValue;
|
|
148
|
+
if (props.multiple) {
|
|
149
|
+
const currentVal = props.value !== undefined
|
|
150
|
+
? Array.isArray(props.value)
|
|
151
|
+
? props.value
|
|
152
|
+
: props.value === null
|
|
153
|
+
? []
|
|
154
|
+
: [props.value]
|
|
155
|
+
: internalSelected || [];
|
|
156
|
+
if (currentVal.includes(option.value)) {
|
|
157
|
+
newValue = currentVal.filter((v) => v !== option.value);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
newValue = [...currentVal, option.value];
|
|
161
|
+
}
|
|
162
|
+
setInternalSelected(newValue);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
newValue = option.value;
|
|
166
|
+
setInternalSelected([newValue]);
|
|
167
|
+
setIsOpen(false);
|
|
168
|
+
}
|
|
169
|
+
if (props.onChange) {
|
|
170
|
+
props.onChange(newValue);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function removeValue(val, event) {
|
|
174
|
+
if (event)
|
|
175
|
+
event.stopPropagation();
|
|
176
|
+
if (props.disabled)
|
|
177
|
+
return;
|
|
178
|
+
const currentVal = props.value !== undefined
|
|
179
|
+
? Array.isArray(props.value)
|
|
180
|
+
? props.value
|
|
181
|
+
: [props.value]
|
|
182
|
+
: internalSelected || [];
|
|
183
|
+
const newValue = currentVal.filter((v) => v !== val);
|
|
184
|
+
setInternalSelected(newValue);
|
|
185
|
+
if (props.onChange) {
|
|
186
|
+
props.onChange(newValue);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function onScrollList(event) {
|
|
190
|
+
if (!props.pagination ||
|
|
191
|
+
!props.onLoadMore ||
|
|
192
|
+
props.loading ||
|
|
193
|
+
!props.hasMore)
|
|
194
|
+
return;
|
|
195
|
+
const { scrollTop, scrollHeight, clientHeight } = event.target;
|
|
196
|
+
if (scrollHeight - scrollTop <= clientHeight + 10) {
|
|
197
|
+
props.onLoadMore();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function isOptionSelected(val) {
|
|
201
|
+
const currentVal = props.value !== undefined
|
|
202
|
+
? Array.isArray(props.value)
|
|
203
|
+
? props.value
|
|
204
|
+
: props.value === null
|
|
205
|
+
? []
|
|
206
|
+
: [props.value]
|
|
207
|
+
: internalSelected || [];
|
|
208
|
+
return currentVal.includes(val);
|
|
209
|
+
}
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
const handleClickOutside = (event) => {
|
|
212
|
+
if (selectRef.current &&
|
|
213
|
+
!selectRef.current.contains(event.target)) {
|
|
214
|
+
setIsOpen(false);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
218
|
+
}, []);
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
if (isOpen && shouldFocusSearch) {
|
|
221
|
+
// Retry a few times if ref is not yet ready (though onUpdate usually implies rendered)
|
|
222
|
+
// We use a small timeout to ensure browser paints or simply check ref
|
|
223
|
+
if (searchInputRef.current) {
|
|
224
|
+
searchInputRef.current.focus();
|
|
225
|
+
setShouldFocusSearch(false);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return (_jsxs("div", { ref: selectRef, className: wrapperClassesList(), children: [props.label ? (_jsxs(Text, { as: "label", variant: "label", weight: "semibold", className: "umds-select__label", children: [props.label, props.required ? (_jsx("span", { className: "umds-select__required", children: " *" })) : null] })) : null, _jsxs("div", { className: "umds-select__container", children: [!(isOpen && props.searchVariant === "inline") ? (_jsxs("div", { role: "combobox", className: "umds-select__trigger", onClick: (event) => toggle(), "aria-expanded": isOpen, tabIndex: props.disabled ? -1 : 0, children: [_jsxs("div", { className: "umds-select__values", children: [displayLabelText() ? (_jsx(Text, { as: "span", variant: "body2", className: isPlaceholder() ? "umds-select__placeholder" : "", children: displayLabelText() })) : null, props.multiple &&
|
|
230
|
+
props.selectionDisplay === "tags" &&
|
|
231
|
+
selectedOptionsList().length > 0 ? (_jsx("div", { className: "umds-select__tags", children: selectedOptionsList()?.map((opt) => (_jsx(Tag, { variant: "outlined", size: "sm", label: opt.label, closable: true, disabled: props.disabled, onClose: (e) => removeValue(opt.value, e) }, opt.value))) })) : null] }), _jsxs("div", { className: "umds-select__actions", children: [props.loading ? _jsx(Spinner, { size: "sm", variant: "secondary" }) : null, _jsx("div", { className: "umds-select__arrow", children: _jsx(Icon, { size: "sm", name: isOpen ? "nav-arrow-up" : "nav-arrow-down" }) })] })] })) : null, isOpen ? (_jsxs("div", { className: "umds-select__dropdown", style: props.searchVariant === "inline"
|
|
232
|
+
? {
|
|
233
|
+
top: "0",
|
|
234
|
+
}
|
|
235
|
+
: {}, children: [props.searchable ? (_jsxs("div", { className: "umds-select__search-container", children: [_jsx("div", { className: "umds-select__search-icon", children: _jsx(Icon, { name: "search", size: "sm" }) }), _jsx("input", { type: "text", placeholder: "Buscar...", className: "umds-select__search-input", ref: searchInputRef, value: searchTerm, onInput: (e) => handleSearch(e) }), props.searchVariant === "inline" ? (_jsx("div", { className: "umds-select__search-close", onClick: (event) => closeSearch(), children: _jsx(Icon, { name: "xmark", size: "sm" }) })) : null] })) : null, _jsxs("div", { className: "umds-select__options", onScroll: (e) => onScrollList(e), children: [filteredOptionsList().length === 0 && !props.loading ? (_jsx("div", { className: "umds-select__no-options", children: _jsx(Text, { variant: "body2", color: "secondary", children: "Nenhum item encontrado" }) })) : null, filteredOptionsList()?.map((option) => (_jsxs("div", { onClick: (event) => selectOption(option), className: [
|
|
236
|
+
"umds-select__option",
|
|
237
|
+
isOptionSelected(option.value)
|
|
238
|
+
? "umds-select__option--selected"
|
|
239
|
+
: "",
|
|
240
|
+
]
|
|
241
|
+
.filter(Boolean)
|
|
242
|
+
.join(" "), children: [props.multiple ? (_jsx("div", { className: "umds-select__option-checkbox", children: _jsx(Checkbox, { checked: isOptionSelected(option.value), readOnly: true }) })) : null, _jsx("div", { className: "umds-select__option-content", children: _jsx(_Fragment, { children: props.item || (_jsx(Text, { variant: "body2", children: option.label })) }) }), !props.multiple && isOptionSelected(option.value) ? (_jsx("div", { className: "umds-select__option-check", children: _jsx(Icon, { name: "check", size: "sm" }) })) : null] }, option.value))), props.loading && props.pagination ? (_jsxs("div", { className: "umds-select__loading-more", children: [_jsx(Spinner, { size: "sm" }), _jsx(Text, { variant: "caption", children: "Carregando mais..." })] })) : null] })] })) : null] }), props.errorMessage ? (_jsx(Text, { variant: "caption", color: "error", className: "umds-select__error-message", children: props.errorMessage })) : null, props.description && !props.errorMessage ? (_jsx(Text, { variant: "caption", color: "secondary", className: "umds-select__description", children: props.description })) : null, props.multiple &&
|
|
243
|
+
props.selectionDisplay === "list" &&
|
|
244
|
+
selectedOptionsList().length > 0 ? (_jsx("div", { className: "umds-select__selected-list", children: selectedOptionsList()?.map((opt) => (_jsxs("div", { className: "umds-select__selected-list-item", children: [_jsx(Text, { variant: "body2", children: opt.label }), _jsx("span", { className: "umds-select__list-remove", onClick: (e) => removeValue(opt.value, e), children: _jsx(Icon, { name: "trash", size: "sm" }) })] }, opt.value))) })) : null] }));
|
|
245
|
+
}
|
|
246
|
+
export default Select;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
.umds-spinner {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.umds-spinner__circle {
|
|
8
|
+
display: block;
|
|
9
|
+
border-radius: 50%;
|
|
10
|
+
border-style: solid;
|
|
11
|
+
border-top-color: transparent;
|
|
12
|
+
border-right-color: transparent;
|
|
13
|
+
animation: umds-spinner-rotate 0.8s linear infinite;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Sizes */
|
|
17
|
+
.umds-spinner--sm .umds-spinner__circle {
|
|
18
|
+
width: 16px;
|
|
19
|
+
height: 16px;
|
|
20
|
+
border-width: 2px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.umds-spinner--md .umds-spinner__circle {
|
|
24
|
+
width: 24px;
|
|
25
|
+
height: 24px;
|
|
26
|
+
border-width: 3px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.umds-spinner--lg .umds-spinner__circle {
|
|
30
|
+
width: 32px;
|
|
31
|
+
height: 32px;
|
|
32
|
+
border-width: 4px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Variants */
|
|
36
|
+
.umds-spinner--primary .umds-spinner__circle {
|
|
37
|
+
border-bottom-color: var(--umds-semantic-color-primary-pure);
|
|
38
|
+
border-left-color: var(--umds-semantic-color-primary-pure);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.umds-spinner--secondary .umds-spinner__circle {
|
|
42
|
+
border-bottom-color: var(--umds-semantic-color-primary-dark);
|
|
43
|
+
border-left-color: var(--umds-semantic-color-primary-dark);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.umds-spinner--neutral .umds-spinner__circle {
|
|
47
|
+
border-bottom-color: var(--umds-semantic-color-neutral-dark-medium);
|
|
48
|
+
border-left-color: var(--umds-semantic-color-neutral-dark-medium);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Animation */
|
|
52
|
+
@keyframes umds-spinner-rotate {
|
|
53
|
+
from {
|
|
54
|
+
transform: rotate(0deg);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
to {
|
|
58
|
+
transform: rotate(360deg);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './Spinner.css';
|
|
2
|
+
/**
|
|
3
|
+
* Spinner component for loading states
|
|
4
|
+
* @property {string} size - Tamanho do spinner: 'sm' (16px), 'md' (24px), 'lg' (32px)
|
|
5
|
+
* @property {string} variant - Variante de cor: 'primary', 'secondary', 'neutral'
|
|
6
|
+
* @property {string} label - Label acessível para leitores de tela
|
|
7
|
+
*/
|
|
8
|
+
export interface SpinnerProps {
|
|
9
|
+
size?: "sm" | "md" | "lg";
|
|
10
|
+
variant?: "primary" | "secondary" | "neutral";
|
|
11
|
+
label?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
declare function Spinner(props: SpinnerProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export default Spinner;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import './Spinner.css';
|
|
3
|
+
function Spinner(props) {
|
|
4
|
+
function classes() {
|
|
5
|
+
return [
|
|
6
|
+
"umds-spinner",
|
|
7
|
+
`umds-spinner--${props.size || "md"}`,
|
|
8
|
+
`umds-spinner--${props.variant || "primary"}`,
|
|
9
|
+
props.className,
|
|
10
|
+
]
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.join(" ");
|
|
13
|
+
}
|
|
14
|
+
return (_jsx("span", { role: "status", "aria-label": props.label || "Carregando", ...props, className: classes(), children: _jsx("span", { className: "umds-spinner__circle" }) }));
|
|
15
|
+
}
|
|
16
|
+
export default Spinner;
|