@rolster/react-components 18.21.33 → 18.21.34

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/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import require$$0, { useState, useEffect, useMemo, useCallback, useRef, createContext } from 'react';
2
- import { currencyFormat, itIsDefined, PartialSealed } from '@rolster/commons';
2
+ import { currencyFormat, floorDecimals, itIsDefined, PartialSealed } from '@rolster/commons';
3
3
  import { dateFormatTemplate, DAY_LABELS, DateRange, normalizeMinTime, assignDayInDate, dateIsBefore, MONTH_NAMES, Month, assignYearInDate, assignMonthInDate } from '@rolster/dates';
4
4
  import { i18n, i18nSubscribe } from '@rolster/i18n';
5
5
  import { PaginationController, verifyDayPicker, createDayPicker, createDayRangePicker, verifyMonthPicker, createMonthPicker, monthLimitTemplate, createYearPicker, verifyYearPicker, ListCollection, locationListCanTop, navigationListFromInput, navigationListFromElement, createAutocompleteStore, dateOutRange, verifyDateRange, PickerListenerEvent } from '@rolster/components';
@@ -1540,21 +1540,28 @@ function RlsCheckBoxControl({ formControl, disabled, identifier, rlsTheme }) {
1540
1540
  return (jsxRuntimeExports.jsx(RlsCheckBox, { identifier: identifier, checked: !!formControl.value, disabled: disabled, onClick: onClick, rlsTheme: rlsTheme }));
1541
1541
  }
1542
1542
 
1543
- function RlsInput({ children, disabled, formControl, identifier, onEnter, onKeyDown, onKeyUp, onValue, placeholder, readOnly, type, value }) {
1543
+ function RlsInput({ children, decimals, disabled, formControl, identifier, onEnter, onKeyDown, onKeyUp, onValue, placeholder, readOnly, type, value }) {
1544
1544
  const valueInitial = formControl?.value ?? value ? String(value) : '';
1545
1545
  const [valueInput, setValueInput] = useState(valueInitial);
1546
1546
  const [focused, setFocused] = useState(false);
1547
+ const isChangeInternal = useRef(false);
1547
1548
  useEffect(() => {
1548
- const valueControl = formControl?.value ? String(formControl.value) : '';
1549
- (!focused || valueInput !== valueControl) && setValueInput(valueControl);
1549
+ if (!isChangeInternal.current) {
1550
+ const control = formControl?.value ? String(formControl.value) : '';
1551
+ valueInput !== control && setValueInput(control);
1552
+ }
1553
+ isChangeInternal.current = false;
1550
1554
  }, [formControl?.value]);
1551
1555
  const _onChange = useCallback((event) => {
1552
1556
  const valueInput = event.target.value;
1553
- const value = type === 'number' ? +valueInput : valueInput;
1557
+ const value = type === 'number'
1558
+ ? floorDecimals(+valueInput, decimals || 0)
1559
+ : valueInput;
1560
+ isChangeInternal.current = true;
1554
1561
  onValue && onValue(value);
1555
1562
  setValueInput(valueInput);
1556
1563
  formControl?.setValue(value);
1557
- }, [formControl, onValue]);
1564
+ }, [formControl, onValue, type, decimals]);
1558
1565
  const _onKeyDown = useCallback((event) => {
1559
1566
  onKeyDown && onKeyDown(event);
1560
1567
  event.key === 'Enter' && onEnter && onEnter();
@@ -2674,17 +2681,17 @@ function RlsFieldAutocompleteTemplate(props) {
2674
2681
  });
2675
2682
  });
2676
2683
  }, []);
2677
- const _disabled = useMemo(() => {
2684
+ const disabled = useMemo(() => {
2678
2685
  return formControl?.disabled || props.disabled;
2679
2686
  }, [formControl?.disabled, props.disabled]);
2680
2687
  const className = useMemo(() => {
2681
2688
  return renderClassStatus('rls-field-box', {
2682
- focused: autocomplete.focused && !_disabled,
2689
+ focused: autocomplete.focused && !disabled,
2683
2690
  error: formControl?.wrong,
2684
- disabled: _disabled,
2691
+ disabled,
2685
2692
  selected: !!autocomplete.value
2686
2693
  }, 'rls-field-list rls-field-autocomplete');
2687
- }, [formControl?.wrong, autocomplete.value, autocomplete.focused, _disabled]);
2694
+ }, [formControl?.wrong, autocomplete.value, autocomplete.focused, disabled]);
2688
2695
  const classNameList = useMemo(() => {
2689
2696
  return renderClassStatus('rls-field-list__suggestions', {
2690
2697
  higher: autocomplete.higher,
@@ -2697,7 +2704,11 @@ function RlsFieldAutocompleteTemplate(props) {
2697
2704
  const onClickPattern = useCallback(() => {
2698
2705
  onSearch && onSearch(autocomplete.pattern);
2699
2706
  }, [onSearch, autocomplete.pattern]);
2700
- return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.contentRef, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("label", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: _disabled, placeholder: placeholder, value: autocomplete.value, onClick: autocomplete.onClickControl }), jsxRuntimeExports.jsx("button", { className: "rls-field-list__action", disabled: _disabled, onClick: autocomplete.onClickAction, children: jsxRuntimeExports.jsx(RlsIcon, { value: autocomplete.value ? 'trash-2' : 'arrow-ios-down' }) })] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsxs("div", { className: classNameList, children: [jsxRuntimeExports.jsx("div", { className: "rls-field-list__suggestions__body", children: jsxRuntimeExports.jsxs("ul", { ref: autocomplete.listRef, className: "rls-field-list__ul", children: [jsxRuntimeExports.jsxs("div", { className: "rls-field-list__ul__search", children: [jsxRuntimeExports.jsx("input", { ref: autocomplete.inputRef, className: "rls-field-list__ul__control", type: "text", placeholder: labels.listInputPlaceholder, value: autocomplete.pattern, onChange: onChangePattern, onFocus: autocomplete.onFocusInput, onBlur: autocomplete.onBlurInput, onKeyDown: autocomplete.onKeydownInput, disabled: _disabled || searching }), onSearch && (jsxRuntimeExports.jsx("button", { disabled: _disabled || searching, onClick: onClickPattern, children: jsxRuntimeExports.jsx(RlsIcon, { value: "search" }) }))] }), searching && jsxRuntimeExports.jsx(RlsProgressBar, { indeterminate: true }), autocomplete.coincidences.map((element, index) => (jsxRuntimeExports.jsx("li", { className: "rls-field-list__element", tabIndex: -1, onClick: autocomplete.onClickElement(element), onKeyDown: autocomplete.onKeydownElement(element), children: render(element) }, index))), !autocomplete.coincidences.length && (jsxRuntimeExports.jsx("li", { className: "rls-field-list__empty", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-list__empty__description", children: [jsxRuntimeExports.jsx("label", { className: "rls-label-bold rls-truncate", children: labels.listEmptyTitle }), jsxRuntimeExports.jsx("p", { className: "rls-caption-regular", children: labels.listEmptyDescription })] }) }))] }) }), jsxRuntimeExports.jsx("div", { className: "rls-field-list__backdrop", onClick: autocomplete.onClickBackdrop })] })] }));
2707
+ const onKeyDownPattern = useCallback((event) => {
2708
+ event.key === 'Enter' && onSearch && onSearch(autocomplete.pattern);
2709
+ autocomplete.onKeydownInput(event);
2710
+ }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
2711
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.contentRef, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("label", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: autocomplete.value, onClick: autocomplete.onClickControl }), jsxRuntimeExports.jsx("button", { className: "rls-field-list__action", disabled: disabled, onClick: autocomplete.onClickAction, children: jsxRuntimeExports.jsx(RlsIcon, { value: autocomplete.value ? 'trash-2' : 'arrow-ios-down' }) })] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsxs("div", { className: classNameList, children: [jsxRuntimeExports.jsx("div", { className: "rls-field-list__suggestions__body", children: jsxRuntimeExports.jsxs("ul", { ref: autocomplete.listRef, className: "rls-field-list__ul", children: [jsxRuntimeExports.jsxs("div", { className: "rls-field-list__ul__search", children: [jsxRuntimeExports.jsx("input", { ref: autocomplete.inputRef, className: "rls-field-list__ul__control", type: "text", placeholder: labels.listInputPlaceholder, value: autocomplete.pattern, onChange: onChangePattern, onFocus: autocomplete.onFocusInput, onBlur: autocomplete.onBlurInput, onKeyDown: onKeyDownPattern, disabled: disabled || searching }), onSearch && (jsxRuntimeExports.jsx("button", { disabled: disabled || searching, onClick: onClickPattern, children: jsxRuntimeExports.jsx(RlsIcon, { value: "search" }) }))] }), searching && jsxRuntimeExports.jsx(RlsProgressBar, { indeterminate: true }), autocomplete.coincidences.map((element, index) => (jsxRuntimeExports.jsx("li", { className: "rls-field-list__element", tabIndex: -1, onClick: autocomplete.onClickElement(element), onKeyDown: autocomplete.onKeydownElement(element), children: render(element) }, index))), !autocomplete.coincidences.length && (jsxRuntimeExports.jsx("li", { className: "rls-field-list__empty", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-list__empty__description", children: [jsxRuntimeExports.jsx("label", { className: "rls-label-bold rls-truncate", children: labels.listEmptyTitle }), jsxRuntimeExports.jsx("p", { className: "rls-caption-regular", children: labels.listEmptyDescription })] }) }))] }) }), jsxRuntimeExports.jsx("div", { className: "rls-field-list__backdrop", onClick: autocomplete.onClickBackdrop })] })] }));
2701
2712
  }
2702
2713
  function RlsFieldAutocomplete(props) {
2703
2714
  const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);