@bbl-digital/snorre 3.0.4 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +204 -96
- package/esm/core/Autocomplete/hooks/useAutocomplete.js +242 -0
- package/esm/core/Autocomplete/hooks/useHandleDimentions.js +19 -0
- package/esm/core/Autocomplete/index.d.js +1 -0
- package/esm/core/Autocomplete/index.interfaces.js +1 -0
- package/esm/core/Autocomplete/index.js +50 -184
- package/esm/core/Autocomplete/styles.js +30 -25
- package/esm/core/DatepickerRange/YearMonthForm.js +56 -0
- package/lib/core/Autocomplete/hooks/useAutocomplete.d.ts +21 -0
- package/lib/core/Autocomplete/hooks/useAutocomplete.d.ts.map +1 -0
- package/lib/core/Autocomplete/hooks/useAutocomplete.js +242 -0
- package/lib/core/Autocomplete/hooks/useHandleDimentions.d.ts +8 -0
- package/lib/core/Autocomplete/hooks/useHandleDimentions.d.ts.map +1 -0
- package/lib/core/Autocomplete/hooks/useHandleDimentions.js +19 -0
- package/lib/core/Autocomplete/index.d.js +1 -0
- package/lib/core/Autocomplete/index.d.ts +2 -74
- package/lib/core/Autocomplete/index.d.ts.map +1 -1
- package/lib/core/Autocomplete/index.interfaces.d.ts +81 -0
- package/lib/core/Autocomplete/index.interfaces.d.ts.map +1 -0
- package/lib/core/Autocomplete/index.interfaces.js +1 -0
- package/lib/core/Autocomplete/index.js +50 -184
- package/lib/core/Autocomplete/styles.d.ts +18 -1
- package/lib/core/Autocomplete/styles.d.ts.map +1 -1
- package/lib/core/Autocomplete/styles.js +30 -25
- package/lib/core/DatepickerRange/YearMonthForm.d.ts +10 -0
- package/lib/core/DatepickerRange/YearMonthForm.d.ts.map +1 -0
- package/lib/core/DatepickerRange/YearMonthForm.js +56 -0
- package/package.json +2 -1
- package/esm/enums/ModifierKey.js +0 -13
- package/lib/enums/ModifierKey.d.ts +0 -12
- package/lib/enums/ModifierKey.d.ts.map +0 -1
- package/lib/enums/ModifierKey.js +0 -13
@@ -1,192 +1,49 @@
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
2
|
-
import React, { createRef
|
3
|
-
import { styles, ErrorMessage } from './styles';
|
2
|
+
import React, { createRef } from 'react';
|
3
|
+
import { styles, ErrorMessage, Clear } from './styles';
|
4
4
|
import { useEffect } from 'react';
|
5
|
-
import { useDebounce } from '../utils/debounce';
|
6
5
|
import IconErrorOutline from '../../icons/General/IconErrorOutline';
|
7
6
|
import Spinner from '../Spinner';
|
8
|
-
import
|
7
|
+
import useHandleDimentions from './hooks/useHandleDimentions';
|
9
8
|
import Link from '../Link';
|
9
|
+
import IconClose from '../../icons/General/IconClose';
|
10
|
+
import useAutocomplete from './hooks/useAutocomplete';
|
10
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
11
12
|
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
12
13
|
import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
13
14
|
const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
14
|
-
onDebounceChange,
|
15
|
-
debounceDelay,
|
16
15
|
height,
|
17
16
|
css,
|
18
17
|
...props
|
19
18
|
}, ref) => {
|
20
|
-
const {
|
21
|
-
optionsHeight,
|
22
|
-
optionsRef
|
23
|
-
} = useHandleOptionsHeight();
|
24
19
|
const valuesRef = /*#__PURE__*/createRef();
|
25
|
-
const
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
const
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
const handleEnter = e => {
|
49
|
-
e.preventDefault();
|
50
|
-
e.stopPropagation();
|
51
|
-
if (!showValues) return;
|
52
|
-
|
53
|
-
if (!props.values?.length) {
|
54
|
-
// If there is no autocomplete value in the list, send object with just { value }
|
55
|
-
props.onSelectItem?.({
|
56
|
-
value
|
57
|
-
});
|
58
|
-
}
|
59
|
-
|
60
|
-
if (highlightedIndex === null || !props.values?.length) {
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
|
64
|
-
const item = props.values[highlightedIndex];
|
65
|
-
props.onSelectItem?.(item);
|
66
|
-
setShowValues(false);
|
67
|
-
};
|
68
|
-
|
69
|
-
const handleUp = e => {
|
70
|
-
e.preventDefault();
|
71
|
-
e.stopPropagation();
|
72
|
-
if (!showValues) return;
|
73
|
-
|
74
|
-
if (highlightedIndex === null || !props.values?.length) {
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
|
78
|
-
const newHighlightIndex = highlightedIndex - 1;
|
79
|
-
|
80
|
-
if (newHighlightIndex < 0) {
|
81
|
-
setHighlightedIndex(null);
|
82
|
-
setShowValues(false);
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
|
86
|
-
setHighlightedIndex(newHighlightIndex);
|
87
|
-
};
|
88
|
-
|
89
|
-
const handleDown = e => {
|
90
|
-
if (!showValues) return;
|
91
|
-
e.preventDefault();
|
92
|
-
e.stopPropagation();
|
93
|
-
|
94
|
-
if (highlightedIndex === null || !props.values?.length) {
|
95
|
-
return;
|
96
|
-
}
|
97
|
-
|
98
|
-
const newHighlightIndex = highlightedIndex + 1;
|
99
|
-
|
100
|
-
if (newHighlightIndex === props.values.length) {
|
101
|
-
setHighlightedIndex(null);
|
102
|
-
setShowValues(false);
|
103
|
-
return;
|
104
|
-
}
|
105
|
-
|
106
|
-
setHighlightedIndex(newHighlightIndex);
|
107
|
-
};
|
108
|
-
|
109
|
-
const handleEscape = () => {
|
110
|
-
setShowValues(false);
|
111
|
-
setHighlightedIndex(null);
|
112
|
-
};
|
113
|
-
|
114
|
-
const handleCustomOnKeyDown = e => {
|
115
|
-
const {
|
116
|
-
key
|
117
|
-
} = e;
|
118
|
-
|
119
|
-
if (key === 'Escape') {
|
120
|
-
handleEscape();
|
121
|
-
return;
|
122
|
-
}
|
123
|
-
|
124
|
-
props.onKeyDown?.(e);
|
125
|
-
};
|
126
|
-
|
127
|
-
const handleOnKeyDown = e => {
|
128
|
-
const {
|
129
|
-
key
|
130
|
-
} = e;
|
131
|
-
|
132
|
-
if (showValues && props.values?.length) {
|
133
|
-
setHighlightedIndex(0);
|
134
|
-
} else {
|
135
|
-
setHighlightedIndex(null);
|
136
|
-
}
|
137
|
-
|
138
|
-
switch (key) {
|
139
|
-
case 'Enter':
|
140
|
-
handleEnter(e);
|
141
|
-
break;
|
142
|
-
|
143
|
-
case 'ArrowUp':
|
144
|
-
handleUp(e);
|
145
|
-
break;
|
146
|
-
|
147
|
-
case 'ArrowDown':
|
148
|
-
case 'Tab':
|
149
|
-
handleDown(e);
|
150
|
-
break;
|
151
|
-
|
152
|
-
case 'Escape':
|
153
|
-
handleEscape();
|
154
|
-
break;
|
155
|
-
|
156
|
-
default:
|
157
|
-
break;
|
158
|
-
}
|
159
|
-
}; // Handle debounce
|
160
|
-
|
161
|
-
|
162
|
-
useEffect(() => {
|
163
|
-
const handleDebounceChange = value => {
|
164
|
-
if (onDebounceChange && inputDirty) {
|
165
|
-
onDebounceChange(value);
|
166
|
-
}
|
167
|
-
};
|
168
|
-
|
169
|
-
handleDebounceChange(debouncedValue); // eslint-disable-next-line react-hooks/exhaustive-deps
|
170
|
-
}, [debouncedValue]);
|
171
|
-
useEffect(() => {
|
172
|
-
setShowValues(!!props.isOpen);
|
173
|
-
}, [props.isOpen]);
|
174
|
-
useEffect(() => {
|
175
|
-
const value = props.value ? props.value : '';
|
176
|
-
setValueChanged(value);
|
177
|
-
}, [props.value]);
|
178
|
-
useEffect(() => {
|
179
|
-
if (!props.openCustomValueInputOnKeyPress) return;
|
180
|
-
if (value.length) setShowValues(true); // eslint-disable-next-line react-hooks/exhaustive-deps
|
181
|
-
}, [value]);
|
20
|
+
const {
|
21
|
+
height: optionsHeight,
|
22
|
+
dimentionsRef: optionsRef
|
23
|
+
} = useHandleDimentions();
|
24
|
+
const {
|
25
|
+
width: inputWrapperWidth,
|
26
|
+
dimentionsRef: inputWrapperRef
|
27
|
+
} = useHandleDimentions();
|
28
|
+
const {
|
29
|
+
value,
|
30
|
+
highlightedIndex,
|
31
|
+
showValues,
|
32
|
+
renderedValues,
|
33
|
+
setShowValues,
|
34
|
+
handleClear,
|
35
|
+
handleOnInputClick,
|
36
|
+
handleCustomOnKeyDown,
|
37
|
+
handleOnKeyDown,
|
38
|
+
handleValueClick,
|
39
|
+
onInputChange,
|
40
|
+
onFuzzyBlur,
|
41
|
+
onFuzzyFocus
|
42
|
+
} = useAutocomplete(props);
|
182
43
|
useEffect(() => {
|
183
44
|
const handleClickOutside = e => {
|
184
45
|
const node = valuesRef.current;
|
185
|
-
|
186
|
-
if (node && node.contains(e.target)) {
|
187
|
-
return;
|
188
|
-
}
|
189
|
-
|
46
|
+
if (node && node.contains(e.target)) return;
|
190
47
|
setShowValues(false);
|
191
48
|
};
|
192
49
|
|
@@ -198,10 +55,11 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
198
55
|
|
199
56
|
return () => {
|
200
57
|
document.removeEventListener('mousedown', handleClickOutside);
|
201
|
-
};
|
58
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
202
59
|
}, [showValues, valuesRef]);
|
203
60
|
return _jsxs(_Fragment, {
|
204
61
|
children: [_jsxs("label", {
|
62
|
+
ref: inputWrapperRef,
|
205
63
|
css: theme => [styles.default(theme), (props.invalid || props.invalidMessage) && styles.invalid(theme), props.validation && styles.validation, props.onLabelClick && styles.clickableLabel, height && styles.height(height), css && css],
|
206
64
|
onClick: props.onLabelClick ? e => e.preventDefault() : undefined,
|
207
65
|
children: [_jsxs("span", {
|
@@ -224,8 +82,8 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
224
82
|
value: value,
|
225
83
|
disabled: props.disabled,
|
226
84
|
autoFocus: props.focus,
|
227
|
-
onBlur: props.onBlur,
|
228
|
-
onFocus: props.onFocus,
|
85
|
+
onBlur: props.fuzzy ? onFuzzyBlur : props.onBlur,
|
86
|
+
onFocus: props.fuzzy ? onFuzzyFocus : props.onFocus,
|
229
87
|
onChange: onInputChange,
|
230
88
|
onKeyDown: props.onKeyDown ? handleCustomOnKeyDown : handleOnKeyDown,
|
231
89
|
onClick: handleOnInputClick,
|
@@ -234,6 +92,12 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
234
92
|
autoComplete: "off",
|
235
93
|
css: theme => [props.disabled && styles.disabled(theme)],
|
236
94
|
children: React.Children.map(props.children, child => child || null)
|
95
|
+
}), props.clear && _jsx(Clear, {
|
96
|
+
nostyle: true,
|
97
|
+
onClick: handleClear,
|
98
|
+
children: _jsx(IconClose, {
|
99
|
+
size: 14
|
100
|
+
})
|
237
101
|
}), props.loading && _jsx(Spinner, {
|
238
102
|
size: 14
|
239
103
|
}), props.actions && _jsx("div", {
|
@@ -253,17 +117,19 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
253
117
|
children: props.invalidMessage
|
254
118
|
})]
|
255
119
|
})]
|
256
|
-
}), (props.values?.length || props.renderCustomValueInput) && !props.loading && showValues && _jsxs("div", {
|
120
|
+
}), (Boolean(props.values?.length) || props.renderCustomValueInput) && !props.loading && showValues && _jsxs("div", {
|
257
121
|
ref: valuesRef,
|
258
|
-
css: () => [!props.renderCustomValueInput && styles.listWrapper, props.dynamicallyPlaceInput && Boolean(optionsHeight) && styles.listWrapperTopPosition(optionsHeight), props.dynamicallyPlaceInput && Boolean(optionsHeight) && props.invalidMessage && styles.listWrapperTopPosition(optionsHeight + 30), props.inputValuesMaxWidth && styles.listWrapperMaxWidth(props.inputValuesMaxWidth)],
|
259
|
-
children: [
|
122
|
+
css: () => [!props.renderCustomValueInput && styles.listWrapper(inputWrapperWidth), props.dynamicallyPlaceInput && Boolean(optionsHeight) && styles.listWrapperTopPosition(optionsHeight), props.dynamicallyPlaceInput && Boolean(optionsHeight) && props.invalidMessage && styles.listWrapperTopPosition(optionsHeight + 30), props.inputValuesMaxWidth && styles.listWrapperMaxWidth(props.inputValuesMaxWidth)],
|
123
|
+
children: [Boolean(renderedValues?.length) && _jsx("ul", {
|
260
124
|
css: theme => [styles.list(theme)],
|
261
|
-
children:
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
125
|
+
children: renderedValues.map((item, index) => {
|
126
|
+
return _jsx("li", {
|
127
|
+
tabIndex: 0,
|
128
|
+
css: index === highlightedIndex ? styles.highlightedItem : null,
|
129
|
+
onClick: () => handleValueClick(item),
|
130
|
+
children: props.labelFromValues ? item[props.labelFromValues] : item.label
|
131
|
+
}, props.keyFromValues ? item[props.keyFromValues] : item.key);
|
132
|
+
})
|
267
133
|
}), props.renderCustomValueInput && _jsx("div", {
|
268
134
|
children: props.renderCustomValueInput
|
269
135
|
})]
|
@@ -9,7 +9,7 @@ declare const styles: {
|
|
9
9
|
validation: import("@emotion/react").SerializedStyles;
|
10
10
|
list: (theme: IAppTheme) => import("@emotion/react").SerializedStyles;
|
11
11
|
highlightedItem: (theme: IAppTheme) => import("@emotion/react").SerializedStyles;
|
12
|
-
listWrapper: import("@emotion/react").SerializedStyles;
|
12
|
+
listWrapper: (width: number) => import("@emotion/react").SerializedStyles;
|
13
13
|
listWrapperMaxWidth: (width: number) => import("@emotion/react").SerializedStyles;
|
14
14
|
listWrapperTopPosition: (top: number) => import("@emotion/react").SerializedStyles;
|
15
15
|
invalid: (theme: IAppTheme) => import("@emotion/react").SerializedStyles;
|
@@ -18,6 +18,23 @@ declare const styles: {
|
|
18
18
|
disabled: (theme: IAppTheme) => import("@emotion/react").SerializedStyles;
|
19
19
|
};
|
20
20
|
export declare const ErrorMessage: (theme: IAppTheme) => import("@emotion/react").SerializedStyles;
|
21
|
+
export declare const Clear: import("@emotion/styled").StyledComponent<import("../private/ButtonOrLink").Props & {
|
22
|
+
success?: boolean | undefined;
|
23
|
+
danger?: boolean | undefined;
|
24
|
+
highlight?: boolean | undefined;
|
25
|
+
outline?: boolean | undefined;
|
26
|
+
nostyle?: boolean | undefined;
|
27
|
+
focusable?: boolean | undefined;
|
28
|
+
border?: string | undefined;
|
29
|
+
css?: import("@emotion/react").SerializedStyles | undefined;
|
30
|
+
loading?: boolean | undefined;
|
31
|
+
back?: boolean | undefined;
|
32
|
+
small?: boolean | undefined;
|
33
|
+
transparentBg?: boolean | undefined;
|
34
|
+
tabIndex?: number | undefined;
|
35
|
+
} & {
|
36
|
+
theme?: import("@emotion/react").Theme | undefined;
|
37
|
+
}, {}, {}>;
|
21
38
|
export default styles;
|
22
39
|
export { styles };
|
23
40
|
//# sourceMappingURL=styles.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/packages/core/Autocomplete/styles.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/packages/core/Autocomplete/styles.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAIjD,QAAA,MAAM,MAAM;qBACO,SAAS;;;0BA2DJ,SAAS;;;;kBAuCjB,SAAS;6BAyBE,SAAS;yBAGb,MAAM;iCAOE,MAAM;kCAGL,MAAM;qBAGnB,SAAS;4BAYF,SAAS;qBA4BhB,MAAM;sBAKL,SAAS;CAM5B,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,SAAS,8CAM5C,CAAA;AAED,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;UAcjB,CAAA;AAED,eAAe,MAAM,CAAA;AAErB,OAAO,EAAE,MAAM,EAAE,CAAA"}
|