@veracity/vui 0.2.4 → 0.3.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.
Files changed (128) hide show
  1. package/button/context.js +2 -2
  2. package/buttonGroup/context.js +2 -2
  3. package/checkbox/context.js +2 -2
  4. package/core/types/index.d.ts +0 -1
  5. package/core/types/index.js +0 -1
  6. package/core/utils.d.ts +1 -3
  7. package/core/utils.js +1 -17
  8. package/footer/consts.d.ts +69 -0
  9. package/footer/consts.js +129 -0
  10. package/footer/footer.d.ts +15 -0
  11. package/footer/footer.js +74 -0
  12. package/footer/footer.types.d.ts +30 -0
  13. package/footer/footerColumn.d.ts +219 -0
  14. package/footer/footerColumn.js +24 -0
  15. package/footer/footerHeading.d.ts +3 -0
  16. package/footer/footerHeading.js +26 -0
  17. package/footer/footerLink.d.ts +3 -0
  18. package/footer/footerLink.js +26 -0
  19. package/footer/footerRow.d.ts +3 -0
  20. package/footer/footerRow.js +24 -0
  21. package/footer/footerSection.d.ts +3 -0
  22. package/footer/footerSection.js +46 -0
  23. package/footer/footerTrademark.d.ts +5 -0
  24. package/footer/footerTrademark.js +31 -0
  25. package/footer/helpers.d.ts +10 -0
  26. package/footer/helpers.js +55 -0
  27. package/footer/index.d.ts +9 -0
  28. package/footer/index.js +27 -0
  29. package/footer/theme.d.ts +7 -0
  30. package/footer/theme.js +12 -0
  31. package/icons/baseIcons/cub/cubPowerBi.d.ts +3 -0
  32. package/icons/baseIcons/cub/cubPowerBi.js +7 -0
  33. package/icons/baseIcons/cub/cubVeracity.d.ts +3 -0
  34. package/icons/baseIcons/cub/cubVeracity.js +7 -0
  35. package/icons/baseIcons/cul/culCircleChart.d.ts +3 -0
  36. package/icons/baseIcons/cul/culCircleChart.js +7 -0
  37. package/icons/baseIcons/cul/culCircleChartAlt.d.ts +3 -0
  38. package/icons/baseIcons/cul/culCircleChartAlt.js +7 -0
  39. package/icons/baseIcons/cul/culNumber1.d.ts +3 -0
  40. package/icons/baseIcons/cul/culNumber1.js +7 -0
  41. package/icons/baseIcons/cul/culTarget.d.ts +3 -0
  42. package/icons/baseIcons/cul/culTarget.js +7 -0
  43. package/icons/baseIcons/fab/fabYoutube.d.ts +3 -0
  44. package/icons/baseIcons/fab/fabYoutube.js +7 -0
  45. package/icons/baseIcons/fal/falLayerGroup.d.ts +3 -0
  46. package/icons/baseIcons/fal/falLayerGroup.js +7 -0
  47. package/icons/baseIcons/fal/falQuestionCircle.d.ts +3 -0
  48. package/icons/baseIcons/fal/falQuestionCircle.js +7 -0
  49. package/icons/baseIcons/fas/fasCalendarAlt.d.ts +3 -0
  50. package/icons/baseIcons/fas/fasCalendarAlt.js +7 -0
  51. package/icons/baseIcons/icons.d.ts +296 -0
  52. package/icons/baseIcons/icons.js +603 -0
  53. package/icons/baseIcons/types.d.ts +1 -1
  54. package/index.d.ts +3 -0
  55. package/index.js +3 -0
  56. package/input/context.js +2 -2
  57. package/link/context.js +2 -2
  58. package/link/link.js +1 -1
  59. package/list/context.js +2 -2
  60. package/list/listDivider.js +1 -1
  61. package/menu/context.d.ts +4 -0
  62. package/menu/context.js +23 -0
  63. package/menu/index.d.ts +6 -0
  64. package/menu/index.js +27 -0
  65. package/menu/menu.d.ts +15 -0
  66. package/menu/menu.js +63 -0
  67. package/menu/menu.types.d.ts +11 -0
  68. package/menu/menu.types.js +2 -0
  69. package/menu/menuButton.d.ts +3 -0
  70. package/menu/menuButton.js +30 -0
  71. package/menu/menuItem.d.ts +3 -0
  72. package/menu/menuItem.js +63 -0
  73. package/menu/menuList.d.ts +11 -0
  74. package/menu/menuList.js +48 -0
  75. package/menu/theme.d.ts +7 -0
  76. package/menu/theme.js +12 -0
  77. package/notification/context.js +2 -2
  78. package/notification/notificationButton.js +1 -1
  79. package/notification/theme.d.ts +0 -5
  80. package/notification/theme.js +6 -7
  81. package/package.json +3 -2
  82. package/popover/context.d.ts +4 -0
  83. package/popover/context.js +23 -0
  84. package/popover/index.d.ts +8 -0
  85. package/popover/index.js +29 -0
  86. package/popover/plugins.d.ts +3 -0
  87. package/popover/plugins.js +24 -0
  88. package/popover/popover.d.ts +9 -0
  89. package/popover/popover.js +32 -0
  90. package/popover/popover.types.d.ts +15 -0
  91. package/popover/popover.types.js +2 -0
  92. package/popover/popoverContent.d.ts +2 -0
  93. package/popover/popoverContent.js +43 -0
  94. package/popover/popoverTrigger.d.ts +2 -0
  95. package/popover/popoverTrigger.js +44 -0
  96. package/popover/theme.d.ts +7 -0
  97. package/popover/theme.js +12 -0
  98. package/popover/usePopover.d.ts +14 -0
  99. package/popover/usePopover.js +114 -0
  100. package/popover/usePopover.types.d.ts +16 -0
  101. package/popover/usePopover.types.js +2 -0
  102. package/radio/context.js +2 -2
  103. package/switch/context.js +2 -2
  104. package/system/flexboxGrids.d.ts +13 -0
  105. package/system/flexboxGrids.js +2 -0
  106. package/system/grids.d.ts +55 -0
  107. package/system/grids.js +2 -0
  108. package/system/system.d.ts +3 -1
  109. package/system/system.js +1 -1
  110. package/system/typography.d.ts +1 -0
  111. package/tag/context.js +2 -2
  112. package/tag/tagButton.js +1 -1
  113. package/tag/theme.d.ts +2 -11
  114. package/tag/theme.js +21 -18
  115. package/theme/components.d.ts +20 -16
  116. package/theme/components.js +38 -32
  117. package/theme/defaultTheme.d.ts +20 -16
  118. package/utils/assertion.d.ts +1 -1
  119. package/utils/function.d.ts +1 -1
  120. package/utils/function.js +3 -2
  121. package/utils/index.d.ts +1 -0
  122. package/utils/index.js +1 -0
  123. package/utils/react.d.ts +18 -0
  124. package/utils/react.js +83 -0
  125. package/utils/types.d.ts +11 -0
  126. package/utils/types.js +0 -1
  127. package/core/types/context.d.ts +0 -10
  128. /package/{core/types/context.js → footer/footer.types.js} +0 -0
package/tag/theme.js CHANGED
@@ -9,18 +9,15 @@ function variantSolid(props) {
9
9
  color: 'white'
10
10
  };
11
11
  var button = {
12
- hoverBorderColor: "transparent",
13
- borderColor: "transparent",
14
- color: 'white',
15
12
  hoverBg: c + ".70",
16
13
  activeBg: c + ".60",
17
14
  bg: c + ".80",
18
- variant: 'solid'
15
+ color: 'white'
19
16
  };
20
17
  if (c === 'yellow') {
21
- container.hoverBg = c + ".80";
22
- container.activeBg = c + ".90";
23
- container.bg = c + ".70";
18
+ container.hoverBg = 'yellow.80';
19
+ container.activeBg = 'yellow.90';
20
+ container.bg = 'yellow.70';
24
21
  button.hoverBg = 'yellow.60';
25
22
  button.activeBg = 'yellow.50';
26
23
  button.bg = 'yellow.70';
@@ -33,16 +30,25 @@ function variantSubtle(props) {
33
30
  hoverBg: c + ".30",
34
31
  activeBg: c + ".40",
35
32
  bg: c + ".20",
36
- color: 'prussian.80'
33
+ color: c + ".90"
37
34
  };
38
35
  var button = {
39
- hoverBorderColor: "transparent",
40
- borderColor: "transparent",
41
- color: c + ".90",
42
36
  hoverBg: c + ".30",
43
37
  activeBg: c + ".40",
44
- variant: 'outlined'
38
+ color: c + ".90"
45
39
  };
40
+ if (c === 'blue') {
41
+ container.color = 'blue.80';
42
+ button.color = 'blue.80';
43
+ }
44
+ if (c === 'grey') {
45
+ container.color = 'prussian.80';
46
+ button.color = 'prussian.80';
47
+ }
48
+ if (c === 'yellow') {
49
+ container.color = 'yellow.100';
50
+ button.color = 'yellow.100';
51
+ }
46
52
  return { container: container, button: button };
47
53
  }
48
54
  var defaultProps = {
@@ -63,8 +69,7 @@ var sizes = {
63
69
  },
64
70
  icon: {
65
71
  size: 'xs'
66
- },
67
- text: {}
72
+ }
68
73
  },
69
74
  md: {
70
75
  container: {
@@ -77,8 +82,7 @@ var sizes = {
77
82
  },
78
83
  icon: {
79
84
  size: 'sm'
80
- },
81
- text: {}
85
+ }
82
86
  },
83
87
  lg: {
84
88
  container: {
@@ -91,8 +95,7 @@ var sizes = {
91
95
  },
92
96
  icon: {
93
97
  size: 'md'
94
- },
95
- text: {}
98
+ }
96
99
  }
97
100
  };
98
101
  var variants = {
@@ -211,6 +211,12 @@ declare const _default: {
211
211
  sizes: {};
212
212
  variants: {};
213
213
  };
214
+ Footer: {
215
+ defaultProps: {};
216
+ parts: string[];
217
+ sizes: {};
218
+ variants: {};
219
+ };
214
220
  Heading: {
215
221
  defaultProps: {
216
222
  size: string;
@@ -462,6 +468,12 @@ declare const _default: {
462
468
  };
463
469
  };
464
470
  };
471
+ Menu: {
472
+ defaultProps: {};
473
+ parts: string[];
474
+ sizes: {};
475
+ variants: {};
476
+ };
465
477
  Notification: {
466
478
  defaultProps: {
467
479
  colorScheme: string;
@@ -481,12 +493,7 @@ declare const _default: {
481
493
  color: string;
482
494
  hoverBg: string;
483
495
  activeBg: string;
484
- variant: string;
485
496
  };
486
- icon: {};
487
- message: {};
488
- text: {};
489
- title: {};
490
497
  };
491
498
  };
492
499
  };
@@ -533,6 +540,12 @@ declare const _default: {
533
540
  };
534
541
  };
535
542
  };
543
+ Popover: {
544
+ defaultProps: {};
545
+ parts: string[];
546
+ sizes: {};
547
+ variants: {};
548
+ };
536
549
  Radio: {
537
550
  defaultProps: {
538
551
  colorScheme: string;
@@ -785,7 +798,6 @@ declare const _default: {
785
798
  icon: {
786
799
  size: string;
787
800
  };
788
- text: {};
789
801
  };
790
802
  md: {
791
803
  container: {
@@ -799,7 +811,6 @@ declare const _default: {
799
811
  icon: {
800
812
  size: string;
801
813
  };
802
- text: {};
803
814
  };
804
815
  lg: {
805
816
  container: {
@@ -813,7 +824,6 @@ declare const _default: {
813
824
  icon: {
814
825
  size: string;
815
826
  };
816
- text: {};
817
827
  };
818
828
  };
819
829
  variants: {
@@ -825,13 +835,10 @@ declare const _default: {
825
835
  color: string;
826
836
  };
827
837
  button: {
828
- hoverBorderColor: string;
829
- borderColor: string;
830
- color: string;
831
838
  hoverBg: string;
832
839
  activeBg: string;
833
840
  bg: string;
834
- variant: string;
841
+ color: string;
835
842
  };
836
843
  };
837
844
  subtle: (props: import("..").Dict<any>) => {
@@ -842,12 +849,9 @@ declare const _default: {
842
849
  color: string;
843
850
  };
844
851
  button: {
845
- hoverBorderColor: string;
846
- borderColor: string;
847
- color: string;
848
852
  hoverBg: string;
849
853
  activeBg: string;
850
- variant: string;
854
+ color: string;
851
855
  };
852
856
  };
853
857
  };
@@ -9,22 +9,25 @@ var theme_3 = __importDefault(require("../button/theme"));
9
9
  var theme_4 = __importDefault(require("../card/theme"));
10
10
  var theme_5 = __importDefault(require("../checkbox/theme"));
11
11
  var theme_6 = __importDefault(require("../divider/theme"));
12
- var theme_7 = __importDefault(require("../heading/theme"));
13
- var theme_8 = __importDefault(require("../icon/theme"));
14
- var theme_9 = __importDefault(require("../image/theme"));
15
- var theme_10 = __importDefault(require("../input/theme"));
16
- var theme_11 = __importDefault(require("../link/theme"));
17
- var theme_12 = __importDefault(require("../list/theme"));
18
- var theme_13 = __importDefault(require("../notification/theme"));
19
- var theme_14 = __importDefault(require("../p/theme"));
20
- var theme_15 = __importDefault(require("../panel/theme"));
21
- var theme_16 = __importDefault(require("../radio/theme"));
22
- var theme_17 = __importDefault(require("../skeleton/theme"));
23
- var theme_18 = __importDefault(require("../spinner/theme"));
24
- var theme_19 = __importDefault(require("../switch/theme"));
25
- var theme_20 = __importDefault(require("../t/theme"));
26
- var theme_21 = __importDefault(require("../tag/theme"));
27
- var theme_22 = __importDefault(require("../textarea/theme"));
12
+ var theme_7 = __importDefault(require("../footer/theme"));
13
+ var theme_8 = __importDefault(require("../heading/theme"));
14
+ var theme_9 = __importDefault(require("../icon/theme"));
15
+ var theme_10 = __importDefault(require("../image/theme"));
16
+ var theme_11 = __importDefault(require("../input/theme"));
17
+ var theme_12 = __importDefault(require("../link/theme"));
18
+ var theme_13 = __importDefault(require("../list/theme"));
19
+ var theme_14 = __importDefault(require("../menu/theme"));
20
+ var theme_15 = __importDefault(require("../notification/theme"));
21
+ var theme_16 = __importDefault(require("../p/theme"));
22
+ var theme_17 = __importDefault(require("../panel/theme"));
23
+ var theme_18 = __importDefault(require("../popover/theme"));
24
+ var theme_19 = __importDefault(require("../radio/theme"));
25
+ var theme_20 = __importDefault(require("../skeleton/theme"));
26
+ var theme_21 = __importDefault(require("../spinner/theme"));
27
+ var theme_22 = __importDefault(require("../switch/theme"));
28
+ var theme_23 = __importDefault(require("../t/theme"));
29
+ var theme_24 = __importDefault(require("../tag/theme"));
30
+ var theme_25 = __importDefault(require("../textarea/theme"));
28
31
  exports.default = {
29
32
  Avatar: theme_1.default,
30
33
  Box: theme_2.default,
@@ -32,20 +35,23 @@ exports.default = {
32
35
  Card: theme_4.default,
33
36
  Checkbox: theme_5.default,
34
37
  Divider: theme_6.default,
35
- Heading: theme_7.default,
36
- Icon: theme_8.default,
37
- Image: theme_9.default,
38
- Input: theme_10.default,
39
- Link: theme_11.default,
40
- List: theme_12.default,
41
- Notification: theme_13.default,
42
- P: theme_14.default,
43
- Panel: theme_15.default,
44
- Radio: theme_16.default,
45
- Skeleton: theme_17.default,
46
- Spinner: theme_18.default,
47
- Switch: theme_19.default,
48
- T: theme_20.default,
49
- Tag: theme_21.default,
50
- Textarea: theme_22.default
38
+ Footer: theme_7.default,
39
+ Heading: theme_8.default,
40
+ Icon: theme_9.default,
41
+ Image: theme_10.default,
42
+ Input: theme_11.default,
43
+ Link: theme_12.default,
44
+ List: theme_13.default,
45
+ Menu: theme_14.default,
46
+ Notification: theme_15.default,
47
+ P: theme_16.default,
48
+ Panel: theme_17.default,
49
+ Popover: theme_18.default,
50
+ Radio: theme_19.default,
51
+ Skeleton: theme_20.default,
52
+ Spinner: theme_21.default,
53
+ Switch: theme_22.default,
54
+ T: theme_23.default,
55
+ Tag: theme_24.default,
56
+ Textarea: theme_25.default
51
57
  };
@@ -374,6 +374,12 @@ declare const defaultTheme: {
374
374
  sizes: {};
375
375
  variants: {};
376
376
  };
377
+ Footer: {
378
+ defaultProps: {};
379
+ parts: string[];
380
+ sizes: {};
381
+ variants: {};
382
+ };
377
383
  Heading: {
378
384
  defaultProps: {
379
385
  size: string;
@@ -625,6 +631,12 @@ declare const defaultTheme: {
625
631
  };
626
632
  };
627
633
  };
634
+ Menu: {
635
+ defaultProps: {};
636
+ parts: string[];
637
+ sizes: {};
638
+ variants: {};
639
+ };
628
640
  Notification: {
629
641
  defaultProps: {
630
642
  colorScheme: string;
@@ -644,12 +656,7 @@ declare const defaultTheme: {
644
656
  color: string;
645
657
  hoverBg: string;
646
658
  activeBg: string;
647
- variant: string;
648
659
  };
649
- icon: {};
650
- message: {};
651
- text: {};
652
- title: {};
653
660
  };
654
661
  };
655
662
  };
@@ -696,6 +703,12 @@ declare const defaultTheme: {
696
703
  };
697
704
  };
698
705
  };
706
+ Popover: {
707
+ defaultProps: {};
708
+ parts: string[];
709
+ sizes: {};
710
+ variants: {};
711
+ };
699
712
  Radio: {
700
713
  defaultProps: {
701
714
  colorScheme: string;
@@ -948,7 +961,6 @@ declare const defaultTheme: {
948
961
  icon: {
949
962
  size: string;
950
963
  };
951
- text: {};
952
964
  };
953
965
  md: {
954
966
  container: {
@@ -962,7 +974,6 @@ declare const defaultTheme: {
962
974
  icon: {
963
975
  size: string;
964
976
  };
965
- text: {};
966
977
  };
967
978
  lg: {
968
979
  container: {
@@ -976,7 +987,6 @@ declare const defaultTheme: {
976
987
  icon: {
977
988
  size: string;
978
989
  };
979
- text: {};
980
990
  };
981
991
  };
982
992
  variants: {
@@ -988,13 +998,10 @@ declare const defaultTheme: {
988
998
  color: string;
989
999
  };
990
1000
  button: {
991
- hoverBorderColor: string;
992
- borderColor: string;
993
- color: string;
994
1001
  hoverBg: string;
995
1002
  activeBg: string;
996
1003
  bg: string;
997
- variant: string;
1004
+ color: string;
998
1005
  };
999
1006
  };
1000
1007
  subtle: (props: import("..").Dict<any>) => {
@@ -1005,12 +1012,9 @@ declare const defaultTheme: {
1005
1012
  color: string;
1006
1013
  };
1007
1014
  button: {
1008
- hoverBorderColor: string;
1009
- borderColor: string;
1010
- color: string;
1011
1015
  hoverBg: string;
1012
1016
  activeBg: string;
1013
- variant: string;
1017
+ color: string;
1014
1018
  };
1015
1019
  };
1016
1020
  };
@@ -3,7 +3,7 @@ import { Dict } from './types';
3
3
  /** Is value an array. */
4
4
  export declare function isArray<T>(value: any): value is T[];
5
5
  /** Is value a function. */
6
- export declare function isFunction<T>(value: any): value is T;
6
+ export declare function isFunction<T extends Function = Function>(value: any): value is T;
7
7
  /** Is value a number. */
8
8
  export declare function isNumber(value: any): value is number;
9
9
  /** Is value an object. */
@@ -2,4 +2,4 @@
2
2
  * If given value is a function, it's called with any additional arguments provided.
3
3
  * Otherwise, the provided value is returned directly.
4
4
  */
5
- export declare function runIfFn(value: any, ...args: any[]): any;
5
+ export declare function runIfFn<T, U>(valueOrFn: T | ((...fnArgs: U[]) => T), ...args: U[]): T;
package/utils/function.js CHANGED
@@ -26,15 +26,16 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
28
  exports.runIfFn = void 0;
29
+ var assertion_1 = require("./assertion");
29
30
  /**
30
31
  * If given value is a function, it's called with any additional arguments provided.
31
32
  * Otherwise, the provided value is returned directly.
32
33
  */
33
- function runIfFn(value) {
34
+ function runIfFn(valueOrFn) {
34
35
  var args = [];
35
36
  for (var _i = 1; _i < arguments.length; _i++) {
36
37
  args[_i - 1] = arguments[_i];
37
38
  }
38
- return typeof value === 'function' ? value.apply(void 0, __spreadArray([], __read(args), false)) : value;
39
+ return (0, assertion_1.isFunction)(valueOrFn) ? valueOrFn.apply(void 0, __spreadArray([], __read(args), false)) : valueOrFn;
39
40
  }
40
41
  exports.runIfFn = runIfFn;
package/utils/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './assertion';
2
2
  export * from './function';
3
3
  export * from './object';
4
+ export * from './react';
4
5
  export * from './styles';
5
6
  export * from './types';
package/utils/index.js CHANGED
@@ -13,5 +13,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./assertion"), exports);
14
14
  __exportStar(require("./function"), exports);
15
15
  __exportStar(require("./object"), exports);
16
+ __exportStar(require("./react"), exports);
16
17
  __exportStar(require("./styles"), exports);
17
18
  __exportStar(require("./types"), exports);
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { CreateContextOptions, CreateContextReturn } from './types';
3
+ declare type ReactRef<T> = React.Ref<T> | React.RefObject<T> | React.MutableRefObject<T>;
4
+ /**
5
+ * Assigns given value to the provided ref.
6
+ * Supports ref as function (e.g. useState) and classic ref (e.g. useRef).
7
+ */
8
+ export declare function assignRef<T = any>(ref: ReactRef<T> | undefined, value: T): void;
9
+ /** Generic function to create new Context and context access hook. */
10
+ export declare function createContext<ContextType>(options?: CreateContextOptions): CreateContextReturn<ContextType>;
11
+ /** Assigns a node to all provided refs. */
12
+ export declare function mergeRefs<T>(...refs: (ReactRef<T> | undefined)[]): (node: T | null) => void;
13
+ /**
14
+ * Saves given function in a ref to ensure stable exported reference.
15
+ * When input function changes, ref is updated.
16
+ */
17
+ export declare function useFnRef(fn?: Function): React.MutableRefObject<Function | undefined>;
18
+ export {};
package/utils/react.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
+ }) : (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ o[k2] = m[k];
9
+ }));
10
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
12
+ }) : function(o, v) {
13
+ o["default"] = v;
14
+ });
15
+ var __importStar = (this && this.__importStar) || function (mod) {
16
+ if (mod && mod.__esModule) return mod;
17
+ var result = {};
18
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
+ __setModuleDefault(result, mod);
20
+ return result;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.useFnRef = exports.mergeRefs = exports.createContext = exports.assignRef = void 0;
24
+ var react_1 = __importStar(require("react"));
25
+ var assertion_1 = require("./assertion");
26
+ /**
27
+ * Assigns given value to the provided ref.
28
+ * Supports ref as function (e.g. useState) and classic ref (e.g. useRef).
29
+ */
30
+ function assignRef(ref, value) {
31
+ if (ref === null || ref === undefined)
32
+ return;
33
+ if ((0, assertion_1.isFunction)(ref)) {
34
+ ref(value);
35
+ return;
36
+ }
37
+ try {
38
+ // @ts-ignore - TS complains about 'current' being read-only
39
+ ref.current = value;
40
+ }
41
+ catch (error) {
42
+ throw new Error("Cannot assign value '" + value + "' to ref '" + ref + "'");
43
+ }
44
+ }
45
+ exports.assignRef = assignRef;
46
+ /** Generic function to create new Context and context access hook. */
47
+ function createContext(options) {
48
+ if (options === void 0) { options = {}; }
49
+ var _a = options.errorMessage, errorMessage = _a === void 0 ? 'Context can only be accessed by components wrapped with the Provider.' : _a, isOptional = options.isOptional, name = options.name;
50
+ var Context = react_1.default.createContext(undefined);
51
+ Context.displayName = name;
52
+ function useContext() {
53
+ var context = react_1.default.useContext(Context);
54
+ if (!isOptional && context === undefined)
55
+ throw new Error(errorMessage);
56
+ return context;
57
+ }
58
+ return [Context.Provider, useContext];
59
+ }
60
+ exports.createContext = createContext;
61
+ /** Assigns a node to all provided refs. */
62
+ function mergeRefs() {
63
+ var refs = [];
64
+ for (var _i = 0; _i < arguments.length; _i++) {
65
+ refs[_i] = arguments[_i];
66
+ }
67
+ return function (node) {
68
+ refs.forEach(function (ref) { return assignRef(ref, node); });
69
+ };
70
+ }
71
+ exports.mergeRefs = mergeRefs;
72
+ /**
73
+ * Saves given function in a ref to ensure stable exported reference.
74
+ * When input function changes, ref is updated.
75
+ */
76
+ function useFnRef(fn) {
77
+ var fnRef = (0, react_1.useRef)(fn);
78
+ (0, react_1.useEffect)(function () {
79
+ fnRef.current = fn;
80
+ }, [fn]);
81
+ return fnRef;
82
+ }
83
+ exports.useFnRef = useFnRef;
package/utils/types.d.ts CHANGED
@@ -6,6 +6,15 @@ export declare type AnyString = string & {};
6
6
  export declare type ChangeEvent<T = HTMLInputElement> = React.ChangeEvent<T>;
7
7
  /** Type of change event handler defaulted to input element */
8
8
  export declare type ChangeEventHandler<T = HTMLInputElement> = React.ChangeEventHandler<T>;
9
+ export interface CreateContextOptions {
10
+ /** Message displayed when context is used outside of the provider */
11
+ errorMessage?: string;
12
+ /** Accessing context outside of provider won't throw error */
13
+ isOptional?: boolean;
14
+ /** Name of the context */
15
+ name?: string;
16
+ }
17
+ export declare type CreateContextReturn<T> = [React.Provider<T>, () => T];
9
18
  export declare type Dict<T = any> = Record<string, T>;
10
19
  /** Type of blur/focus event defaulted to any html element */
11
20
  export declare type FocusEvent<T = HTMLElement> = React.FocusEvent<T>;
@@ -19,9 +28,11 @@ export declare type KeyboardEventHandler<T = HTMLElement> = React.KeyboardEventH
19
28
  export declare type MouseEvent<T = HTMLElement> = React.MouseEvent<T>;
20
29
  /** Type of mouse event handler defaulted to any html element */
21
30
  export declare type MouseEventHandler<T = HTMLElement> = React.MouseEventHandler<T>;
31
+ export declare type PropGetter<T extends ElementType, Props = {}> = (props: PropsOf<T, Props>, ref?: React.Ref<any> | React.RefObject<any>) => RefPropsOf<T>;
22
32
  /** Merges component/element base props and custom props */
23
33
  export declare type PropsOf<C extends ElementType, Props = {}> = RightJoinProps<ComponentPropsWithoutRef<C>, Props>;
24
34
  /** Merges component/element base props and custom props including ref */
25
35
  export declare type RefPropsOf<C extends ElementType, Props = {}> = RightJoinProps<ComponentPropsWithRef<C>, Props>;
36
+ export declare type RenderProps<P> = React.ReactNode | ((props: P) => React.ReactNode);
26
37
  /** Merges props definitions, overriding source keys */
27
38
  export declare type RightJoinProps<SourceProps, OverrideProps> = Omit<SourceProps, keyof OverrideProps> & OverrideProps;
package/utils/types.js CHANGED
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-types */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- export interface CreateContextOptions {
3
- /** Message displayed when context is used outside of the provider */
4
- errorMessage?: string;
5
- /** Accessing context outside of provider won't throw error */
6
- isOptional?: boolean;
7
- /** Name of the context */
8
- name?: string;
9
- }
10
- export declare type CreateContextReturn<T> = [React.Provider<T>, () => T];