@rolster/react-components 18.10.4 → 18.10.6

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/cjs/index.js CHANGED
@@ -1127,7 +1127,7 @@ const ELEMENT_SIZE_REM = 4;
1127
1127
  const BASE_SIZE_PX = 16;
1128
1128
  const ELEMENT_SIZE_PX = BASE_SIZE_PX * ELEMENT_SIZE_REM;
1129
1129
  const MAZ_LIST_SIZE_PX = BASE_SIZE_PX * LIST_SIZE_REM;
1130
- function useListControl({ suggestions, formControl, withHigher = false }) {
1130
+ function useListControl({ suggestions, formControl, higher: withHigher = false }) {
1131
1131
  const boxContentRef = react.useRef(null);
1132
1132
  const listRef = react.useRef(null);
1133
1133
  const inputRef = react.useRef(null);
@@ -1219,10 +1219,7 @@ function useListControl({ suggestions, formControl, withHigher = false }) {
1219
1219
  setPositionElement(0);
1220
1220
  elements.item(0).focus();
1221
1221
  setTimeout(() => {
1222
- listRef?.current?.scroll({
1223
- top: 0,
1224
- behavior: 'smooth'
1225
- });
1222
+ listRef?.current?.scroll({ top: 0, behavior: 'smooth' });
1226
1223
  }, 100);
1227
1224
  }
1228
1225
  }
@@ -1254,19 +1251,19 @@ function useListControl({ suggestions, formControl, withHigher = false }) {
1254
1251
  higher,
1255
1252
  inputRef,
1256
1253
  listRef,
1257
- value,
1258
- visible,
1259
1254
  navigationElement,
1260
1255
  navigationInput,
1261
1256
  setFocused,
1262
1257
  setValue,
1263
- setVisible
1258
+ setVisible,
1259
+ value,
1260
+ visible
1264
1261
  };
1265
1262
  }
1266
1263
 
1267
1264
  const DURATION_ANIMATION$1 = 240;
1268
1265
  const MAX_ELEMENTS = 6;
1269
- function useAutocompleteField({ suggestions, disabled, formControl, onSelect, onValue }) {
1266
+ function useAutocompleteField({ disabled, formControl, onSelect, onValue, suggestions }) {
1270
1267
  const [pattern, setPattern] = react.useState('');
1271
1268
  const [coincidences, setCoincidences] = react.useState([]);
1272
1269
  const [store, setStore] = react.useState({
@@ -1277,25 +1274,35 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1277
1274
  const listControl = useListControl({
1278
1275
  suggestions,
1279
1276
  formControl,
1280
- withHigher: true
1277
+ higher: true
1281
1278
  });
1282
- const { collection, inputRef, setFocused, setValue, setVisible, navigationElement, navigationInput } = listControl;
1279
+ const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1283
1280
  const [changeInternal, setChangeInternal] = react.useState(false);
1284
1281
  react.useEffect(() => filterSuggestions(pattern, true), [suggestions]);
1285
1282
  react.useEffect(() => filterSuggestions(pattern), [pattern]);
1286
1283
  react.useEffect(() => {
1287
- changeInternal ? setChangeInternal(false) : resetComponent();
1284
+ changeInternal
1285
+ ? setChangeInternal(false)
1286
+ : reset(collection, formControl?.state);
1288
1287
  }, [formControl?.state]);
1289
- react.useEffect(() => setValue(requestCurrentElement()?.description || ''), [collection]);
1290
- function requestCurrentElement() {
1291
- return formControl?.state && collection.find(formControl.state);
1292
- }
1293
- function resetComponent() {
1294
- const element = requestCurrentElement();
1295
- setValue(element?.description || '');
1296
- if (!element) {
1297
- setChangeInternal(true);
1298
- formControl?.setState(undefined);
1288
+ react.useEffect(() => reset(collection, formControl?.state), [collection]);
1289
+ function setFormState(value) {
1290
+ setChangeInternal(true);
1291
+ formControl?.setState(value);
1292
+ }
1293
+ function reset(collection, state) {
1294
+ if (state) {
1295
+ const element = collection.find(state);
1296
+ if (element) {
1297
+ setValue(element.description);
1298
+ }
1299
+ else {
1300
+ setValue('');
1301
+ setFormState(undefined);
1302
+ }
1303
+ }
1304
+ else {
1305
+ setValue('');
1299
1306
  }
1300
1307
  }
1301
1308
  function onClickControl() {
@@ -1327,8 +1334,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1327
1334
  setVisible(false);
1328
1335
  setValue('');
1329
1336
  if (formControl) {
1330
- setChangeInternal(true);
1331
- formControl.setState(undefined);
1337
+ setFormState(undefined);
1332
1338
  }
1333
1339
  if (onValue) {
1334
1340
  onValue(undefined);
@@ -1361,8 +1367,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1361
1367
  }
1362
1368
  else {
1363
1369
  if (formControl) {
1364
- setChangeInternal(true);
1365
- formControl.setState(value);
1370
+ setFormState(value);
1366
1371
  }
1367
1372
  setValue(description);
1368
1373
  }
@@ -1416,7 +1421,6 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1416
1421
  return {
1417
1422
  coincidences,
1418
1423
  listControl,
1419
- pattern,
1420
1424
  onBlurInput,
1421
1425
  onClickAction,
1422
1426
  onClickBackdrop,
@@ -1425,6 +1429,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1425
1429
  onFocusInput,
1426
1430
  onKeydownElement,
1427
1431
  onKeydownInput,
1432
+ pattern,
1428
1433
  setPattern
1429
1434
  };
1430
1435
  }
@@ -1744,9 +1749,9 @@ function RlsDateField({ children, date, disabled, formControl, maxDate, minDate,
1744
1749
  }
1745
1750
  function onChange(value, ignoreControl = false) {
1746
1751
  if (!ignoreControl) {
1747
- formControl?.setState(undefined);
1752
+ formControl?.setState(value);
1748
1753
  }
1749
- setValue(undefined);
1754
+ setValue(value);
1750
1755
  if (onValue) {
1751
1756
  onValue(value);
1752
1757
  }
@@ -1888,21 +1893,31 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
1888
1893
 
1889
1894
  function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1890
1895
  const listControl = useListControl({ suggestions, formControl });
1891
- const { collection, inputRef, visible, setFocused, setValue, setVisible, navigationElement, navigationInput } = listControl;
1896
+ const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1892
1897
  const [changeInternal, setChangeInternal] = react.useState(false);
1893
1898
  react.useEffect(() => {
1894
- changeInternal ? setChangeInternal(false) : resetComponent();
1899
+ changeInternal
1900
+ ? setChangeInternal(false)
1901
+ : reset(collection, formControl?.state);
1895
1902
  }, [formControl?.state]);
1896
- react.useEffect(() => setValue(requestCurrentElement()?.description || ''), [collection]);
1897
- function requestCurrentElement() {
1898
- return formControl?.state && collection.find(formControl.state);
1899
- }
1900
- function resetComponent() {
1901
- const element = requestCurrentElement();
1902
- setValue(element?.description || '');
1903
- if (!element) {
1904
- setChangeInternal(true);
1905
- formControl?.setState(undefined);
1903
+ react.useEffect(() => reset(collection, formControl?.state), [collection]);
1904
+ function setFormState(value) {
1905
+ setChangeInternal(true);
1906
+ formControl?.setState(value);
1907
+ }
1908
+ function reset(collection, state) {
1909
+ if (state) {
1910
+ const element = collection.find(state);
1911
+ if (element) {
1912
+ setValue(element.description);
1913
+ }
1914
+ else {
1915
+ setValue('');
1916
+ setFormState(undefined);
1917
+ }
1918
+ }
1919
+ else {
1920
+ setValue('');
1906
1921
  }
1907
1922
  }
1908
1923
  function onFocusInput() {
@@ -1968,8 +1983,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1968
1983
  }
1969
1984
  else {
1970
1985
  if (formControl) {
1971
- setChangeInternal(true);
1972
- formControl.setState(value);
1986
+ setFormState(value);
1973
1987
  }
1974
1988
  setValue(description);
1975
1989
  }