@kwiz/fluentui 1.0.61 → 1.0.63

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.
Files changed (77) hide show
  1. package/README.md +37 -11
  2. package/dist/controls/button.d.ts +11 -11
  3. package/dist/controls/button.js +2 -3
  4. package/dist/controls/button.js.map +1 -1
  5. package/dist/controls/centered.js +1 -8
  6. package/dist/controls/centered.js.map +1 -1
  7. package/dist/controls/date.js +1 -1
  8. package/dist/controls/date.js.map +1 -1
  9. package/dist/controls/diagram-picker.d.ts +2 -2
  10. package/dist/controls/divider.d.ts +2 -2
  11. package/dist/controls/dropdown.d.ts +4 -9
  12. package/dist/controls/dropdown.js +27 -28
  13. package/dist/controls/dropdown.js.map +1 -1
  14. package/dist/controls/file-upload.d.ts +1 -1
  15. package/dist/controls/horizontal.d.ts +2 -2
  16. package/dist/controls/index.d.ts +1 -0
  17. package/dist/controls/index.js +1 -0
  18. package/dist/controls/index.js.map +1 -1
  19. package/dist/controls/input.js +1 -1
  20. package/dist/controls/input.js.map +1 -1
  21. package/dist/controls/list.js +4 -1
  22. package/dist/controls/list.js.map +1 -1
  23. package/dist/controls/merge-text.d.ts +16 -0
  24. package/dist/controls/merge-text.js +81 -0
  25. package/dist/controls/merge-text.js.map +1 -0
  26. package/dist/controls/progress-bar.d.ts +2 -2
  27. package/dist/controls/prompt.d.ts +1 -1
  28. package/dist/controls/search.d.ts +3 -2
  29. package/dist/controls/search.js +20 -34
  30. package/dist/controls/search.js.map +1 -1
  31. package/dist/controls/section.d.ts +3 -2
  32. package/dist/controls/section.js +15 -5
  33. package/dist/controls/section.js.map +1 -1
  34. package/dist/controls/svg.d.ts +3 -0
  35. package/dist/controls/svg.js +5 -0
  36. package/dist/controls/svg.js.map +1 -1
  37. package/dist/controls/toolbar.js +2 -3
  38. package/dist/controls/toolbar.js.map +1 -1
  39. package/dist/controls/vertical.d.ts +4 -2
  40. package/dist/controls/vertical.js +6 -1
  41. package/dist/controls/vertical.js.map +1 -1
  42. package/dist/helpers/context-const.d.ts +2 -0
  43. package/dist/helpers/context-const.js.map +1 -1
  44. package/dist/helpers/context-export.d.ts +6 -1
  45. package/dist/helpers/context-export.js +44 -6
  46. package/dist/helpers/context-export.js.map +1 -1
  47. package/dist/helpers/forwardRef.d.ts +4 -0
  48. package/dist/helpers/forwardRef.js +2 -0
  49. package/dist/helpers/forwardRef.js.map +1 -0
  50. package/dist/helpers/hooks-events.d.ts +3 -3
  51. package/dist/helpers/hooks-events.js.map +1 -1
  52. package/dist/helpers/hooks.d.ts +1 -1
  53. package/dist/helpers/hooks.js +15 -6
  54. package/dist/helpers/hooks.js.map +1 -1
  55. package/dist/styles/styles.d.ts +5 -1
  56. package/dist/styles/styles.js +5 -18
  57. package/dist/styles/styles.js.map +1 -1
  58. package/package.json +3 -1
  59. package/src/controls/button.tsx +2 -3
  60. package/src/controls/centered.tsx +2 -10
  61. package/src/controls/date.tsx +1 -1
  62. package/src/controls/dropdown.tsx +37 -36
  63. package/src/controls/index.ts +2 -0
  64. package/src/controls/input.tsx +1 -1
  65. package/src/controls/list.tsx +4 -2
  66. package/src/controls/merge-text.tsx +126 -0
  67. package/src/controls/search.tsx +20 -33
  68. package/src/controls/section.tsx +17 -5
  69. package/src/controls/svg.tsx +8 -0
  70. package/src/controls/toolbar.tsx +2 -4
  71. package/src/controls/vertical.tsx +9 -1
  72. package/src/helpers/context-const.ts +2 -0
  73. package/src/helpers/context-export.tsx +52 -8
  74. package/src/helpers/forwardRef.ts +7 -0
  75. package/src/helpers/hooks-events.ts +2 -2
  76. package/src/helpers/hooks.tsx +16 -7
  77. package/src/styles/styles.ts +5 -18
@@ -1,31 +1,75 @@
1
- import { makeStyles } from "@fluentui/react-components";
2
- import React, { useEffect, useState } from "react";
1
+ import { makeStaticStyles, makeStyles } from "@fluentui/react-components";
2
+ import React, { PropsWithChildren, useEffect, useState } from "react";
3
+ import { GetLogger } from "../_modules/config";
4
+ import { KnownClassNames } from "../styles";
3
5
  import { iKWIZFluentContext, KWIZFluentContext } from "./context-const";
6
+ import { DragDropContextProvider } from "./drag-drop";
4
7
  export type { iKWIZFluentContext } from "./context-const";
5
-
8
+ const logger = GetLogger("KWIZFluentContextProvider");
6
9
  const useContextStyles = makeStyles({
7
10
  root: {
8
11
  "& *": {
9
12
  scrollbarWidth: "thin"
10
- }
13
+ },
14
+ [`& .${KnownClassNames.printShow}`]: {
15
+ '@media print': {
16
+ display: 'unset',
17
+ }
18
+ },
19
+ [`& .${KnownClassNames.printHide}`]: {
20
+ '@media print': {
21
+ display: 'none !important'
22
+ }
23
+ },
24
+ },
25
+ });
26
+ export const useStaticStyles = makeStaticStyles({
27
+ [`.${KnownClassNames.printShow}`]: {
28
+ display: 'none'
11
29
  },
12
- })
30
+ [`body.${KnownClassNames.print} .${KnownClassNames.printHide}`]: {
31
+ display: "none !important"
32
+ },
33
+ [`body.${KnownClassNames.print} .${KnownClassNames.printShow}`]: {
34
+ display: "unset"
35
+ }
36
+ });
13
37
 
38
+ /** @deprecated - use KWIZFluentProvider instead of using this + DragDropContextProvider */
14
39
  export function useKWIZFluentContextProvider(options: {
15
40
  root?: React.MutableRefObject<HTMLDivElement>;
16
41
  ctx?: iKWIZFluentContext;
17
42
  }) {
43
+ useStaticStyles();
18
44
  const classes = useContextStyles();
19
45
  let v: iKWIZFluentContext = options && options.ctx || {};
20
46
  const [kwizFluentContext, setKwizFluentContext] = useState<iKWIZFluentContext>(v);
21
47
  useEffect(() => {
22
- options.root?.current?.classList.add(...classes.root.split(' '));
48
+ if (options.root?.current) logger.warn('Sending a root node is not recommended, if you have set up your packages correctly to mark react and fluent UI as external dialogs should open correctly.');
49
+ let styleRoot = options.root?.current || document.body;
50
+ styleRoot.classList.add(...classes.root.split(' '));
23
51
  // ref only updates in useEffect, not in useMemo or anything else.
24
52
  // we need to set it into state so it will trigger a ui update
25
53
  setKwizFluentContext({
26
54
  ...v,
27
- mountNode: options.root.current
55
+ mountNode: options.root?.current
28
56
  });
29
57
  }, [options.root]);
30
- return { KWIZFluentContext, value: kwizFluentContext };
58
+ return {
59
+ KWIZFluentContext,
60
+ value: kwizFluentContext
61
+ };
62
+ }
63
+
64
+ export const KWIZFluentProvider = (props: PropsWithChildren<{
65
+ ctx?: iKWIZFluentContext;
66
+ }>) => {
67
+
68
+ const cp = useKWIZFluentContextProvider({ ctx: props.ctx });
69
+
70
+ return <cp.KWIZFluentContext.Provider value={cp.value}>
71
+ <DragDropContextProvider>
72
+ {props.children}
73
+ </DragDropContextProvider>
74
+ </cp.KWIZFluentContext.Provider>;
31
75
  }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ //need to redeclare to support forward ref with generic types
3
+ declare module "react" {
4
+ function forwardRef<T, P = {}>(
5
+ render: (props: P, ref: React.Ref<T>) => React.JSX.Element | null
6
+ ): (props: P & React.RefAttributes<T>) => React.JSX.Element | null;
7
+ }
@@ -3,8 +3,8 @@ import { MutableRefObject, useEffect, useRef, useState } from "react";
3
3
  import { KnownClassNames } from "../styles/styles";
4
4
  import { useEffectOnlyOnMount } from "./hooks";
5
5
 
6
- export function useTrackFocus(props: { onFocus: () => void, onLoseFocus: () => void, ref?: MutableRefObject<HTMLElement> }) {
7
- const wrapperDiv = props.ref || useRef<HTMLDivElement>(null);
6
+ export function useTrackFocus<elmType extends HTMLElement>(props: { onFocus: () => void, onLoseFocus: () => void, ref?: MutableRefObject<elmType> }) {
7
+ const wrapperDiv: MutableRefObject<elmType> = props.ref || useRef<HTMLDivElement>(null) as any;
8
8
  useEffect(() => {
9
9
  function focusIn(e: FocusEvent) {
10
10
  let elm = e.target as HTMLElement;//document.activeElement;
@@ -2,13 +2,12 @@ import { isFunction, isNotEmptyArray, isNullOrEmptyString, isPrimitiveValue, jso
2
2
  import { MutableRefObject, SetStateAction, useCallback, useEffect, useRef, useState } from "react";
3
3
  import { GetLogger } from "../_modules/config";
4
4
 
5
- const logger = GetLogger("helpers/hooks");
6
5
  /** Empty array ensures that effect is only run on mount */
7
6
  export const useEffectOnlyOnMount = [];
8
7
 
9
8
  /** set state on steroids. provide promise callback after render, onChange transformer and automatic skip-set when value not changed */
10
9
  export function useStateEX<ValueType>(initialValue: ValueType, options?: {
11
- onChange?: (newValue: SetStateAction<ValueType>) => SetStateAction<ValueType>;
10
+ onChange?: (newValue: SetStateAction<ValueType>, isValueChanged: boolean) => SetStateAction<ValueType>;
12
11
  //will not set state if value did not change
13
12
  skipUpdateIfSame?: boolean;
14
13
  //optional, provide a name for better logging
@@ -53,26 +52,36 @@ export function useStateEX<ValueType>(initialValue: ValueType, options?: {
53
52
  }
54
53
  }, [value, resolveState.current]);
55
54
 
56
- let setValueWithCheck = !options.skipUpdateIfSame ? setValueInState : (newValue: ValueType) => {
57
- logger.groupSync('conditional value change', log => {
55
+ function getIsValueChanged(newValue: ValueType): boolean {
56
+ return logger.groupSync('getIsValueChanged', log => {
58
57
  if (logger.getLevel() === LoggerLevel.VERBOSE) {
59
58
  log('old: ' + jsonStringify(currentValue.current));
60
59
  log('new: ' + jsonStringify(newValue));
61
60
  }
62
61
  if (!objectsEqual(newValue as object, currentValue.current as object)) {
63
62
  log(`value changed`);
64
- setValueInState(newValue);
63
+ return true;
65
64
  }
66
65
  else {
67
66
  log(`value unchanged`);
68
- resolvePromises();
67
+ return false;
69
68
  }
70
69
  });
70
+ };
71
+
72
+ let setValueWithCheck = !options.skipUpdateIfSame ? setValueInState : (newValue: ValueType) => {
73
+ const isValueChanged = getIsValueChanged(newValue);
74
+ if (isValueChanged) {
75
+ setValueInState(newValue);
76
+ }
77
+ else {
78
+ resolvePromises();
79
+ }
71
80
  }
72
81
 
73
82
 
74
83
  let setValueWithEvents = wrapFunction(setValueWithCheck, {
75
- before: (newValue: ValueType) => isFunction(options.onChange) ? options.onChange(newValue) : newValue,
84
+ before: (newValue: ValueType) => isFunction(options.onChange) ? options.onChange(newValue, getIsValueChanged(newValue)) : newValue,
76
85
  after: (newValue: ValueType) => currentValue.current = isPrimitiveValue(newValue) || isFunction(newValue)
77
86
  ? newValue
78
87
  //fix skipUpdateIfSame for complex objects
@@ -58,6 +58,8 @@ export module mixins {
58
58
 
59
59
  export const KnownClassNames = {
60
60
  print: 'print-root',
61
+ printHide: 'print-hide',
62
+ printShow: 'print-show',
61
63
  section: 'kfui-section',
62
64
  vertical: 'kfui-vertical',
63
65
  horizontal: 'kfui-horizontal',
@@ -67,26 +69,11 @@ export const KnownClassNames = {
67
69
  accordionBody: 'kfui-accordion-body',
68
70
  accordionBodyWrapper: 'kfui-accordion-body-wrapper',
69
71
  isOpen: 'is-opened',
70
- progressBarStepLabel: 'step-label'
72
+ progressBarStepLabel: 'step-label',
73
+ left: 'float-left',
74
+ right: 'float-right'
71
75
  }
72
76
  export const useCommonStyles = makeStyles({
73
- printShow: {
74
- display: 'none',
75
- [`:global(body.${KnownClassNames.print})`]: {
76
- display: 'unset',
77
- },
78
- '@media print': {
79
- display: 'unset',
80
- }
81
- },
82
- printHide: {
83
- [`:global(body.${KnownClassNames.print})`]: {
84
- display: 'none !important'
85
- },
86
- '@media print': {
87
- display: 'none !important'
88
- }
89
- },
90
77
  hintLabel: {
91
78
  color: tokens.colorNeutralForeground3,
92
79
  fontSize: tokens.fontSizeBase200,