@kwiz/fluentui 1.0.57 → 1.0.59
Sign up to get free protection for your applications and to get access to all the features.
- package/.dependency-cruiser.js +399 -0
- package/dist/controls/ColorPickerDialog.js +1 -1
- package/dist/controls/ColorPickerDialog.js.map +1 -1
- package/dist/controls/button.js +1 -1
- package/dist/controls/button.js.map +1 -1
- package/dist/controls/canvas/DrawPad.js +1 -1
- package/dist/controls/canvas/DrawPad.js.map +1 -1
- package/dist/controls/date.js +2 -2
- package/dist/controls/date.js.map +1 -1
- package/dist/controls/diagram-picker.js +2 -2
- package/dist/controls/diagram-picker.js.map +1 -1
- package/dist/controls/dropdown.js +1 -1
- package/dist/controls/dropdown.js.map +1 -1
- package/dist/controls/file-upload.js +1 -2
- package/dist/controls/file-upload.js.map +1 -1
- package/dist/controls/index.d.ts +31 -0
- package/dist/controls/index.js +32 -0
- package/dist/controls/index.js.map +1 -0
- package/dist/controls/input.js +1 -1
- package/dist/controls/input.js.map +1 -1
- package/dist/controls/kwizoverflow.js +1 -1
- package/dist/controls/kwizoverflow.js.map +1 -1
- package/dist/controls/menu.js +2 -2
- package/dist/controls/menu.js.map +1 -1
- package/dist/controls/prompt.js +2 -2
- package/dist/controls/prompt.js.map +1 -1
- package/dist/controls/search.js +1 -1
- package/dist/controls/search.js.map +1 -1
- package/dist/controls/section.js +1 -1
- package/dist/controls/section.js.map +1 -1
- package/dist/controls/vertical-content.js +1 -1
- package/dist/controls/vertical-content.js.map +1 -1
- package/dist/helpers/block-nav.d.ts +11 -0
- package/dist/helpers/block-nav.js +79 -0
- package/dist/helpers/block-nav.js.map +1 -0
- package/dist/helpers/{context.d.ts → context-export.d.ts} +4 -3
- package/dist/helpers/context-export.js +23 -0
- package/dist/helpers/context-export.js.map +1 -0
- package/dist/helpers/context-internal.d.ts +4 -0
- package/dist/helpers/{context.js → context-internal.js} +1 -1
- package/dist/helpers/context-internal.js.map +1 -0
- package/dist/helpers/drag-drop/drag-drop-container.d.ts +1 -2
- package/dist/helpers/drag-drop/drag-drop-container.js.map +1 -1
- package/dist/helpers/drag-drop/drag-drop-context-internal.d.ts +4 -0
- package/dist/helpers/drag-drop/drag-drop-context-internal.js +9 -0
- package/dist/helpers/drag-drop/drag-drop-context-internal.js.map +1 -0
- package/dist/helpers/drag-drop/drag-drop-context.d.ts +1 -9
- package/dist/helpers/drag-drop/drag-drop-context.js +2 -9
- package/dist/helpers/drag-drop/drag-drop-context.js.map +1 -1
- package/dist/helpers/drag-drop/drag-drop.types.d.ts +19 -0
- package/dist/helpers/drag-drop/drag-drop.types.js +2 -0
- package/dist/helpers/drag-drop/drag-drop.types.js.map +1 -0
- package/dist/helpers/drag-drop/{exports.d.ts → index.d.ts} +2 -4
- package/dist/helpers/drag-drop/{exports.js → index.js} +1 -1
- package/dist/helpers/drag-drop/index.js.map +1 -0
- package/dist/helpers/drag-drop/use-draggable.d.ts +1 -8
- package/dist/helpers/drag-drop/use-draggable.js +1 -1
- package/dist/helpers/drag-drop/use-draggable.js.map +1 -1
- package/dist/helpers/drag-drop/use-droppable.d.ts +2 -9
- package/dist/helpers/drag-drop/use-droppable.js +1 -2
- package/dist/helpers/drag-drop/use-droppable.js.map +1 -1
- package/dist/helpers/hooks-events.d.ts +21 -0
- package/dist/helpers/hooks-events.js +146 -0
- package/dist/helpers/hooks-events.js.map +1 -0
- package/dist/helpers/hooks.d.ts +0 -69
- package/dist/helpers/hooks.js +1 -310
- package/dist/helpers/hooks.js.map +1 -1
- package/dist/helpers/index.d.ts +7 -0
- package/dist/helpers/index.js +8 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/use-alerts.d.ts +14 -0
- package/dist/helpers/use-alerts.js +65 -0
- package/dist/helpers/use-alerts.js.map +1 -0
- package/dist/helpers/use-toast.d.ts +18 -0
- package/dist/helpers/use-toast.js +17 -0
- package/dist/helpers/use-toast.js.map +1 -0
- package/dist/index.d.ts +3 -36
- package/dist/index.js +3 -35
- package/dist/index.js.map +1 -1
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +2 -0
- package/dist/styles/index.js.map +1 -0
- package/package.json +5 -3
- package/src/controls/ColorPickerDialog.tsx +1 -1
- package/src/controls/button.tsx +1 -1
- package/src/controls/canvas/DrawPad.tsx +1 -1
- package/src/controls/date.tsx +2 -2
- package/src/controls/diagram-picker.tsx +2 -2
- package/src/controls/dropdown.tsx +1 -1
- package/src/controls/file-upload.tsx +1 -3
- package/src/controls/index.ts +31 -0
- package/src/controls/input.tsx +1 -1
- package/src/controls/kwizoverflow.tsx +1 -1
- package/src/controls/menu.tsx +2 -2
- package/src/controls/prompt.tsx +2 -2
- package/src/controls/search.tsx +1 -1
- package/src/controls/section.tsx +1 -1
- package/src/controls/vertical-content.tsx +1 -1
- package/src/helpers/block-nav.tsx +89 -0
- package/src/helpers/context-export.ts +53 -0
- package/src/helpers/context-internal.ts +17 -0
- package/src/helpers/drag-drop/drag-drop-container.tsx +1 -2
- package/src/helpers/drag-drop/drag-drop-context-internal.tsx +10 -0
- package/src/helpers/drag-drop/drag-drop-context.tsx +5 -15
- package/src/helpers/drag-drop/drag-drop.types.ts +21 -0
- package/src/helpers/drag-drop/{exports.ts → index.ts} +2 -4
- package/src/helpers/drag-drop/use-draggable.ts +2 -10
- package/src/helpers/drag-drop/use-droppable.ts +3 -12
- package/src/helpers/hooks-events.ts +153 -0
- package/src/helpers/hooks.tsx +1 -360
- package/src/helpers/index.ts +8 -0
- package/src/helpers/use-alerts.tsx +75 -0
- package/src/helpers/use-toast.tsx +30 -0
- package/src/index.ts +3 -37
- package/src/styles/index.ts +1 -0
- package/dist/helpers/context.js.map +0 -1
- package/dist/helpers/drag-drop/exports.js.map +0 -1
- package/src/helpers/context.ts +0 -40
@@ -0,0 +1,53 @@
|
|
1
|
+
import { makeStyles } from "@fluentui/react-components";
|
2
|
+
import { useEffect, useState } from "react";
|
3
|
+
|
4
|
+
export interface iKWIZFluentContext {
|
5
|
+
/**
|
6
|
+
* Where the portal children are mounted on DOM
|
7
|
+
*
|
8
|
+
* @default a new element on document.body without any styling
|
9
|
+
*/
|
10
|
+
mountNode?: HTMLElement | null | {
|
11
|
+
element?: HTMLElement | null;
|
12
|
+
className?: string;
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Controls the colors and borders of the input.
|
16
|
+
*
|
17
|
+
* @default 'underline'
|
18
|
+
*/
|
19
|
+
inputAppearance?: 'outline' | 'underline' | 'filled-darker' | 'filled-lighter';
|
20
|
+
|
21
|
+
/**
|
22
|
+
* A button can be rounded, circular, or square.
|
23
|
+
*
|
24
|
+
* @default 'rounded'
|
25
|
+
*/
|
26
|
+
buttonShape?: 'rounded' | 'circular' | 'square';
|
27
|
+
}
|
28
|
+
|
29
|
+
const useContextStyles = makeStyles({
|
30
|
+
root: {
|
31
|
+
"& *": {
|
32
|
+
scrollbarWidth: "thin"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
})
|
36
|
+
export function useKWIZFluentContextProvider(options: {
|
37
|
+
root?: React.MutableRefObject<HTMLDivElement>;
|
38
|
+
ctx?: iKWIZFluentContext;
|
39
|
+
}) {
|
40
|
+
const classes = useContextStyles();
|
41
|
+
let v: iKWIZFluentContext = options && options.ctx || {};
|
42
|
+
const [kwizFluentContext, setKwizFluentContext] = useState<iKWIZFluentContext>(v);
|
43
|
+
useEffect(() => {
|
44
|
+
options.root?.current?.classList.add(...classes.root.split(' '));
|
45
|
+
// ref only updates in useEffect, not in useMemo or anything else.
|
46
|
+
// we need to set it into state so it will trigger a ui update
|
47
|
+
setKwizFluentContext({
|
48
|
+
...v,
|
49
|
+
mountNode: options.root.current
|
50
|
+
});
|
51
|
+
}, [options.root]);
|
52
|
+
return kwizFluentContext;
|
53
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { isNullOrUndefined } from "@kwiz/common";
|
2
|
+
import React from "react";
|
3
|
+
import { iKWIZFluentContext } from "./context-export";
|
4
|
+
|
5
|
+
|
6
|
+
//create context
|
7
|
+
export const KWIZFluentContext = React.createContext<iKWIZFluentContext>(null);
|
8
|
+
//use context from within controls
|
9
|
+
export function useKWIZFluentContext() {
|
10
|
+
let ctx = React.useContext(KWIZFluentContext) || {};
|
11
|
+
//set defaults
|
12
|
+
if (isNullOrUndefined(ctx.inputAppearance))
|
13
|
+
ctx.inputAppearance = "underline";
|
14
|
+
if (isNullOrUndefined(ctx.buttonShape))
|
15
|
+
ctx.buttonShape = "circular";
|
16
|
+
return ctx;
|
17
|
+
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { mergeClasses } from "@fluentui/react-components";
|
2
2
|
import { useDragDropContext } from "./drag-drop-context";
|
3
|
-
import { iDraggableProps, iDraggedItemType } from "./
|
4
|
-
import { iDroppableProps } from "./use-droppable";
|
3
|
+
import { iDraggableProps, iDraggedItemType, iDroppableProps } from "./drag-drop.types";
|
5
4
|
|
6
5
|
interface one<DragItemType extends iDraggedItemType<string>> {
|
7
6
|
dragInfo: iDraggableProps<DragItemType>;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import React, { useContext } from "react";
|
2
|
+
import { iDragDropContext } from "./drag-drop.types";
|
3
|
+
|
4
|
+
//create context
|
5
|
+
export const DragDropContext = React.createContext<iDragDropContext>(null);
|
6
|
+
//use context from within controls
|
7
|
+
export function useDragDropContextInternal() {
|
8
|
+
const dragDropContext = useContext(DragDropContext);
|
9
|
+
return dragDropContext;
|
10
|
+
}
|
@@ -1,23 +1,13 @@
|
|
1
1
|
import { isNullOrUndefined } from "@kwiz/common";
|
2
|
-
import React
|
2
|
+
import React from "react";
|
3
3
|
import { DndProvider } from "react-dnd";
|
4
4
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
5
5
|
import { useStateEX } from "../hooks";
|
6
|
-
import {
|
7
|
-
import
|
6
|
+
import { DragDropContext, useDragDropContextInternal } from "./drag-drop-context-internal";
|
7
|
+
import { iDragDropContext, iDraggableProps, iDraggedItemType, iDroppableProps } from "./drag-drop.types";
|
8
|
+
import { useDraggable } from "./use-draggable";
|
9
|
+
import { useDroppable } from "./use-droppable";
|
8
10
|
|
9
|
-
export interface iDragDropContext {
|
10
|
-
isDragging: boolean;
|
11
|
-
dragItem: iDraggedItemType<string>;
|
12
|
-
setDragItem: (value: iDraggedItemType<string>) => void;
|
13
|
-
}
|
14
|
-
//create context
|
15
|
-
export const DragDropContext = React.createContext<iDragDropContext>(null);
|
16
|
-
//use context from within controls
|
17
|
-
export function useDragDropContextInternal() {
|
18
|
-
const dragDropContext = useContext(DragDropContext);
|
19
|
-
return dragDropContext;
|
20
|
-
}
|
21
11
|
export function useDragDropContext<
|
22
12
|
DragItemType extends iDraggedItemType<string> = never,
|
23
13
|
DropInfoType extends iDroppableProps<string, any> = never
|
@@ -0,0 +1,21 @@
|
|
1
|
+
export interface iDraggedItemType<DragType extends string> {
|
2
|
+
type: DragType;
|
3
|
+
}
|
4
|
+
export interface iDraggableProps<ItemType extends iDraggedItemType<string>> {
|
5
|
+
item: ItemType;
|
6
|
+
onBeginDrag?: () => void;
|
7
|
+
onEndDrag?: (dropResult: any) => void;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface iDroppableProps<DropTypes extends string, ItemTypes extends iDraggedItemType<DropTypes>> {
|
11
|
+
acceptTypes: DropTypes[];
|
12
|
+
onItemDrop: (item: ItemTypes) => void;
|
13
|
+
onHover?: (item: ItemTypes) => void;
|
14
|
+
onDrop?: () => void;
|
15
|
+
}
|
16
|
+
|
17
|
+
export interface iDragDropContext {
|
18
|
+
isDragging: boolean;
|
19
|
+
dragItem: iDraggedItemType<string>;
|
20
|
+
setDragItem: (value: iDraggedItemType<string>) => void;
|
21
|
+
}
|
@@ -1,11 +1,9 @@
|
|
1
1
|
import { NativeTypes } from 'react-dnd-html5-backend';
|
2
|
-
import { iDraggedItemType } from './
|
3
|
-
import { iDroppableProps } from './use-droppable';
|
2
|
+
import { iDraggedItemType, iDroppableProps } from './drag-drop.types';
|
4
3
|
|
5
4
|
export { DragDropContainer } from './drag-drop-container';
|
6
5
|
export { DragDropContextProvider, useDragDropContext } from "./drag-drop-context";
|
7
|
-
export type { iDraggedItemType } from "./
|
8
|
-
export type { iDroppableProps } from "./use-droppable";
|
6
|
+
export type { iDraggedItemType, iDroppableProps } from "./drag-drop.types";
|
9
7
|
|
10
8
|
type fileNativeType = typeof NativeTypes.FILE;
|
11
9
|
interface dragFiles extends iDraggedItemType<fileNativeType> {
|
@@ -1,15 +1,7 @@
|
|
1
1
|
import { useEffect } from 'react';
|
2
2
|
import { ConnectDragSource, DragSourceMonitor, useDrag } from 'react-dnd';
|
3
|
-
import { useDragDropContextInternal } from './drag-drop-context';
|
4
|
-
|
5
|
-
export interface iDraggedItemType<DragType extends string> {
|
6
|
-
type: DragType;
|
7
|
-
}
|
8
|
-
export interface iDraggableProps<ItemType extends iDraggedItemType<string>> {
|
9
|
-
item: ItemType;
|
10
|
-
onBeginDrag?: () => void;
|
11
|
-
onEndDrag?: (dropResult: any) => void;
|
12
|
-
}
|
3
|
+
import { useDragDropContextInternal } from './drag-drop-context-internal';
|
4
|
+
import { iDraggableProps, iDraggedItemType } from './drag-drop.types';
|
13
5
|
|
14
6
|
export function useDraggable<ItemType extends iDraggedItemType<string>>(props?: iDraggableProps<ItemType>): {
|
15
7
|
isDragging: boolean;
|
@@ -1,14 +1,7 @@
|
|
1
1
|
import { ConnectDropTarget, DropTargetMonitor, useDrop } from 'react-dnd';
|
2
|
-
import { iDraggedItemType } from './
|
2
|
+
import { iDraggedItemType, iDroppableProps } from './drag-drop.types';
|
3
3
|
|
4
|
-
export
|
5
|
-
acceptTypes: DropTypes[];
|
6
|
-
onItemDrop: (item: ItemTypes) => void;
|
7
|
-
onHover?: (item: ItemTypes) => void;
|
8
|
-
onDrop?: () => void;
|
9
|
-
}
|
10
|
-
|
11
|
-
function useDroppable<DropType extends string, ItemType extends iDraggedItemType<DropType>>(props?: iDroppableProps<DropType, ItemType>): {
|
4
|
+
export function useDroppable<DropType extends string, ItemType extends iDraggedItemType<DropType>>(props?: iDroppableProps<DropType, ItemType>): {
|
12
5
|
canDrop: boolean;
|
13
6
|
isOver: boolean;
|
14
7
|
dropRef: ConnectDropTarget;
|
@@ -43,6 +36,4 @@ function useDroppable<DropType extends string, ItemType extends iDraggedItemType
|
|
43
36
|
isOver,
|
44
37
|
dropRef,
|
45
38
|
};
|
46
|
-
}
|
47
|
-
|
48
|
-
export default useDroppable;
|
39
|
+
}
|
@@ -0,0 +1,153 @@
|
|
1
|
+
import { isDebug, isFunction } from "@kwiz/common";
|
2
|
+
import { MutableRefObject, useEffect, useRef, useState } from "react";
|
3
|
+
import { KnownClassNames } from "../styles/styles";
|
4
|
+
import { useEffectOnlyOnMount } from "./hooks";
|
5
|
+
|
6
|
+
export function useTrackFocus(props: { onFocus: () => void, onLoseFocus: () => void, ref?: MutableRefObject<HTMLElement> }) {
|
7
|
+
const wrapperDiv = props.ref || useRef<HTMLDivElement>(null);
|
8
|
+
useEffect(() => {
|
9
|
+
function focusIn(e: FocusEvent) {
|
10
|
+
let elm = e.target as HTMLElement;//document.activeElement;
|
11
|
+
if (wrapperDiv.current) {
|
12
|
+
while (elm && elm !== wrapperDiv.current) {
|
13
|
+
elm = elm.parentElement;
|
14
|
+
}
|
15
|
+
} else elm = null;
|
16
|
+
if (wrapperDiv.current && elm === wrapperDiv.current) props.onFocus();
|
17
|
+
else props.onLoseFocus();
|
18
|
+
}
|
19
|
+
|
20
|
+
if (wrapperDiv.current) {
|
21
|
+
if (wrapperDiv.current) wrapperDiv.current.tabIndex = 1;
|
22
|
+
window.addEventListener("focusin", focusIn);
|
23
|
+
// Remove event listener on cleanup
|
24
|
+
return () => window.removeEventListener("focusin", focusIn);
|
25
|
+
}
|
26
|
+
}, [wrapperDiv.current]);
|
27
|
+
return wrapperDiv;
|
28
|
+
}
|
29
|
+
export function useWindowSize() {
|
30
|
+
// Initialize state with undefined width/height so server and client renders match
|
31
|
+
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
32
|
+
const [windowSize, setWindowSize] = useState<{
|
33
|
+
width: number,
|
34
|
+
height: number
|
35
|
+
}>({
|
36
|
+
width: undefined,
|
37
|
+
height: undefined
|
38
|
+
});
|
39
|
+
useEffect(() => {
|
40
|
+
// Handler to call on window resize
|
41
|
+
function handleResize() {
|
42
|
+
|
43
|
+
// Set window width/height to state
|
44
|
+
setWindowSize({
|
45
|
+
width: window.innerWidth,
|
46
|
+
height: window.innerHeight
|
47
|
+
});
|
48
|
+
}
|
49
|
+
// Add event listener
|
50
|
+
window.addEventListener("resize", handleResize);
|
51
|
+
// Call handler right away so state gets updated with initial window size
|
52
|
+
handleResize();
|
53
|
+
// Remove event listener on cleanup
|
54
|
+
return () => window.removeEventListener("resize", handleResize);
|
55
|
+
}, useEffectOnlyOnMount);
|
56
|
+
return windowSize;
|
57
|
+
}
|
58
|
+
export function useElementSize(elm: HTMLElement) {
|
59
|
+
// Initialize state with undefined width/height so server and client renders match
|
60
|
+
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
61
|
+
const [elmSize, setELmSize] = useState<{
|
62
|
+
width: number,
|
63
|
+
height: number
|
64
|
+
}>({
|
65
|
+
width: undefined,
|
66
|
+
height: undefined
|
67
|
+
});
|
68
|
+
useEffect(() => {
|
69
|
+
if (elm) {
|
70
|
+
// Handler to call on elm resize
|
71
|
+
function handleResize() {
|
72
|
+
// Set elm width/height to state
|
73
|
+
setELmSize({
|
74
|
+
width: (elm instanceof Window) ? elm.innerWidth : elm.clientWidth,
|
75
|
+
height: (elm instanceof Window) ? elm.innerHeight : elm.clientHeight,
|
76
|
+
});
|
77
|
+
}
|
78
|
+
// Add event listener
|
79
|
+
const observer = new ResizeObserver(handleResize);
|
80
|
+
observer.observe(elm);
|
81
|
+
// Call handler right away so state gets updated with initial elm size
|
82
|
+
handleResize();
|
83
|
+
// Remove event listener on cleanup
|
84
|
+
return () => observer.disconnect();
|
85
|
+
}
|
86
|
+
}, [elm]);
|
87
|
+
return elmSize;
|
88
|
+
}
|
89
|
+
export function useIsInPrint() {
|
90
|
+
// Initialize state with false
|
91
|
+
const [printMode, setPrintMode] = useState<boolean>(false);
|
92
|
+
useEffect(() => {
|
93
|
+
function forcePrint(e: KeyboardEvent) {
|
94
|
+
if (e.ctrlKey && e.shiftKey && e.altKey) {
|
95
|
+
if (e.key.toLocaleLowerCase() === "q") {
|
96
|
+
document.body.classList.remove(KnownClassNames.print);
|
97
|
+
handlePrint(e, false);
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
console.warn('forced print mode - to exit refresh to ctrl+shift+alt+q');
|
101
|
+
document.body.classList.add(KnownClassNames.print);
|
102
|
+
handlePrint(e, true);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
// Handler to call on printing
|
107
|
+
function handlePrint(e?: Event, force?: boolean) {
|
108
|
+
if (force === true) setPrintMode(true);
|
109
|
+
else if (window.matchMedia) {
|
110
|
+
var mediaQueryList = window.matchMedia('print');
|
111
|
+
if (mediaQueryList.matches) {
|
112
|
+
setPrintMode(true);
|
113
|
+
} else {
|
114
|
+
setPrintMode(false);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
// Add event listener
|
119
|
+
window.addEventListener("print", handlePrint);
|
120
|
+
if (isDebug())
|
121
|
+
window.addEventListener("keydown", forcePrint);
|
122
|
+
// Call handler right away so state gets updated with initial printing state
|
123
|
+
handlePrint();
|
124
|
+
// Remove event listener on cleanup
|
125
|
+
return () => {
|
126
|
+
window.removeEventListener("print", handlePrint);
|
127
|
+
if (isDebug())
|
128
|
+
window.removeEventListener("keydown", forcePrint);
|
129
|
+
};
|
130
|
+
}, useEffectOnlyOnMount);
|
131
|
+
return printMode;
|
132
|
+
}
|
133
|
+
|
134
|
+
export function useKeyDown(options: {
|
135
|
+
//default use document
|
136
|
+
elm?: HTMLElement | Document;
|
137
|
+
onEnter?: (e: KeyboardEvent) => void;
|
138
|
+
onEscape?: (e: KeyboardEvent) => void;
|
139
|
+
onKeyDown?: (e: KeyboardEvent) => void;
|
140
|
+
}) {
|
141
|
+
let elm = options.elm || document;
|
142
|
+
|
143
|
+
useEffect(() => {
|
144
|
+
let handler = (e: KeyboardEvent) => {
|
145
|
+
if (e.key === "Enter" && isFunction(options.onEnter)) options.onEnter(e);
|
146
|
+
else if (e.key === "Escape" && isFunction(options.onEscape)) options.onEscape(e);
|
147
|
+
if (isFunction(options.onKeyDown))
|
148
|
+
options.onKeyDown(e);
|
149
|
+
};
|
150
|
+
elm.addEventListener("keydown", handler);
|
151
|
+
return () => elm.removeEventListener("keydown", handler);
|
152
|
+
}, [elm, options.onEnter, options.onEscape, options.onKeyDown]);
|
153
|
+
}
|