datocms-react-ui 0.3.24 → 0.3.28

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 (94) hide show
  1. package/dist/cjs/SelectInput/index.js +2 -2
  2. package/dist/cjs/SelectInput/index.js.map +1 -1
  3. package/dist/esm/SelectInput/index.js +2 -2
  4. package/dist/esm/SelectInput/index.js.map +1 -1
  5. package/package.json +4 -3
  6. package/src/Button/index.tsx +173 -0
  7. package/src/Button/styles.module.css +149 -0
  8. package/src/Button/styles.module.css.json +1 -0
  9. package/src/ButtonGroup/Button/index.tsx +40 -0
  10. package/src/ButtonGroup/Button/styles.module.css +72 -0
  11. package/src/ButtonGroup/Button/styles.module.css.json +1 -0
  12. package/src/ButtonGroup/Group/index.tsx +31 -0
  13. package/src/ButtonGroup/Group/styles.module.css +6 -0
  14. package/src/ButtonGroup/Group/styles.module.css.json +1 -0
  15. package/src/ButtonGroup/index.ts +4 -0
  16. package/src/Canvas/index.tsx +556 -0
  17. package/src/Canvas/styles.module.css +75 -0
  18. package/src/Canvas/styles.module.css.json +1 -0
  19. package/src/ContextInspector/index.tsx +316 -0
  20. package/src/ContextInspector/styles.module.css +90 -0
  21. package/src/ContextInspector/styles.module.css.json +1 -0
  22. package/src/Dropdown/Dropdown.tsx +171 -0
  23. package/src/Dropdown/DropdownContext.tsx +10 -0
  24. package/src/Dropdown/Group.tsx +16 -0
  25. package/src/Dropdown/Menu.tsx +351 -0
  26. package/src/Dropdown/MenuContext.tsx +18 -0
  27. package/src/Dropdown/Option.tsx +148 -0
  28. package/src/Dropdown/OptionAction.tsx +42 -0
  29. package/src/Dropdown/Portal.tsx +46 -0
  30. package/src/Dropdown/Separator.tsx +13 -0
  31. package/src/Dropdown/Text.tsx +8 -0
  32. package/src/Dropdown/index.tsx +26 -0
  33. package/src/Dropdown/styles.module.css +331 -0
  34. package/src/Dropdown/styles.module.css.json +1 -0
  35. package/src/FieldError/index.tsx +10 -0
  36. package/src/FieldError/styles.module.css +6 -0
  37. package/src/FieldError/styles.module.css.json +1 -0
  38. package/src/FieldGroup/index.tsx +25 -0
  39. package/src/FieldGroup/styles.module.css +12 -0
  40. package/src/FieldGroup/styles.module.css.json +1 -0
  41. package/src/FieldHint/index.tsx +10 -0
  42. package/src/FieldHint/styles.module.css +6 -0
  43. package/src/FieldHint/styles.module.css.json +1 -0
  44. package/src/Form/index.tsx +145 -0
  45. package/src/Form/styles.module.css +19 -0
  46. package/src/Form/styles.module.css.json +1 -0
  47. package/src/FormLabel/index.tsx +36 -0
  48. package/src/FormLabel/styles.module.css +31 -0
  49. package/src/FormLabel/styles.module.css.json +1 -0
  50. package/src/Section/index.tsx +104 -0
  51. package/src/Section/styles.module.css +100 -0
  52. package/src/Section/styles.module.css.json +1 -0
  53. package/src/SelectField/index.tsx +244 -0
  54. package/src/SelectInput/index.tsx +233 -0
  55. package/src/SidebarPanel/index.tsx +110 -0
  56. package/src/SidebarPanel/styles.module.css +49 -0
  57. package/src/SidebarPanel/styles.module.css.json +1 -0
  58. package/src/Spinner/index.tsx +68 -0
  59. package/src/Spinner/styles.module.css +31 -0
  60. package/src/Spinner/styles.module.css.json +1 -0
  61. package/src/SwitchField/index.tsx +67 -0
  62. package/src/SwitchField/styles.module.css +25 -0
  63. package/src/SwitchField/styles.module.css.json +1 -0
  64. package/src/SwitchInput/index.tsx +74 -0
  65. package/src/SwitchInput/styles.module.css +100 -0
  66. package/src/SwitchInput/styles.module.css.json +1 -0
  67. package/src/TextField/index.tsx +58 -0
  68. package/src/TextField/styles.module.css +0 -0
  69. package/src/TextField/styles.module.css.json +1 -0
  70. package/src/TextInput/index.tsx +73 -0
  71. package/src/TextInput/styles.module.css +52 -0
  72. package/src/TextInput/styles.module.css.json +1 -0
  73. package/src/Toolbar/Button/index.tsx +32 -0
  74. package/src/Toolbar/Button/styles.module.css +43 -0
  75. package/src/Toolbar/Button/styles.module.css.json +1 -0
  76. package/src/Toolbar/Stack/index.tsx +33 -0
  77. package/src/Toolbar/Stack/styles.module.css +18 -0
  78. package/src/Toolbar/Stack/styles.module.css.json +1 -0
  79. package/src/Toolbar/Title/index.tsx +17 -0
  80. package/src/Toolbar/Title/styles.module.css +12 -0
  81. package/src/Toolbar/Title/styles.module.css.json +1 -0
  82. package/src/Toolbar/Toolbar/index.tsx +112 -0
  83. package/src/Toolbar/Toolbar/styles.module.css +15 -0
  84. package/src/Toolbar/Toolbar/styles.module.css.json +1 -0
  85. package/src/Toolbar/index.ts +8 -0
  86. package/src/base.css +89 -0
  87. package/src/generateStyleFromCtx/index.ts +25 -0
  88. package/src/global.css +23 -0
  89. package/src/icons.tsx +108 -0
  90. package/src/index.ts +23 -0
  91. package/src/mergeRefs/index.ts +8 -0
  92. package/src/useClickOutside/index.ts +30 -0
  93. package/src/useMediaQuery/index.ts +185 -0
  94. package/types.json +8 -8
@@ -0,0 +1,185 @@
1
+ import React from 'react';
2
+
3
+ const list: Record<
4
+ string,
5
+ {
6
+ mql: MediaQueryList;
7
+ notifiers: Array<(value: Record<string, never>) => void>;
8
+ listener: (mql: MediaQueryListEvent) => void;
9
+ }
10
+ > = {};
11
+
12
+ export function useMediaQuery(media: string): MediaQueryList {
13
+ const mediaQueryList = React.useMemo(() => {
14
+ // We have an existing mediaQueryList for media.
15
+ if (list[media]) {
16
+ return list[media].mql;
17
+ }
18
+
19
+ if (typeof window !== 'undefined') {
20
+ return matchMedia(media);
21
+ }
22
+
23
+ // Server: use a fallback.
24
+ return { matches: true, media } as MediaQueryList;
25
+ }, [list, media]);
26
+
27
+ // Since the mediaQueryList is shared we use state to trigger re-renders.
28
+ // This is done with update({}) (a new object instance will force a re-rendering).
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ const [_, update] = React.useState<Record<string, never>>({});
31
+
32
+ React.useLayoutEffect(() => {
33
+ if (list[media]) {
34
+ list[media].notifiers.push(update);
35
+ } else {
36
+ list[media] = {
37
+ mql: mediaQueryList,
38
+ notifiers: [update],
39
+ listener: (mql) => {
40
+ const match = list[mql.media];
41
+ if (match) {
42
+ match.notifiers.forEach((updateFn) => updateFn({}));
43
+ }
44
+ },
45
+ };
46
+ list[media].mql.addEventListener('change', list[media].listener);
47
+ }
48
+ return () => {
49
+ const notifierIndex = list[media].notifiers.indexOf(update);
50
+ if (notifierIndex > -1) {
51
+ // Remove `update`.
52
+ list[media].notifiers.splice(notifierIndex, 1);
53
+ }
54
+ if (list[media].notifiers.length === 0) {
55
+ list[media].mql.removeEventListener('change', list[media].listener);
56
+ delete list[media];
57
+ }
58
+ };
59
+ }, [list, media, mediaQueryList]);
60
+
61
+ return mediaQueryList;
62
+ }
63
+
64
+ export type MediaQueryProps = {
65
+ media: string;
66
+ children: (mql: MediaQueryList) => JSX.Element;
67
+ };
68
+
69
+ export function MediaQuery({
70
+ media,
71
+ children,
72
+ }: MediaQueryProps): JSX.Element | null {
73
+ const mql = useMediaQuery(media);
74
+ return typeof children === 'function' ? children(mql) : null;
75
+ }
76
+
77
+ const DOM_LAYOUT_HANDLER_NAME = '__reactLayoutHandler';
78
+
79
+ const supportsBorderBox = (() => {
80
+ if (typeof document === 'undefined') {
81
+ return false;
82
+ }
83
+ const e = document.body.appendChild(document.createElement('div'));
84
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
85
+ const observer = new ResizeObserver(() => {});
86
+ try {
87
+ observer.observe(e, { box: 'border-box' });
88
+ observer.unobserve(e);
89
+ return true;
90
+ } catch (error) {
91
+ return false;
92
+ } finally {
93
+ document.body.removeChild(e);
94
+ }
95
+ })();
96
+
97
+ let resizeObserver: ResizeObserver | null = null;
98
+
99
+ function getResizeObserver(): ResizeObserver | undefined {
100
+ if (resizeObserver) {
101
+ return resizeObserver;
102
+ }
103
+
104
+ if (typeof ResizeObserver === 'undefined') {
105
+ return;
106
+ }
107
+
108
+ resizeObserver = new ResizeObserver((entries) => {
109
+ entries.forEach((entry) => {
110
+ const node = entry.target;
111
+
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ const onLayout = (node as any)[DOM_LAYOUT_HANDLER_NAME] as
114
+ | React.Dispatch<React.SetStateAction<DOMRect>>
115
+ | undefined;
116
+
117
+ if (typeof onLayout !== 'function') {
118
+ return;
119
+ }
120
+
121
+ if (supportsBorderBox && entry.borderBoxSize) {
122
+ const boxSize = entry.borderBoxSize[0] || entry.borderBoxSize;
123
+ onLayout((prevRect) => {
124
+ if (
125
+ prevRect.width === boxSize.inlineSize &&
126
+ prevRect.height === boxSize.blockSize
127
+ ) {
128
+ return prevRect;
129
+ }
130
+ return new DOMRect(0, 0, boxSize.inlineSize, boxSize.blockSize);
131
+ });
132
+ return;
133
+ }
134
+
135
+ const elRect = entry.target.getBoundingClientRect();
136
+
137
+ onLayout((prevRect) => {
138
+ if (
139
+ prevRect.width === elRect.width &&
140
+ prevRect.height === elRect.height
141
+ ) {
142
+ return prevRect;
143
+ }
144
+ return new DOMRect(0, 0, elRect.width, elRect.height);
145
+ });
146
+ });
147
+ });
148
+
149
+ return resizeObserver;
150
+ }
151
+
152
+ export function useElementLayout(
153
+ ref: React.MutableRefObject<Element> | React.RefObject<Element>,
154
+ ): DOMRect {
155
+ const observer = getResizeObserver();
156
+ const [rect, setRect] = React.useState(new DOMRect());
157
+
158
+ React.useLayoutEffect(() => {
159
+ const node = ref.current;
160
+
161
+ if (node) {
162
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
+ (node as any)[DOM_LAYOUT_HANDLER_NAME] = setRect;
164
+ }
165
+
166
+ if (node && observer) {
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ if (typeof (node as any)[DOM_LAYOUT_HANDLER_NAME] === 'function') {
169
+ observer.observe(
170
+ node,
171
+ supportsBorderBox ? { box: 'border-box' } : undefined,
172
+ );
173
+ } else {
174
+ observer.unobserve(node);
175
+ }
176
+ }
177
+ return () => {
178
+ if (node != null && observer != null) {
179
+ observer.unobserve(node);
180
+ }
181
+ };
182
+ }, [ref, observer]);
183
+
184
+ return rect;
185
+ }
package/types.json CHANGED
@@ -8753,7 +8753,7 @@
8753
8753
  "sources": [
8754
8754
  {
8755
8755
  "fileName": "src/SelectInput/index.tsx",
8756
- "line": 205,
8756
+ "line": 206,
8757
8757
  "character": 12
8758
8758
  }
8759
8759
  ],
@@ -8854,7 +8854,7 @@
8854
8854
  "sources": [
8855
8855
  {
8856
8856
  "fileName": "src/SelectInput/index.tsx",
8857
- "line": 148,
8857
+ "line": 149,
8858
8858
  "character": 12
8859
8859
  }
8860
8860
  ],
@@ -9970,7 +9970,7 @@
9970
9970
  "sources": [
9971
9971
  {
9972
9972
  "fileName": "src/SelectInput/index.tsx",
9973
- "line": 176,
9973
+ "line": 177,
9974
9974
  "character": 12
9975
9975
  }
9976
9976
  ],
@@ -11082,7 +11082,7 @@
11082
11082
  "sources": [
11083
11083
  {
11084
11084
  "fileName": "src/SelectInput/index.tsx",
11085
- "line": 119,
11085
+ "line": 120,
11086
11086
  "character": 12
11087
11087
  }
11088
11088
  ],
@@ -12444,7 +12444,7 @@
12444
12444
  "sources": [
12445
12445
  {
12446
12446
  "fileName": "src/SelectInput/index.tsx",
12447
- "line": 212,
12447
+ "line": 213,
12448
12448
  "character": 16
12449
12449
  }
12450
12450
  ],
@@ -12664,7 +12664,7 @@
12664
12664
  "sources": [
12665
12665
  {
12666
12666
  "fileName": "src/SelectInput/index.tsx",
12667
- "line": 154,
12667
+ "line": 155,
12668
12668
  "character": 16
12669
12669
  }
12670
12670
  ],
@@ -13283,7 +13283,7 @@
13283
13283
  "sources": [
13284
13284
  {
13285
13285
  "fileName": "src/SelectInput/index.tsx",
13286
- "line": 183,
13286
+ "line": 184,
13287
13287
  "character": 16
13288
13288
  }
13289
13289
  ],
@@ -14098,7 +14098,7 @@
14098
14098
  "sources": [
14099
14099
  {
14100
14100
  "fileName": "src/SelectInput/index.tsx",
14101
- "line": 126,
14101
+ "line": 127,
14102
14102
  "character": 16
14103
14103
  }
14104
14104
  ],