@vincentgraul/react-components 1.0.18 → 1.0.19
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 +2 -0
- package/build/language-selector/LanguageSelector.d.ts +12 -0
- package/build/language-selector/LanguageSelector.d.ts.map +1 -0
- package/build/language-selector/LanguageSelector.js +42 -0
- package/build/outside-alerter/useOutsideAlerter.d.ts +6 -1
- package/build/outside-alerter/useOutsideAlerter.d.ts.map +1 -1
- package/build/outside-alerter/useOutsideAlerter.js +4 -1
- package/build/select/Select.d.ts +287 -0
- package/build/select/Select.d.ts.map +1 -0
- package/build/select/Select.js +92 -0
- package/build/table/Table.d.ts +831 -3
- package/build/table/Table.d.ts.map +1 -1
- package/package.json +16 -12
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
| useOutsideAlerter | React hook to know if an click has been triggered outside an element |
|
|
16
16
|
| Modal | React component used to display a modal |
|
|
17
17
|
| Loader | React component used to display a loader |
|
|
18
|
+
| Select | React component used to display a select |
|
|
19
|
+
| LanguageSelector | React component used to display a language selector |
|
|
18
20
|
|
|
19
21
|
## License
|
|
20
22
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
languages: string[];
|
|
4
|
+
onChange?: (option: Option) => void;
|
|
5
|
+
}
|
|
6
|
+
interface Option {
|
|
7
|
+
value: string;
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export default function LanguageSelector(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=LanguageSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LanguageSelector.d.ts","sourceRoot":"","sources":["../../src/language-selector/LanguageSelector.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAI9D,UAAU,KAAK;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,KAAK,2CA+BpD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { useEffect, useState } from "react";
|
|
12
|
+
import styled from "styled-components";
|
|
13
|
+
import Select from "../select/Select";
|
|
14
|
+
export default function LanguageSelector(props) {
|
|
15
|
+
const { languages, onChange } = props;
|
|
16
|
+
const [options, setOptions] = useState(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const fetchIcon = (name) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const { default: path } = yield import(`./flags/${name}.svg`);
|
|
20
|
+
return path;
|
|
21
|
+
});
|
|
22
|
+
const prepareOptions = () => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
setOptions(yield Promise.all(languages.map((language) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return {
|
|
25
|
+
value: language,
|
|
26
|
+
label: _jsx(Flag, { src: yield fetchIcon(language) }),
|
|
27
|
+
};
|
|
28
|
+
}))));
|
|
29
|
+
});
|
|
30
|
+
prepareOptions();
|
|
31
|
+
}, [languages]);
|
|
32
|
+
if (!options) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return _jsx(Select, { options: options, onChange: onChange });
|
|
36
|
+
}
|
|
37
|
+
const Flag = styled.img `
|
|
38
|
+
display: block;
|
|
39
|
+
width: 30px;
|
|
40
|
+
margin: auto;
|
|
41
|
+
border-radius: 2px;
|
|
42
|
+
`;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
|
|
2
|
+
interface OutsideAlerter {
|
|
3
|
+
hasClickedOutside: boolean;
|
|
4
|
+
onReset: () => void;
|
|
5
|
+
}
|
|
6
|
+
export default function useOutsideAlerter(ref: RefObject<HTMLElement>): OutsideAlerter;
|
|
7
|
+
export {};
|
|
3
8
|
//# sourceMappingURL=useOutsideAlerter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOutsideAlerter.d.ts","sourceRoot":"","sources":["../../src/outside-alerter/useOutsideAlerter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAY,MAAM,OAAO,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"useOutsideAlerter.d.ts","sourceRoot":"","sources":["../../src/outside-alerter/useOutsideAlerter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAY,MAAM,OAAO,CAAC;AAEvD,UAAU,cAAc;IACtB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,cAAc,CAyBrF"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
export default function useOutsideAlerter(ref) {
|
|
3
3
|
const [hasClickedOutside, setClickedOutside] = useState(false);
|
|
4
|
+
const handleOnReset = () => {
|
|
5
|
+
setClickedOutside(false);
|
|
6
|
+
};
|
|
4
7
|
const handleOnClickOutside = (event) => {
|
|
5
8
|
if (event.target && ref.current) {
|
|
6
9
|
if (!ref.current.contains(event.target)) {
|
|
@@ -16,5 +19,5 @@ export default function useOutsideAlerter(ref) {
|
|
|
16
19
|
document.removeEventListener("mousedown", (event) => handleOnClickOutside(event));
|
|
17
20
|
};
|
|
18
21
|
}, [ref]);
|
|
19
|
-
return hasClickedOutside;
|
|
22
|
+
return { hasClickedOutside, onReset: handleOnReset };
|
|
20
23
|
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
interface Option {
|
|
3
|
+
id: number;
|
|
4
|
+
label: string | ReactNode;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
export type OptionWithoutId = Omit<Option, "id">;
|
|
8
|
+
interface Props {
|
|
9
|
+
options: OptionWithoutId[];
|
|
10
|
+
onChange?: (option: Option) => void;
|
|
11
|
+
}
|
|
12
|
+
export default function Select(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
declare const Option: import("styled-components").IStyledComponent<"web", {
|
|
14
|
+
ref?: React.LegacyRef<HTMLLIElement>;
|
|
15
|
+
key?: React.Key;
|
|
16
|
+
value?: string | number | readonly string[];
|
|
17
|
+
defaultChecked?: boolean;
|
|
18
|
+
defaultValue?: string | number | readonly string[];
|
|
19
|
+
suppressContentEditableWarning?: boolean;
|
|
20
|
+
suppressHydrationWarning?: boolean;
|
|
21
|
+
accessKey?: string;
|
|
22
|
+
autoFocus?: boolean;
|
|
23
|
+
className?: string;
|
|
24
|
+
contentEditable?: "inherit" | (boolean | "true" | "false");
|
|
25
|
+
contextMenu?: string;
|
|
26
|
+
dir?: string;
|
|
27
|
+
draggable?: boolean | "true" | "false";
|
|
28
|
+
hidden?: boolean;
|
|
29
|
+
id?: string;
|
|
30
|
+
lang?: string;
|
|
31
|
+
nonce?: string;
|
|
32
|
+
placeholder?: string;
|
|
33
|
+
slot?: string;
|
|
34
|
+
spellCheck?: boolean | "true" | "false";
|
|
35
|
+
style?: React.CSSProperties;
|
|
36
|
+
tabIndex?: number;
|
|
37
|
+
title?: string;
|
|
38
|
+
translate?: "yes" | "no";
|
|
39
|
+
radioGroup?: string;
|
|
40
|
+
role?: React.AriaRole;
|
|
41
|
+
about?: string;
|
|
42
|
+
content?: string;
|
|
43
|
+
datatype?: string;
|
|
44
|
+
inlist?: any;
|
|
45
|
+
prefix?: string;
|
|
46
|
+
property?: string;
|
|
47
|
+
rel?: string;
|
|
48
|
+
resource?: string;
|
|
49
|
+
rev?: string;
|
|
50
|
+
typeof?: string;
|
|
51
|
+
vocab?: string;
|
|
52
|
+
autoCapitalize?: string;
|
|
53
|
+
autoCorrect?: string;
|
|
54
|
+
autoSave?: string;
|
|
55
|
+
color?: string;
|
|
56
|
+
itemProp?: string;
|
|
57
|
+
itemScope?: boolean;
|
|
58
|
+
itemType?: string;
|
|
59
|
+
itemID?: string;
|
|
60
|
+
itemRef?: string;
|
|
61
|
+
results?: number;
|
|
62
|
+
security?: string;
|
|
63
|
+
unselectable?: "on" | "off";
|
|
64
|
+
inputMode?: "search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal";
|
|
65
|
+
is?: string;
|
|
66
|
+
'aria-activedescendant'?: string;
|
|
67
|
+
'aria-atomic'?: boolean | "true" | "false";
|
|
68
|
+
'aria-autocomplete'?: "none" | "list" | "inline" | "both";
|
|
69
|
+
'aria-braillelabel'?: string;
|
|
70
|
+
'aria-brailleroledescription'?: string;
|
|
71
|
+
'aria-busy'?: boolean | "true" | "false";
|
|
72
|
+
'aria-checked'?: boolean | "true" | "false" | "mixed";
|
|
73
|
+
'aria-colcount'?: number;
|
|
74
|
+
'aria-colindex'?: number;
|
|
75
|
+
'aria-colindextext'?: string;
|
|
76
|
+
'aria-colspan'?: number;
|
|
77
|
+
'aria-controls'?: string;
|
|
78
|
+
'aria-current'?: boolean | "time" | "page" | "step" | "true" | "false" | "location" | "date";
|
|
79
|
+
'aria-describedby'?: string;
|
|
80
|
+
'aria-description'?: string;
|
|
81
|
+
'aria-details'?: string;
|
|
82
|
+
'aria-disabled'?: boolean | "true" | "false";
|
|
83
|
+
'aria-dropeffect'?: "copy" | "link" | "none" | "execute" | "move" | "popup";
|
|
84
|
+
'aria-errormessage'?: string;
|
|
85
|
+
'aria-expanded'?: boolean | "true" | "false";
|
|
86
|
+
'aria-flowto'?: string;
|
|
87
|
+
'aria-grabbed'?: boolean | "true" | "false";
|
|
88
|
+
'aria-haspopup'?: boolean | "dialog" | "menu" | "true" | "false" | "grid" | "listbox" | "tree";
|
|
89
|
+
'aria-hidden'?: boolean | "true" | "false";
|
|
90
|
+
'aria-invalid'?: boolean | "true" | "false" | "grammar" | "spelling";
|
|
91
|
+
'aria-keyshortcuts'?: string;
|
|
92
|
+
'aria-label'?: string;
|
|
93
|
+
'aria-labelledby'?: string;
|
|
94
|
+
'aria-level'?: number;
|
|
95
|
+
'aria-live'?: "off" | "assertive" | "polite";
|
|
96
|
+
'aria-modal'?: boolean | "true" | "false";
|
|
97
|
+
'aria-multiline'?: boolean | "true" | "false";
|
|
98
|
+
'aria-multiselectable'?: boolean | "true" | "false";
|
|
99
|
+
'aria-orientation'?: "horizontal" | "vertical";
|
|
100
|
+
'aria-owns'?: string;
|
|
101
|
+
'aria-placeholder'?: string;
|
|
102
|
+
'aria-posinset'?: number;
|
|
103
|
+
'aria-pressed'?: boolean | "true" | "false" | "mixed";
|
|
104
|
+
'aria-readonly'?: boolean | "true" | "false";
|
|
105
|
+
'aria-relevant'?: "text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals";
|
|
106
|
+
'aria-required'?: boolean | "true" | "false";
|
|
107
|
+
'aria-roledescription'?: string;
|
|
108
|
+
'aria-rowcount'?: number;
|
|
109
|
+
'aria-rowindex'?: number;
|
|
110
|
+
'aria-rowindextext'?: string;
|
|
111
|
+
'aria-rowspan'?: number;
|
|
112
|
+
'aria-selected'?: boolean | "true" | "false";
|
|
113
|
+
'aria-setsize'?: number;
|
|
114
|
+
'aria-sort'?: "none" | "ascending" | "descending" | "other";
|
|
115
|
+
'aria-valuemax'?: number;
|
|
116
|
+
'aria-valuemin'?: number;
|
|
117
|
+
'aria-valuenow'?: number;
|
|
118
|
+
'aria-valuetext'?: string;
|
|
119
|
+
children?: React.ReactNode;
|
|
120
|
+
dangerouslySetInnerHTML?: {
|
|
121
|
+
__html: string | TrustedHTML;
|
|
122
|
+
};
|
|
123
|
+
onCopy?: React.ClipboardEventHandler<HTMLLIElement>;
|
|
124
|
+
onCopyCapture?: React.ClipboardEventHandler<HTMLLIElement>;
|
|
125
|
+
onCut?: React.ClipboardEventHandler<HTMLLIElement>;
|
|
126
|
+
onCutCapture?: React.ClipboardEventHandler<HTMLLIElement>;
|
|
127
|
+
onPaste?: React.ClipboardEventHandler<HTMLLIElement>;
|
|
128
|
+
onPasteCapture?: React.ClipboardEventHandler<HTMLLIElement>;
|
|
129
|
+
onCompositionEnd?: React.CompositionEventHandler<HTMLLIElement>;
|
|
130
|
+
onCompositionEndCapture?: React.CompositionEventHandler<HTMLLIElement>;
|
|
131
|
+
onCompositionStart?: React.CompositionEventHandler<HTMLLIElement>;
|
|
132
|
+
onCompositionStartCapture?: React.CompositionEventHandler<HTMLLIElement>;
|
|
133
|
+
onCompositionUpdate?: React.CompositionEventHandler<HTMLLIElement>;
|
|
134
|
+
onCompositionUpdateCapture?: React.CompositionEventHandler<HTMLLIElement>;
|
|
135
|
+
onFocus?: React.FocusEventHandler<HTMLLIElement>;
|
|
136
|
+
onFocusCapture?: React.FocusEventHandler<HTMLLIElement>;
|
|
137
|
+
onBlur?: React.FocusEventHandler<HTMLLIElement>;
|
|
138
|
+
onBlurCapture?: React.FocusEventHandler<HTMLLIElement>;
|
|
139
|
+
onChange?: React.FormEventHandler<HTMLLIElement>;
|
|
140
|
+
onChangeCapture?: React.FormEventHandler<HTMLLIElement>;
|
|
141
|
+
onBeforeInput?: React.FormEventHandler<HTMLLIElement>;
|
|
142
|
+
onBeforeInputCapture?: React.FormEventHandler<HTMLLIElement>;
|
|
143
|
+
onInput?: React.FormEventHandler<HTMLLIElement>;
|
|
144
|
+
onInputCapture?: React.FormEventHandler<HTMLLIElement>;
|
|
145
|
+
onReset?: React.FormEventHandler<HTMLLIElement>;
|
|
146
|
+
onResetCapture?: React.FormEventHandler<HTMLLIElement>;
|
|
147
|
+
onSubmit?: React.FormEventHandler<HTMLLIElement>;
|
|
148
|
+
onSubmitCapture?: React.FormEventHandler<HTMLLIElement>;
|
|
149
|
+
onInvalid?: React.FormEventHandler<HTMLLIElement>;
|
|
150
|
+
onInvalidCapture?: React.FormEventHandler<HTMLLIElement>;
|
|
151
|
+
onLoad?: React.ReactEventHandler<HTMLLIElement>;
|
|
152
|
+
onLoadCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
153
|
+
onError?: React.ReactEventHandler<HTMLLIElement>;
|
|
154
|
+
onErrorCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
155
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLLIElement>;
|
|
156
|
+
onKeyDownCapture?: React.KeyboardEventHandler<HTMLLIElement>;
|
|
157
|
+
onKeyPress?: React.KeyboardEventHandler<HTMLLIElement>;
|
|
158
|
+
onKeyPressCapture?: React.KeyboardEventHandler<HTMLLIElement>;
|
|
159
|
+
onKeyUp?: React.KeyboardEventHandler<HTMLLIElement>;
|
|
160
|
+
onKeyUpCapture?: React.KeyboardEventHandler<HTMLLIElement>;
|
|
161
|
+
onAbort?: React.ReactEventHandler<HTMLLIElement>;
|
|
162
|
+
onAbortCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
163
|
+
onCanPlay?: React.ReactEventHandler<HTMLLIElement>;
|
|
164
|
+
onCanPlayCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
165
|
+
onCanPlayThrough?: React.ReactEventHandler<HTMLLIElement>;
|
|
166
|
+
onCanPlayThroughCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
167
|
+
onDurationChange?: React.ReactEventHandler<HTMLLIElement>;
|
|
168
|
+
onDurationChangeCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
169
|
+
onEmptied?: React.ReactEventHandler<HTMLLIElement>;
|
|
170
|
+
onEmptiedCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
171
|
+
onEncrypted?: React.ReactEventHandler<HTMLLIElement>;
|
|
172
|
+
onEncryptedCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
173
|
+
onEnded?: React.ReactEventHandler<HTMLLIElement>;
|
|
174
|
+
onEndedCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
175
|
+
onLoadedData?: React.ReactEventHandler<HTMLLIElement>;
|
|
176
|
+
onLoadedDataCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
177
|
+
onLoadedMetadata?: React.ReactEventHandler<HTMLLIElement>;
|
|
178
|
+
onLoadedMetadataCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
179
|
+
onLoadStart?: React.ReactEventHandler<HTMLLIElement>;
|
|
180
|
+
onLoadStartCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
181
|
+
onPause?: React.ReactEventHandler<HTMLLIElement>;
|
|
182
|
+
onPauseCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
183
|
+
onPlay?: React.ReactEventHandler<HTMLLIElement>;
|
|
184
|
+
onPlayCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
185
|
+
onPlaying?: React.ReactEventHandler<HTMLLIElement>;
|
|
186
|
+
onPlayingCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
187
|
+
onProgress?: React.ReactEventHandler<HTMLLIElement>;
|
|
188
|
+
onProgressCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
189
|
+
onRateChange?: React.ReactEventHandler<HTMLLIElement>;
|
|
190
|
+
onRateChangeCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
191
|
+
onResize?: React.ReactEventHandler<HTMLLIElement>;
|
|
192
|
+
onResizeCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
193
|
+
onSeeked?: React.ReactEventHandler<HTMLLIElement>;
|
|
194
|
+
onSeekedCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
195
|
+
onSeeking?: React.ReactEventHandler<HTMLLIElement>;
|
|
196
|
+
onSeekingCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
197
|
+
onStalled?: React.ReactEventHandler<HTMLLIElement>;
|
|
198
|
+
onStalledCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
199
|
+
onSuspend?: React.ReactEventHandler<HTMLLIElement>;
|
|
200
|
+
onSuspendCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
201
|
+
onTimeUpdate?: React.ReactEventHandler<HTMLLIElement>;
|
|
202
|
+
onTimeUpdateCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
203
|
+
onVolumeChange?: React.ReactEventHandler<HTMLLIElement>;
|
|
204
|
+
onVolumeChangeCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
205
|
+
onWaiting?: React.ReactEventHandler<HTMLLIElement>;
|
|
206
|
+
onWaitingCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
207
|
+
onAuxClick?: React.MouseEventHandler<HTMLLIElement>;
|
|
208
|
+
onAuxClickCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
209
|
+
onClick?: React.MouseEventHandler<HTMLLIElement>;
|
|
210
|
+
onClickCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
211
|
+
onContextMenu?: React.MouseEventHandler<HTMLLIElement>;
|
|
212
|
+
onContextMenuCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
213
|
+
onDoubleClick?: React.MouseEventHandler<HTMLLIElement>;
|
|
214
|
+
onDoubleClickCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
215
|
+
onDrag?: React.DragEventHandler<HTMLLIElement>;
|
|
216
|
+
onDragCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
217
|
+
onDragEnd?: React.DragEventHandler<HTMLLIElement>;
|
|
218
|
+
onDragEndCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
219
|
+
onDragEnter?: React.DragEventHandler<HTMLLIElement>;
|
|
220
|
+
onDragEnterCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
221
|
+
onDragExit?: React.DragEventHandler<HTMLLIElement>;
|
|
222
|
+
onDragExitCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
223
|
+
onDragLeave?: React.DragEventHandler<HTMLLIElement>;
|
|
224
|
+
onDragLeaveCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
225
|
+
onDragOver?: React.DragEventHandler<HTMLLIElement>;
|
|
226
|
+
onDragOverCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
227
|
+
onDragStart?: React.DragEventHandler<HTMLLIElement>;
|
|
228
|
+
onDragStartCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
229
|
+
onDrop?: React.DragEventHandler<HTMLLIElement>;
|
|
230
|
+
onDropCapture?: React.DragEventHandler<HTMLLIElement>;
|
|
231
|
+
onMouseDown?: React.MouseEventHandler<HTMLLIElement>;
|
|
232
|
+
onMouseDownCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
233
|
+
onMouseEnter?: React.MouseEventHandler<HTMLLIElement>;
|
|
234
|
+
onMouseLeave?: React.MouseEventHandler<HTMLLIElement>;
|
|
235
|
+
onMouseMove?: React.MouseEventHandler<HTMLLIElement>;
|
|
236
|
+
onMouseMoveCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
237
|
+
onMouseOut?: React.MouseEventHandler<HTMLLIElement>;
|
|
238
|
+
onMouseOutCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
239
|
+
onMouseOver?: React.MouseEventHandler<HTMLLIElement>;
|
|
240
|
+
onMouseOverCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
241
|
+
onMouseUp?: React.MouseEventHandler<HTMLLIElement>;
|
|
242
|
+
onMouseUpCapture?: React.MouseEventHandler<HTMLLIElement>;
|
|
243
|
+
onSelect?: React.ReactEventHandler<HTMLLIElement>;
|
|
244
|
+
onSelectCapture?: React.ReactEventHandler<HTMLLIElement>;
|
|
245
|
+
onTouchCancel?: React.TouchEventHandler<HTMLLIElement>;
|
|
246
|
+
onTouchCancelCapture?: React.TouchEventHandler<HTMLLIElement>;
|
|
247
|
+
onTouchEnd?: React.TouchEventHandler<HTMLLIElement>;
|
|
248
|
+
onTouchEndCapture?: React.TouchEventHandler<HTMLLIElement>;
|
|
249
|
+
onTouchMove?: React.TouchEventHandler<HTMLLIElement>;
|
|
250
|
+
onTouchMoveCapture?: React.TouchEventHandler<HTMLLIElement>;
|
|
251
|
+
onTouchStart?: React.TouchEventHandler<HTMLLIElement>;
|
|
252
|
+
onTouchStartCapture?: React.TouchEventHandler<HTMLLIElement>;
|
|
253
|
+
onPointerDown?: React.PointerEventHandler<HTMLLIElement>;
|
|
254
|
+
onPointerDownCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
255
|
+
onPointerMove?: React.PointerEventHandler<HTMLLIElement>;
|
|
256
|
+
onPointerMoveCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
257
|
+
onPointerUp?: React.PointerEventHandler<HTMLLIElement>;
|
|
258
|
+
onPointerUpCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
259
|
+
onPointerCancel?: React.PointerEventHandler<HTMLLIElement>;
|
|
260
|
+
onPointerCancelCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
261
|
+
onPointerEnter?: React.PointerEventHandler<HTMLLIElement>;
|
|
262
|
+
onPointerEnterCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
263
|
+
onPointerLeave?: React.PointerEventHandler<HTMLLIElement>;
|
|
264
|
+
onPointerLeaveCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
265
|
+
onPointerOver?: React.PointerEventHandler<HTMLLIElement>;
|
|
266
|
+
onPointerOverCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
267
|
+
onPointerOut?: React.PointerEventHandler<HTMLLIElement>;
|
|
268
|
+
onPointerOutCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
269
|
+
onGotPointerCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
270
|
+
onGotPointerCaptureCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
271
|
+
onLostPointerCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
272
|
+
onLostPointerCaptureCapture?: React.PointerEventHandler<HTMLLIElement>;
|
|
273
|
+
onScroll?: React.UIEventHandler<HTMLLIElement>;
|
|
274
|
+
onScrollCapture?: React.UIEventHandler<HTMLLIElement>;
|
|
275
|
+
onWheel?: React.WheelEventHandler<HTMLLIElement>;
|
|
276
|
+
onWheelCapture?: React.WheelEventHandler<HTMLLIElement>;
|
|
277
|
+
onAnimationStart?: React.AnimationEventHandler<HTMLLIElement>;
|
|
278
|
+
onAnimationStartCapture?: React.AnimationEventHandler<HTMLLIElement>;
|
|
279
|
+
onAnimationEnd?: React.AnimationEventHandler<HTMLLIElement>;
|
|
280
|
+
onAnimationEndCapture?: React.AnimationEventHandler<HTMLLIElement>;
|
|
281
|
+
onAnimationIteration?: React.AnimationEventHandler<HTMLLIElement>;
|
|
282
|
+
onAnimationIterationCapture?: React.AnimationEventHandler<HTMLLIElement>;
|
|
283
|
+
onTransitionEnd?: React.TransitionEventHandler<HTMLLIElement>;
|
|
284
|
+
onTransitionEndCapture?: React.TransitionEventHandler<HTMLLIElement>;
|
|
285
|
+
}>;
|
|
286
|
+
export {};
|
|
287
|
+
//# sourceMappingURL=Select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../src/select/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AAKtE,UAAU,MAAM;IACd,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEjD,UAAU,KAAK;IACb,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,KAAK,2CAiE1C;AAoCD,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBX,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import Arrow from "./icons/arrow-bottom.svg";
|
|
5
|
+
import useOutsideAlerter from "../outside-alerter/useOutsideAlerter";
|
|
6
|
+
export default function Select(props) {
|
|
7
|
+
const { onChange } = props;
|
|
8
|
+
const [options, setOptions] = useState(null);
|
|
9
|
+
const [isListVisible, setListVisibility] = useState(false);
|
|
10
|
+
const [selectedOption, setSelectedOption] = useState(null);
|
|
11
|
+
const ref = useRef(null);
|
|
12
|
+
const { hasClickedOutside, onReset: onResetOutsideAlerter } = useOutsideAlerter(ref);
|
|
13
|
+
const handleSelectedOptionClick = () => {
|
|
14
|
+
onResetOutsideAlerter();
|
|
15
|
+
setListVisibility(!isListVisible);
|
|
16
|
+
};
|
|
17
|
+
const handleOptionClick = (option) => {
|
|
18
|
+
setSelectedOption(option);
|
|
19
|
+
setListVisibility(false);
|
|
20
|
+
if (onChange) {
|
|
21
|
+
onChange(option);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setOptions(props.options.map((option, index) => (Object.assign(Object.assign({}, option), { id: index }))));
|
|
26
|
+
}, [props.options]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (options) {
|
|
29
|
+
setSelectedOption(options[0]);
|
|
30
|
+
}
|
|
31
|
+
}, [options]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (hasClickedOutside) {
|
|
34
|
+
setListVisibility(false);
|
|
35
|
+
}
|
|
36
|
+
}, [hasClickedOutside]);
|
|
37
|
+
if (!options || !selectedOption) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return (_jsxs(Container, { className: "select", ref: ref, children: [_jsxs(SelectedOptionContainer, { onClick: handleSelectedOptionClick, children: [_jsx(SelectedOptionText, { children: selectedOption.label }), _jsx(SelectedOptionArrow, { src: Arrow })] }), isListVisible && (_jsx(OptionsList, { className: "select-options", children: options
|
|
41
|
+
.filter((option) => option.id !== selectedOption.id)
|
|
42
|
+
.map((option) => (_jsx(Option, { onClick: () => handleOptionClick(option), children: option.label }, option.id))) }))] }));
|
|
43
|
+
}
|
|
44
|
+
const Container = styled.div `
|
|
45
|
+
width: fit-content;
|
|
46
|
+
`;
|
|
47
|
+
const SelectedOptionContainer = styled.div `
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
user-select: none;
|
|
52
|
+
padding: 10px;
|
|
53
|
+
background-color: white;
|
|
54
|
+
border-radius: 5px;
|
|
55
|
+
`;
|
|
56
|
+
const SelectedOptionText = styled.span `
|
|
57
|
+
padding-right: 10px;
|
|
58
|
+
border-right: 1px solid black;
|
|
59
|
+
`;
|
|
60
|
+
const SelectedOptionArrow = styled.img `
|
|
61
|
+
width: 15px;
|
|
62
|
+
margin-left: 10px;
|
|
63
|
+
`;
|
|
64
|
+
const OptionsList = styled.ul `
|
|
65
|
+
width: 100%;
|
|
66
|
+
list-style: none;
|
|
67
|
+
padding: 0;
|
|
68
|
+
margin: 10px 0 0 0;
|
|
69
|
+
user-select: none;
|
|
70
|
+
background-color: white;
|
|
71
|
+
border-radius: 5px;
|
|
72
|
+
`;
|
|
73
|
+
const Option = styled.li `
|
|
74
|
+
padding: 10px;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
|
|
77
|
+
&:hover {
|
|
78
|
+
background-color: #ecf0f1;
|
|
79
|
+
|
|
80
|
+
&:first-child {
|
|
81
|
+
border-radius: 5px 5px 0 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&:last-child {
|
|
85
|
+
border-radius: 0 0 5px 5px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&:only-child {
|
|
89
|
+
border-radius: 5px;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
`;
|