@linzjs/lui 21.34.1-3 → 21.35.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,10 @@
1
+ # [21.35.0](https://github.com/linz/lui/compare/v21.34.0...v21.35.0) (2024-06-26)
2
+
3
+
4
+ ### Features
5
+
6
+ * **useToast:** upgrade toasts ([#1125](https://github.com/linz/lui/issues/1125)) ([b1a293c](https://github.com/linz/lui/commit/b1a293c02195b43c266c22aa58bde974b0a4e4ab)), closes [#1](https://github.com/linz/lui/issues/1)
7
+
1
8
  # [21.34.0](https://github.com/linz/lui/compare/v21.33.0...v21.34.0) (2024-06-05)
2
9
 
3
10
 
@@ -0,0 +1,9 @@
1
+ import './ToastSection.scss';
2
+ import * as React from 'react';
3
+ import { IToast, ToastPosition } from './ToastTypes';
4
+ export declare const ToastSection: ({ position, list, remove, defaultTimeout, }: {
5
+ position: ToastPosition;
6
+ list: IToast[];
7
+ remove: (id: number) => void;
8
+ defaultTimeout: number;
9
+ }) => React.ReactPortal;
@@ -0,0 +1,34 @@
1
+ import { ReactNode } from 'react';
2
+ declare type VerticalSide = 'top' | 'bottom';
3
+ declare type HorizontalSide = 'Left' | 'Center' | 'Right';
4
+ export declare type ToastPosition = `${VerticalSide}${HorizontalSide}`;
5
+ export declare type ToastNode = ReactNode | ((e: {
6
+ close: () => void;
7
+ }) => ReactNode);
8
+ export declare type ToastOptions = {
9
+ timeout?: number;
10
+ position?: ToastPosition;
11
+ onLeave?: (id: number) => void;
12
+ };
13
+ export declare type ToastAction = {
14
+ type: 'add';
15
+ notification: ToastNode;
16
+ options?: ToastOptions;
17
+ id: number;
18
+ } | {
19
+ type: 'remove';
20
+ id: number;
21
+ } | {
22
+ type: 'update';
23
+ notification: ToastNode;
24
+ options?: ToastOptions;
25
+ id: number;
26
+ };
27
+ export interface IToast {
28
+ id: number;
29
+ notification: ToastNode;
30
+ options?: ToastOptions;
31
+ createdAt: number;
32
+ updatedAt: number;
33
+ }
34
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Retrieves the toast provider container element. It creates a new
3
+ * one if it hasn't been created already.
4
+ *
5
+ * @description It is expected that application A, renders application B, that happens to render
6
+ * the new toasts as well. In this case, application B will still render the context
7
+ * provider to handle their toasts, but it will re-use the portal created by A.
8
+ *
9
+ * When the provider is created, it will observe older toasts coming to the screen
10
+ * to make them visually align with the new ones. This needs to happens when the portal is
11
+ * created, regardless of what app has created it.
12
+ *
13
+ * @returns HTMLDivElement
14
+ */
15
+ export declare const getToastProviderEl: () => HTMLDivElement;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const ToastUsage: () => JSX.Element;
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { IToast, ToastAction } from './ToastTypes';
3
+ declare type ToastState = {
4
+ toasts: IToast[];
5
+ stack: number;
6
+ };
7
+ export declare const reducer: (state: ToastState, action: ToastAction) => ToastState;
8
+ export declare const useToastState: ({ stack }: {
9
+ stack: number;
10
+ }) => {
11
+ toasts: {
12
+ topLeft: IToast[];
13
+ topCenter: IToast[];
14
+ topRight: IToast[];
15
+ bottomLeft: IToast[];
16
+ bottomCenter: IToast[];
17
+ bottomRight: IToast[];
18
+ };
19
+ dispatch: import("react").Dispatch<ToastAction>;
20
+ };
21
+ export {};
@@ -0,0 +1,10 @@
1
+ import './ToastProvider.scss';
2
+ import * as React from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { ToastAction } from './Helpers/ToastTypes';
5
+ export declare const ToastContext: React.Context<React.Dispatch<ToastAction> | undefined>;
6
+ export declare const ToastProvider: ({ children, defaultTimeout, stack, }: {
7
+ defaultTimeout?: number | undefined;
8
+ stack?: number | undefined;
9
+ children: ReactNode;
10
+ }) => JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { ComponentProps } from 'react';
2
+ import { LuiToastMessage } from '../../LuiToastMessage/LuiToastMessage';
3
+ declare type Props = ComponentProps<typeof LuiToastMessage>;
4
+ export declare const LuiToastMessageCompatibleInterface: (props: Props) => JSX.Element;
5
+ export {};
@@ -0,0 +1,14 @@
1
+ import { ComponentProps, ReactNode } from 'react';
2
+ import { LuiToastMessage as LuiToastMessageOld } from '../../LuiToastMessage/LuiToastMessage';
3
+ declare type ProviderProps = {
4
+ children: ReactNode;
5
+ upgrade?: boolean;
6
+ };
7
+ /**
8
+ * @deprecated Use ToastProvider or LuiMessagingContextProvider with upgrade prop set to true to get the new designs
9
+ */
10
+ export declare const LuiMessagingContextProvider: (props: ProviderProps) => JSX.Element;
11
+ export declare const useShowLUIMessage: () => (props: import("../../../contexts/LuiMessagingContextProvider").ShowMessageProps) => void;
12
+ declare type LuiToastMessageProps = ComponentProps<typeof LuiToastMessageOld>;
13
+ export declare const LuiToastMessage: (props: LuiToastMessageProps) => JSX.Element;
14
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Observes DOM changes in the elements tree to identify older toasts
3
+ * that have been added to the page, to calculate a CSS top value so
4
+ * that these are stacked below the new ones, if any.
5
+ */
6
+ export declare const observeOlderToasts: (portal: HTMLDivElement) => void;
@@ -0,0 +1,5 @@
1
+ import { ShowMessageProps } from '../../../contexts/LuiMessagingContextProvider';
2
+ /**
3
+ * Provide new toast hook with old interface from original useShowLUIMessage
4
+ */
5
+ export declare const useShowLUIMessageCompatibleInterface: () => (props: ShowMessageProps) => void;
@@ -0,0 +1,2 @@
1
+ export { ToastProvider } from './ToastProvider';
2
+ export { useToast } from './useToast';
@@ -0,0 +1,16 @@
1
+ import './ToastProvider.scss';
2
+ import { ReactNode } from 'react';
3
+ import { ToastNode, ToastOptions } from './Helpers/ToastTypes';
4
+ declare type BannerToast = (children: ReactNode, config?: ToastOptions) => number;
5
+ declare type Result = {
6
+ toast: (notification: ToastNode, options?: ToastOptions) => number;
7
+ update: (toastId: number, notification: ToastNode, options?: ToastOptions) => number;
8
+ dismiss: (toastId: number) => void;
9
+ info: BannerToast;
10
+ success: BannerToast;
11
+ error: BannerToast;
12
+ warning: BannerToast;
13
+ plain: BannerToast;
14
+ };
15
+ export declare const useToast: () => Result;
16
+ export {};
@@ -5,7 +5,6 @@
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;
9
8
  /**
10
9
  * A hook which allows handling of click event anywhere on the page.
11
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 { MutableRefObject, RefObject } from 'react';
1
+ import React 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 { MutableRefObject, RefObject } from 'react';
11
11
  return <button ref={refElement}>Click Me!</button>;
12
12
  ```
13
13
  */
14
- export declare function useClickedOutsideElement(refElement: RefObject<HTMLElement> | MutableRefObject<HTMLElement>, handleClickOutside: CallableFunction): void;
14
+ export declare function useClickedOutsideElement(refElement: React.RefObject<HTMLElement>, handleClickOutside: CallableFunction): void;
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export { LuiBanner, LuiBannerContent } from './components/LuiBanner/LuiBanner';
2
2
  export { LuiStaticMessage } from './components/LuiStaticMessage/LuiStaticMessage';
3
3
  export { LuiButton } from './components/LuiButton/LuiButton';
4
4
  export { LuiFloatingWindow, type ILuiFloatingWindowProps, LUI_WINDOW_NAME, LuiFloatingWindowContextProvider, useLuiFloatingWindow, } from './components/LuiFloatingWindow/LuiFloatingWindow';
5
- export * from './components/LuiToastMessage/LuiToastMessage';
6
- export * from './contexts/LuiMessagingContextProvider';
5
+ export { type ILuiToastMessageLevels } from './components/LuiToastMessage/LuiToastMessage';
6
+ export { type MessageLevel, type MessageType, type IUIMessagingContext, type ShowMessageProps, } from './contexts/LuiMessagingContextProvider';
7
7
  export { LuiButtonGroup } from './components/LuiButton/LuiButton';
8
8
  export { LuiExpandableBanner } from './components/LuiExpandableBanner/LuiExpandableBanner';
9
9
  export { LuiMenu, LuiControlledMenu } from './components/LuiMenu/LuiMenu';
@@ -37,8 +37,6 @@ 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';
42
40
  export { type ISearchInputProps, LuiSearchInput, } from './components/LuiSearchInput/LuiSearchInput';
43
41
  export { type ISearchGroupedResult, type ISearchResult, } from './components/LuiSearchInput/ResultsDisplay';
44
42
  export { type ISearchMenuOption, type ILuiSearchBoxProps, LuiSearchBox, } from './components/LuiSearchBox/LuiSearchBox';
@@ -74,3 +72,5 @@ export { LuiPagination } from './components/LuiPagination/LuiPagination';
74
72
  export { Splitter } from './components/Splitter/Splitter';
75
73
  export { useSplitterRef } from './components/Splitter/useSplitterRef';
76
74
  export { LuiBannerV2 } from './components/LuiBannerV2/LuiBannerV2';
75
+ export { useToast, ToastProvider } from './components/Toast';
76
+ export { LuiMessagingContextProvider, useShowLUIMessage, LuiToastMessage, } from './components/Toast/Upgrade';