@bbl-digital/snorre 3.0.11 → 3.0.15

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 CHANGED
@@ -30324,6 +30324,7 @@
30324
30324
  css,
30325
30325
  validation,
30326
30326
  invalidMessage,
30327
+ autoFocus,
30327
30328
  onChange,
30328
30329
  onBlur
30329
30330
  }) => {
@@ -30421,6 +30422,7 @@
30421
30422
  type: "text",
30422
30423
  value: inputStateValue,
30423
30424
  disabled: disabled,
30425
+ autoFocus: autoFocus,
30424
30426
  css: theme => [disabled && styles$7.disabled(theme), css && css],
30425
30427
  onChange: event => onInputChange(event, v => onChange && onChange(v)),
30426
30428
  onBlur: onBlur,
@@ -31850,41 +31852,45 @@
31850
31852
  const [inputDirty, setInputDirty] = React.useState(false);
31851
31853
  const debouncedValue = useDebounce(value, props.debounceDelay ?? 0);
31852
31854
  const [inputValues, setInputValues] = React.useState(props.values);
31855
+ const labelKey = props.labelFromValues ?? 'label';
31853
31856
 
31854
31857
  const handleValueClick = value => {
31855
31858
  props.onSelectItem?.(value);
31859
+ if (props.fuzzy) setValueChanged(value[labelKey]);
31856
31860
  setShowValues(false);
31857
31861
  };
31858
31862
 
31859
31863
  const clearSelectedItem = () => handleValueClick({
31860
- [props.labelFromValues ?? 'label']: '',
31864
+ [labelKey]: '',
31861
31865
  [props.keyFromValues ?? 'key']: ''
31862
31866
  });
31863
31867
 
31864
31868
  const onInputChange = e => {
31865
31869
  setInputDirty(true);
31866
- if (inputValues) setHighlightedIndex(0);
31870
+ if (renderedValues) setHighlightedIndex(0);
31867
31871
  setValueChanged(e.target.value); // Should not use onChange whenever we have fuzzy search on
31868
31872
 
31869
- if (props.fuzzy) return;
31873
+ if (props.fuzzy) {
31874
+ setShowValues(Boolean(value));
31875
+ return;
31876
+ }
31877
+
31870
31878
  if (props.onChange) props.onChange(e);
31871
31879
  };
31872
31880
 
31873
31881
  const handleOnInputClick = () => {
31874
- if (inputValues?.length) setHighlightedIndex(0);
31882
+ if (renderedValues?.length) setHighlightedIndex(0);
31875
31883
  setShowValues(true);
31876
31884
  };
31877
31885
 
31878
31886
  const onFuzzyBlur = e => {
31879
- // If the value of the input is changed, and does not match the value of the values array,
31880
- // we should revert back the input value to the original value
31881
31887
  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
31882
31888
 
31883
31889
  if (inputValues?.length) {
31884
- const valueInInputValues = inputValues.find(item => item[props.labelFromValues ?? 'label'].length && item[props.labelFromValues ?? 'label'].toLowerCase() === e.target.value.toLowerCase());
31890
+ const valueInInputValues = inputValues.find(item => item[labelKey].length && item[labelKey].toLowerCase() === e.target.value.toLowerCase());
31885
31891
 
31886
31892
  if (valueInInputValues) {
31887
- const val = valueInInputValues[props.labelFromValues ?? 'label'];
31893
+ const val = valueInInputValues[labelKey];
31888
31894
  setValueChanged(val);
31889
31895
  handleValueClick(valueInInputValues);
31890
31896
  return;
@@ -31902,9 +31908,8 @@
31902
31908
 
31903
31909
  if (props.fuzzy) {
31904
31910
  const fuzzyOptions = {
31905
- keys: [props.labelFromValues ?? 'label']
31911
+ keys: [labelKey]
31906
31912
  };
31907
- setShowValues(Boolean(value));
31908
31913
  return matchSorter.matchSorter(props.values, value ?? '', fuzzyOptions);
31909
31914
  }
31910
31915
 
@@ -31933,11 +31938,11 @@
31933
31938
  });
31934
31939
  }
31935
31940
 
31936
- if (highlightedIndex === null || !inputValues?.length) {
31941
+ if (highlightedIndex === null || !renderedValues?.length) {
31937
31942
  return;
31938
31943
  }
31939
31944
 
31940
- const item = inputValues[highlightedIndex];
31945
+ const item = renderedValues[highlightedIndex];
31941
31946
  handleValueClick(item);
31942
31947
  setShowValues(false);
31943
31948
  };
@@ -31947,7 +31952,7 @@
31947
31952
  e.stopPropagation();
31948
31953
  if (!showValues) return;
31949
31954
 
31950
- if (highlightedIndex === null || !inputValues?.length) {
31955
+ if (highlightedIndex === null || !renderedValues?.length) {
31951
31956
  return;
31952
31957
  }
31953
31958
 
@@ -31967,13 +31972,13 @@
31967
31972
  e.preventDefault();
31968
31973
  e.stopPropagation();
31969
31974
 
31970
- if (highlightedIndex === null || !inputValues?.length) {
31975
+ if (highlightedIndex === null || !renderedValues?.length) {
31971
31976
  return;
31972
31977
  }
31973
31978
 
31974
31979
  const newHighlightIndex = highlightedIndex + 1;
31975
31980
 
31976
- if (newHighlightIndex === inputValues.length) {
31981
+ if (newHighlightIndex === renderedValues.length) {
31977
31982
  setHighlightedIndex(null);
31978
31983
  setShowValues(false);
31979
31984
  return;
@@ -32001,7 +32006,7 @@
32001
32006
  key
32002
32007
  } = e;
32003
32008
 
32004
- if (showValues && inputValues?.length) {
32009
+ if (showValues && renderedValues?.length) {
32005
32010
  setHighlightedIndex(0);
32006
32011
  } else {
32007
32012
  setHighlightedIndex(null);
@@ -10,41 +10,45 @@ const useAutocomplete = props => {
10
10
  const [inputDirty, setInputDirty] = useState(false);
11
11
  const debouncedValue = useDebounce(value, props.debounceDelay ?? 0);
12
12
  const [inputValues, setInputValues] = useState(props.values);
13
+ const labelKey = props.labelFromValues ?? 'label';
13
14
 
14
15
  const handleValueClick = value => {
15
16
  props.onSelectItem?.(value);
17
+ if (props.fuzzy) setValueChanged(value[labelKey]);
16
18
  setShowValues(false);
17
19
  };
18
20
 
19
21
  const clearSelectedItem = () => handleValueClick({
20
- [props.labelFromValues ?? 'label']: '',
22
+ [labelKey]: '',
21
23
  [props.keyFromValues ?? 'key']: ''
22
24
  });
23
25
 
24
26
  const onInputChange = e => {
25
27
  setInputDirty(true);
26
- if (inputValues) setHighlightedIndex(0);
28
+ if (renderedValues) setHighlightedIndex(0);
27
29
  setValueChanged(e.target.value); // Should not use onChange whenever we have fuzzy search on
28
30
 
29
- if (props.fuzzy) return;
31
+ if (props.fuzzy) {
32
+ setShowValues(Boolean(value));
33
+ return;
34
+ }
35
+
30
36
  if (props.onChange) props.onChange(e);
31
37
  };
32
38
 
33
39
  const handleOnInputClick = () => {
34
- if (inputValues?.length) setHighlightedIndex(0);
40
+ if (renderedValues?.length) setHighlightedIndex(0);
35
41
  setShowValues(true);
36
42
  };
37
43
 
38
44
  const onFuzzyBlur = e => {
39
- // If the value of the input is changed, and does not match the value of the values array,
40
- // we should revert back the input value to the original value
41
45
  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
42
46
 
43
47
  if (inputValues?.length) {
44
- const valueInInputValues = inputValues.find(item => item[props.labelFromValues ?? 'label'].length && item[props.labelFromValues ?? 'label'].toLowerCase() === e.target.value.toLowerCase());
48
+ const valueInInputValues = inputValues.find(item => item[labelKey].length && item[labelKey].toLowerCase() === e.target.value.toLowerCase());
45
49
 
46
50
  if (valueInInputValues) {
47
- const val = valueInInputValues[props.labelFromValues ?? 'label'];
51
+ const val = valueInInputValues[labelKey];
48
52
  setValueChanged(val);
49
53
  handleValueClick(valueInInputValues);
50
54
  return;
@@ -62,9 +66,8 @@ const useAutocomplete = props => {
62
66
 
63
67
  if (props.fuzzy) {
64
68
  const fuzzyOptions = {
65
- keys: [props.labelFromValues ?? 'label']
69
+ keys: [labelKey]
66
70
  };
67
- setShowValues(Boolean(value));
68
71
  return matchSorter(props.values, value ?? '', fuzzyOptions);
69
72
  }
70
73
 
@@ -93,11 +96,11 @@ const useAutocomplete = props => {
93
96
  });
94
97
  }
95
98
 
96
- if (highlightedIndex === null || !inputValues?.length) {
99
+ if (highlightedIndex === null || !renderedValues?.length) {
97
100
  return;
98
101
  }
99
102
 
100
- const item = inputValues[highlightedIndex];
103
+ const item = renderedValues[highlightedIndex];
101
104
  handleValueClick(item);
102
105
  setShowValues(false);
103
106
  };
@@ -107,7 +110,7 @@ const useAutocomplete = props => {
107
110
  e.stopPropagation();
108
111
  if (!showValues) return;
109
112
 
110
- if (highlightedIndex === null || !inputValues?.length) {
113
+ if (highlightedIndex === null || !renderedValues?.length) {
111
114
  return;
112
115
  }
113
116
 
@@ -127,13 +130,13 @@ const useAutocomplete = props => {
127
130
  e.preventDefault();
128
131
  e.stopPropagation();
129
132
 
130
- if (highlightedIndex === null || !inputValues?.length) {
133
+ if (highlightedIndex === null || !renderedValues?.length) {
131
134
  return;
132
135
  }
133
136
 
134
137
  const newHighlightIndex = highlightedIndex + 1;
135
138
 
136
- if (newHighlightIndex === inputValues.length) {
139
+ if (newHighlightIndex === renderedValues.length) {
137
140
  setHighlightedIndex(null);
138
141
  setShowValues(false);
139
142
  return;
@@ -161,7 +164,7 @@ const useAutocomplete = props => {
161
164
  key
162
165
  } = e;
163
166
 
164
- if (showValues && inputValues?.length) {
167
+ if (showValues && renderedValues?.length) {
165
168
  setHighlightedIndex(0);
166
169
  } else {
167
170
  setHighlightedIndex(null);
@@ -18,6 +18,7 @@ const TimePicker = ({
18
18
  css,
19
19
  validation,
20
20
  invalidMessage,
21
+ autoFocus,
21
22
  onChange,
22
23
  onBlur
23
24
  }) => {
@@ -115,6 +116,7 @@ const TimePicker = ({
115
116
  type: "text",
116
117
  value: inputStateValue,
117
118
  disabled: disabled,
119
+ autoFocus: autoFocus,
118
120
  css: theme => [disabled && styles.disabled(theme), css && css],
119
121
  onChange: event => onInputChange(event, v => onChange && onChange(v)),
120
122
  onBlur: onBlur,
@@ -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,qBAAqB,CAAA;AAE1D,QAAA,MAAM,eAAe,UAAW,MAAM;;;;;;uBAuBV,MAAM,WAAW,CAAC,gBAAgB,CAAC;yBAkJjC,mBAAmB,CAAC,gBAAgB,CAAC;+BAZ/B,mBAAmB,CAAC,gBAAgB,CAAC;;qBArH/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;;;;;;uBA2BV,MAAM,WAAW,CAAC,gBAAgB,CAAC;yBA6IjC,mBAAmB,CAAC,gBAAgB,CAAC;+BAZ/B,mBAAmB,CAAC,gBAAgB,CAAC;;qBA7G/C,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC;;;;;;CAuMpE,CAAA;AAED,eAAe,eAAe,CAAA"}
@@ -10,41 +10,45 @@ const useAutocomplete = props => {
10
10
  const [inputDirty, setInputDirty] = useState(false);
11
11
  const debouncedValue = useDebounce(value, props.debounceDelay ?? 0);
12
12
  const [inputValues, setInputValues] = useState(props.values);
13
+ const labelKey = props.labelFromValues ?? 'label';
13
14
 
14
15
  const handleValueClick = value => {
15
16
  props.onSelectItem?.(value);
17
+ if (props.fuzzy) setValueChanged(value[labelKey]);
16
18
  setShowValues(false);
17
19
  };
18
20
 
19
21
  const clearSelectedItem = () => handleValueClick({
20
- [props.labelFromValues ?? 'label']: '',
22
+ [labelKey]: '',
21
23
  [props.keyFromValues ?? 'key']: ''
22
24
  });
23
25
 
24
26
  const onInputChange = e => {
25
27
  setInputDirty(true);
26
- if (inputValues) setHighlightedIndex(0);
28
+ if (renderedValues) setHighlightedIndex(0);
27
29
  setValueChanged(e.target.value); // Should not use onChange whenever we have fuzzy search on
28
30
 
29
- if (props.fuzzy) return;
31
+ if (props.fuzzy) {
32
+ setShowValues(Boolean(value));
33
+ return;
34
+ }
35
+
30
36
  if (props.onChange) props.onChange(e);
31
37
  };
32
38
 
33
39
  const handleOnInputClick = () => {
34
- if (inputValues?.length) setHighlightedIndex(0);
40
+ if (renderedValues?.length) setHighlightedIndex(0);
35
41
  setShowValues(true);
36
42
  };
37
43
 
38
44
  const onFuzzyBlur = e => {
39
- // If the value of the input is changed, and does not match the value of the values array,
40
- // we should revert back the input value to the original value
41
45
  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
42
46
 
43
47
  if (inputValues?.length) {
44
- const valueInInputValues = inputValues.find(item => item[props.labelFromValues ?? 'label'].length && item[props.labelFromValues ?? 'label'].toLowerCase() === e.target.value.toLowerCase());
48
+ const valueInInputValues = inputValues.find(item => item[labelKey].length && item[labelKey].toLowerCase() === e.target.value.toLowerCase());
45
49
 
46
50
  if (valueInInputValues) {
47
- const val = valueInInputValues[props.labelFromValues ?? 'label'];
51
+ const val = valueInInputValues[labelKey];
48
52
  setValueChanged(val);
49
53
  handleValueClick(valueInInputValues);
50
54
  return;
@@ -62,9 +66,8 @@ const useAutocomplete = props => {
62
66
 
63
67
  if (props.fuzzy) {
64
68
  const fuzzyOptions = {
65
- keys: [props.labelFromValues ?? 'label']
69
+ keys: [labelKey]
66
70
  };
67
- setShowValues(Boolean(value));
68
71
  return matchSorter(props.values, value ?? '', fuzzyOptions);
69
72
  }
70
73
 
@@ -93,11 +96,11 @@ const useAutocomplete = props => {
93
96
  });
94
97
  }
95
98
 
96
- if (highlightedIndex === null || !inputValues?.length) {
99
+ if (highlightedIndex === null || !renderedValues?.length) {
97
100
  return;
98
101
  }
99
102
 
100
- const item = inputValues[highlightedIndex];
103
+ const item = renderedValues[highlightedIndex];
101
104
  handleValueClick(item);
102
105
  setShowValues(false);
103
106
  };
@@ -107,7 +110,7 @@ const useAutocomplete = props => {
107
110
  e.stopPropagation();
108
111
  if (!showValues) return;
109
112
 
110
- if (highlightedIndex === null || !inputValues?.length) {
113
+ if (highlightedIndex === null || !renderedValues?.length) {
111
114
  return;
112
115
  }
113
116
 
@@ -127,13 +130,13 @@ const useAutocomplete = props => {
127
130
  e.preventDefault();
128
131
  e.stopPropagation();
129
132
 
130
- if (highlightedIndex === null || !inputValues?.length) {
133
+ if (highlightedIndex === null || !renderedValues?.length) {
131
134
  return;
132
135
  }
133
136
 
134
137
  const newHighlightIndex = highlightedIndex + 1;
135
138
 
136
- if (newHighlightIndex === inputValues.length) {
139
+ if (newHighlightIndex === renderedValues.length) {
137
140
  setHighlightedIndex(null);
138
141
  setShowValues(false);
139
142
  return;
@@ -161,7 +164,7 @@ const useAutocomplete = props => {
161
164
  key
162
165
  } = e;
163
166
 
164
- if (showValues && inputValues?.length) {
167
+ if (showValues && renderedValues?.length) {
165
168
  setHighlightedIndex(0);
166
169
  } else {
167
170
  setHighlightedIndex(null);
@@ -29,6 +29,8 @@ interface IProps {
29
29
  validation?: boolean;
30
30
  /** Invalid message */
31
31
  invalidMessage?: string;
32
+ /** If input field should have auto focus */
33
+ autoFocus?: boolean;
32
34
  }
33
35
  declare const TimePicker: React.FC<IProps>;
34
36
  export default TimePicker;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/Timepicker/index.tsx"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAgC,MAAM,OAAO,CAAA;AAapD,aAAK,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;AAElD,UAAU,MAAM;IACd,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qBAAqB;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,6CAA6C;IAC7C,QAAQ,EAAE,YAAY,CAAA;IACtB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IACxB,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+FAA+F;IAC/F,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gBA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;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CA0LhC,CAAA;AAED,eAAe,UAAU,CAAA"}
@@ -18,6 +18,7 @@ const TimePicker = ({
18
18
  css,
19
19
  validation,
20
20
  invalidMessage,
21
+ autoFocus,
21
22
  onChange,
22
23
  onBlur
23
24
  }) => {
@@ -115,6 +116,7 @@ const TimePicker = ({
115
116
  type: "text",
116
117
  value: inputStateValue,
117
118
  disabled: disabled,
119
+ autoFocus: autoFocus,
118
120
  css: theme => [disabled && styles.disabled(theme), css && css],
119
121
  onChange: event => onInputChange(event, v => onChange && onChange(v)),
120
122
  onBlur: onBlur,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbl-digital/snorre",
3
- "version": "3.0.11",
3
+ "version": "3.0.15",
4
4
  "description": "Design library for BBL Digital",
5
5
  "license": "MIT",
6
6
  "main": "./lib/index.js",