@bbl-digital/snorre 3.0.6 → 3.0.9

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { IProps, IValuesProps } from '../index.d';
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;
@@ -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,YAAY,CAAA;AAEjD,QAAA,MAAM,eAAe,UAAW,MAAM;;;;;;uBAuBV,MAAM,WAAW,CAAC,gBAAgB,CAAC;yBAmJjC,mBAAmB,CAAC,gBAAgB,CAAC;+BAZ/B,mBAAmB,CAAC,gBAAgB,CAAC;;qBAtH/C,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC;;;;;CA+MpE,CAAA;AAED,eAAe,eAAe,CAAA"}
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;yBAgJjC,mBAAmB,CAAC,gBAAgB,CAAC;+BAZ/B,mBAAmB,CAAC,gBAAgB,CAAC;;qBAnH/C,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC;;;;;CA4MpE,CAAA;AAED,eAAe,eAAe,CAAA"}
@@ -38,8 +38,6 @@ const useAutocomplete = props => {
38
38
  const onFuzzyBlur = e => {
39
39
  // If the value of the input is changed, and does not match the value of the values array,
40
40
  // we should revert back the input value to the original value
41
- //What
42
- // if (!e.target.value.length) clearSelectedItem()
43
41
  if (e.target.value === props.value) return; // If target value is the same as a value from the values array, we should set the value for the user
44
42
 
45
43
  if (inputValues?.length) {
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ declare const useHandleDimentions: () => {
3
+ height: number;
4
+ width: number;
5
+ dimentionsRef: import("react").RefObject<any>;
6
+ };
7
+ export default useHandleDimentions;
8
+ //# sourceMappingURL=useHandleDimentions.d.ts.map
@@ -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.d';
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,WAAW,CAAA;AAGlC,oBAAY,GAAG,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAA;AAEhD,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CA+KjC,CAAA;AAEF,eAAe,YAAY,CAAA"}
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,CAoLjC,CAAA;AAEF,eAAe,YAAY,CAAA"}
@@ -0,0 +1,81 @@
1
+ import { SerializedStyles } from '@emotion/react';
2
+ import { ReactNode } from 'react';
3
+ export interface IValuesProps {
4
+ /** The default key name is key */
5
+ /** The default display name is label */
6
+ /** When setting any other than label/key as default, use labelFromValues and keyFromValues for this */
7
+ [x: string]: string;
8
+ }
9
+ export interface IProps {
10
+ /** Input label */
11
+ label?: string;
12
+ /** Secondary label placed on the top right of the autocomplete */
13
+ labelSecondary?: ReactNode;
14
+ /** Autofocus */
15
+ focus?: boolean;
16
+ /** Placeholder text */
17
+ placeholder?: string;
18
+ /** Default value. */
19
+ value?: string;
20
+ /** Disabled. */
21
+ disabled?: boolean;
22
+ /** Callback fired when blur. */
23
+ onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
24
+ /** Callback fired when focus. */
25
+ onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
26
+ /** Callback fired when the value changes. */
27
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>, reason?: string) => void;
28
+ /** Children. */
29
+ children?: ReactNode;
30
+ /** Include if input field should include debound effect after typing. Specifices delay in ms */
31
+ debounceDelay?: number;
32
+ /** Sends up the value from a option click */
33
+ onSelectItem?: (value: {
34
+ [x: string]: any;
35
+ }) => void;
36
+ /** Callback when using debounce. */
37
+ onDebounceChange?: (value: string) => void;
38
+ /** A button instead of standard label, requires to set a label */
39
+ onLabelClick?: (e: React.MouseEvent) => void;
40
+ /** Custom on key down handler */
41
+ onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
42
+ /** Specify override styling */
43
+ css?: SerializedStyles;
44
+ /** Input name */
45
+ name?: string;
46
+ /** Validation on input */
47
+ validation?: boolean;
48
+ /** Invalid message */
49
+ invalidMessage?: string;
50
+ /** Activates invalid styling for custom external validation */
51
+ invalid?: boolean;
52
+ /** Set the height of the input, border comes in addition to height */
53
+ height?: string;
54
+ /** Sets a spinner on the input */
55
+ loading?: boolean;
56
+ /** Sets actions on the end of the input field */
57
+ actions?: ReactNode;
58
+ /** Renders options shown under input */
59
+ renderOptions?: ReactNode[] | ReactNode;
60
+ /** Places values dynamically to the input field, defaults to being placed under the input field */
61
+ dynamicallyPlaceInput?: boolean;
62
+ /** Renders a custom input list */
63
+ renderCustomValueInput?: ReactNode;
64
+ /** Open custom value input when starting to write */
65
+ openCustomValueInputOnKeyPress?: boolean;
66
+ /** Values to list out */
67
+ values?: IValuesProps[];
68
+ /** Gets specific value as label from values property */
69
+ labelFromValues?: string;
70
+ /** Gets specific value as key from values property */
71
+ keyFromValues?: string;
72
+ /** Max width of the input values */
73
+ inputValuesMaxWidth?: number;
74
+ /** Custom open for showing values */
75
+ isOpen?: boolean;
76
+ /** Has fuzzy search */
77
+ fuzzy?: boolean;
78
+ /** Has clear button */
79
+ clear?: boolean;
80
+ }
81
+ //# sourceMappingURL=index.interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.interfaces.d.ts","sourceRoot":"","sources":["../../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AAK,CAAC,EAAE,OAAO,CAAA;CAChB"}
@@ -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 useHandleOptionsHeight from './utils/useHandleOptionsHeight';
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
- } = useHandleOptionsHeight();
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,
@@ -54,8 +58,9 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
54
58
  }, [showValues, valuesRef]);
55
59
  return _jsxs(_Fragment, {
56
60
  children: [_jsxs("label", {
57
- 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],
61
+ ref: inputWrapperRef,
58
62
  onClick: props.onLabelClick ? e => e.preventDefault() : undefined,
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],
59
64
  children: [_jsxs("span", {
60
65
  css: styles.label,
61
66
  children: [props.label && (props.onLabelClick ? _jsx(Link, {
@@ -113,7 +118,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
113
118
  })]
114
119
  }), (Boolean(props.values?.length) || props.renderCustomValueInput) && !props.loading && showValues && _jsxs("div", {
115
120
  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)],
121
+ 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
122
  children: [Boolean(renderedValues?.length) && _jsx("ul", {
118
123
  css: theme => [styles.list(theme)],
119
124
  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;;iCAQL,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"}
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"}