@linzjs/lui 21.34.0 → 21.34.1-1

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.
@@ -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>>;
@@ -0,0 +1,30 @@
1
+ import { FC, PropsWithChildren, ReactNode } 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`. */
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
+ export declare const LuiModalV2: FC<PropsWithChildren<LuiModalV2Props>>;
26
+ export declare const LuiModalV2Buttons: FC<PropsWithChildren<unknown>>;
27
+ /** Allows injecting the modal header text */
28
+ export declare const LuiModalV2HeadingText: FC<{
29
+ children?: ReactNode;
30
+ }>;
@@ -5,6 +5,7 @@
5
5
  * @param onEscape the handler function
6
6
  */
7
7
  export declare const useEscapeFunction: (onEscape: () => void) => void;
8
+ export declare const useEscapeFunction2: (onEscape: (e: KeyboardEvent) => void | Promise<void>, trigger?: 'keyup' | 'keydown') => void;
8
9
  /**
9
10
  * A hook which allows handling of click event anywhere on the page.
10
11
  * 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, LuiModalV2Buttons, LuiModalV2HeadingText, 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
@@ -39924,6 +39924,14 @@ var useEscapeFunction = function (onEscape) {
39924
39924
  };
39925
39925
  }, [escFunction]);
39926
39926
  };
39927
+ var useEscapeFunction2 = function (onEscape, trigger) {
39928
+ if (trigger === void 0) { trigger = 'keydown'; }
39929
+ var escFunction = React.useCallback(function (event) { return event.key === 'Escape' && onEscape(event); }, [onEscape]);
39930
+ React.useEffect(function () {
39931
+ document.addEventListener(trigger, escFunction);
39932
+ return function () { return document.removeEventListener(trigger, escFunction); };
39933
+ }, [escFunction]);
39934
+ };
39927
39935
  /**
39928
39936
  * A hook which allows handling of click event anywhere on the page.
39929
39937
  * Provides a way of handling clicks done inside or outside the element bound to the returned react ref.
@@ -42283,6 +42291,117 @@ var LuiModalHeader = function (props) {
42283
42291
  React__default["default"].createElement(LuiIcon, { name: "ic_clear", alt: "Help", size: "lg" }))))))));
42284
42292
  };
42285
42293
 
42294
+ /**
42295
+ * This hook will callback with handleClickOutside() when "mousedown" dom event occurs off the refElement
42296
+ * usage:
42297
+ ```typescript
42298
+ const refElement = React.useRef<HTMLButtonElement>(null);
42299
+ const handleClickOutside = () => {
42300
+ console.log("hello world");
42301
+ };
42302
+ useClickedOutsideElement(refElement, handleClickOutside);
42303
+ return <button ref={refElement}>Click Me!</button>;
42304
+ ```
42305
+ */
42306
+ function useClickedOutsideElement(refElement, handleClickOutside) {
42307
+ React__default["default"].useEffect(function () {
42308
+ function onOutsideClicked(event) {
42309
+ var element = refElement.current;
42310
+ if (!(element === null || element === void 0 ? void 0 : element.contains(event.target))) {
42311
+ handleClickOutside();
42312
+ }
42313
+ }
42314
+ document.addEventListener('mousedown', onOutsideClicked);
42315
+ return function () {
42316
+ document.removeEventListener('mousedown', onOutsideClicked);
42317
+ };
42318
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42319
+ }, []);
42320
+ }
42321
+
42322
+ var _a;
42323
+ // this is here for the tests
42324
+ 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';
42325
+ if (!isTest)
42326
+ Modal.setAppElement('#root');
42327
+ var LuiModalV2 = function (props) {
42328
+ var _a;
42329
+ var modalRef = React.useRef(null);
42330
+ 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]);
42331
+ useClickedOutsideElement(modalRef, handleClickOutside);
42332
+ var handleEsc = React.useCallback(function (e) {
42333
+ var _a;
42334
+ if (props.shouldCloseOnEsc !== false) {
42335
+ e.stopPropagation();
42336
+ (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
42337
+ }
42338
+ }, [props.shouldCloseOnEsc, props.onClose]);
42339
+ useEscapeFunction2(handleEsc, props.shouldCloseOnEsc === 'use-keyup' ? 'keyup' : 'keydown');
42340
+ var handleAutoFocus = function (el) {
42341
+ if (props.preventAutoFocus)
42342
+ return;
42343
+ if (el && !el.contains(el.ownerDocument.activeElement)) {
42344
+ var firstFocusableElement = el.querySelector('input,button');
42345
+ firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
42346
+ }
42347
+ };
42348
+ var showCloseButton = Boolean(props.showCloseButton && props.onClose);
42349
+ var showHelpButton = Boolean(props.helpLink);
42350
+ var showButtons = showCloseButton || showHelpButton;
42351
+ var showHeadingIcon = props.headingIcon && !props.isLoading;
42352
+ return (React__default["default"].createElement(Modal, { key: props.key, isOpen: true,
42353
+ // disble the `shouldClose` props as we handle them ourselves
42354
+ shouldCloseOnOverlayClick: false, shouldCloseOnEsc: false, overlayClassName: "modal", className: props.lowContrast ? 'lui-scrim-low-contrast' : 'lui-scrim',
42355
+ // required to prevent warnings that are not applicable in real usage
42356
+ ariaHideApp: !isTest, parentSelector: props.appendToElement },
42357
+ React__default["default"].createElement("div", { ref: function (el) {
42358
+ modalRef.current = el;
42359
+ handleAutoFocus(el);
42360
+ }, className: clsx('lui-modal-v2 lui-box-shadow', props.maxWidth && 'lui-max-width', props.className) },
42361
+ React__default["default"].createElement("div", { className: "lui-modal-v2-header", id: "lui-modal-v2-header" },
42362
+ props.isLoading && (React__default["default"].createElement(LuiMiniSpinner, { size: 20, divProps: { className: 'lui-modal-v2-header-spinner' } })),
42363
+ showHeadingIcon && (React__default["default"].createElement("div", { className: "lui-modal-v2-header-icon" },
42364
+ 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) })))),
42365
+ props.headingText && (React__default["default"].createElement("h2", { className: "lui-modal-v2-header-title" }, props.headingText)),
42366
+ showButtons && (React__default["default"].createElement("div", { className: "lui-modal-v2-header-buttons" },
42367
+ showHelpButton && React__default["default"].createElement(HelpButton, { helpLink: props.helpLink }),
42368
+ showCloseButton && React__default["default"].createElement(CloseButton, { onClose: props.onClose })))),
42369
+ React__default["default"].createElement("div", { className: "lui-modal-v2-contents" }, props.children))));
42370
+ };
42371
+ var LuiModalV2Buttons = function (props) { return (React__default["default"].createElement("div", { className: "lui-modal-v2-btn-row" }, props.children)); };
42372
+ 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'
42373
+ ? function () { return window.open(props.helpLink, '_blank'); }
42374
+ : props.helpLink },
42375
+ React__default["default"].createElement(LuiIcon, { name: "ic_help_outline", alt: "Help", size: "md" }))); };
42376
+ 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 },
42377
+ React__default["default"].createElement(LuiIcon, { name: "ic_clear", alt: "Help", size: "md" }))); };
42378
+ /** Allows injecting the modal header text */
42379
+ var LuiModalV2HeadingText = function (_a) {
42380
+ var children = _a.children;
42381
+ var _b = React.useState(), target = _b[0], setTarget = _b[1];
42382
+ React.useEffect(function () {
42383
+ var modalHeader = document.querySelector('#lui-modal-v2-header');
42384
+ modalHeader && setTarget(modalHeader);
42385
+ }, []);
42386
+ if (!target)
42387
+ return null;
42388
+ return require$$1.createPortal(React__default["default"].createElement("h2", { className: "lui-modal-v2-header-title lui-modal-v2-header-title-portal" }, children), target);
42389
+ };
42390
+
42391
+ var LuiAlertModalV2 = function (props) {
42392
+ var level = props.level, className = props.className, children = props.children, rest = __rest(props, ["level", "className", "children"]);
42393
+ var materialIcon = getMaterialIconForLevel(level);
42394
+ var status = Object.keys(ICON_STATUS).includes(level)
42395
+ ? level
42396
+ : 'interactive';
42397
+ return (React__default["default"].createElement(LuiModalV2, __assign({}, rest, { className: clsx("lui-modal-v2-".concat(level), className), headingIcon: {
42398
+ name: "ic_".concat(materialIcon),
42399
+ alt: level,
42400
+ size: 'md',
42401
+ status: status
42402
+ } }), children));
42403
+ };
42404
+
42286
42405
  var css_248z$e = "@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";
42287
42406
  styleInject(css_248z$e);
42288
42407
 
@@ -46881,34 +47000,6 @@ var LuiTooltip = function (props) {
46881
47000
  return React__default["default"].createElement(Tippy, __assign({}, tippyProps), children);
46882
47001
  };
46883
47002
 
46884
- /**
46885
- * This hook will callback with handleClickOutside() when "mousedown" dom event occurs off the refElement
46886
- * usage:
46887
- ```typescript
46888
- const refElement = React.useRef<HTMLButtonElement>(null);
46889
- const handleClickOutside = () => {
46890
- console.log("hello world");
46891
- };
46892
- useClickedOutsideElement(refElement, handleClickOutside);
46893
- return <button ref={refElement}>Click Me!</button>;
46894
- ```
46895
- */
46896
- function useClickedOutsideElement(refElement, handleClickOutside) {
46897
- React__default["default"].useEffect(function () {
46898
- function onOutsideClicked(event) {
46899
- var element = refElement.current;
46900
- if (!(element === null || element === void 0 ? void 0 : element.contains(event.target))) {
46901
- handleClickOutside();
46902
- }
46903
- }
46904
- document.addEventListener('mousedown', onOutsideClicked);
46905
- return function () {
46906
- document.removeEventListener('mousedown', onOutsideClicked);
46907
- };
46908
- // eslint-disable-next-line react-hooks/exhaustive-deps
46909
- }, []);
46910
- }
46911
-
46912
47003
  var getFillClassName = function (fillVariation, backgroundFill) {
46913
47004
  if (backgroundFill) {
46914
47005
  return 'LuiBadge--fill';
@@ -59321,6 +59412,7 @@ exports.LuiAccordicardStatic = LuiAccordicardStatic;
59321
59412
  exports.LuiAccordion = LuiAccordion;
59322
59413
  exports.LuiAlertModal = LuiAlertModal;
59323
59414
  exports.LuiAlertModalButtons = LuiAlertModalButtons;
59415
+ exports.LuiAlertModalV2 = LuiAlertModalV2;
59324
59416
  exports.LuiAppFooterSml = LuiAppFooterSml;
59325
59417
  exports.LuiBadge = LuiBadge;
59326
59418
  exports.LuiBanner = LuiBanner;
@@ -59374,6 +59466,9 @@ exports.LuiMenuCloseButtonV2 = LuiMenuCloseButtonV2;
59374
59466
  exports.LuiMessagingContextProvider = LuiMessagingContextProvider;
59375
59467
  exports.LuiMiniSpinner = LuiMiniSpinner;
59376
59468
  exports.LuiModal = LuiModal;
59469
+ exports.LuiModalV2 = LuiModalV2;
59470
+ exports.LuiModalV2Buttons = LuiModalV2Buttons;
59471
+ exports.LuiModalV2HeadingText = LuiModalV2HeadingText;
59377
59472
  exports.LuiMoneyInput = LuiMoneyInput;
59378
59473
  exports.LuiMultiSwitch = LuiMultiSwitch;
59379
59474
  exports.LuiMultiSwitchYesNo = LuiMultiSwitchYesNo;