@bbl-digital/snorre 3.0.6 → 3.0.7
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/bundle.js +47 -40
- package/esm/core/Autocomplete/hooks/useAutocomplete.js +6 -0
- package/esm/core/Autocomplete/hooks/useHandleDimentions.js +19 -0
- package/esm/core/Autocomplete/index.interfaces.js +1 -0
- package/esm/core/Autocomplete/index.js +13 -7
- package/esm/core/Autocomplete/styles.js +18 -26
- package/lib/core/Autocomplete/hooks/useAutocomplete.d.ts +2 -1
- package/lib/core/Autocomplete/hooks/useAutocomplete.d.ts.map +1 -1
- package/lib/core/Autocomplete/hooks/useAutocomplete.js +6 -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.ts +1 -1
- package/lib/core/Autocomplete/index.d.ts.map +1 -1
- package/lib/core/Autocomplete/index.interfaces.d.ts +80 -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 +13 -7
- package/lib/core/Autocomplete/styles.d.ts +1 -1
- package/lib/core/Autocomplete/styles.d.ts.map +1 -1
- package/lib/core/Autocomplete/styles.js +18 -26
- package/package.json +1 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
-
import { IProps, IValuesProps } from '../index.
|
2
|
+
import { IProps, IValuesProps } from '../index.interfaces';
|
3
3
|
declare const useAutocomplete: (props: IProps) => {
|
4
4
|
setShowValues: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
5
5
|
handleClear: () => void;
|
@@ -11,6 +11,7 @@ declare const useAutocomplete: (props: IProps) => {
|
|
11
11
|
handleCustomOnKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
12
12
|
handleOnInputClick: () => void;
|
13
13
|
onFuzzyBlur: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
|
14
|
+
onFuzzyFocus: () => void;
|
14
15
|
value: string;
|
15
16
|
highlightedIndex: number | null;
|
16
17
|
showValues: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAutocomplete.d.ts","sourceRoot":"","sources":["../../../../src/packages/core/Autocomplete/hooks/useAutocomplete.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"useAutocomplete.d.ts","sourceRoot":"","sources":["../../../../src/packages/core/Autocomplete/hooks/useAutocomplete.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE1D,QAAA,MAAM,eAAe,UAAW,MAAM;;;;;;uBAuBV,MAAM,WAAW,CAAC,gBAAgB,CAAC;yBAwJjC,mBAAmB,CAAC,gBAAgB,CAAC;+BAZ/B,mBAAmB,CAAC,gBAAgB,CAAC;;qBA3H/C,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC;;;;;;CAqNpE,CAAA;AAED,eAAe,eAAe,CAAA"}
|
@@ -57,6 +57,11 @@ const useAutocomplete = props => {
|
|
57
57
|
}
|
58
58
|
};
|
59
59
|
|
60
|
+
const onFuzzyFocus = () => {
|
61
|
+
setValueChanged('');
|
62
|
+
if (props.values?.length) setShowValues(true);
|
63
|
+
};
|
64
|
+
|
60
65
|
const renderedValues = useMemo(() => {
|
61
66
|
if (!props.values?.length) return [];
|
62
67
|
|
@@ -226,6 +231,7 @@ const useAutocomplete = props => {
|
|
226
231
|
handleCustomOnKeyDown,
|
227
232
|
handleOnInputClick,
|
228
233
|
onFuzzyBlur,
|
234
|
+
onFuzzyFocus,
|
229
235
|
value,
|
230
236
|
highlightedIndex,
|
231
237
|
showValues,
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useHandleDimentions.d.ts","sourceRoot":"","sources":["../../../../src/packages/core/Autocomplete/hooks/useHandleDimentions.ts"],"names":[],"mappings":";AAEA,QAAA,MAAM,mBAAmB;;;;CAaxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { createRef, useEffect, useState } from 'react';
|
2
|
+
|
3
|
+
const useHandleDimentions = () => {
|
4
|
+
const [height, setHeight] = useState(0);
|
5
|
+
const [width, setWidth] = useState(0);
|
6
|
+
const dimentionsRef = /*#__PURE__*/createRef();
|
7
|
+
useEffect(() => {
|
8
|
+
const rect = dimentionsRef.current?.getBoundingClientRect();
|
9
|
+
setHeight(rect?.height || 0);
|
10
|
+
setWidth(rect?.width || 0); // eslint-disable-next-line react-hooks/exhaustive-deps
|
11
|
+
}, [dimentionsRef.current]);
|
12
|
+
return {
|
13
|
+
height,
|
14
|
+
width,
|
15
|
+
dimentionsRef
|
16
|
+
};
|
17
|
+
};
|
18
|
+
|
19
|
+
export default useHandleDimentions;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
2
2
|
import React, { ForwardedRef } from 'react';
|
3
|
-
import { IProps } from './index.
|
3
|
+
import { IProps } from './index.interfaces';
|
4
4
|
export declare type Ref = ForwardedRef<HTMLInputElement>;
|
5
5
|
declare const Autocomplete: React.FC<IProps>;
|
6
6
|
export default Autocomplete;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/Autocomplete/index.tsx"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAa,YAAY,EAAE,MAAM,OAAO,CAAA;AAQtD,OAAO,EAAE,MAAM,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/Autocomplete/index.tsx"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAa,YAAY,EAAE,MAAM,OAAO,CAAA;AAQtD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAG3C,oBAAY,GAAG,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAA;AAEhD,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAqLjC,CAAA;AAEF,eAAe,YAAY,CAAA"}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import { SerializedStyles } from '@emotion/react';
|
2
|
+
import { ReactNode } from 'react';
|
3
|
+
export interface IValuesProps {
|
4
|
+
key: string;
|
5
|
+
label: string;
|
6
|
+
[x: string]: string;
|
7
|
+
}
|
8
|
+
export interface IProps {
|
9
|
+
/** Input label */
|
10
|
+
label?: string;
|
11
|
+
/** Secondary label placed on the top right of the autocomplete */
|
12
|
+
labelSecondary?: ReactNode;
|
13
|
+
/** Autofocus */
|
14
|
+
focus?: boolean;
|
15
|
+
/** Placeholder text */
|
16
|
+
placeholder?: string;
|
17
|
+
/** Default value. */
|
18
|
+
value?: string;
|
19
|
+
/** Disabled. */
|
20
|
+
disabled?: boolean;
|
21
|
+
/** Callback fired when blur. */
|
22
|
+
onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
23
|
+
/** Callback fired when focus. */
|
24
|
+
onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
25
|
+
/** Callback fired when the value changes. */
|
26
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>, reason?: string) => void;
|
27
|
+
/** Children. */
|
28
|
+
children?: ReactNode;
|
29
|
+
/** Include if input field should include debound effect after typing. Specifices delay in ms */
|
30
|
+
debounceDelay?: number;
|
31
|
+
/** Sends up the value from a option click */
|
32
|
+
onSelectItem?: (value: {
|
33
|
+
[x: string]: any;
|
34
|
+
}) => void;
|
35
|
+
/** Callback when using debounce. */
|
36
|
+
onDebounceChange?: (value: string) => void;
|
37
|
+
/** A button instead of standard label, requires to set a label */
|
38
|
+
onLabelClick?: (e: React.MouseEvent) => void;
|
39
|
+
/** Custom on key down handler */
|
40
|
+
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
41
|
+
/** Specify override styling */
|
42
|
+
css?: SerializedStyles;
|
43
|
+
/** Input name */
|
44
|
+
name?: string;
|
45
|
+
/** Validation on input */
|
46
|
+
validation?: boolean;
|
47
|
+
/** Invalid message */
|
48
|
+
invalidMessage?: string;
|
49
|
+
/** Activates invalid styling for custom external validation */
|
50
|
+
invalid?: boolean;
|
51
|
+
/** Set the height of the input, border comes in addition to height */
|
52
|
+
height?: string;
|
53
|
+
/** Sets a spinner on the input */
|
54
|
+
loading?: boolean;
|
55
|
+
/** Sets actions on the end of the input field */
|
56
|
+
actions: ReactNode;
|
57
|
+
/** Renders options shown under input */
|
58
|
+
renderOptions?: ReactNode[] | ReactNode;
|
59
|
+
/** Places values dynamically to the input field, defaults to being placed under the input field */
|
60
|
+
dynamicallyPlaceInput?: boolean;
|
61
|
+
/** Renders a custom input list */
|
62
|
+
renderCustomValueInput?: ReactNode;
|
63
|
+
/** Open custom value input when starting to write */
|
64
|
+
openCustomValueInputOnKeyPress?: boolean;
|
65
|
+
/** Values to list out */
|
66
|
+
values?: IValuesProps[];
|
67
|
+
/** Gets specific value as label from values property */
|
68
|
+
labelFromValues?: string;
|
69
|
+
/** Gets specific value as key from values property */
|
70
|
+
keyFromValues?: string;
|
71
|
+
/** Max width of the input values */
|
72
|
+
inputValuesMaxWidth?: number;
|
73
|
+
/** Custom open for showing values */
|
74
|
+
isOpen?: boolean;
|
75
|
+
/** Has fuzzy search */
|
76
|
+
fuzzy?: boolean;
|
77
|
+
/** Has clear button */
|
78
|
+
clear?: boolean;
|
79
|
+
}
|
80
|
+
//# sourceMappingURL=index.interfaces.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.interfaces.d.ts","sourceRoot":"","sources":["../../../src/packages/core/Autocomplete/index.interfaces.ts"],"names":[],"mappings":"AAAA,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0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -4,7 +4,7 @@ import { styles, ErrorMessage, Clear } from './styles';
|
|
4
4
|
import { useEffect } from 'react';
|
5
5
|
import IconErrorOutline from '../../icons/General/IconErrorOutline';
|
6
6
|
import Spinner from '../Spinner';
|
7
|
-
import
|
7
|
+
import useHandleDimentions from './hooks/useHandleDimentions';
|
8
8
|
import Link from '../Link';
|
9
9
|
import IconClose from '../../icons/General/IconClose';
|
10
10
|
import useAutocomplete from './hooks/useAutocomplete';
|
@@ -18,9 +18,13 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
18
18
|
}, ref) => {
|
19
19
|
const valuesRef = /*#__PURE__*/createRef();
|
20
20
|
const {
|
21
|
-
optionsHeight,
|
22
|
-
optionsRef
|
23
|
-
} =
|
21
|
+
height: optionsHeight,
|
22
|
+
dimentionsRef: optionsRef
|
23
|
+
} = useHandleDimentions();
|
24
|
+
const {
|
25
|
+
width: inputWrapperWidth,
|
26
|
+
dimentionsRef: inputWrapperRef
|
27
|
+
} = useHandleDimentions();
|
24
28
|
const {
|
25
29
|
value,
|
26
30
|
highlightedIndex,
|
@@ -33,7 +37,8 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
33
37
|
handleOnKeyDown,
|
34
38
|
handleValueClick,
|
35
39
|
onInputChange,
|
36
|
-
onFuzzyBlur
|
40
|
+
onFuzzyBlur,
|
41
|
+
onFuzzyFocus
|
37
42
|
} = useAutocomplete(props);
|
38
43
|
useEffect(() => {
|
39
44
|
const handleClickOutside = e => {
|
@@ -54,6 +59,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
54
59
|
}, [showValues, valuesRef]);
|
55
60
|
return _jsxs(_Fragment, {
|
56
61
|
children: [_jsxs("label", {
|
62
|
+
ref: inputWrapperRef,
|
57
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],
|
58
64
|
onClick: props.onLabelClick ? e => e.preventDefault() : undefined,
|
59
65
|
children: [_jsxs("span", {
|
@@ -77,7 +83,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
77
83
|
disabled: props.disabled,
|
78
84
|
autoFocus: props.focus,
|
79
85
|
onBlur: props.fuzzy ? onFuzzyBlur : props.onBlur,
|
80
|
-
onFocus: props.onFocus,
|
86
|
+
onFocus: props.fuzzy ? onFuzzyFocus : props.onFocus,
|
81
87
|
onChange: onInputChange,
|
82
88
|
onKeyDown: props.onKeyDown ? handleCustomOnKeyDown : handleOnKeyDown,
|
83
89
|
onClick: handleOnInputClick,
|
@@ -113,7 +119,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
|
|
113
119
|
})]
|
114
120
|
}), (Boolean(props.values?.length) || props.renderCustomValueInput) && !props.loading && showValues && _jsxs("div", {
|
115
121
|
ref: valuesRef,
|
116
|
-
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)],
|
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)],
|
117
123
|
children: [Boolean(renderedValues?.length) && _jsx("ul", {
|
118
124
|
css: theme => [styles.list(theme)],
|
119
125
|
children: renderedValues.map((item, index) => {
|
@@ -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;
|
@@ -1 +1 @@
|
|
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
|
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"}
|