@kwiz/fluentui 1.0.56 → 1.0.59

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. package/.dependency-cruiser.js +399 -0
  2. package/dist/controls/ColorPickerDialog.js +1 -1
  3. package/dist/controls/ColorPickerDialog.js.map +1 -1
  4. package/dist/controls/button.js +1 -1
  5. package/dist/controls/button.js.map +1 -1
  6. package/dist/controls/canvas/DrawPad.js +1 -1
  7. package/dist/controls/canvas/DrawPad.js.map +1 -1
  8. package/dist/controls/date.js +2 -2
  9. package/dist/controls/date.js.map +1 -1
  10. package/dist/controls/diagram-picker.js +2 -2
  11. package/dist/controls/diagram-picker.js.map +1 -1
  12. package/dist/controls/dropdown.js +1 -1
  13. package/dist/controls/dropdown.js.map +1 -1
  14. package/dist/controls/file-upload.js +16 -10
  15. package/dist/controls/file-upload.js.map +1 -1
  16. package/dist/controls/index.d.ts +31 -0
  17. package/dist/controls/index.js +32 -0
  18. package/dist/controls/index.js.map +1 -0
  19. package/dist/controls/input.js +1 -1
  20. package/dist/controls/input.js.map +1 -1
  21. package/dist/controls/kwizoverflow.js +1 -1
  22. package/dist/controls/kwizoverflow.js.map +1 -1
  23. package/dist/controls/menu.js +2 -2
  24. package/dist/controls/menu.js.map +1 -1
  25. package/dist/controls/prompt.js +2 -2
  26. package/dist/controls/prompt.js.map +1 -1
  27. package/dist/controls/search.js +1 -1
  28. package/dist/controls/search.js.map +1 -1
  29. package/dist/controls/section.js +1 -1
  30. package/dist/controls/section.js.map +1 -1
  31. package/dist/controls/vertical-content.js +1 -1
  32. package/dist/controls/vertical-content.js.map +1 -1
  33. package/dist/helpers/block-nav.d.ts +11 -0
  34. package/dist/helpers/block-nav.js +79 -0
  35. package/dist/helpers/block-nav.js.map +1 -0
  36. package/dist/helpers/{context.d.ts → context-export.d.ts} +4 -3
  37. package/dist/helpers/context-export.js +23 -0
  38. package/dist/helpers/context-export.js.map +1 -0
  39. package/dist/helpers/context-internal.d.ts +4 -0
  40. package/dist/helpers/{context.js → context-internal.js} +1 -1
  41. package/dist/helpers/context-internal.js.map +1 -0
  42. package/dist/helpers/drag-drop/drag-drop-container.d.ts +1 -2
  43. package/dist/helpers/drag-drop/drag-drop-container.js.map +1 -1
  44. package/dist/helpers/drag-drop/drag-drop-context-internal.d.ts +4 -0
  45. package/dist/helpers/drag-drop/drag-drop-context-internal.js +9 -0
  46. package/dist/helpers/drag-drop/drag-drop-context-internal.js.map +1 -0
  47. package/dist/helpers/drag-drop/drag-drop-context.d.ts +1 -9
  48. package/dist/helpers/drag-drop/drag-drop-context.js +2 -9
  49. package/dist/helpers/drag-drop/drag-drop-context.js.map +1 -1
  50. package/dist/helpers/drag-drop/drag-drop.types.d.ts +19 -0
  51. package/dist/helpers/drag-drop/drag-drop.types.js +2 -0
  52. package/dist/helpers/drag-drop/drag-drop.types.js.map +1 -0
  53. package/dist/helpers/drag-drop/{exports.d.ts → index.d.ts} +2 -4
  54. package/dist/helpers/drag-drop/{exports.js → index.js} +1 -1
  55. package/dist/helpers/drag-drop/index.js.map +1 -0
  56. package/dist/helpers/drag-drop/use-draggable.d.ts +1 -8
  57. package/dist/helpers/drag-drop/use-draggable.js +1 -1
  58. package/dist/helpers/drag-drop/use-draggable.js.map +1 -1
  59. package/dist/helpers/drag-drop/use-droppable.d.ts +2 -9
  60. package/dist/helpers/drag-drop/use-droppable.js +1 -2
  61. package/dist/helpers/drag-drop/use-droppable.js.map +1 -1
  62. package/dist/helpers/hooks-events.d.ts +21 -0
  63. package/dist/helpers/hooks-events.js +146 -0
  64. package/dist/helpers/hooks-events.js.map +1 -0
  65. package/dist/helpers/hooks.d.ts +0 -69
  66. package/dist/helpers/hooks.js +1 -310
  67. package/dist/helpers/hooks.js.map +1 -1
  68. package/dist/helpers/index.d.ts +7 -0
  69. package/dist/helpers/index.js +8 -0
  70. package/dist/helpers/index.js.map +1 -0
  71. package/dist/helpers/use-alerts.d.ts +14 -0
  72. package/dist/helpers/use-alerts.js +65 -0
  73. package/dist/helpers/use-alerts.js.map +1 -0
  74. package/dist/helpers/use-toast.d.ts +18 -0
  75. package/dist/helpers/use-toast.js +17 -0
  76. package/dist/helpers/use-toast.js.map +1 -0
  77. package/dist/index.d.ts +3 -36
  78. package/dist/index.js +3 -35
  79. package/dist/index.js.map +1 -1
  80. package/dist/styles/index.d.ts +1 -0
  81. package/dist/styles/index.js +2 -0
  82. package/dist/styles/index.js.map +1 -0
  83. package/package.json +5 -3
  84. package/src/controls/ColorPickerDialog.tsx +1 -1
  85. package/src/controls/button.tsx +1 -1
  86. package/src/controls/canvas/DrawPad.tsx +1 -1
  87. package/src/controls/date.tsx +2 -2
  88. package/src/controls/diagram-picker.tsx +2 -2
  89. package/src/controls/dropdown.tsx +1 -1
  90. package/src/controls/file-upload.tsx +18 -11
  91. package/src/controls/index.ts +31 -0
  92. package/src/controls/input.tsx +1 -1
  93. package/src/controls/kwizoverflow.tsx +1 -1
  94. package/src/controls/menu.tsx +2 -2
  95. package/src/controls/prompt.tsx +2 -2
  96. package/src/controls/search.tsx +1 -1
  97. package/src/controls/section.tsx +1 -1
  98. package/src/controls/vertical-content.tsx +1 -1
  99. package/src/helpers/block-nav.tsx +89 -0
  100. package/src/helpers/context-export.ts +53 -0
  101. package/src/helpers/context-internal.ts +17 -0
  102. package/src/helpers/drag-drop/drag-drop-container.tsx +1 -2
  103. package/src/helpers/drag-drop/drag-drop-context-internal.tsx +10 -0
  104. package/src/helpers/drag-drop/drag-drop-context.tsx +5 -15
  105. package/src/helpers/drag-drop/drag-drop.types.ts +21 -0
  106. package/src/helpers/drag-drop/{exports.ts → index.ts} +2 -4
  107. package/src/helpers/drag-drop/use-draggable.ts +2 -10
  108. package/src/helpers/drag-drop/use-droppable.ts +3 -12
  109. package/src/helpers/hooks-events.ts +153 -0
  110. package/src/helpers/hooks.tsx +1 -360
  111. package/src/helpers/index.ts +8 -0
  112. package/src/helpers/use-alerts.tsx +75 -0
  113. package/src/helpers/use-toast.tsx +30 -0
  114. package/src/index.ts +3 -37
  115. package/src/styles/index.ts +1 -0
  116. package/dist/helpers/context.js.map +0 -1
  117. package/dist/helpers/drag-drop/exports.js.map +0 -1
  118. package/src/helpers/context.ts +0 -40
@@ -3,7 +3,7 @@ import { ColorRegular } from "@fluentui/react-icons";
3
3
  import { isFunction, isNullOrEmptyString, isNumber } from "@kwiz/common";
4
4
  import * as React from "react";
5
5
  import ColorPicker, { Color } from 'react-pick-color';
6
- import { useEffectOnlyOnMount, useStateEX } from "../helpers/hooks";
6
+ import { useEffectOnlyOnMount, useStateEX } from "../helpers";
7
7
  import { ButtonEX } from "./button";
8
8
  import { InputEx } from "./input";
9
9
  import { Prompter } from "./prompt";
@@ -1,7 +1,7 @@
1
1
  import { Button, ButtonProps, CompoundButton, compoundButtonClassNames, CompoundButtonProps, makeStyles, mergeClasses, tokens, Tooltip } from '@fluentui/react-components';
2
2
  import { capitalizeFirstLetter, isFunction, isNullOrEmptyString, isNullOrUndefined, isString, PushNoDuplicate } from '@kwiz/common';
3
3
  import React from 'react';
4
- import { useKWIZFluentContext } from '../helpers/context';
4
+ import { useKWIZFluentContext } from '../helpers/context-internal';
5
5
  import { commonSizes, useCommonStyles } from '../styles/styles';
6
6
 
7
7
  interface IProps {
@@ -2,7 +2,7 @@ import { Field, tokens } from "@fluentui/react-components";
2
2
  import { ArrowMaximizeRegular, ArrowMinimizeRegular, ArrowUploadRegular, CalligraphyPenRegular, DismissRegular } from "@fluentui/react-icons";
3
3
  import { debounce, getCSSVariableValue, ImageFileTypes, isElement, isNotEmptyString, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined } from "@kwiz/common";
4
4
  import * as React from "react";
5
- import { useAlerts, useElementSize, useStateEX } from "../../helpers/hooks";
5
+ import { useAlerts, useElementSize, useStateEX } from "../../helpers";
6
6
  import { ButtonEX } from "../button";
7
7
  import { ColorPickerEx } from "../ColorPickerDialog";
8
8
  import { FileUpload } from "../file-upload";
@@ -4,8 +4,8 @@ import { TimePicker, TimePickerProps } from '@fluentui/react-timepicker-compat';
4
4
  import { CalendarCancelRegular } from '@fluentui/react-icons';
5
5
  import { isDate } from '@kwiz/common';
6
6
  import * as React from 'react';
7
- import { useKWIZFluentContext } from '../helpers/context';
8
- import { useStateEX } from '../helpers/hooks';
7
+ import { useKWIZFluentContext } from '../helpers/context-internal';
8
+ import { useStateEX } from '../helpers';
9
9
  import { Horizontal } from './horizontal';
10
10
 
11
11
  interface IProps {
@@ -2,8 +2,8 @@ import { Dialog, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTr
2
2
  import { ImageSparkleRegular } from '@fluentui/react-icons';
3
3
  import { DiagramOptions, stockUrl } from '@kwiz/common';
4
4
  import React from 'react';
5
- import { useKWIZFluentContext } from '../helpers/context';
6
- import { useStateEX } from '../helpers/hooks';
5
+ import { useKWIZFluentContext } from '../helpers/context-internal';
6
+ import { useStateEX } from '../helpers';
7
7
  import { ButtonEXPrimarySubtle } from './button';
8
8
  import { Horizontal } from './horizontal';
9
9
  import { Section } from './section';
@@ -1,7 +1,7 @@
1
1
  import { Dropdown, DropdownProps, makeStyles, mergeClasses, Option } from '@fluentui/react-components';
2
2
  import { filterEmptyEntries, firstOrNull, isNullOrUndefined } from '@kwiz/common';
3
3
  import React from 'react';
4
- import { useKWIZFluentContext } from '../helpers/context';
4
+ import { useKWIZFluentContext } from '../helpers/context-internal';
5
5
 
6
6
  const useStyles = makeStyles({
7
7
  root: {
@@ -2,9 +2,7 @@ import { makeStyles, shorthands, tokens } from "@fluentui/react-components";
2
2
  import { ArrowUploadRegular } from "@fluentui/react-icons";
3
3
  import { isFunction, isNotEmptyArray, isNotEmptyString, isNullOrEmptyString, lastOrNull } from '@kwiz/common';
4
4
  import * as React from "react";
5
- import { useDragDropContext } from "../helpers/drag-drop/drag-drop-context";
6
- import { dropFiles } from "../helpers/drag-drop/exports";
7
- import { useEffectOnlyOnMount } from "../helpers/hooks";
5
+ import { dropFiles, useDragDropContext, useEffectOnlyOnMount } from "../helpers";
8
6
  import { ButtonEX, ButtonEXProps, CompoundButtonEXSecondary } from "./button";
9
7
 
10
8
  const useStyles = makeStyles({
@@ -33,10 +31,23 @@ interface iProps {
33
31
  export const FileUpload = React.forwardRef<HTMLButtonElement, (iProps)>((props, ref) => {
34
32
  const classes = useStyles();
35
33
  const hiddenFileInput = React.useRef(null);
34
+ const onChangeRef = React.useRef(props.onChange);
35
+ const asBase64Ref = React.useRef(props.asBase64);
36
+
36
37
  const isMulti = props.allowMultiple === true;
37
38
  const icon = props.icon || <ArrowUploadRegular />;
38
39
  const title = isNotEmptyString(props.title) ? props.title : `Drop or select ${isMulti ? 'files' : 'file'}`;
39
40
 
41
+ //keep onChange up to date
42
+ React.useEffect(() => {
43
+ onChangeRef.current = props.onChange;
44
+ }, [props.onChange]);
45
+ //keep onChange up to date
46
+ React.useEffect(() => {
47
+ asBase64Ref.current = props.asBase64;
48
+ }, [props.asBase64]);
49
+
50
+
40
51
  const onGotFiles = React.useCallback(async (rawFiles: FileList) => {
41
52
  let errors: string[] = [];
42
53
  let acceptedFiles: File[] = [];
@@ -66,18 +77,14 @@ export const FileUpload = React.forwardRef<HTMLButtonElement, (iProps)>((props,
66
77
  }
67
78
 
68
79
  if (isMulti) {
69
- if (isFunction(props.onChange)) {
70
- props.onChange(acceptedFiles, errors);
71
- }
80
+ onChangeRef.current?.(acceptedFiles, errors);
72
81
  }
73
82
  else {
74
83
  const fileUploaded = acceptedFiles[0];
75
- if (isFunction(props.onChange)) {
76
- props.onChange(fileUploaded, errors);
77
- }
84
+ onChangeRef.current?.(fileUploaded, errors);
78
85
  }
79
86
 
80
- if (isFunction(props.asBase64)) {
87
+ if (isFunction(asBase64Ref.current)) {
81
88
  const filesAs64: base64Result[] = [];
82
89
  for (let i = 0; i < (isMulti ? acceptedFiles.length : 1); i++) {
83
90
  const currentFile = acceptedFiles[i];
@@ -95,7 +102,7 @@ export const FileUpload = React.forwardRef<HTMLButtonElement, (iProps)>((props,
95
102
  else errors.push(`Could not read file ${acceptedFiles[i].name}`);
96
103
  }
97
104
  }
98
- props.asBase64(filesAs64, errors);
105
+ asBase64Ref.current?.(filesAs64, errors);
99
106
  }
100
107
  }, useEffectOnlyOnMount);
101
108
 
@@ -0,0 +1,31 @@
1
+ export * from './accordion';
2
+ export * from './button';
3
+ export * from './canvas/DrawPad';
4
+ export * from './card';
5
+ export * from './card-list';
6
+ export * from './centered';
7
+ export * from './ColorPickerDialog';
8
+ export * from './date';
9
+ export * from './diagram-picker';
10
+ export * from './divider';
11
+ export * from './dropdown';
12
+ export * from './error-boundary';
13
+ export * from './field-editor';
14
+ export * from './file-upload';
15
+ export * from './horizontal';
16
+ export * from './html-editor/editor';
17
+ export * from './input';
18
+ export * from './kwizoverflow';
19
+ export * from './list';
20
+ export * from './loading';
21
+ export * from './menu';
22
+ export * from './please-wait';
23
+ export * from './progress-bar';
24
+ export * from './prompt';
25
+ export * from './qrcode';
26
+ export * from './search';
27
+ export * from './section';
28
+ export * from './svg';
29
+ export * from './toolbar';
30
+ export * from './vertical';
31
+ export * from './vertical-content';
@@ -1,7 +1,7 @@
1
1
  import { GriffelStyle, Input, InputOnChangeData, InputProps, Label, Link, makeStyles, mergeClasses, Textarea, TextareaProps } from '@fluentui/react-components';
2
2
  import { isFunction, isNotEmptyArray, isNullOrEmptyString, isNullOrNaN, isNullOrUndefined, isNumber } from '@kwiz/common';
3
3
  import React from 'react';
4
- import { useKWIZFluentContext } from '../helpers/context';
4
+ import { useKWIZFluentContext } from '../helpers/context-internal';
5
5
  import { useCommonStyles } from '../styles/styles';
6
6
  import { Horizontal } from './horizontal';
7
7
  import { MenuEx } from './menu';
@@ -4,7 +4,7 @@ import {
4
4
  } from "@fluentui/react-components";
5
5
  import { MoreHorizontalFilled } from "@fluentui/react-icons";
6
6
  import { isNumber } from '@kwiz/common';
7
- import { useKWIZFluentContext } from "../helpers/context";
7
+ import { useKWIZFluentContext } from "../helpers/context-internal";
8
8
 
9
9
  interface IProps<ItemType> {
10
10
  /** you cannot have a menu with trigger in overflow items. put those in groupWrapper controls before/after rendering children. */
@@ -2,8 +2,8 @@ import { Menu, MenuDivider, MenuGroup, MenuGroupHeader, MenuItem, MenuList, Menu
2
2
  import { ChevronLeftRegular, ChevronRightRegular } from '@fluentui/react-icons';
3
3
  import { IDictionary, isNotEmptyArray, isNotEmptyString, isNullOrEmptyString, isNullOrUndefined, isNumber, isString, isUndefined, jsonClone, stopEvent } from '@kwiz/common';
4
4
  import React from 'react';
5
- import { useKWIZFluentContext } from '../helpers/context';
6
- import { useStateEX } from '../helpers/hooks';
5
+ import { useKWIZFluentContext } from '../helpers/context-internal';
6
+ import { useStateEX } from '../helpers';
7
7
  import { ButtonEX, ButtonEXProps } from './button';
8
8
  import { Horizontal } from './horizontal';
9
9
  import { Search } from './search';
@@ -2,8 +2,8 @@ import { Dialog, DialogActions, DialogBody, DialogContent, DialogModalType, Dial
2
2
  import { DismissRegular } from '@fluentui/react-icons';
3
3
  import { isNotEmptyArray, isNullOrEmptyString, noops, PushNoDuplicate, RemoveItemFromArr, stopEvent } from '@kwiz/common';
4
4
  import React from 'react';
5
- import { useKWIZFluentContext } from '../helpers/context';
6
- import { useKeyDown } from '../helpers/hooks';
5
+ import { useKWIZFluentContext } from '../helpers/context-internal';
6
+ import { useKeyDown } from '../helpers/hooks-events';
7
7
  import { ButtonEX, ButtonEXProps, ButtonEXSecondary } from './button';
8
8
 
9
9
  export interface IPrompterProps {
@@ -3,7 +3,7 @@ import { DismissRegular, SearchRegular } from "@fluentui/react-icons";
3
3
  import { debounce, isFunction, isNullOrEmptyString, isUndefined } from '@kwiz/common';
4
4
  import React, { useState } from 'react';
5
5
  import { GetLogger } from '../_modules/config';
6
- import { useStateEX } from '../helpers/hooks';
6
+ import { useStateEX } from '../helpers';
7
7
  import { mixins } from '../styles/styles';
8
8
  const logger = GetLogger("Search");
9
9
 
@@ -1,7 +1,7 @@
1
1
  import { makeStyles, mergeClasses, Portal, tokens } from '@fluentui/react-components';
2
2
  import { isFunction, isNotEmptyArray } from '@kwiz/common';
3
3
  import React from 'react';
4
- import { useKWIZFluentContext } from '../helpers/context';
4
+ import { useKWIZFluentContext } from '../helpers/context-internal';
5
5
  import { KnownClassNames, mixins, useCommonStyles } from '../styles/styles';
6
6
 
7
7
  const useStyles = makeStyles({
@@ -1,7 +1,7 @@
1
1
  import { makeStyles, mergeClasses } from '@fluentui/react-components';
2
2
  import { isNotEmptyArray } from '@kwiz/common';
3
3
  import React from 'react';
4
- import { useWindowSize } from '../helpers/hooks';
4
+ import { useWindowSize } from '../helpers';
5
5
 
6
6
  const useStyles = makeStyles({
7
7
  verticalContainer: {
@@ -0,0 +1,89 @@
1
+ import { IDictionary, isNotEmptyArray, isNullOrEmptyString, jsonClone, objectsEqual } from "@kwiz/common";
2
+ import { useCallback, useEffect } from "react";
3
+ import { IPrompterProps, Prompter } from "../controls/prompt";
4
+ import { useEffectOnlyOnMount, useStateEX } from "./hooks";
5
+
6
+ export interface iBlockNav {
7
+ setMessage: (id: string, message?: string) => void;
8
+ onNav: (nav: () => void) => void;
9
+ navPrompt?: JSX.Element;
10
+
11
+ }
12
+ /** set block message if you want to block nav.
13
+ * - call setMessage to add a blocker message
14
+ * - call onNav when you have internal navigation (open / close popups)
15
+ * - render the navPrompt control to your page
16
+ * FYI for page unload, most modern browsers won't show your message but a generic one instead. */
17
+ export function useBlockNav(): iBlockNav {
18
+ const [, setBlockNavMessages, blockNavMessagesRef] = useStateEX<IDictionary<string>>({});
19
+ const [_prompt, setPrompt] = useStateEX<IPrompterProps>(null);
20
+
21
+ const getMessagesArr = useCallback(() => {
22
+ return Object.keys(blockNavMessagesRef.current).map(id => blockNavMessagesRef.current[id]);
23
+ }, useEffectOnlyOnMount);
24
+
25
+ const getMessages = useCallback(() => {
26
+ return getMessagesArr().join();
27
+ }, useEffectOnlyOnMount);
28
+
29
+ const onNav = useCallback((nav: () => void) => {
30
+ let messages = getMessagesArr();
31
+ if (isNotEmptyArray(messages)) {
32
+ //need to release react to re-render the prompt
33
+ window.setTimeout(() => {
34
+ //prompt, if ok - clear messages and nav.
35
+ setPrompt({
36
+ okButtonText: "Leave",
37
+ cancelButtonText: "Cancel",
38
+ title: "Leave page?",
39
+ children: messages.length > 1
40
+ ? <ul>
41
+ {messages.map((m, i) => <li key={`m${i}`}>{m}</li>)}
42
+ </ul>
43
+ : <p>{messages[0]}</p>,
44
+ onCancel: () => setPrompt(null),
45
+ onOK: () => {
46
+ setPrompt(null);
47
+ setBlockNavMessages({});//clear messages
48
+ nav();
49
+ }
50
+ });
51
+ }, 1);
52
+ }
53
+ else nav();
54
+ }, useEffectOnlyOnMount);
55
+
56
+
57
+ useEffect(() => {
58
+ function handleBeforeUnload(e: BeforeUnloadEvent) {
59
+ //todo: use blockMessageRef.current so that we don't have to re-register every time message changes.
60
+ //otherwise we would have to add blockMessage as a dependency for this useEffect
61
+ const message = getMessages();
62
+ if (!isNullOrEmptyString(message)) {
63
+ e.preventDefault();
64
+ e.returnValue = message;
65
+ }
66
+ }
67
+ // Add event listener
68
+ window.addEventListener("beforeunload", handleBeforeUnload);
69
+ // Remove event listener on cleanup
70
+ return () => window.removeEventListener("beforeunload", handleBeforeUnload);
71
+ }, useEffectOnlyOnMount);
72
+ return {
73
+ setMessage: (id: string, message?: string) => {
74
+ let current = jsonClone(blockNavMessagesRef.current);
75
+ if (isNullOrEmptyString(message))
76
+ delete current[id];
77
+ else current[id] = message;
78
+ if (!objectsEqual(current, blockNavMessagesRef.current))
79
+ setBlockNavMessages(current);
80
+ },
81
+ // clearMessages: () => {
82
+ // setBlockNavMessages({});
83
+ // },
84
+ // getMessages,
85
+ // getMessagesArr,
86
+ onNav,
87
+ navPrompt: _prompt ? <Prompter {..._prompt} /> : undefined
88
+ };
89
+ }
@@ -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 "./use-draggable";
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, { useContext } from "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 { iDraggableProps, iDraggedItemType, useDraggable } from "./use-draggable";
7
- import useDroppable, { iDroppableProps } from "./use-droppable";
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 './use-draggable';
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 "./use-draggable";
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 './use-draggable';
2
+ import { iDraggedItemType, iDroppableProps } from './drag-drop.types';
3
3
 
4
- export interface iDroppableProps<DropTypes extends string, ItemTypes extends iDraggedItemType<DropTypes>> {
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
+ }