@rolster/react-components 19.6.4 → 19.6.7

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import require$$0, { useMemo, useState, useRef, useCallback, useEffect, useEffectEvent, createContext } from 'react';
1
+ import require$$0, { useMemo, useState, useRef, useCallback, useEffect, useEffectEvent, createContext, useContext } from 'react';
2
2
  import { currencyFormat, BigDecimal, valueIsDefined, SealedPartial } from '@rolster/commons';
3
3
  import { i18n, i18nSubscribe } from '@rolster/i18n';
4
4
  import { PaginationController, verifyDayPicker, createDayPicker, createDayRangePicker, verifyMonthPicker, createMonthPicker, monthLimitTemplate, createYearPicker, verifyYearPicker, ListCollection, navigationListFromInput, navigationListFromElement, createAutocompleteStore, PickerListenerEvent, dateOutRange, verifyDateRange } from '@rolster/components';
@@ -1571,9 +1571,9 @@ function RlsFieldArea(props) {
1571
1571
  return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsx("div", { className: "rls-field-box__body", children: jsxRuntimeExports.jsx(RlsAreaText, { ...props }) }) }), !props.msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1572
1572
  }
1573
1573
 
1574
- function RlsFieldFile({ accept, children, disabled: disabledProp, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value }) {
1574
+ function RlsFieldFile({ accept, children, disabled: _disabled, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value }) {
1575
1575
  const inputRef = useRef(null);
1576
- const disabled = useMemo(() => formControl?.disabled || disabledProp, [formControl?.disabled, disabledProp]);
1576
+ const disabled = useMemo(() => formControl?.disabled || _disabled, [formControl?.disabled, _disabled]);
1577
1577
  const className = useMemo(() => renderClassStatus('rls-field-box', {
1578
1578
  disabled,
1579
1579
  error: formControl?.wrong,
@@ -1605,7 +1605,7 @@ function RlsFieldFile({ accept, children, disabled: disabledProp, formControl, i
1605
1605
  const onClickControl = useCallback(() => {
1606
1606
  !readOnly && !disabled && inputRef.current?.click();
1607
1607
  }, [readOnly, disabled]);
1608
- return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", onClick: onClickControl, children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-input__component", readOnly: true, type: "text", value: displayValue, placeholder: placeholder }), jsxRuntimeExports.jsx("input", { ref: inputRef, className: "rls-field-file__input", type: "file", accept: accept, disabled: disabled || readOnly, onChange: onChangeInput }), jsxRuntimeExports.jsx(RlsButtonAction, { icon: currentFile ? 'close' : 'attach-2', disabled: disabled, onClick: onClickAction })] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1608
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", onClick: onClickControl, children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-input__component", readOnly: true, type: "text", value: displayValue, placeholder: placeholder }), jsxRuntimeExports.jsx("input", { ref: inputRef, className: "rls-field-file__input", type: "file", accept: accept, disabled: disabled || readOnly, onChange: onChangeInput }), jsxRuntimeExports.jsx(RlsButtonAction, { icon: currentFile ? 'close' : 'attach', disabled: disabled, onClick: onClickAction })] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }));
1609
1609
  }
1610
1610
 
1611
1611
  const reactI18n = i18n({
@@ -2593,7 +2593,7 @@ function useListController(props) {
2593
2593
  };
2594
2594
  }
2595
2595
 
2596
- const DURATION_ANIMATION$1 = 240;
2596
+ const DURATION_ANIMATION$2 = 240;
2597
2597
  const MAX_ELEMENTS = 6;
2598
2598
  function useFieldAutocomplete(props) {
2599
2599
  const controller = useListController(props);
@@ -2650,7 +2650,7 @@ function useFieldAutocomplete(props) {
2650
2650
  clearTimeout(focusTimeoutId.current);
2651
2651
  focusTimeoutId.current = setTimeout(() => {
2652
2652
  controller.refInput?.current?.focus();
2653
- }, DURATION_ANIMATION$1);
2653
+ }, DURATION_ANIMATION$2);
2654
2654
  }
2655
2655
  }, [controller.setState, props.readOnly]);
2656
2656
  useEffect(() => {
@@ -4300,6 +4300,60 @@ function RlsModalSheet({ autoclose, children, className, controller, onAutoClose
4300
4300
  return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameModal, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal-sheet__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal-sheet__backdrop", onClick: onClickBackdrop })] }), document.body);
4301
4301
  }
4302
4302
 
4303
+ const DURATION_ANIMATION$1 = 240;
4304
+ const DURATION_DEFAULT = 4000;
4305
+ let _id = 0;
4306
+ function generateId() {
4307
+ return `rls-notification-${++_id}`;
4308
+ }
4309
+ function RlsNotification({ content, icon, onClose, rlsTheme, title, visible }) {
4310
+ const className = useMemo(() => {
4311
+ return renderClassStatus('rls-notification', { visible });
4312
+ }, [visible]);
4313
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [icon && (jsxRuntimeExports.jsx("div", { className: "rls-notification__avatar", children: jsxRuntimeExports.jsx(RlsIcon, { value: icon }) })), jsxRuntimeExports.jsxs("div", { className: "rls-notification__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-notification__header", children: [jsxRuntimeExports.jsx("div", { className: "rls-notification__title", children: title }), jsxRuntimeExports.jsx("button", { onClick: onClose, children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) })] }), jsxRuntimeExports.jsx("div", { className: "rls-notification__content", children: content })] })] }));
4314
+ }
4315
+ function useNotifications() {
4316
+ const [notifications, setNotifications] = useState([]);
4317
+ const timersRef = useRef(new Map());
4318
+ useEffect(() => {
4319
+ const timers = timersRef.current;
4320
+ return () => {
4321
+ timers.forEach((timer) => clearTimeout(timer));
4322
+ timers.clear();
4323
+ };
4324
+ }, []);
4325
+ const remove = useCallback((id) => {
4326
+ const timer = timersRef.current.get(id);
4327
+ if (timer) {
4328
+ clearTimeout(timer);
4329
+ timersRef.current.delete(id);
4330
+ }
4331
+ setNotifications((notifications) => notifications.map((notification) => notification.id === id
4332
+ ? { ...notification, visible: false }
4333
+ : notification));
4334
+ setTimeout(() => {
4335
+ setNotifications((notifications) => notifications.filter((notification) => notification.id !== id));
4336
+ }, DURATION_ANIMATION$1);
4337
+ }, []);
4338
+ const notify = useCallback((config) => {
4339
+ const id = generateId();
4340
+ const duration = config.duration ?? DURATION_DEFAULT;
4341
+ setNotifications((notifications) => [
4342
+ ...notifications,
4343
+ { id, config, visible: true }
4344
+ ]);
4345
+ const timer = setTimeout(() => {
4346
+ remove(id);
4347
+ }, duration);
4348
+ timersRef.current.set(id, timer);
4349
+ }, [remove]);
4350
+ const RlsNotifications = ReactDOM.createPortal(jsxRuntimeExports.jsx("div", { className: "rls-notifications", children: notifications.map((notification) => (jsxRuntimeExports.jsx(RlsNotification, { ...notification.config, visible: notification.visible, onClose: () => remove(notification.id) }, notification.id))) }), document.body);
4351
+ return {
4352
+ RlsNotifications,
4353
+ notify
4354
+ };
4355
+ }
4356
+
4303
4357
  const DURATION_ANIMATION = 240;
4304
4358
  const DURATION_CHAR = 75;
4305
4359
  const DURATION_MAX = 9000;
@@ -4363,17 +4417,17 @@ function useSnackbar() {
4363
4417
  };
4364
4418
  }
4365
4419
 
4366
- const RlsContext = createContext({
4367
- confirmation: () => {
4368
- return Promise.resolve(ConfirmationResult.approved());
4369
- },
4370
- snackbar: () => { },
4371
- setIsMobile: () => { },
4372
- setNavbarInApp: () => { },
4373
- setNavbarIsCondense: () => { }
4374
- });
4420
+ const RlsContext = createContext(null);
4421
+ function useRlsContext() {
4422
+ const state = useContext(RlsContext);
4423
+ if (!state) {
4424
+ throw new Error('RlsApplication not wrapped in Project');
4425
+ }
4426
+ return state;
4427
+ }
4375
4428
  function RlsApplication({ children }) {
4376
4429
  const { RlsConfirmation, confirmation } = useConfirmation();
4430
+ const { RlsNotifications, notify } = useNotifications();
4377
4431
  const { RlsSnackbar, snackbar } = useSnackbar();
4378
4432
  const [navbarInApp, setNavbarInApp] = useState(false);
4379
4433
  const [navbarIsCondense, setNavbarIsCondense] = useState(false);
@@ -4387,11 +4441,12 @@ function RlsApplication({ children }) {
4387
4441
  }, [appIsMobile, navbarInApp, navbarIsCondense]);
4388
4442
  return (jsxRuntimeExports.jsxs(RlsContext, { value: {
4389
4443
  confirmation,
4444
+ notify,
4390
4445
  snackbar,
4391
4446
  setIsMobile,
4392
4447
  setNavbarInApp,
4393
4448
  setNavbarIsCondense
4394
- }, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, RlsSnackbar] }), RlsConfirmation] }));
4449
+ }, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, RlsSnackbar] }), RlsNotifications, RlsConfirmation] }));
4395
4450
  }
4396
4451
 
4397
4452
  const DEFAULT_DESIGN_SYSTEM = 'bordered';
@@ -4517,5 +4572,5 @@ function usePortalController() {
4517
4572
  return { close, open, visible };
4518
4573
  }
4519
4574
 
4520
- export { ConfirmationResult, DEFAULT_COLOR, RlsAccordion, RlsAlert, RlsAmount, RlsApplication, RlsAreaText, RlsAvatar, RlsBadge, RlsBallot, RlsBody, RlsBottomSheet, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonIcon, RlsButtonOption, RlsButtonProgress, RlsButtonStepper, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsConfirmation, RlsContent, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsDropdown, RlsFieldArea, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldClock, RlsFieldColor, RlsFieldDate, RlsFieldDateRange, RlsFieldDecimal, RlsFieldFile, RlsFieldList, RlsFieldListSuggestions, RlsFieldListTemplate, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldPercentage, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImage, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputCounter, RlsInputDecimal, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputPercentage, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsLed, RlsMessageEmpty, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsModalSheet, RlsNavbar, RlsNavbarMenu, RlsPagination, RlsPickerClock, RlsPickerColor, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSpinner, RlsSwitch, RlsSwitchControl, RlsTabs, RlsTabularText, RlsToolbar, calculateImgDimension, generateThemePalette, hexIsValid, hexToHsl, hexToHsv, hexToRgb, hslToHex, hsvToHex, hsvToRgb, normalizeHex, rangeFormatTemplate, renderClassStatus, rgbToHex, rgbToHsl, rgbToHsv, setDesignSystem, setErrorsI18n, setThemeColor, useConfirmation, useDatatable, useDesingSystemController, useDropdownController, useFieldAutocomplete, useFieldList, useFieldSelect, useFormSingleSelectionController, useFormToggleController, useImageEditorController, useListController, usePortalController, useRelocationOnComponent, useResize, useSnackbar };
4575
+ export { ConfirmationResult, DEFAULT_COLOR, RlsAccordion, RlsAlert, RlsAmount, RlsApplication, RlsAreaText, RlsAvatar, RlsBadge, RlsBallot, RlsBody, RlsBottomSheet, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonIcon, RlsButtonOption, RlsButtonProgress, RlsButtonStepper, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsConfirmation, RlsContent, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsDropdown, RlsFieldArea, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldClock, RlsFieldColor, RlsFieldDate, RlsFieldDateRange, RlsFieldDecimal, RlsFieldFile, RlsFieldList, RlsFieldListSuggestions, RlsFieldListTemplate, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldPercentage, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImage, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputCounter, RlsInputDecimal, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputPercentage, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsLed, RlsMessageEmpty, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsModalSheet, RlsNavbar, RlsNavbarMenu, RlsPagination, RlsPickerClock, RlsPickerColor, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSpinner, RlsSwitch, RlsSwitchControl, RlsTabs, RlsTabularText, RlsToolbar, calculateImgDimension, generateThemePalette, hexIsValid, hexToHsl, hexToHsv, hexToRgb, hslToHex, hsvToHex, hsvToRgb, normalizeHex, rangeFormatTemplate, renderClassStatus, rgbToHex, rgbToHsl, rgbToHsv, setDesignSystem, setErrorsI18n, setThemeColor, useConfirmation, useDatatable, useDesingSystemController, useDropdownController, useFieldAutocomplete, useFieldList, useFieldSelect, useFormSingleSelectionController, useFormToggleController, useImageEditorController, useListController, useNotifications, usePortalController, useRelocationOnComponent, useResize, useRlsContext, useSnackbar };
4521
4576
  //# sourceMappingURL=index.mjs.map