@rolster/react-components 18.13.3 → 18.13.5

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.
@@ -575,6 +575,8 @@
575
575
  column-gap: var(--rls-sizing-x2);
576
576
  }
577
577
  .rls-message-icon span {
578
+ font-size: var(--rls-caption-font-size);
579
+ letter-spacing: var(--rls-caption-letter-spacing);
578
580
  color: var(--rls-app-color-300);
579
581
  }
580
582
 
package/dist/cjs/index.js CHANGED
@@ -176,7 +176,7 @@ function RlsLabel({ children, rlsTheme }) {
176
176
  }
177
177
 
178
178
  function RlsMessageIcon({ icon, children, rlsTheme }) {
179
- return (jsxRuntime.jsxs("div", { className: "rls-message-icon", "rls-theme": rlsTheme, children: [icon && jsxRuntime.jsx(RlsIcon, { value: icon }), jsxRuntime.jsx("span", { className: "caption-regular truncate", children: children })] }));
179
+ return (jsxRuntime.jsxs("div", { className: "rls-message-icon", "rls-theme": rlsTheme, children: [icon && jsxRuntime.jsx(RlsIcon, { value: icon }), jsxRuntime.jsx("span", { className: "truncate", children: children })] }));
180
180
  }
181
181
 
182
182
  function RlsPoster({ children, rlsTheme }) {
@@ -1371,41 +1371,63 @@ const MAX_ELEMENTS = 6;
1371
1371
  function useAutocompleteField({ disabled, formControl, onSelect, onValue, suggestions }) {
1372
1372
  const [pattern, setPattern] = react.useState('');
1373
1373
  const [coincidences, setCoincidences] = react.useState([]);
1374
- const [store, setStore] = react.useState({
1374
+ const currentStore = react.useRef({
1375
1375
  pattern: '',
1376
1376
  coincidences: [],
1377
1377
  previous: null
1378
1378
  });
1379
1379
  const listControl = useListControl({ suggestions, formControl });
1380
1380
  const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1381
+ const initializedState = react.useRef(false);
1382
+ const initializedCollection = react.useRef(false);
1381
1383
  const changeInternal = react.useRef(false);
1382
- react.useEffect(() => filterSuggestions(pattern, true), [suggestions]);
1383
- react.useEffect(() => filterSuggestions(pattern), [pattern]);
1384
1384
  react.useEffect(() => {
1385
+ refreshCoincidences(pattern, true);
1386
+ }, [suggestions]);
1387
+ react.useEffect(() => {
1388
+ refreshCoincidences(pattern);
1389
+ }, [pattern]);
1390
+ react.useEffect(() => {
1391
+ if (!initializedState.current || !initializedCollection.current) {
1392
+ initializedState.current = true;
1393
+ return;
1394
+ }
1385
1395
  if (changeInternal.current) {
1386
1396
  changeInternal.current = false;
1397
+ return;
1387
1398
  }
1388
- else {
1389
- resetState(formControl?.state);
1390
- }
1399
+ refresh(collection, formControl?.state);
1391
1400
  }, [formControl?.state]);
1392
- react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1401
+ react.useEffect(() => {
1402
+ if (!initializedCollection.current || !initializedState.current) {
1403
+ initializedCollection.current = true;
1404
+ return;
1405
+ }
1406
+ refresh(collection, formControl?.state);
1407
+ }, [collection]);
1408
+ function refresh(collection, state) {
1409
+ if (!state) {
1410
+ return setValue('');
1411
+ }
1412
+ const element = collection.find(state);
1413
+ if (element) {
1414
+ return setValue(element.description);
1415
+ }
1416
+ setValue('');
1417
+ setFormState(undefined);
1418
+ }
1393
1419
  function setFormState(value) {
1394
1420
  if (formControl) {
1395
1421
  changeInternal.current = true;
1396
1422
  formControl.setState(value);
1397
1423
  }
1398
1424
  }
1399
- function resetCollection(collection, state) {
1400
- setValue(state ? collection.find(state)?.description || '' : '');
1401
- }
1402
- function resetState(state) {
1403
- resetCollection(collection, state);
1404
- }
1405
1425
  function onClickControl() {
1406
1426
  if (!disabled) {
1407
1427
  setVisible(true);
1408
- setTimeout(() => inputRef?.current?.focus(), DURATION_ANIMATION$1);
1428
+ setTimeout(() => {
1429
+ inputRef?.current?.focus();
1430
+ }, DURATION_ANIMATION$1);
1409
1431
  }
1410
1432
  }
1411
1433
  function onFocusInput() {
@@ -1459,15 +1481,15 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1459
1481
  onValue(value);
1460
1482
  }
1461
1483
  }
1462
- function filterSuggestions(pattern, reboot = false) {
1463
- const result = createStoreAutocomplete({
1484
+ function refreshCoincidences(pattern, reboot = false) {
1485
+ const { collection, store } = createStoreAutocomplete({
1464
1486
  pattern,
1465
1487
  suggestions,
1466
1488
  reboot,
1467
- store
1489
+ store: currentStore.current
1468
1490
  });
1469
- setCoincidences(result.collection.slice(0, MAX_ELEMENTS));
1470
- setStore(result.store);
1491
+ currentStore.current = store;
1492
+ setCoincidences(collection.slice(0, MAX_ELEMENTS));
1471
1493
  }
1472
1494
  return {
1473
1495
  coincidences,
@@ -1807,7 +1829,7 @@ function RlsDateField({ children, date, disabled, formControl, maxDate, minDate,
1807
1829
  setModalIsVisible(true);
1808
1830
  }
1809
1831
  }
1810
- return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: value && helpersDate.dateFormatTemplate(value, DATE_RANGE_FORMAT), readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsxRuntime.jsx("div", { className: "rls-box-field__error", children: jsxRuntime.jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsxRuntime.jsx(RlsModal, { visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
1832
+ return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: value ? helpersDate.dateFormatTemplate(value, DATE_RANGE_FORMAT) : '', readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsxRuntime.jsx("div", { className: "rls-box-field__error", children: jsxRuntime.jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsxRuntime.jsx(RlsModal, { visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
1811
1833
  if (type !== PickerListenerType.Cancel) {
1812
1834
  onChange(value, true);
1813
1835
  }
@@ -1893,7 +1915,7 @@ function RlsDateRangeField({ children, date: datePicker, disabled, formControl,
1893
1915
  setModalIsVisible(true);
1894
1916
  }
1895
1917
  }
1896
- return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: "rls-box-field", children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: value && rangeFormatTemplate(value), readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClickAction, disabled: disabled, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) })] }), jsxRuntime.jsx(RlsModal, { visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDateRangePicker, { formControl: formControl, date: currentDate, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
1918
+ return (jsxRuntime.jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxRuntime.jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsxRuntime.jsx("label", { className: "rls-box-field__label", children: children }), jsxRuntime.jsx("div", { className: "rls-box-field__component", children: jsxRuntime.jsxs("div", { className: "rls-box-field__body", children: [jsxRuntime.jsx("input", { className: "rls-date-field__control", type: "text", value: value ? rangeFormatTemplate(value) : '', readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsxRuntime.jsx("button", { className: "rls-date-field__action", onClick: onClickAction, disabled: disabled, children: jsxRuntime.jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) })] }), jsxRuntime.jsx(RlsModal, { visible: modalIsVisible, rlsTheme: rlsTheme, children: jsxRuntime.jsx(RlsDateRangePicker, { formControl: formControl, date: currentDate, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
1897
1919
  if (value) {
1898
1920
  setValue(value);
1899
1921
  }
@@ -1908,28 +1930,44 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
1908
1930
  function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1909
1931
  const listControl = useListControl({ suggestions, formControl });
1910
1932
  const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1933
+ const initializedState = react.useRef(false);
1934
+ const initializedCollection = react.useRef(false);
1911
1935
  const changeInternal = react.useRef(false);
1912
1936
  react.useEffect(() => {
1937
+ if (!initializedState.current || !initializedCollection.current) {
1938
+ initializedState.current = true;
1939
+ return;
1940
+ }
1913
1941
  if (changeInternal.current) {
1914
1942
  changeInternal.current = false;
1943
+ return;
1915
1944
  }
1916
- else {
1917
- resetState(formControl?.state);
1918
- }
1945
+ refresh(collection, formControl?.state);
1919
1946
  }, [formControl?.state]);
1920
- react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1947
+ react.useEffect(() => {
1948
+ if (!initializedCollection.current || !initializedState.current) {
1949
+ initializedCollection.current = true;
1950
+ return;
1951
+ }
1952
+ refresh(collection, formControl?.state);
1953
+ }, [collection]);
1954
+ function refresh(collection, state) {
1955
+ if (!state) {
1956
+ return setValue('');
1957
+ }
1958
+ const element = collection.find(state);
1959
+ if (element) {
1960
+ return setValue(element.description);
1961
+ }
1962
+ setValue('');
1963
+ setFormState(undefined);
1964
+ }
1921
1965
  function setFormState(value) {
1922
1966
  if (formControl) {
1923
1967
  changeInternal.current = true;
1924
1968
  formControl.setState(value);
1925
1969
  }
1926
1970
  }
1927
- function resetCollection(collection, state) {
1928
- setValue(state ? collection.find(state)?.description || '' : '');
1929
- }
1930
- function resetState(state) {
1931
- resetCollection(collection, state);
1932
- }
1933
1971
  function onFocusInput() {
1934
1972
  setFocused(true);
1935
1973
  }
@@ -1955,9 +1993,8 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1955
1993
  }
1956
1994
  }
1957
1995
  function onClickAction() {
1958
- const newVisible = !visible;
1959
- setVisible(newVisible);
1960
- if (newVisible) {
1996
+ setVisible(!visible);
1997
+ if (!visible) {
1961
1998
  inputRef?.current?.focus();
1962
1999
  }
1963
2000
  }