@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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Rolster Technology
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Rolster Technology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1573,9 +1573,9 @@ function RlsFieldArea(props) {
1573
1573
  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 }))] }));
1574
1574
  }
1575
1575
 
1576
- function RlsFieldFile({ accept, children, disabled: disabledProp, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value }) {
1576
+ function RlsFieldFile({ accept, children, disabled: _disabled, formControl, identifier, msgErrorDisabled, onValue, placeholder, readOnly, rlsTheme, value }) {
1577
1577
  const inputRef = require$$0.useRef(null);
1578
- const disabled = require$$0.useMemo(() => formControl?.disabled || disabledProp, [formControl?.disabled, disabledProp]);
1578
+ const disabled = require$$0.useMemo(() => formControl?.disabled || _disabled, [formControl?.disabled, _disabled]);
1579
1579
  const className = require$$0.useMemo(() => renderClassStatus('rls-field-box', {
1580
1580
  disabled,
1581
1581
  error: formControl?.wrong,
@@ -1607,7 +1607,7 @@ function RlsFieldFile({ accept, children, disabled: disabledProp, formControl, i
1607
1607
  const onClickControl = require$$0.useCallback(() => {
1608
1608
  !readOnly && !disabled && inputRef.current?.click();
1609
1609
  }, [readOnly, disabled]);
1610
- 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 }))] }));
1610
+ 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 }))] }));
1611
1611
  }
1612
1612
 
1613
1613
  const reactI18n = i18n.i18n({
@@ -2595,7 +2595,7 @@ function useListController(props) {
2595
2595
  };
2596
2596
  }
2597
2597
 
2598
- const DURATION_ANIMATION$1 = 240;
2598
+ const DURATION_ANIMATION$2 = 240;
2599
2599
  const MAX_ELEMENTS = 6;
2600
2600
  function useFieldAutocomplete(props) {
2601
2601
  const controller = useListController(props);
@@ -2652,7 +2652,7 @@ function useFieldAutocomplete(props) {
2652
2652
  clearTimeout(focusTimeoutId.current);
2653
2653
  focusTimeoutId.current = setTimeout(() => {
2654
2654
  controller.refInput?.current?.focus();
2655
- }, DURATION_ANIMATION$1);
2655
+ }, DURATION_ANIMATION$2);
2656
2656
  }
2657
2657
  }, [controller.setState, props.readOnly]);
2658
2658
  require$$0.useEffect(() => {
@@ -4302,6 +4302,60 @@ function RlsModalSheet({ autoclose, children, className, controller, onAutoClose
4302
4302
  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);
4303
4303
  }
4304
4304
 
4305
+ const DURATION_ANIMATION$1 = 240;
4306
+ const DURATION_DEFAULT = 4000;
4307
+ let _id = 0;
4308
+ function generateId() {
4309
+ return `rls-notification-${++_id}`;
4310
+ }
4311
+ function RlsNotification({ content, icon, onClose, rlsTheme, title, visible }) {
4312
+ const className = require$$0.useMemo(() => {
4313
+ return renderClassStatus('rls-notification', { visible });
4314
+ }, [visible]);
4315
+ 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 })] })] }));
4316
+ }
4317
+ function useNotifications() {
4318
+ const [notifications, setNotifications] = require$$0.useState([]);
4319
+ const timersRef = require$$0.useRef(new Map());
4320
+ require$$0.useEffect(() => {
4321
+ const timers = timersRef.current;
4322
+ return () => {
4323
+ timers.forEach((timer) => clearTimeout(timer));
4324
+ timers.clear();
4325
+ };
4326
+ }, []);
4327
+ const remove = require$$0.useCallback((id) => {
4328
+ const timer = timersRef.current.get(id);
4329
+ if (timer) {
4330
+ clearTimeout(timer);
4331
+ timersRef.current.delete(id);
4332
+ }
4333
+ setNotifications((notifications) => notifications.map((notification) => notification.id === id
4334
+ ? { ...notification, visible: false }
4335
+ : notification));
4336
+ setTimeout(() => {
4337
+ setNotifications((notifications) => notifications.filter((notification) => notification.id !== id));
4338
+ }, DURATION_ANIMATION$1);
4339
+ }, []);
4340
+ const notify = require$$0.useCallback((config) => {
4341
+ const id = generateId();
4342
+ const duration = config.duration ?? DURATION_DEFAULT;
4343
+ setNotifications((notifications) => [
4344
+ ...notifications,
4345
+ { id, config, visible: true }
4346
+ ]);
4347
+ const timer = setTimeout(() => {
4348
+ remove(id);
4349
+ }, duration);
4350
+ timersRef.current.set(id, timer);
4351
+ }, [remove]);
4352
+ 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);
4353
+ return {
4354
+ RlsNotifications,
4355
+ notify
4356
+ };
4357
+ }
4358
+
4305
4359
  const DURATION_ANIMATION = 240;
4306
4360
  const DURATION_CHAR = 75;
4307
4361
  const DURATION_MAX = 9000;
@@ -4365,17 +4419,17 @@ function useSnackbar() {
4365
4419
  };
4366
4420
  }
4367
4421
 
4368
- const RlsContext = require$$0.createContext({
4369
- confirmation: () => {
4370
- return Promise.resolve(ConfirmationResult.approved());
4371
- },
4372
- snackbar: () => { },
4373
- setIsMobile: () => { },
4374
- setNavbarInApp: () => { },
4375
- setNavbarIsCondense: () => { }
4376
- });
4422
+ const RlsContext = require$$0.createContext(null);
4423
+ function useRlsContext() {
4424
+ const state = require$$0.useContext(RlsContext);
4425
+ if (!state) {
4426
+ throw new Error('RlsApplication not wrapped in Project');
4427
+ }
4428
+ return state;
4429
+ }
4377
4430
  function RlsApplication({ children }) {
4378
4431
  const { RlsConfirmation, confirmation } = useConfirmation();
4432
+ const { RlsNotifications, notify } = useNotifications();
4379
4433
  const { RlsSnackbar, snackbar } = useSnackbar();
4380
4434
  const [navbarInApp, setNavbarInApp] = require$$0.useState(false);
4381
4435
  const [navbarIsCondense, setNavbarIsCondense] = require$$0.useState(false);
@@ -4389,11 +4443,12 @@ function RlsApplication({ children }) {
4389
4443
  }, [appIsMobile, navbarInApp, navbarIsCondense]);
4390
4444
  return (jsxRuntimeExports.jsxs(RlsContext, { value: {
4391
4445
  confirmation,
4446
+ notify,
4392
4447
  snackbar,
4393
4448
  setIsMobile,
4394
4449
  setNavbarInApp,
4395
4450
  setNavbarIsCondense
4396
- }, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, RlsSnackbar] }), RlsConfirmation] }));
4451
+ }, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, RlsSnackbar] }), RlsNotifications, RlsConfirmation] }));
4397
4452
  }
4398
4453
 
4399
4454
  const DEFAULT_DESIGN_SYSTEM = 'bordered';
@@ -4654,8 +4709,10 @@ exports.useFormSingleSelectionController = useFormSingleSelectionController;
4654
4709
  exports.useFormToggleController = useFormToggleController;
4655
4710
  exports.useImageEditorController = useImageEditorController;
4656
4711
  exports.useListController = useListController;
4712
+ exports.useNotifications = useNotifications;
4657
4713
  exports.usePortalController = usePortalController;
4658
4714
  exports.useRelocationOnComponent = useRelocationOnComponent;
4659
4715
  exports.useResize = useResize;
4716
+ exports.useRlsContext = useRlsContext;
4660
4717
  exports.useSnackbar = useSnackbar;
4661
4718
  //# sourceMappingURL=index.cjs.map