@linzjs/lui 21.35.1-0 → 21.37.0

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/lui.esm.js CHANGED
@@ -42089,6 +42089,9 @@ var FeatureIFrame = function (_a) {
42089
42089
  React__default.createElement("iframe", __assign({ width: iframeConfig.width, height: iframeConfig.height, src: iframeConfig.url, title: iframeConfig.title }, iFrameProps))));
42090
42090
  };
42091
42091
 
42092
+ /**
42093
+ * @deprecated this is replaced by `LuiModalV2`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42094
+ */
42092
42095
  var LuiModal = function (props) {
42093
42096
  var _a;
42094
42097
  var node = useRef(null);
@@ -42144,6 +42147,9 @@ var LuiModal = function (props) {
42144
42147
  }
42145
42148
  } }, props.children))));
42146
42149
  };
42150
+ /**
42151
+ * @deprecated this is replaced by `LuiAlertModalV2`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42152
+ */
42147
42153
  var LuiAlertModal = function (props) {
42148
42154
  var materialIcon = getMaterialIconForLevel(props.level);
42149
42155
  var level = props.level, className = props.className, children = props.children, rest = __rest(props, ["level", "className", "children"]);
@@ -42151,9 +42157,15 @@ var LuiAlertModal = function (props) {
42151
42157
  React__default.createElement(LuiIcon, { name: "ic_".concat(materialIcon), alt: "".concat(level, " status icon"), size: "lg", className: "lui-msg-status-icon" }),
42152
42158
  children));
42153
42159
  };
42160
+ /**
42161
+ * @deprecated this is replaced by `LuiModalV2.Buttons`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42162
+ */
42154
42163
  var LuiAlertModalButtons = function (props) {
42155
42164
  return React__default.createElement("div", { className: "modal-btn-row" }, props.children);
42156
42165
  };
42166
+ /**
42167
+ * @deprecated this is deprecated alongside `LuiModal`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42168
+ */
42157
42169
  var LuiModalHeader = function (props) {
42158
42170
  var _a;
42159
42171
  var headerStyle = (_a = props.style) !== null && _a !== void 0 ? _a : 'default';
@@ -42197,6 +42209,7 @@ function useClickedOutsideElement(refElement, handleClickOutside) {
42197
42209
  }
42198
42210
 
42199
42211
  var _a;
42212
+ /** Implements the [updated modal design system](https://www.figma.com/design/E7g3n5ziI7bR8MisISayia/FigLUI?node-id=9924-54717&t=q2r6Gct1cKGP9Q5B-0), keeping the same api as `LuiModal` as much as possible. */
42200
42213
  var LuiModalV2 = function (props) {
42201
42214
  var _a;
42202
42215
  var modalRef = useRef(null);
@@ -59461,20 +59474,23 @@ var Toast = function (props) {
59461
59474
  var reducer = function (state, action) {
59462
59475
  var updatedAt = new Date().getTime();
59463
59476
  if (action.type === 'add') {
59464
- var createdAt = updatedAt;
59465
- var notification = action.notification, options = action.options, id = action.id;
59466
- var toast = { notification: notification, options: options, id: id, updatedAt: updatedAt, createdAt: createdAt };
59467
- var toasts = __spreadArray([toast], state.toasts, true);
59468
- return trim(__assign(__assign({}, state), { toasts: toasts }));
59477
+ var notification = action.notification, options = action.options, id_1 = action.id;
59478
+ var base = { notification: notification, options: options, id: id_1, updatedAt: updatedAt };
59479
+ var found = state.toasts.find(function (t) { return t.id === id_1; });
59480
+ if (!found) {
59481
+ var toast = __assign(__assign({}, base), { createdAt: updatedAt });
59482
+ var toasts = __spreadArray([toast], state.toasts, true);
59483
+ return trim(__assign(__assign({}, state), { toasts: toasts }));
59484
+ }
59485
+ else {
59486
+ var toast_1 = __assign(__assign({}, found), base);
59487
+ var toasts = state.toasts.map(function (t) { return (t.id !== id_1 ? t : toast_1); });
59488
+ return __assign(__assign({}, state), { toasts: toasts });
59489
+ }
59469
59490
  }
59470
59491
  if (action.type === 'remove') {
59471
59492
  return __assign(__assign({}, state), { toasts: state.toasts.filter(function (t) { return t.id !== action.id; }) });
59472
59493
  }
59473
- if (action.type === 'update') {
59474
- var notification = action.notification, options = action.options, id_1 = action.id;
59475
- var updated_1 = { notification: notification, options: options, id: id_1, updatedAt: updatedAt };
59476
- return __assign(__assign({}, state), { toasts: state.toasts.map(function (t) { return (t.id !== id_1 ? t : __assign(__assign({}, t), updated_1)); }) });
59477
- }
59478
59494
  return state;
59479
59495
  };
59480
59496
  var useToastState = function (_a) {
@@ -59510,6 +59526,9 @@ var trim = function (state) { return (__assign(__assign({}, state), { toasts: Ob
59510
59526
  })
59511
59527
  .flat() })); };
59512
59528
 
59529
+ var ToastVersion = createContext('v1');
59530
+ var useToastVersion = function () { return useContext(ToastVersion); };
59531
+
59513
59532
  var ToastContext = React.createContext(undefined);
59514
59533
  var portal = getToastProviderEl();
59515
59534
  var ToastProvider = function (_a) {
@@ -59519,7 +59538,7 @@ var ToastProvider = function (_a) {
59519
59538
  if (useContext(ToastContext)) {
59520
59539
  return React.createElement(React.Fragment, null, children);
59521
59540
  }
59522
- return (React.createElement(React.Fragment, null,
59541
+ return (React.createElement(ToastVersion.Provider, { value: "v2" },
59523
59542
  ReactDOM.createPortal(React.createElement(React.Fragment, null, Object.entries(toasts).map(function (_a) {
59524
59543
  var section = _a[0], list = _a[1];
59525
59544
  return (React.createElement(ToastSection, __assign({ key: section }, {
@@ -59532,30 +59551,35 @@ var ToastProvider = function (_a) {
59532
59551
  React.createElement(ToastContext.Provider, { value: dispatch }, children)));
59533
59552
  };
59534
59553
 
59535
- var getUniqueToastId = function () { return Math.floor(Math.random() * 10000); };
59554
+ var getUniqueToastId = function () {
59555
+ var _a;
59556
+ var id = Number("".concat(Math.floor(Math.random() * 10000000)).slice(0, 4));
59557
+ var selector = "[data-toastid=\"".concat(id, "\"]");
59558
+ var duplicate = ((_a = getToastProviderEl().querySelectorAll(selector)) === null || _a === void 0 ? void 0 : _a.length) > 0;
59559
+ if (duplicate) {
59560
+ return getUniqueToastId();
59561
+ }
59562
+ return id;
59563
+ };
59536
59564
  var toastFunctions = function (dispatch) {
59537
- var toast = function (notification, options) {
59538
- var id = getUniqueToastId();
59565
+ var toast = function (notification, config) {
59566
+ if (config === void 0) { config = {}; }
59567
+ var _a = config.id, id = _a === void 0 ? getUniqueToastId() : _a, options = __rest(config, ["id"]);
59539
59568
  dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'add', notification: notification, options: options, id: id });
59540
59569
  return id;
59541
59570
  };
59542
- var update = function (id, notification, options) {
59543
- dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'update', notification: notification, options: options, id: id });
59544
- return id;
59545
- };
59546
59571
  var banner = function (level, defaults) {
59547
59572
  if (defaults === void 0) { defaults = {}; }
59548
59573
  return function (children, options) {
59549
59574
  if (options === void 0) { options = defaults; }
59550
59575
  return toast(function (_a) {
59551
- var close = _a.close;
59552
- return (React.createElement(LuiBannerV2, __assign({}, { level: level, children: children }, { onDismiss: options.timeout === Infinity ? close : undefined })));
59576
+ var onDismiss = _a.close;
59577
+ return (React.createElement(LuiBannerV2, __assign({}, { level: level, children: children, onDismiss: onDismiss })));
59553
59578
  }, options);
59554
59579
  };
59555
59580
  };
59556
59581
  return {
59557
59582
  toast: toast,
59558
- update: update,
59559
59583
  dismiss: function (id) { return dispatch === null || dispatch === void 0 ? void 0 : dispatch({ type: 'remove', id: id }); },
59560
59584
  info: banner('info'),
59561
59585
  success: banner('success'),
@@ -59564,6 +59588,32 @@ var toastFunctions = function (dispatch) {
59564
59588
  plain: banner()
59565
59589
  };
59566
59590
  };
59591
+ /**
59592
+ * Hook to display pop-up messages in response to a user action or state change. Examples include: Saving, exporting, committing, deleting, etc.
59593
+ * It requires 'LuiMessagingContextProvider' with property version set to 'v2'.
59594
+ * Toasts that are `warning` or `error` won't timeout automatically, unless configured otherwise.
59595
+ * @description Hook to trigger pop-up messages (a.k.a. toasts). Each toast helper function returns a a toast id `number` that can be used for manual dismiss or updates.
59596
+ * @example
59597
+ * // Error message
59598
+ * const { error } = useToast();
59599
+ * error("Failed to save");
59600
+ * @example
59601
+ * // Toast error and then turn toast into success
59602
+ * const { error, success } = useToast();
59603
+ * const toastId = error("Failed to save");
59604
+ * success('Toast updated to success', { id: toastId });
59605
+ * @example
59606
+ * // Dismiss info toast that won't dismiss automatically
59607
+ * const { info, dismiss } = useToast();
59608
+ * const toastId = info(<a href="#">Some useful link</a>, { timeout: Infinity });
59609
+ * dismiss(toastId);
59610
+ * @example
59611
+ * // Custom toasts accept `ReactNode` or `({ close: () => void }) => ReactNode`
59612
+ * const { toast } = useToast();
59613
+ * toast(({ close }) => <button onClick={() => close()}>Click me to dismiss</button>, { timeout: Infinity });
59614
+ * toast(<div>I will be dismissed in 3s.</div>, { timeout: 3000 });
59615
+ * toast("I'm placed in the topLeft of the page", { position: 'topLeft' });
59616
+ */
59567
59617
  var useToast = function () {
59568
59618
  var dispatch = useContext(ToastContext);
59569
59619
  return useMemo(function () { return toastFunctions(dispatch); }, [dispatch]);
@@ -59655,7 +59705,7 @@ var LuiToastMessageCompatibleInterface = function (props) {
59655
59705
  var toastIdRef = useRef(undefined);
59656
59706
  var onceDismissedRef = useRef(false);
59657
59707
  var displayRef = useRef(display);
59658
- var _c = useToast(), toast = _c.toast, dismiss = _c.dismiss, update = _c.update;
59708
+ var _c = useToast(), toast = _c.toast, dismiss = _c.dismiss;
59659
59709
  displayRef.current = display;
59660
59710
  // Close when it's unmounted
59661
59711
  useEffect(function () {
@@ -59671,23 +59721,18 @@ var LuiToastMessageCompatibleInterface = function (props) {
59671
59721
  if (display && !onceDismissed) {
59672
59722
  var notification = function (_a) {
59673
59723
  var close = _a.close;
59674
- var onDismiss = requireDismiss ? close : undefined;
59675
- return React__default.createElement(LuiBannerV2, __assign({}, { level: level, onDismiss: onDismiss, children: children }));
59724
+ return React__default.createElement(LuiBannerV2, __assign({}, { level: level, onDismiss: close, children: children }));
59676
59725
  };
59677
59726
  var options = {
59678
- timeout: displayTimeout === 0 ? Infinity : displayTimeout,
59727
+ timeout: requireDismiss || !displayTimeout ? Infinity : displayTimeout,
59679
59728
  onLeave: function () {
59680
59729
  onClose === null || onClose === void 0 ? void 0 : onClose();
59681
59730
  onceDismissedRef.current = displayRef.current;
59682
59731
  toastIdRef.current = undefined;
59683
- }
59732
+ },
59733
+ id: toastIdRef.current
59684
59734
  };
59685
- if (!toastIdRef.current) {
59686
- toastIdRef.current = toast(notification, options);
59687
- }
59688
- else {
59689
- update(toastIdRef.current, notification, options);
59690
- }
59735
+ toastIdRef.current = toast(notification, options);
59691
59736
  }
59692
59737
  if (!display && toastIdRef.current !== undefined) {
59693
59738
  dismiss(toastIdRef.current);
@@ -59697,48 +59742,50 @@ var LuiToastMessageCompatibleInterface = function (props) {
59697
59742
  return React__default.createElement(React__default.Fragment, null);
59698
59743
  };
59699
59744
 
59745
+ var getTimeout = function (_a) {
59746
+ var requireDismiss = _a.requireDismiss, messageLevel = _a.messageLevel;
59747
+ return (requireDismiss !== null && requireDismiss !== void 0 ? requireDismiss : messageLevel === 'error') ? Infinity : undefined;
59748
+ };
59700
59749
  /**
59701
59750
  * Provide new toast hook with old interface from original useShowLUIMessage
59702
59751
  */
59703
59752
  var useShowLUIMessageCompatibleInterface = function () {
59704
- var toast = useToast().toast;
59753
+ var t = useToast();
59705
59754
  return function (props) {
59706
- var message = props.message, messageLevel = props.messageLevel, requireDismiss = props.requireDismiss;
59707
- var toastProps = { children: message, level: messageLevel };
59708
- if (requireDismiss || messageLevel === 'error') {
59709
- toast(function (_a) {
59710
- var close = _a.close;
59711
- return React__default.createElement(LuiBannerV2, __assign({}, toastProps, { onDismiss: close }));
59712
- });
59713
- }
59714
- else {
59715
- toast(React__default.createElement(LuiBannerV2, __assign({}, toastProps)));
59716
- }
59755
+ return t[props.messageLevel](props.message, { timeout: getTimeout(props) });
59717
59756
  };
59718
59757
  };
59719
59758
 
59720
- var ToastUpgrade = createContext(false);
59721
- var useToastUpgrade = function () { return useContext(ToastUpgrade); };
59722
59759
  /**
59723
- * @deprecated Use ToastProvider or LuiMessagingContextProvider with upgrade prop set to true to get the new designs
59760
+ * Context provider to handle global logic of toast messages. It defaults to legacy version 'v1'.
59761
+ * @description Set version property to 'v2' to get the latest designs.
59724
59762
  */
59725
59763
  var LuiMessagingContextProvider = function (props) {
59726
- var _a = props.upgrade, upgrade = _a === void 0 ? false : _a, rest = __rest(props, ["upgrade"]);
59727
59764
  if (useContext(ToastContext)) {
59728
- return React__default.createElement(React__default.Fragment, null, rest.children);
59765
+ return React__default.createElement(React__default.Fragment, null, props.children);
59729
59766
  }
59730
- return (React__default.createElement(ToastUpgrade.Provider, { value: upgrade }, upgrade ? (React__default.createElement(ToastProvider, __assign({}, rest))) : (React__default.createElement(LuiMessagingContextProvider$1, __assign({}, rest)))));
59767
+ return (React__default.createElement(React__default.Fragment, null, props.version === 'v2' ? (React__default.createElement(ToastProvider, { stack: props.stack, defaultTimeout: props.defaultTimeout }, props.children)) : (React__default.createElement(ToastVersion.Provider, { value: "v1" },
59768
+ React__default.createElement(LuiMessagingContextProvider$1, null, props.children)))));
59731
59769
  };
59770
+ /**
59771
+ * Hook to display pop-up messages in response to a user action or state change. Examples include: Saving, exporting, committing, deleting, etc.
59772
+ * @description Legacy hook to trigger toasts. It requires {@linkcode LuiMessagingContextProvider}.
59773
+ * @alias useToast. For a more flexible API when you're using v2 designs, using useToast is recommended.
59774
+ * @returns Toaster function to trigger branded toasts (e.g. warning, error, info) in the top right of the page.
59775
+ * @example
59776
+ * const toaster = useShowLUIMessage();
59777
+ * toaster({ message: 'Failed to save', messageType: 'toast', messageLevel: 'error' });
59778
+ */
59732
59779
  var useShowLUIMessage = function () {
59733
- var upgrade = useToastUpgrade();
59780
+ var version = useToastVersion();
59734
59781
  var older = useShowLUIMessage$1();
59735
59782
  var newer = useShowLUIMessageCompatibleInterface();
59736
- return upgrade ? newer : older;
59783
+ return version === 'v2' ? newer : older;
59737
59784
  };
59738
59785
  var LuiToastMessage = function (props) {
59739
- var upgrade = useToastUpgrade();
59740
- return upgrade ? (React__default.createElement(LuiToastMessageCompatibleInterface, __assign({}, props))) : (React__default.createElement(LuiToastMessage$1, __assign({}, props)));
59786
+ var version = useToastVersion();
59787
+ return version === 'v2' ? (React__default.createElement(LuiToastMessageCompatibleInterface, __assign({}, props))) : (React__default.createElement(LuiToastMessage$1, __assign({}, props)));
59741
59788
  };
59742
59789
 
59743
- export { CheckboxItemRenderer, LUI_WINDOW_NAME, LuiAccordicard, LuiAccordicardStatic, LuiAccordion, LuiAlertModal, LuiAlertModalButtons, LuiAlertModalV2, LuiAppFooterSml, LuiBadge, LuiBanner, LuiBannerContent, LuiBannerV2, LuiBearingInput, LuiButton, LuiButtonGroup, LuiCheckboxInput, LuiCloseableHeaderMenuContext, LuiCloseableHeaderMenuContextV2, LuiCloseableHeaderMenuItem, LuiCloseableHeaderMenuItemV2, LuiComboSelect, LuiControlledMenu, LuiCounter, LuiDateInput, LuiDrawerMenu, LuiDrawerMenuDivider, LuiDrawerMenuDividerV2, LuiDrawerMenuOption, LuiDrawerMenuOptionV2, LuiDrawerMenuOptions, LuiDrawerMenuOptionsV2, LuiDrawerMenuSection, LuiDrawerMenuSectionV2, LuiDrawerMenuV2, LuiDropdownMenu, LuiDropdownMenuV2, LuiDropdownMenuV2DropContent, LuiErrorIllustration, LuiErrorPage, LuiExpandableBanner, LuiFileInputBox, LuiFilterContainer, LuiFilterMenu, LuiFloatingWindow, $F as LuiFloatingWindowContextProvider, LuiFooter, LuiFormSectionHeader, LuiHeader, LuiHeaderMenuItem, LuiHeaderMenuItemV2, LuiHeaderV2, LuiIcon, LuiListBox, LuiLoadingSpinner, LuiMenu, LuiMenuCloseButton, LuiMenuCloseButtonV2, LuiMessagingContextProvider, LuiMiniSpinner, LuiModal, LuiModalV2, LuiMoneyInput, LuiMultiSwitch, LuiMultiSwitchYesNo, LuiPagination, LuiProgressBar, LuiRadioInput, LuiResizableLayout, LuiSearchBox, LuiSearchInput, LuiSelectDataMenu, LuiSelectInput, LuiSelectMenu, LuiSelectMenuItem, LuiSelectMenuItemSwitch, LuiSelectSubMenuItem, LuiShadow, LuiSideMenu, LuiSideMenuItem, LuiSidePanel, LuiSidePanelProvider, LuiSideToolbar, LuiSplitButton, LuiSplitButtonMenuItem, LuiSplitButtonPosition, LuiStaticMessage, LuiStatusSpinner, LuiSwitchButton, LuiTab, LuiTabs, LuiTabsContext, LuiTabsGroup, LuiTabsPanel, LuiTabsPanelSwitch, LuiTextAreaInput, LuiTextInput, LuiToastMessage, LuiTooltip, LuiUpdatesSplashModal, RadioItemRenderer, SplitPanelState, Splitter, ToastProvider, ToolbarButton, ToolbarDirection, ToolbarItem, ToolbarItemSeparator, breakpointQuery, breakpoints, isChromatic, useClickedOutsideElement, useEscapeFunction, useLuiCloseableHeaderMenuContextV2, lR as useLuiFloatingWindow, useMediaQuery, usePageClickFunction, useShowLUIMessage, useSplitterRef, useToast };
59790
+ export { CheckboxItemRenderer, LUI_WINDOW_NAME, LuiAccordicard, LuiAccordicardStatic, LuiAccordion, LuiAlertModal, LuiAlertModalButtons, LuiAlertModalV2, LuiAppFooterSml, LuiBadge, LuiBanner, LuiBannerContent, LuiBannerV2, LuiBearingInput, LuiButton, LuiButtonGroup, LuiCheckboxInput, LuiCloseableHeaderMenuContext, LuiCloseableHeaderMenuContextV2, LuiCloseableHeaderMenuItem, LuiCloseableHeaderMenuItemV2, LuiComboSelect, LuiControlledMenu, LuiCounter, LuiDateInput, LuiDrawerMenu, LuiDrawerMenuDivider, LuiDrawerMenuDividerV2, LuiDrawerMenuOption, LuiDrawerMenuOptionV2, LuiDrawerMenuOptions, LuiDrawerMenuOptionsV2, LuiDrawerMenuSection, LuiDrawerMenuSectionV2, LuiDrawerMenuV2, LuiDropdownMenu, LuiDropdownMenuV2, LuiDropdownMenuV2DropContent, LuiErrorIllustration, LuiErrorPage, LuiExpandableBanner, LuiFileInputBox, LuiFilterContainer, LuiFilterMenu, LuiFloatingWindow, $F as LuiFloatingWindowContextProvider, LuiFooter, LuiFormSectionHeader, LuiHeader, LuiHeaderMenuItem, LuiHeaderMenuItemV2, LuiHeaderV2, LuiIcon, LuiListBox, LuiLoadingSpinner, LuiMenu, LuiMenuCloseButton, LuiMenuCloseButtonV2, LuiMessagingContextProvider, LuiMiniSpinner, LuiModal, LuiModalV2, LuiMoneyInput, LuiMultiSwitch, LuiMultiSwitchYesNo, LuiPagination, LuiProgressBar, LuiRadioInput, LuiResizableLayout, LuiSearchBox, LuiSearchInput, LuiSelectDataMenu, LuiSelectInput, LuiSelectMenu, LuiSelectMenuItem, LuiSelectMenuItemSwitch, LuiSelectSubMenuItem, LuiShadow, LuiSideMenu, LuiSideMenuItem, LuiSidePanel, LuiSidePanelProvider, LuiSideToolbar, LuiSplitButton, LuiSplitButtonMenuItem, LuiSplitButtonPosition, LuiStaticMessage, LuiStatusSpinner, LuiSwitchButton, LuiTab, LuiTabs, LuiTabsContext, LuiTabsGroup, LuiTabsPanel, LuiTabsPanelSwitch, LuiTextAreaInput, LuiTextInput, LuiToastMessage, LuiTooltip, LuiUpdatesSplashModal, RadioItemRenderer, SplitPanelState, Splitter, ToolbarButton, ToolbarDirection, ToolbarItem, ToolbarItemSeparator, breakpointQuery, breakpoints, isChromatic, useClickedOutsideElement, useEscapeFunction, useLuiCloseableHeaderMenuContextV2, lR as useLuiFloatingWindow, useMediaQuery, usePageClickFunction, useShowLUIMessage, useSplitterRef, useToast };
59744
59791
  //# sourceMappingURL=lui.esm.js.map