@linzjs/lui 23.6.1 → 23.7.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 +14 -0
- package/dist/components/Drawer/Drawer.d.ts +44 -0
- package/dist/components/Drawer/DrawerContext.d.ts +7 -0
- package/dist/components/Drawer/DrawerGlobal.d.ts +13 -0
- package/dist/components/Drawer/DrawerGlobalContext.d.ts +14 -0
- package/dist/components/Drawer/utils.d.ts +7 -0
- package/dist/components/common/Hooks.d.ts +5 -2
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/lui.esm.js +14 -6
- package/dist/lui.esm.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [23.7.0](https://github.com/linz/lui/compare/v23.6.2...v23.7.0) (2025-07-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Drawer ([#1083](https://github.com/linz/lui/issues/1083)) ([f6f5609](https://github.com/linz/lui/commit/f6f56098fe4be1a2f1b49cfbc266cada5d07bb18))
|
|
7
|
+
|
|
8
|
+
## [23.6.2](https://github.com/linz/lui/compare/v23.6.1...v23.6.2) (2025-07-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* remove console log ([#1237](https://github.com/linz/lui/issues/1237)) ([80e2282](https://github.com/linz/lui/commit/80e2282e03bc1fe474b7582fb8ed69318e9894c5))
|
|
14
|
+
|
|
1
15
|
## [23.6.1](https://github.com/linz/lui/compare/v23.6.0...v23.6.1) (2025-07-07)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { ComponentProps, PropsWithChildren } from 'react';
|
|
2
|
+
import { Splitter } from '../Splitter/Splitter';
|
|
3
|
+
import './Drawer.scss';
|
|
4
|
+
import { UseDisableParentScroll } from './utils';
|
|
5
|
+
type Position = 'top' | 'bottom' | 'left' | 'right';
|
|
6
|
+
export type DrawerProps = PropsWithChildren<{
|
|
7
|
+
/** It's not recommended to make this prop dynamic during runtime as it might affect the opening animation. See the `Positions` story for more info. */
|
|
8
|
+
position?: Position;
|
|
9
|
+
/** Drawer open state is fully handled by the parent */
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
/** Allows the Drawer to request closing itself (must be handled by the parent). For accessibility reasons, you must pass this prop unless you implement your custom close button, `closeOnEsc` and `closeOnClickOutside` functionality. */
|
|
12
|
+
onRequestClose: () => void;
|
|
13
|
+
/** Enables resizing the drawer via UI. `true` by default. Note: the drawer is always resizeable programmatically. */
|
|
14
|
+
resizeable?: boolean;
|
|
15
|
+
/** Pressing `ESC` calls `onRequestClose` */
|
|
16
|
+
closeOnEsc?: boolean;
|
|
17
|
+
/** Clicking `div.overlay` calls `onRequestClose`.
|
|
18
|
+
*
|
|
19
|
+
* Must be used in conjunction with `passThroughOverlayClick={false}`.*/
|
|
20
|
+
closeOnClickOutside?: boolean;
|
|
21
|
+
/** Allows pointer events through the non-content panel. If you set this to `false`, it is recommended that you style `div.overlay` to dim the background.
|
|
22
|
+
*
|
|
23
|
+
* Must be set to false to enable `closeOnClickOutside`.
|
|
24
|
+
*/
|
|
25
|
+
passThroughOverlayClick?: boolean;
|
|
26
|
+
/** Controls the drawer size. Valid values are from `0` to `100`, in percent of screen width or height occupied by content.
|
|
27
|
+
*
|
|
28
|
+
* If `undefined`, the drawer will be uncontrolled, and resizeable purely via DOM/CSS.
|
|
29
|
+
*
|
|
30
|
+
* Note: if `resizeable` is true, the drawer will revert to the value of the `size` prop when rerendered. If you use both `size` and `resizeable` make sure the parent updates `size` via `onResized`*/
|
|
31
|
+
size?: number;
|
|
32
|
+
/** `0` to `100`, in percent of screen width or height occupied by content. If `undefined`, the drawer will take up half the screen when first mounting. */
|
|
33
|
+
initialSize?: number;
|
|
34
|
+
/** Disables scrolling the document or the parent element when the drawer is open.*/
|
|
35
|
+
disableScroll?: UseDisableParentScroll['mode'];
|
|
36
|
+
/** A close button is visible by default. Use this if you're implementing a custom button. */
|
|
37
|
+
hideCloseButton?: boolean;
|
|
38
|
+
/** By default, `children` is mounted when the drawer opens for the first time. */
|
|
39
|
+
mountChildrenOn?: 'mount' | 'first-open';
|
|
40
|
+
/** Called when the drawer is resized either manually or programmatically. */
|
|
41
|
+
onResized?: ComponentProps<typeof Splitter>['onResized'];
|
|
42
|
+
}> & Omit<ComponentProps<typeof Splitter>, 'ratio' | 'orientation' | 'onResized'>;
|
|
43
|
+
export declare const Drawer: React.ForwardRefExoticComponent<Pick<DrawerProps, "onResized" | "parts" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "startAt" | "min" | "max" | "key" | "isOpen" | "onRequestClose" | "position" | "size" | "initialSize" | "resizeable" | "passThroughOverlayClick" | "closeOnClickOutside" | "closeOnEsc" | "disableScroll" | "hideCloseButton" | "mountChildrenOn"> & React.RefAttributes<HTMLDivElement>>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type DrawerContext = {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
requestClose: () => void | Promise<void>;
|
|
5
|
+
};
|
|
6
|
+
export declare const DrawerContext: import("react").Context<DrawerContext | null>;
|
|
7
|
+
export declare const useDrawerContext: () => DrawerContext;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DrawerProps } from './Drawer';
|
|
3
|
+
import './Drawer.scss';
|
|
4
|
+
type DrawerGlobalProps = Omit<DrawerProps, 'isOpen' | 'onRequestClose'> & {
|
|
5
|
+
/** Uniquely identifies your drawer undet the global context. It's extremely important that `id` be unique, as it will also be attached to the DOM element. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Return `false` to prevent the drawer from closing. Useful for controlling flow, or for side-effects.
|
|
8
|
+
*
|
|
9
|
+
* Unlike in the vanilla `Drawer`, where the consumer must handle the open/close state, here state is handled by `DrawerGlobalContext`. */
|
|
10
|
+
onBeforeClose?: () => boolean | Promise<boolean>;
|
|
11
|
+
};
|
|
12
|
+
export declare const DrawerGlobal: React.ForwardRefExoticComponent<Pick<DrawerGlobalProps, "onResized" | "parts" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "startAt" | "min" | "max" | "key" | "position" | "size" | "initialSize" | "resizeable" | "passThroughOverlayClick" | "closeOnClickOutside" | "closeOnEsc" | "disableScroll" | "hideCloseButton" | "mountChildrenOn" | "onBeforeClose"> & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { FC, PropsWithChildren } from 'react';
|
|
2
|
+
export type DrawerGlobalContext = {
|
|
3
|
+
/** Tracks the currently open `DrawerGlobal`. Multiple `DrawerGlobal`s can be mounted/rendered simultaneoulsy but only a single one can be open at any time. */
|
|
4
|
+
currentOpenId?: string;
|
|
5
|
+
/** Imperatively opens a drawer mounted with a specific `id`. */
|
|
6
|
+
requestOpen: (drawerId?: string) => void | Promise<void>;
|
|
7
|
+
/** Imperatively closes a drawer mounted with a specific `id`. Note that usually a given drawer should only be able to close itself, but you can pass an arbitrary `drawerId` or even `forceClose` for more complex use cases. */
|
|
8
|
+
requestClose: (drawerId?: string,
|
|
9
|
+
/** Closes currently open drawer regardless of `drawerId`. */
|
|
10
|
+
forceClose?: boolean) => void | Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const DrawerGlobalContext: React.Context<DrawerGlobalContext | null>;
|
|
13
|
+
export declare const useDrawerGlobalContext: () => DrawerGlobalContext;
|
|
14
|
+
export declare const DrawerGlobalProvider: FC<PropsWithChildren<{}>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
export type UseDisableParentScroll = {
|
|
3
|
+
shouldDisable?: boolean;
|
|
4
|
+
parentRef?: MutableRefObject<HTMLElement | null>;
|
|
5
|
+
mode?: 'body' | 'parent';
|
|
6
|
+
};
|
|
7
|
+
export declare const useDisableParentScroll: ({ shouldDisable, mode, parentRef, }: UseDisableParentScroll) => void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* A hook which allows you to register a handler when the escape key is pressed
|
|
4
4
|
*
|
|
5
5
|
* @param onEscape the handler function
|
|
6
|
+
* @param elRef a react ref to the element that should listen to the key event. If this argument is `undefined` it means the consumer wants to attach the listener to `document`. If this argument is a ref to `null` no event listener will be added.
|
|
6
7
|
*/
|
|
7
|
-
export declare const useEscapeFunction: (onEscape: (e: KeyboardEvent) => void | Promise<void>, trigger?: 'keyup' | 'keydown') => void;
|
|
8
|
+
export declare const useEscapeFunction: (onEscape: (e: KeyboardEvent) => void | Promise<void>, trigger?: 'keyup' | 'keydown', elRef?: MutableRefObject<HTMLElement | null>) => 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.
|
|
@@ -14,6 +15,8 @@ export declare const useEscapeFunction: (onEscape: (e: KeyboardEvent) => void |
|
|
|
14
15
|
* @return a react ref which can be bound to an html element
|
|
15
16
|
*/
|
|
16
17
|
export declare const usePageClickFunction: <H extends Element>(onClickInsideArg: (event: MouseEvent) => void, onClickOutsideArg: (event: MouseEvent) => void) => import("react").RefObject<H>;
|
|
18
|
+
/** Disables scrolling on an specified element */
|
|
19
|
+
export declare const useDisableScroll: (el?: HTMLElement | null, shouldDisable?: boolean) => void;
|
|
17
20
|
/**
|
|
18
21
|
* Provides a stable ID across renders, can be replaced in react 18+ by native implementation
|
|
19
22
|
*/
|
package/dist/index.js
CHANGED
|
@@ -7202,7 +7202,6 @@ var LuiTextAreaInput = React__default["default"].forwardRef(function (props, ref
|
|
|
7202
7202
|
var _a, _b;
|
|
7203
7203
|
var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
|
|
7204
7204
|
var rows = props.rows !== undefined ? props.rows : 5;
|
|
7205
|
-
console.log('🚀 ~ rows:', rows);
|
|
7206
7205
|
return (React__default["default"].createElement("div", { className: clsx('LuiTextAreaInput', ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.disabled) ? 'isDisabled' : '', props.error ? 'hasError' : '', props.warning ? 'hasWarning' : '') },
|
|
7207
7206
|
React__default["default"].createElement("label", { htmlFor: id },
|
|
7208
7207
|
props.mandatory && (React__default["default"].createElement("span", { className: "LuiTextAreaInput-mandatory" }, "*")),
|
|
@@ -15098,14 +15097,23 @@ var motif = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0id
|
|
|
15098
15097
|
* A hook which allows you to register a handler when the escape key is pressed
|
|
15099
15098
|
*
|
|
15100
15099
|
* @param onEscape the handler function
|
|
15100
|
+
* @param elRef a react ref to the element that should listen to the key event. If this argument is `undefined` it means the consumer wants to attach the listener to `document`. If this argument is a ref to `null` no event listener will be added.
|
|
15101
15101
|
*/
|
|
15102
|
-
var useEscapeFunction = function (onEscape, trigger) {
|
|
15102
|
+
var useEscapeFunction = function (onEscape, trigger, elRef) {
|
|
15103
15103
|
if (trigger === void 0) { trigger = 'keydown'; }
|
|
15104
|
-
var escFunction = React.useCallback(function (event) {
|
|
15104
|
+
var escFunction = React.useCallback(function (event) {
|
|
15105
|
+
if (event.keyCode === 27) {
|
|
15106
|
+
onEscape(event);
|
|
15107
|
+
}
|
|
15108
|
+
}, [onEscape]);
|
|
15105
15109
|
React.useEffect(function () {
|
|
15106
|
-
|
|
15107
|
-
|
|
15108
|
-
|
|
15110
|
+
var _a;
|
|
15111
|
+
if ((elRef === null || elRef === void 0 ? void 0 : elRef.current) === null)
|
|
15112
|
+
return;
|
|
15113
|
+
var el = (_a = elRef === null || elRef === void 0 ? void 0 : elRef.current) !== null && _a !== void 0 ? _a : document;
|
|
15114
|
+
el.addEventListener(trigger, escFunction, false);
|
|
15115
|
+
return function () { return el.removeEventListener(trigger, escFunction, false); };
|
|
15116
|
+
}, [escFunction, elRef === null || elRef === void 0 ? void 0 : elRef.current]);
|
|
15109
15117
|
};
|
|
15110
15118
|
/**
|
|
15111
15119
|
* A hook which allows handling of click event anywhere on the page.
|