@linzjs/lui 21.36.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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [21.37.0](https://github.com/linz/lui/compare/v21.36.0...v21.37.0) (2024-07-01)
2
+
3
+
4
+ ### Features
5
+
6
+ * **LuiModalV2:** trigger release ([#1129](https://github.com/linz/lui/issues/1129)) ([a914f10](https://github.com/linz/lui/commit/a914f10d05d070d40cda00b30aecab808c27ffe2))
7
+ * **LuiModalV2:** Update modals UI ([#1127](https://github.com/linz/lui/issues/1127)) ([05d3ae5](https://github.com/linz/lui/commit/05d3ae571ff52dedabfc93ec4a056a0d0b3fe508))
8
+
1
9
  # [21.36.0](https://github.com/linz/lui/compare/v21.35.0...v21.36.0) (2024-07-01)
2
10
 
3
11
 
@@ -0,0 +1,7 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+ import { LuiModalV2Props } from './LuiModalV2';
3
+ export declare type LuiAlertModalLevel = 'success' | 'info' | 'warning' | 'error';
4
+ export declare type LuiAlertModalV2Props = Omit<LuiModalV2Props, 'headingIcon'> & {
5
+ level: LuiAlertModalLevel;
6
+ };
7
+ export declare const LuiAlertModalV2: FC<PropsWithChildren<LuiAlertModalV2Props>>;
@@ -13,10 +13,19 @@ interface ILuiModal {
13
13
  appendToElement?: () => HTMLElement;
14
14
  headerStyle?: 'light' | 'default';
15
15
  }
16
+ /**
17
+ * @deprecated this is replaced by `LuiModalV2`. [Migration notes](https://github.com/linz/Lui/pull/1127).
18
+ */
16
19
  export declare const LuiModal: React.FC<React.PropsWithChildren<ILuiModal>>;
20
+ /**
21
+ * @deprecated this is replaced by `LuiAlertModalV2`. [Migration notes](https://github.com/linz/Lui/pull/1127).
22
+ */
17
23
  export declare const LuiAlertModal: React.FC<React.PropsWithChildren<{
18
24
  level: 'success' | 'info' | 'warning' | 'error';
19
25
  } & ILuiModal>>;
26
+ /**
27
+ * @deprecated this is replaced by `LuiModalV2.Buttons`. [Migration notes](https://github.com/linz/Lui/pull/1127).
28
+ */
20
29
  export declare const LuiAlertModalButtons: React.FC<React.PropsWithChildren<unknown>>;
21
30
  interface IModalHeader {
22
31
  headingText?: string;
@@ -24,5 +33,8 @@ interface IModalHeader {
24
33
  onClose?: () => void;
25
34
  style?: 'light' | 'default';
26
35
  }
36
+ /**
37
+ * @deprecated this is deprecated alongside `LuiModal`. [Migration notes](https://github.com/linz/Lui/pull/1127).
38
+ */
27
39
  export declare const LuiModalHeader: React.FC<React.PropsWithChildren<IModalHeader>>;
28
40
  export {};
@@ -0,0 +1,34 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { LuiIconProps } from '../LuiIcon/LuiIcon';
3
+ export declare type LuiModalV2Props = {
4
+ key?: string;
5
+ /** Default `true` */
6
+ shouldCloseOnOverlayClick?: boolean;
7
+ /** Default `true` */
8
+ shouldCloseOnEsc?: boolean | 'use-keyup';
9
+ onClose?: () => void | Promise<void>;
10
+ showCloseButton?: boolean;
11
+ className?: string;
12
+ /** If set to true, the modal will take the full screen width. Default `false` */
13
+ maxWidth?: boolean;
14
+ headingText?: string;
15
+ headingIcon?: LuiIconProps;
16
+ helpLink?: string | (() => void | Promise<void>);
17
+ isLoading?: boolean;
18
+ /** Sets the overlay to white. This is only to be used for situations when the user is working in a component and there is benefit to hiding the surrounding page. An example is editing types of instruments in the Dealings flow in LOL. */
19
+ lowContrast?: boolean;
20
+ /** By default, the modal autofocuses the first `input` or `button` inside it. Set this prop to `true` to disable that behaviour. Default `false`. This is kept from LuiModal "V1" for backwards compatibility. */
21
+ preventAutoFocus?: boolean;
22
+ /** By default, the modal portal will be appended to the document's body, but we might need to append it to another element. This is passed the React Modal `parentSelector` prop. */
23
+ appendToElement?: () => HTMLElement;
24
+ };
25
+ /** 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. */
26
+ export declare const LuiModalV2: {
27
+ (props: PropsWithChildren<LuiModalV2Props>): JSX.Element;
28
+ Buttons: React.FC<React.PropsWithChildren<{
29
+ className?: string | undefined;
30
+ }>>;
31
+ HeaderTitle: React.FC<React.PropsWithChildren<{
32
+ className?: string | undefined;
33
+ }>>;
34
+ };
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * @param onEscape the handler function
6
6
  */
7
- export declare const useEscapeFunction: (onEscape: () => void) => void;
7
+ export declare const useEscapeFunction: (onEscape: (e: KeyboardEvent) => void | Promise<void>, trigger?: 'keyup' | 'keydown') => void;
8
8
  /**
9
9
  * A hook which allows handling of click event anywhere on the page.
10
10
  * Provides a way of handling clicks done inside or outside the element bound to the returned react ref.
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { MutableRefObject, RefObject } from 'react';
2
2
  /**
3
3
  * This hook will callback with handleClickOutside() when "mousedown" dom event occurs off the refElement
4
4
  * usage:
@@ -11,4 +11,4 @@ import React from 'react';
11
11
  return <button ref={refElement}>Click Me!</button>;
12
12
  ```
13
13
  */
14
- export declare function useClickedOutsideElement(refElement: React.RefObject<HTMLElement>, handleClickOutside: CallableFunction): void;
14
+ export declare function useClickedOutsideElement(refElement: RefObject<HTMLElement> | MutableRefObject<HTMLElement>, handleClickOutside: CallableFunction): void;
package/dist/index.d.ts CHANGED
@@ -37,6 +37,8 @@ export * from './components/LuiHeaderMenu/LuiHeaderMenus';
37
37
  export * from './components/LuiHeaderMenuV2/LuiHeaderMenusV2';
38
38
  export { LuiUpdatesSplashModal } from './components/LuiUpdateSplashModal/LuiUpdatesSplashModal';
39
39
  export { LuiModal, LuiAlertModal, LuiAlertModalButtons, } from './components/LuiModal/LuiModal';
40
+ export { LuiModalV2, type LuiModalV2Props, } from './components/LuiModal/LuiModalV2';
41
+ export { LuiAlertModalV2, type LuiAlertModalLevel, type LuiAlertModalV2Props, } from './components/LuiModal/LuiAlertModalV2';
40
42
  export { type ISearchInputProps, LuiSearchInput, } from './components/LuiSearchInput/LuiSearchInput';
41
43
  export { type ISearchGroupedResult, type ISearchResult, } from './components/LuiSearchInput/ResultsDisplay';
42
44
  export { type ISearchMenuOption, type ILuiSearchBoxProps, LuiSearchBox, } from './components/LuiSearchBox/LuiSearchBox';
package/dist/index.js CHANGED
@@ -39830,17 +39830,12 @@ var motif = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0id
39830
39830
  *
39831
39831
  * @param onEscape the handler function
39832
39832
  */
39833
- var useEscapeFunction = function (onEscape) {
39834
- var escFunction = React.useCallback(function (event) {
39835
- if (event.keyCode === 27) {
39836
- onEscape();
39837
- }
39838
- }, [onEscape]);
39833
+ var useEscapeFunction = function (onEscape, trigger) {
39834
+ if (trigger === void 0) { trigger = 'keydown'; }
39835
+ var escFunction = React.useCallback(function (event) { return event.key === 'Escape' && onEscape(event); }, [onEscape]);
39839
39836
  React.useEffect(function () {
39840
- document.addEventListener('keydown', escFunction, false);
39841
- return function () {
39842
- document.removeEventListener('keydown', escFunction, false);
39843
- };
39837
+ document.addEventListener(trigger, escFunction);
39838
+ return function () { return document.removeEventListener(trigger, escFunction); };
39844
39839
  }, [escFunction]);
39845
39840
  };
39846
39841
  /**
@@ -42123,6 +42118,9 @@ var FeatureIFrame = function (_a) {
42123
42118
  React__default["default"].createElement("iframe", __assign({ width: iframeConfig.width, height: iframeConfig.height, src: iframeConfig.url, title: iframeConfig.title }, iFrameProps))));
42124
42119
  };
42125
42120
 
42121
+ /**
42122
+ * @deprecated this is replaced by `LuiModalV2`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42123
+ */
42126
42124
  var LuiModal = function (props) {
42127
42125
  var _a;
42128
42126
  var node = React.useRef(null);
@@ -42178,6 +42176,9 @@ var LuiModal = function (props) {
42178
42176
  }
42179
42177
  } }, props.children))));
42180
42178
  };
42179
+ /**
42180
+ * @deprecated this is replaced by `LuiAlertModalV2`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42181
+ */
42181
42182
  var LuiAlertModal = function (props) {
42182
42183
  var materialIcon = getMaterialIconForLevel(props.level);
42183
42184
  var level = props.level, className = props.className, children = props.children, rest = __rest(props, ["level", "className", "children"]);
@@ -42185,9 +42186,15 @@ var LuiAlertModal = function (props) {
42185
42186
  React__default["default"].createElement(LuiIcon, { name: "ic_".concat(materialIcon), alt: "".concat(level, " status icon"), size: "lg", className: "lui-msg-status-icon" }),
42186
42187
  children));
42187
42188
  };
42189
+ /**
42190
+ * @deprecated this is replaced by `LuiModalV2.Buttons`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42191
+ */
42188
42192
  var LuiAlertModalButtons = function (props) {
42189
42193
  return React__default["default"].createElement("div", { className: "modal-btn-row" }, props.children);
42190
42194
  };
42195
+ /**
42196
+ * @deprecated this is deprecated alongside `LuiModal`. [Migration notes](https://github.com/linz/Lui/pull/1127).
42197
+ */
42191
42198
  var LuiModalHeader = function (props) {
42192
42199
  var _a;
42193
42200
  var headerStyle = (_a = props.style) !== null && _a !== void 0 ? _a : 'default';
@@ -42202,6 +42209,120 @@ var LuiModalHeader = function (props) {
42202
42209
  React__default["default"].createElement(LuiIcon, { name: "ic_clear", alt: "Help", size: "lg" }))))))));
42203
42210
  };
42204
42211
 
42212
+ /**
42213
+ * This hook will callback with handleClickOutside() when "mousedown" dom event occurs off the refElement
42214
+ * usage:
42215
+ ```typescript
42216
+ const refElement = React.useRef<HTMLButtonElement>(null);
42217
+ const handleClickOutside = () => {
42218
+ console.log("hello world");
42219
+ };
42220
+ useClickedOutsideElement(refElement, handleClickOutside);
42221
+ return <button ref={refElement}>Click Me!</button>;
42222
+ ```
42223
+ */
42224
+ function useClickedOutsideElement(refElement, handleClickOutside) {
42225
+ React__default["default"].useEffect(function () {
42226
+ function onOutsideClicked(event) {
42227
+ var element = refElement.current;
42228
+ if (!(element === null || element === void 0 ? void 0 : element.contains(event.target))) {
42229
+ handleClickOutside();
42230
+ }
42231
+ }
42232
+ document.addEventListener('mousedown', onOutsideClicked);
42233
+ return function () {
42234
+ document.removeEventListener('mousedown', onOutsideClicked);
42235
+ };
42236
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42237
+ }, []);
42238
+ }
42239
+
42240
+ var _a;
42241
+ /** 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. */
42242
+ var LuiModalV2 = function (props) {
42243
+ var _a;
42244
+ var modalRef = React.useRef(null);
42245
+ var handleClickOutside = React.useCallback(function () { var _a; return props.shouldCloseOnOverlayClick && ((_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props)); }, [props.shouldCloseOnEsc, props.onClose]);
42246
+ useClickedOutsideElement(modalRef, handleClickOutside);
42247
+ var handleEsc = React.useCallback(function (e) {
42248
+ var _a;
42249
+ if (props.shouldCloseOnEsc !== false) {
42250
+ e.stopPropagation();
42251
+ (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
42252
+ }
42253
+ }, [props.shouldCloseOnEsc, props.onClose]);
42254
+ useEscapeFunction(handleEsc, props.shouldCloseOnEsc === 'use-keyup' ? 'keyup' : 'keydown');
42255
+ var handleAutoFocus = function (el) {
42256
+ if (props.preventAutoFocus)
42257
+ return;
42258
+ if (el && !el.contains(el.ownerDocument.activeElement)) {
42259
+ var firstFocusableElement = el.querySelector('input,button');
42260
+ firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
42261
+ }
42262
+ };
42263
+ var showCloseButton = Boolean(props.showCloseButton && props.onClose);
42264
+ var showHelpButton = Boolean(props.helpLink);
42265
+ var showButtons = showCloseButton || showHelpButton;
42266
+ var showHeadingIcon = props.headingIcon && !props.isLoading;
42267
+ return (React__default["default"].createElement(Modal, { key: props.key, isOpen: true,
42268
+ // disble the `shouldClose` props as we handle them ourselves
42269
+ shouldCloseOnOverlayClick: false, shouldCloseOnEsc: false, overlayClassName: "modal", className: props.lowContrast ? 'lui-scrim-low-contrast' : 'lui-scrim',
42270
+ // required to prevent warnings that are not applicable in real usage
42271
+ ariaHideApp: !isTest, parentSelector: props.appendToElement },
42272
+ React__default["default"].createElement("div", { ref: function (el) {
42273
+ modalRef.current = el;
42274
+ handleAutoFocus(el);
42275
+ }, className: clsx('lui-modal-v2 lui-box-shadow', props.maxWidth && 'lui-max-width', props.className) },
42276
+ React__default["default"].createElement("div", { className: "lui-modal-v2-header" },
42277
+ props.isLoading && (React__default["default"].createElement(LuiMiniSpinner, { size: 20, divProps: { className: 'lui-modal-v2-header-spinner' } })),
42278
+ showHeadingIcon && (React__default["default"].createElement("div", { className: "lui-modal-v2-header-icon" },
42279
+ React__default["default"].createElement(LuiIcon, __assign({ size: "md", name: "", alt: "Help" }, props.headingIcon, { className: clsx('', (_a = props.headingIcon) === null || _a === void 0 ? void 0 : _a.className) })))),
42280
+ props.headingText && (React__default["default"].createElement("h2", { className: "lui-modal-v2-header-title" }, props.headingText)),
42281
+ showButtons && (React__default["default"].createElement("div", { className: "lui-modal-v2-header-buttons" },
42282
+ showHelpButton && React__default["default"].createElement(HelpButton, { helpLink: props.helpLink }),
42283
+ showCloseButton && React__default["default"].createElement(CloseButton, { onClose: props.onClose })))),
42284
+ React__default["default"].createElement("div", { className: "lui-modal-v2-contents" }, props.children))));
42285
+ };
42286
+ var ButtonRow = function (props) { return (React__default["default"].createElement("div", { className: clsx('lui-modal-v2-btn-row', props.className) }, props.children)); };
42287
+ LuiModalV2.Buttons = ButtonRow;
42288
+ var HelpButton = function (props) { return (React__default["default"].createElement("button", { "aria-label": "Modal Help", title: "Help", className: "lui-modal-v2-header-help-btn", onClick: typeof props.helpLink === 'string'
42289
+ ? function () { return window.open(props.helpLink, '_blank'); }
42290
+ : props.helpLink },
42291
+ React__default["default"].createElement(LuiIcon, { name: "ic_help_outline", alt: "Help", size: "md" }))); };
42292
+ var CloseButton = function (props) { return (React__default["default"].createElement("button", { "aria-label": "Modal Close", title: "Close", className: "lui-modal-v2-header-close-btn", onClick: props.onClose },
42293
+ React__default["default"].createElement(LuiIcon, { name: "ic_clear", alt: "Help", size: "md" }))); };
42294
+ /** Allows injecting the modal header text. Useful when you can't use the `headingText` prop directly, or when you need to render styled content. */
42295
+ var HeaderTitle = function (props) {
42296
+ var _a = React.useState(), target = _a[0], setTarget = _a[1];
42297
+ // on mount, find the parent modal and set it as the target
42298
+ if (!target)
42299
+ return (React__default["default"].createElement("div", { style: { display: 'none' }, ref: function (el) {
42300
+ var modal = el === null || el === void 0 ? void 0 : el.closest(".lui-modal-v2");
42301
+ var modalHeader = modal === null || modal === void 0 ? void 0 : modal.querySelector(':scope > .lui-modal-v2-header');
42302
+ modalHeader && setTarget(modalHeader);
42303
+ } }));
42304
+ return ReactDOM.createPortal(React__default["default"].createElement("h2", { className: clsx('lui-modal-v2-header-title lui-modal-v2-header-title-portal', props.className) }, props.children), target);
42305
+ };
42306
+ LuiModalV2.HeaderTitle = HeaderTitle;
42307
+ // this is here for the tests
42308
+ var isTest = typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'test';
42309
+ if (!isTest)
42310
+ Modal.setAppElement('#root');
42311
+
42312
+ var LuiAlertModalV2 = function (props) {
42313
+ var level = props.level, className = props.className, children = props.children, rest = __rest(props, ["level", "className", "children"]);
42314
+ var materialIcon = getMaterialIconForLevel(level);
42315
+ var status = Object.keys(ICON_STATUS).includes(level)
42316
+ ? level
42317
+ : 'interactive';
42318
+ return (React__default["default"].createElement(LuiModalV2, __assign({}, rest, { className: clsx("lui-modal-v2-alert lui-modal-v2-".concat(level), className), headingIcon: {
42319
+ name: "ic_".concat(materialIcon),
42320
+ alt: "".concat(level, " status icon"),
42321
+ size: 'md',
42322
+ status: status
42323
+ } }), children));
42324
+ };
42325
+
42205
42326
  var css_248z$g = "@keyframes react-loading-skeleton {\n 100% {\n transform: translateX(100%);\n }\n}\n\n.react-loading-skeleton {\n --base-color: #ebebeb;\n --highlight-color: #f5f5f5;\n --animation-duration: 1.5s;\n --animation-direction: normal;\n --pseudo-element-display: block; /* Enable animation */\n\n background-color: var(--base-color);\n\n width: 100%;\n border-radius: 0.25rem;\n display: inline-flex;\n line-height: 1;\n\n position: relative;\n user-select: none;\n overflow: hidden;\n z-index: 1; /* Necessary for overflow: hidden to work correctly in Safari */\n}\n\n.react-loading-skeleton::after {\n content: ' ';\n display: var(--pseudo-element-display);\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n height: 100%;\n background-repeat: no-repeat;\n background-image: linear-gradient(\n 90deg,\n var(--base-color),\n var(--highlight-color),\n var(--base-color)\n );\n transform: translateX(-100%);\n\n animation-name: react-loading-skeleton;\n animation-direction: var(--animation-direction);\n animation-duration: var(--animation-duration);\n animation-timing-function: ease-in-out;\n animation-iteration-count: infinite;\n}\n\n@media (prefers-reduced-motion) {\n .react-loading-skeleton {\n --pseudo-element-display: none; /* Disable animation */\n }\n}\n";
42206
42327
  styleInject(css_248z$g);
42207
42328
 
@@ -46800,34 +46921,6 @@ var LuiTooltip = function (props) {
46800
46921
  return React__default["default"].createElement(Tippy, __assign({}, tippyProps), children);
46801
46922
  };
46802
46923
 
46803
- /**
46804
- * This hook will callback with handleClickOutside() when "mousedown" dom event occurs off the refElement
46805
- * usage:
46806
- ```typescript
46807
- const refElement = React.useRef<HTMLButtonElement>(null);
46808
- const handleClickOutside = () => {
46809
- console.log("hello world");
46810
- };
46811
- useClickedOutsideElement(refElement, handleClickOutside);
46812
- return <button ref={refElement}>Click Me!</button>;
46813
- ```
46814
- */
46815
- function useClickedOutsideElement(refElement, handleClickOutside) {
46816
- React__default["default"].useEffect(function () {
46817
- function onOutsideClicked(event) {
46818
- var element = refElement.current;
46819
- if (!(element === null || element === void 0 ? void 0 : element.contains(event.target))) {
46820
- handleClickOutside();
46821
- }
46822
- }
46823
- document.addEventListener('mousedown', onOutsideClicked);
46824
- return function () {
46825
- document.removeEventListener('mousedown', onOutsideClicked);
46826
- };
46827
- // eslint-disable-next-line react-hooks/exhaustive-deps
46828
- }, []);
46829
- }
46830
-
46831
46924
  var getFillClassName = function (fillVariation, backgroundFill) {
46832
46925
  if (backgroundFill) {
46833
46926
  return 'LuiBadge--fill';
@@ -59730,6 +59823,7 @@ exports.LuiAccordicardStatic = LuiAccordicardStatic;
59730
59823
  exports.LuiAccordion = LuiAccordion;
59731
59824
  exports.LuiAlertModal = LuiAlertModal;
59732
59825
  exports.LuiAlertModalButtons = LuiAlertModalButtons;
59826
+ exports.LuiAlertModalV2 = LuiAlertModalV2;
59733
59827
  exports.LuiAppFooterSml = LuiAppFooterSml;
59734
59828
  exports.LuiBadge = LuiBadge;
59735
59829
  exports.LuiBanner = LuiBanner;
@@ -59783,6 +59877,7 @@ exports.LuiMenuCloseButtonV2 = LuiMenuCloseButtonV2;
59783
59877
  exports.LuiMessagingContextProvider = LuiMessagingContextProvider;
59784
59878
  exports.LuiMiniSpinner = LuiMiniSpinner;
59785
59879
  exports.LuiModal = LuiModal;
59880
+ exports.LuiModalV2 = LuiModalV2;
59786
59881
  exports.LuiMoneyInput = LuiMoneyInput;
59787
59882
  exports.LuiMultiSwitch = LuiMultiSwitch;
59788
59883
  exports.LuiMultiSwitchYesNo = LuiMultiSwitchYesNo;