reshaped 3.10.0-canary.6 → 3.10.0-canary.8

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 (175) hide show
  1. package/dist/bundle.d.ts +4 -11
  2. package/dist/bundle.js +2 -2
  3. package/dist/components/Accordion/Accordion.types.d.ts +3 -2
  4. package/dist/components/Accordion/AccordionControlled.js +1 -2
  5. package/dist/components/Accordion/AccordionTrigger.js +1 -1
  6. package/dist/components/ActionBar/ActionBar.js +1 -1
  7. package/dist/components/ActionBar/ActionBar.types.d.ts +3 -2
  8. package/dist/components/Actionable/Actionable.d.ts +2 -2
  9. package/dist/components/Actionable/Actionable.js +1 -1
  10. package/dist/components/Actionable/Actionable.types.d.ts +1 -1
  11. package/dist/components/Actionable/index.d.ts +1 -1
  12. package/dist/components/Alert/Alert.types.d.ts +3 -2
  13. package/dist/components/Autocomplete/Autocomplete.js +1 -3
  14. package/dist/components/Avatar/Avatar.js +1 -1
  15. package/dist/components/Avatar/Avatar.types.d.ts +5 -4
  16. package/dist/components/Badge/Badge.js +1 -1
  17. package/dist/components/Badge/Badge.types.d.ts +4 -4
  18. package/dist/components/Badge/BadgeContainer.js +1 -1
  19. package/dist/components/Breadcrumbs/Breadcrumbs.js +1 -1
  20. package/dist/components/Breadcrumbs/Breadcrumbs.types.d.ts +3 -3
  21. package/dist/components/Button/Button.js +1 -1
  22. package/dist/components/Button/Button.types.d.ts +3 -2
  23. package/dist/components/Button/ButtonGroup.js +1 -1
  24. package/dist/components/Calendar/CalendarDate.js +1 -1
  25. package/dist/components/Calendar/useCalendarKeyboardNavigation.js +1 -1
  26. package/dist/components/Card/Card.d.ts +6 -14
  27. package/dist/components/Card/Card.js +1 -1
  28. package/dist/components/Card/Card.types.d.ts +4 -3
  29. package/dist/components/Carousel/Carousel.js +2 -4
  30. package/dist/components/Carousel/Carousel.types.d.ts +3 -2
  31. package/dist/components/Carousel/CarouselControl.js +1 -2
  32. package/dist/components/Checkbox/Checkbox.js +1 -2
  33. package/dist/components/Checkbox/Checkbox.types.d.ts +4 -3
  34. package/dist/components/Container/Container.js +1 -1
  35. package/dist/components/Container/Container.types.d.ts +3 -2
  36. package/dist/components/ContextMenu/ContextMenu.js +1 -2
  37. package/dist/components/Dismissible/Dismissible.js +1 -1
  38. package/dist/components/Dismissible/Dismissible.types.d.ts +3 -3
  39. package/dist/components/Divider/Divider.js +1 -1
  40. package/dist/components/Divider/Divider.types.d.ts +3 -2
  41. package/dist/components/DropdownMenu/DropdownMenu.js +1 -3
  42. package/dist/components/FileUpload/FileUpload.js +1 -2
  43. package/dist/components/FileUpload/FileUpload.types.d.ts +4 -3
  44. package/dist/components/Flyout/Flyout.types.d.ts +6 -6
  45. package/dist/components/Flyout/FlyoutContent.js +1 -2
  46. package/dist/components/Flyout/FlyoutControlled.js +2 -6
  47. package/dist/components/Flyout/useFlyout.d.ts +2 -2
  48. package/dist/components/Flyout/useFlyout.js +2 -2
  49. package/dist/components/Flyout/utilities/safeArea.d.ts +2 -2
  50. package/dist/components/Flyout/utilities/safeArea.js +0 -14
  51. package/dist/components/Grid/Grid.js +1 -1
  52. package/dist/components/Grid/Grid.types.d.ts +5 -4
  53. package/dist/components/Hidden/Hidden.js +1 -1
  54. package/dist/components/HiddenInput/HiddenInput.js +1 -1
  55. package/dist/components/HiddenInput/HiddenInput.types.d.ts +3 -2
  56. package/dist/components/Hotkey/Hotkey.js +1 -1
  57. package/dist/components/Hotkey/Hotkey.types.d.ts +3 -3
  58. package/dist/components/Icon/Icon.js +1 -1
  59. package/dist/components/Icon/Icon.types.d.ts +3 -2
  60. package/dist/components/Image/Image.js +1 -1
  61. package/dist/components/Image/Image.types.d.ts +5 -4
  62. package/dist/components/Link/Link.js +1 -1
  63. package/dist/components/Loader/Loader.js +1 -1
  64. package/dist/components/Loader/Loader.types.d.ts +3 -2
  65. package/dist/components/MenuItem/MenuItem.js +1 -1
  66. package/dist/components/MenuItem/MenuItem.types.d.ts +3 -2
  67. package/dist/components/Modal/Modal.js +2 -3
  68. package/dist/components/Modal/Modal.types.d.ts +4 -3
  69. package/dist/components/NumberField/NumberFieldControlled.js +1 -2
  70. package/dist/components/Overlay/Overlay.js +4 -10
  71. package/dist/components/Overlay/Overlay.types.d.ts +3 -3
  72. package/dist/components/Pagination/Pagination.types.d.ts +3 -3
  73. package/dist/components/PinField/PinField.types.d.ts +4 -3
  74. package/dist/components/PinField/PinFieldControlled.js +1 -1
  75. package/dist/components/Popover/Popover.js +1 -1
  76. package/dist/components/Progress/Progress.js +1 -1
  77. package/dist/components/Progress/Progress.types.d.ts +3 -3
  78. package/dist/components/ProgressIndicator/ProgressIndicator.js +1 -1
  79. package/dist/components/ProgressIndicator/ProgressIndicator.types.d.ts +3 -3
  80. package/dist/components/Radio/Radio.js +1 -1
  81. package/dist/components/Radio/Radio.types.d.ts +4 -3
  82. package/dist/components/RadioGroup/RadioGroup.types.d.ts +3 -2
  83. package/dist/components/Reshaped/Reshaped.js +4 -11
  84. package/dist/components/Reshaped/Reshaped.types.d.ts +3 -2
  85. package/dist/components/Resizable/Resizable.js +1 -1
  86. package/dist/components/Resizable/ResizableHandle.js +1 -1
  87. package/dist/components/Scrim/Scrim.js +1 -1
  88. package/dist/components/Scrim/Scrim.types.d.ts +4 -4
  89. package/dist/components/ScrollArea/ScrollArea.js +2 -4
  90. package/dist/components/ScrollArea/ScrollArea.types.d.ts +5 -3
  91. package/dist/components/Select/Select.types.d.ts +5 -4
  92. package/dist/components/Select/SelectNative.js +1 -1
  93. package/dist/components/Select/SelectRoot.js +1 -1
  94. package/dist/components/Skeleton/Skeleton.js +1 -1
  95. package/dist/components/Skeleton/Skeleton.types.d.ts +3 -3
  96. package/dist/components/Slider/Slider.types.d.ts +3 -3
  97. package/dist/components/Slider/SliderControlled.js +2 -4
  98. package/dist/components/Slider/SliderThumb.js +1 -1
  99. package/dist/components/Stepper/Stepper.types.d.ts +5 -4
  100. package/dist/components/Switch/Switch.js +1 -1
  101. package/dist/components/Switch/Switch.types.d.ts +4 -3
  102. package/dist/components/Table/Table.js +1 -1
  103. package/dist/components/Table/Table.types.d.ts +12 -12
  104. package/dist/components/Tabs/Tabs.types.d.ts +6 -6
  105. package/dist/components/Tabs/TabsItem.js +2 -3
  106. package/dist/components/Tabs/TabsList.js +1 -4
  107. package/dist/components/Tabs/TabsPanel.js +2 -2
  108. package/dist/components/Text/Text.js +1 -1
  109. package/dist/components/Text/Text.types.d.ts +3 -2
  110. package/dist/components/TextArea/TextArea.js +1 -1
  111. package/dist/components/TextArea/TextArea.types.d.ts +5 -4
  112. package/dist/components/TextField/TextField.js +1 -1
  113. package/dist/components/TextField/TextField.types.d.ts +4 -3
  114. package/dist/components/Theme/GlobalColorMode.js +1 -1
  115. package/dist/components/Theme/Theme.js +1 -2
  116. package/dist/components/Theme/Theme.types.d.ts +2 -1
  117. package/dist/components/Timeline/Timeline.js +1 -1
  118. package/dist/components/Timeline/Timeline.types.d.ts +5 -5
  119. package/dist/components/Toast/Toast.types.d.ts +3 -3
  120. package/dist/components/Toast/ToastContainer.js +2 -3
  121. package/dist/components/Toast/ToastRegion.js +2 -2
  122. package/dist/components/ToggleButton/ToggleButtonUncontrolled.js +1 -1
  123. package/dist/components/ToggleButtonGroup/ToggleButtonGroupControlled.js +1 -1
  124. package/dist/components/View/View.js +1 -1
  125. package/dist/components/View/View.types.d.ts +5 -4
  126. package/dist/components/_private/Aligner/Aligner.js +1 -1
  127. package/dist/components/_private/Aligner/Aligner.types.d.ts +3 -3
  128. package/dist/components/_private/Expandable/Expandable.js +2 -2
  129. package/dist/components/_private/Expandable/Expandable.types.d.ts +2 -2
  130. package/dist/components/_private/Portal/Portal.js +1 -2
  131. package/dist/hooks/_private/useDrag.js +2 -4
  132. package/dist/hooks/_private/useFadeSide.js +2 -3
  133. package/dist/hooks/_private/useSingletonViewport.d.ts +10 -0
  134. package/dist/hooks/_private/useSingletonViewport.js +52 -0
  135. package/dist/hooks/useResponsiveClientValue.js +15 -53
  136. package/dist/hooks/useViewport.d.ts +2 -0
  137. package/dist/hooks/useViewport.js +6 -0
  138. package/dist/index.d.ts +4 -11
  139. package/dist/index.js +2 -10
  140. package/dist/styles/mixin.d.ts +2 -2
  141. package/dist/styles/types.d.ts +2 -1
  142. package/dist/tests/ThemesPlayground.js +1 -1
  143. package/dist/types/global.d.ts +0 -15
  144. package/dist/utilities/props.d.ts +2 -1
  145. package/package.json +2 -2
  146. package/dist/core/Actionable/Actionable.d.ts +0 -4
  147. package/dist/core/Actionable/Actionable.js +0 -73
  148. package/dist/core/Actionable/Actionable.types.d.ts +0 -34
  149. package/dist/core/Actionable/Actionable.types.js +0 -1
  150. package/dist/core/Actionable/index.d.ts +0 -2
  151. package/dist/core/Actionable/index.js +0 -1
  152. package/dist/hooks/_private/useSingletonEnvironment.d.ts +0 -9
  153. package/dist/hooks/_private/useSingletonEnvironment.js +0 -33
  154. package/dist/hooks/_private/useSingletonHotkeys.d.ts +0 -35
  155. package/dist/hooks/_private/useSingletonHotkeys.js +0 -191
  156. package/dist/hooks/_private/useSingletonKeyboardMode.d.ts +0 -13
  157. package/dist/hooks/_private/useSingletonKeyboardMode.js +0 -58
  158. package/dist/hooks/useHandlerRef.d.ts +0 -8
  159. package/dist/hooks/useHandlerRef.js +0 -16
  160. package/dist/hooks/useHotkeys.d.ts +0 -11
  161. package/dist/hooks/useHotkeys.js +0 -27
  162. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +0 -3
  163. package/dist/hooks/useIsomorphicLayoutEffect.js +0 -4
  164. package/dist/hooks/useKeyboardArrowNavigation.d.ts +0 -9
  165. package/dist/hooks/useKeyboardArrowNavigation.js +0 -62
  166. package/dist/hooks/useKeyboardMode.d.ts +0 -7
  167. package/dist/hooks/useKeyboardMode.js +0 -13
  168. package/dist/hooks/useOnClickOutside.d.ts +0 -5
  169. package/dist/hooks/useOnClickOutside.js +0 -63
  170. package/dist/hooks/useRTL.d.ts +0 -2
  171. package/dist/hooks/useRTL.js +0 -7
  172. package/dist/hooks/useScrollLock.d.ts +0 -10
  173. package/dist/hooks/useScrollLock.js +0 -25
  174. package/dist/hooks/useToggle.d.ts +0 -7
  175. package/dist/hooks/useToggle.js +0 -19
@@ -1,35 +0,0 @@
1
- import React from "react";
2
- /**
3
- * Types
4
- */
5
- type Callback = (e?: KeyboardEvent) => void;
6
- type PressedMap = Map<string, KeyboardEvent>;
7
- export type Hotkeys = Record<string, Callback | null>;
8
- type HotkeyOptions = {
9
- preventDefault?: boolean;
10
- };
11
- type Context = {
12
- isPressed: (key: string) => boolean;
13
- addHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement | null>, options?: HotkeyOptions) => (() => void) | undefined;
14
- };
15
- type HotkeyData = {
16
- callback: Callback;
17
- ref: React.RefObject<HTMLElement | null>;
18
- options: HotkeyOptions;
19
- };
20
- export declare class HotkeyStore {
21
- hotkeyMap: Record<string, Set<HotkeyData>>;
22
- getSize: () => number;
23
- bindHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement | null>, options: HotkeyOptions) => void;
24
- unbindHotkeys: (hotkeys: Hotkeys) => void;
25
- handleKeyDown: (pressedMap: PressedMap, e: KeyboardEvent) => void;
26
- }
27
- /**
28
- * Components / Hooks
29
- */
30
- export declare const HotkeyContext: React.Context<Context>;
31
- export declare const SingletonHotkeysProvider: React.FC<{
32
- children: React.ReactNode;
33
- }>;
34
- declare const useSingletonHotkeys: () => Context;
35
- export default useSingletonHotkeys;
@@ -1,191 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from "react";
3
- /**
4
- * Utilities
5
- */
6
- const COMBINATION_DELIMETER = "+";
7
- const pressedMap = new Map();
8
- let modifiedKeys = [];
9
- const formatHotkey = (hotkey) => {
10
- if (hotkey === " ")
11
- return hotkey;
12
- return hotkey.replace(/\s/g, "").toLowerCase();
13
- };
14
- // Normalize passed key combinations to turn them into a consistent ids
15
- const getHotkeyId = (hotkey) => {
16
- return formatHotkey(hotkey).split(COMBINATION_DELIMETER).sort().join(COMBINATION_DELIMETER);
17
- };
18
- const getEventKey = (e) => {
19
- if (!e.key)
20
- return;
21
- // Having alt pressed modifies e.key value, so relying on e.code for it
22
- if (e.altKey && /^[Key|Digit|Numpad]/.test(e.code)) {
23
- return e.code.toLowerCase().replace(/key|digit|numpad/, "");
24
- }
25
- return e.key.toLowerCase();
26
- };
27
- // Removing the unknown gets highlighted an invalid syntax
28
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
29
- const walkHotkeys = (hotkeys, cb) => {
30
- Object.keys(hotkeys).forEach((key) => {
31
- key.split(",").forEach((hotkey) => {
32
- const data = hotkeys[key];
33
- if (!data)
34
- return;
35
- cb(getHotkeyId(hotkey), data);
36
- });
37
- });
38
- };
39
- export class HotkeyStore {
40
- hotkeyMap = {};
41
- getSize = () => Object.keys(this.hotkeyMap).length;
42
- bindHotkeys = (hotkeys, ref, options) => {
43
- walkHotkeys(hotkeys, (id, hotkeyData) => {
44
- if (!hotkeyData)
45
- return;
46
- if (!this.hotkeyMap[id]) {
47
- this.hotkeyMap[id] = new Set();
48
- }
49
- this.hotkeyMap[id].add({ callback: hotkeyData, ref, options });
50
- });
51
- };
52
- unbindHotkeys = (hotkeys) => {
53
- walkHotkeys(hotkeys, (id, hotkeyCallback) => {
54
- if (!hotkeyCallback)
55
- return;
56
- this.hotkeyMap[id]?.forEach((data) => {
57
- if (data.callback === hotkeyCallback) {
58
- this.hotkeyMap[id].delete(data);
59
- }
60
- });
61
- if (!this.hotkeyMap[id]?.size) {
62
- delete this.hotkeyMap[id];
63
- }
64
- });
65
- };
66
- handleKeyDown = (pressedMap, e) => {
67
- if (!pressedMap.size)
68
- return;
69
- const pressedKeys = [...pressedMap.keys()];
70
- const pressedId = getHotkeyId(pressedKeys.join(COMBINATION_DELIMETER));
71
- const pressedFormattedKeys = pressedId.split(COMBINATION_DELIMETER);
72
- const hotkeyData = this.hotkeyMap[pressedId];
73
- /**
74
- * Support for `mod` that represents both Mac and Win keyboards
75
- * We create the hotkeyId again to sort the mod key correctly
76
- */
77
- const controlToModPressedId = getHotkeyId(pressedId.replace("control", "mod"));
78
- const metaToModPressedId = getHotkeyId(pressedId.replace("meta", "mod"));
79
- const hotkeyControlModData = pressedFormattedKeys.includes("control") && this.hotkeyMap[controlToModPressedId];
80
- const hotkeyMetaModData = pressedFormattedKeys.includes("meta") && this.hotkeyMap[metaToModPressedId];
81
- [hotkeyData, hotkeyControlModData, hotkeyMetaModData].forEach((hotkeyData) => {
82
- if (!hotkeyData)
83
- return;
84
- if (hotkeyData?.size) {
85
- hotkeyData.forEach((data) => {
86
- const eventTarget = e.composedPath()[0];
87
- if (data.ref.current &&
88
- !(eventTarget === data.ref.current || data.ref.current.contains(eventTarget))) {
89
- return;
90
- }
91
- const resolvedEvent = pressedMap.get(pressedId);
92
- if (data.options.preventDefault) {
93
- resolvedEvent?.preventDefault();
94
- e.preventDefault();
95
- }
96
- data.callback(e);
97
- });
98
- }
99
- });
100
- };
101
- }
102
- const globalHotkeyStore = new HotkeyStore();
103
- /**
104
- * Components / Hooks
105
- */
106
- export const HotkeyContext = React.createContext({});
107
- export const SingletonHotkeysProvider = (props) => {
108
- const { children } = props;
109
- // eslint-disable-next-line
110
- const [_, setTriggerCount] = React.useState(0);
111
- // Only handle key presses when there is at least one hook listening for hotkeys
112
- const [hooksCount, setHooksCount] = React.useState(0);
113
- const addPressedKey = React.useCallback((e) => {
114
- if (e.repeat || hooksCount === 0)
115
- return;
116
- const eventKey = getEventKey(e);
117
- if (!eventKey)
118
- return;
119
- pressedMap.set(eventKey, e);
120
- setTriggerCount(pressedMap.size);
121
- // Key up won't trigger for other keys while Meta is pressed so we need to cache them
122
- // and remove on Meta keyup
123
- if (e.metaKey)
124
- modifiedKeys.push(...pressedMap.keys());
125
- if (pressedMap.has("Meta"))
126
- modifiedKeys.push(eventKey);
127
- }, [hooksCount]);
128
- const removePressedKey = React.useCallback((e) => {
129
- if (hooksCount === 0)
130
- return;
131
- const eventKey = getEventKey(e);
132
- if (!eventKey)
133
- return;
134
- pressedMap.delete(eventKey);
135
- if (eventKey === "meta" || eventKey === "control") {
136
- pressedMap.delete("mod");
137
- }
138
- if (eventKey === "meta") {
139
- modifiedKeys.forEach((key) => {
140
- if (!pressedMap.has(key))
141
- return;
142
- pressedMap.delete(key);
143
- });
144
- modifiedKeys = [];
145
- }
146
- setTriggerCount(pressedMap.size);
147
- }, [hooksCount]);
148
- const isPressed = (hotkey) => {
149
- const keys = formatHotkey(hotkey).split(COMBINATION_DELIMETER);
150
- if (keys.some((key) => !pressedMap.has(key)))
151
- return false;
152
- return true;
153
- };
154
- const handleWindowKeyDown = React.useCallback((e) => {
155
- // Browsers trigger keyboard event without passing e.key when you click on autocomplete
156
- if (!e.key)
157
- return;
158
- addPressedKey(e);
159
- globalHotkeyStore.handleKeyDown(pressedMap, e);
160
- }, [addPressedKey]);
161
- const handleWindowKeyUp = React.useCallback((e) => {
162
- if (!e.key)
163
- return;
164
- removePressedKey(e);
165
- }, [removePressedKey]);
166
- const handleWindowBlur = React.useCallback(() => {
167
- pressedMap.clear();
168
- modifiedKeys = [];
169
- }, []);
170
- const addHotkeys = React.useCallback((hotkeys, ref, options = {}) => {
171
- setHooksCount((prev) => prev + 1);
172
- globalHotkeyStore.bindHotkeys(hotkeys, ref, options);
173
- return () => {
174
- setHooksCount((prev) => prev - 1);
175
- globalHotkeyStore.unbindHotkeys(hotkeys);
176
- };
177
- }, []);
178
- React.useEffect(() => {
179
- window.addEventListener("keydown", handleWindowKeyDown);
180
- window.addEventListener("keyup", handleWindowKeyUp);
181
- window.addEventListener("blur", handleWindowBlur);
182
- return () => {
183
- window.removeEventListener("keydown", handleWindowKeyDown);
184
- window.removeEventListener("keyup", handleWindowKeyUp);
185
- window.removeEventListener("blur", handleWindowBlur);
186
- };
187
- }, [handleWindowKeyDown, handleWindowKeyUp, handleWindowBlur]);
188
- return (_jsx(HotkeyContext.Provider, { value: { addHotkeys, isPressed }, children: children }));
189
- };
190
- const useSingletonHotkeys = () => React.useContext(HotkeyContext);
191
- export default useSingletonHotkeys;
@@ -1,13 +0,0 @@
1
- import React from "react";
2
- type ContextProps = {
3
- disabledRef: React.RefObject<boolean> | null;
4
- disable: () => void;
5
- enable: () => void;
6
- activate: () => void;
7
- deactivate: () => void;
8
- };
9
- export declare const SingletonKeyboardModeContext: React.Context<ContextProps>;
10
- export declare const SingletonKeyboardModeProvider: React.FC<{
11
- children: React.ReactNode;
12
- }>;
13
- export {};
@@ -1,58 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { activateKeyboardMode, deactivateKeyboardMode } from "@reshaped/utilities/internal";
4
- import React from "react";
5
- import * as keys from "../../constants/keys.js";
6
- export const SingletonKeyboardModeContext = React.createContext({
7
- disabledRef: null,
8
- disable: () => { },
9
- enable: () => { },
10
- activate: () => { },
11
- deactivate: () => { },
12
- });
13
- export const SingletonKeyboardModeProvider = (props) => {
14
- const disabledRef = React.useRef(false);
15
- const disable = React.useCallback(() => {
16
- disabledRef.current = true;
17
- }, []);
18
- const enable = React.useCallback(() => {
19
- disabledRef.current = false;
20
- }, []);
21
- const activate = React.useCallback(() => {
22
- if (disabledRef.current)
23
- return;
24
- activateKeyboardMode();
25
- }, []);
26
- const deactivate = React.useCallback(() => {
27
- if (disabledRef.current)
28
- return;
29
- deactivateKeyboardMode();
30
- }, []);
31
- const handleKeyDown = React.useCallback((e) => {
32
- if (e.metaKey || e.altKey || e.ctrlKey)
33
- return;
34
- // Prevent focus ring from appearing when using mouse but closing with esc
35
- if (e.key === keys.ESC)
36
- return;
37
- activate();
38
- }, [activate]);
39
- const handleClick = React.useCallback(() => {
40
- deactivate();
41
- }, [deactivate]);
42
- React.useEffect(() => {
43
- window.addEventListener("keydown", handleKeyDown);
44
- window.addEventListener("mousedown", handleClick);
45
- return () => {
46
- window.removeEventListener("keydown", handleKeyDown);
47
- window.removeEventListener("mousedown", handleClick);
48
- };
49
- }, [handleClick, handleKeyDown]);
50
- const value = React.useMemo(() => ({
51
- disabledRef,
52
- disable,
53
- enable,
54
- activate,
55
- deactivate,
56
- }), [disable, enable, activate, deactivate]);
57
- return (_jsx(SingletonKeyboardModeContext.Provider, { value: value, children: props.children }));
58
- };
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- /**
3
- * Hook for wrapping event handlers passed as props with a ref
4
- * This way we can keep the instance of the ref the same and pass this ref to the effects dependency array
5
- * While also making sure that function implementation stays up-to-date
6
- */
7
- declare const useHandlerRef: <T>(cb: T) => React.RefObject<T>;
8
- export default useHandlerRef;
@@ -1,16 +0,0 @@
1
- import React from "react";
2
- import useIsomorphicLayoutEffect from "./useIsomorphicLayoutEffect.js";
3
- /**
4
- * Hook for wrapping event handlers passed as props with a ref
5
- * This way we can keep the instance of the ref the same and pass this ref to the effects dependency array
6
- * While also making sure that function implementation stays up-to-date
7
- */
8
- const useHandlerRef = (cb) => {
9
- const ref = React.useRef(cb);
10
- // Update the callback on every render, keeping the ref instance the same
11
- useIsomorphicLayoutEffect(() => {
12
- ref.current = cb;
13
- }, [cb]);
14
- return ref;
15
- };
16
- export default useHandlerRef;
@@ -1,11 +0,0 @@
1
- import React from "react";
2
- import { type Hotkeys } from "./_private/useSingletonHotkeys";
3
- declare const useHotkeys: <Element extends HTMLElement>(hotkeys: Hotkeys, deps?: unknown[], options?: {
4
- ref?: React.RefObject<Element | null>;
5
- disabled?: boolean;
6
- preventDefault?: boolean;
7
- }) => {
8
- ref: React.RefObject<Element | null>;
9
- checkHotkeyState: (key: string) => boolean;
10
- };
11
- export default useHotkeys;
@@ -1,27 +0,0 @@
1
- "use client";
2
- import React from "react";
3
- import useSingletonHotkey from "./_private/useSingletonHotkeys.js";
4
- const useHotkeys = (hotkeys, deps = [], options) => {
5
- const { addHotkeys, isPressed } = useSingletonHotkey();
6
- const generatedRef = React.useRef(null);
7
- const elementRef = options?.ref || generatedRef;
8
- React.useEffect(() => {
9
- if (options?.disabled)
10
- return;
11
- const remove = addHotkeys(hotkeys, elementRef, {
12
- preventDefault: options?.preventDefault,
13
- });
14
- return () => remove?.();
15
- // eslint-disable-next-line react-hooks/exhaustive-deps
16
- }, [
17
- addHotkeys,
18
- // eslint-disable-next-line react-hooks/exhaustive-deps
19
- Object.keys(hotkeys).join(","),
20
- options?.disabled,
21
- options?.preventDefault,
22
- // eslint-disable-next-line react-hooks/exhaustive-deps
23
- ...deps,
24
- ]);
25
- return { ref: elementRef, checkHotkeyState: isPressed };
26
- };
27
- export default useHotkeys;
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- declare const useIsomorphicLayoutEffect: typeof React.useEffect;
3
- export default useIsomorphicLayoutEffect;
@@ -1,4 +0,0 @@
1
- "use client";
2
- import React from "react";
3
- const useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
4
- export default useIsomorphicLayoutEffect;
@@ -1,9 +0,0 @@
1
- import React from "react";
2
- type Props = {
3
- ref: React.RefObject<HTMLElement | null>;
4
- disabled?: boolean;
5
- orientation?: "vertical" | "horizontal";
6
- circular?: boolean;
7
- };
8
- declare const useKeyboardArrowNavigation: (props: Props) => void;
9
- export default useKeyboardArrowNavigation;
@@ -1,62 +0,0 @@
1
- import { focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getFocusableElements, } from "@reshaped/utilities/internal";
2
- import React, { useEffect } from "react";
3
- import useHotkeys from "./useHotkeys.js";
4
- const useKeyboardArrowNavigation = (props) => {
5
- const { ref, disabled, orientation, circular } = props;
6
- const backHotkeys = [];
7
- const forwardHotkeys = [];
8
- if (!orientation || orientation === "vertical") {
9
- backHotkeys.push("ArrowUp");
10
- forwardHotkeys.push("ArrowDown");
11
- }
12
- if (!orientation || orientation === "horizontal") {
13
- backHotkeys.push("ArrowLeft");
14
- forwardHotkeys.push("ArrowRight");
15
- }
16
- const updateTabIndex = React.useCallback((options) => {
17
- const { el, focusableElements } = options;
18
- const initialEl = focusableElements.find((el) => el.getAttribute("tabindex") !== "-1");
19
- const activeEl = el ?? initialEl ?? focusableElements[0];
20
- focusableElements.forEach((el) => el.setAttribute("tabindex", "-1"));
21
- activeEl?.setAttribute("tabindex", "0");
22
- }, []);
23
- useEffect(() => {
24
- if (!ref.current)
25
- return;
26
- if (disabled)
27
- return;
28
- const focusableElements = getFocusableElements(ref.current);
29
- updateTabIndex({ focusableElements });
30
- }, [ref, updateTabIndex, disabled]);
31
- useHotkeys({
32
- [backHotkeys.join(", ")]: () => {
33
- if (!ref.current)
34
- return;
35
- const data = focusPreviousElement(ref.current, { circular });
36
- updateTabIndex(data);
37
- },
38
- [forwardHotkeys.join(", ")]: () => {
39
- if (!ref.current)
40
- return;
41
- const data = focusNextElement(ref.current, { circular });
42
- updateTabIndex(data);
43
- },
44
- Home: () => {
45
- if (!ref.current)
46
- return;
47
- const data = focusFirstElement(ref.current);
48
- updateTabIndex(data);
49
- },
50
- End: () => {
51
- if (!ref.current)
52
- return;
53
- const data = focusLastElement(ref.current);
54
- updateTabIndex(data);
55
- },
56
- }, [updateTabIndex, circular], {
57
- ref,
58
- preventDefault: true,
59
- disabled,
60
- });
61
- };
62
- export default useKeyboardArrowNavigation;
@@ -1,7 +0,0 @@
1
- declare const useKeyboardMode: () => {
2
- enable: () => void;
3
- disable: () => void;
4
- activate: () => void;
5
- deactivate: () => void;
6
- };
7
- export default useKeyboardMode;
@@ -1,13 +0,0 @@
1
- "use client";
2
- import React from "react";
3
- import { SingletonKeyboardModeContext } from "./_private/useSingletonKeyboardMode.js";
4
- const useKeyboardMode = () => {
5
- const singletonKeyboardMode = React.useContext(SingletonKeyboardModeContext);
6
- return React.useMemo(() => ({
7
- enable: singletonKeyboardMode.enable,
8
- disable: singletonKeyboardMode.disable,
9
- activate: singletonKeyboardMode.activate,
10
- deactivate: singletonKeyboardMode.deactivate,
11
- }), [singletonKeyboardMode]);
12
- };
13
- export default useKeyboardMode;
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- declare const useOnClickOutside: (refs: React.RefObject<HTMLElement | null>[], handler: (event: Event) => void, options?: {
3
- disabled?: boolean;
4
- }) => void;
5
- export default useOnClickOutside;
@@ -1,63 +0,0 @@
1
- import React from "react";
2
- import * as keys from "../constants/keys.js";
3
- import useHandlerRef from "./useHandlerRef.js";
4
- const useOnClickOutside = (refs, handler, options) => {
5
- const { disabled } = options || {};
6
- const handlerRef = useHandlerRef(handler);
7
- /**
8
- * We're checking the element position in the DOM on mousedown to make sure
9
- * it happens before any other click events that could potentially remove the clicked el
10
- * before we checked if it's inside the refs
11
- */
12
- const isMouseDownInsideRef = React.useRef(false);
13
- React.useEffect(() => {
14
- /**
15
- * Not checking for disabled here since some components can enable the hook
16
- * after it was clicked
17
- */
18
- const handleMouseDown = (event) => {
19
- isMouseDownInsideRef.current = false;
20
- const clickedEl = event.composedPath()[0];
21
- refs.forEach((elRef) => {
22
- if (!elRef.current)
23
- return;
24
- if (elRef.current === clickedEl || elRef.current.contains(clickedEl)) {
25
- isMouseDownInsideRef.current = true;
26
- }
27
- });
28
- };
29
- const handleKeyDown = (event) => {
30
- if (![keys.ENTER, keys.SPACE].includes(event.key))
31
- return;
32
- handleMouseDown(event);
33
- };
34
- document.addEventListener("mousedown", handleMouseDown, { passive: true });
35
- document.addEventListener("touchstart", handleMouseDown, { passive: true });
36
- document.addEventListener("keydown", handleKeyDown, { passive: true });
37
- return () => {
38
- document.removeEventListener("mousedown", handleMouseDown);
39
- document.removeEventListener("touchstart", handleMouseDown);
40
- document.removeEventListener("keydown", handleKeyDown);
41
- };
42
- // eslint-disable-next-line react-hooks/exhaustive-deps
43
- }, [...refs]);
44
- React.useEffect(() => {
45
- if (!handlerRef.current)
46
- return;
47
- if (disabled)
48
- return;
49
- const handleClick = (event) => {
50
- if ("button" in event && event.button === 2)
51
- return;
52
- if (isMouseDownInsideRef.current)
53
- return;
54
- handlerRef.current?.(event);
55
- };
56
- document.addEventListener("click", handleClick);
57
- return () => {
58
- document.removeEventListener("click", handleClick);
59
- };
60
- // eslint-disable-next-line react-hooks/exhaustive-deps
61
- }, [handlerRef, disabled, ...refs]);
62
- };
63
- export default useOnClickOutside;
@@ -1,2 +0,0 @@
1
- declare const useRTL: () => [boolean, (state: boolean) => void];
2
- export default useRTL;
@@ -1,7 +0,0 @@
1
- "use client";
2
- import React from "react";
3
- import { SingletonEnvironmentContext } from "./_private/useSingletonEnvironment.js";
4
- const useRTL = () => {
5
- return React.useContext(SingletonEnvironmentContext).rtl;
6
- };
7
- export default useRTL;
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- declare const useScrollLock: (options?: {
3
- containerRef?: React.RefObject<HTMLElement | null>;
4
- originRef?: React.RefObject<HTMLElement | null>;
5
- }) => {
6
- scrollLocked: boolean;
7
- lockScroll: () => void;
8
- unlockScroll: () => void;
9
- };
10
- export default useScrollLock;
@@ -1,25 +0,0 @@
1
- "use client";
2
- import { lockScroll } from "@reshaped/utilities";
3
- import React from "react";
4
- const useScrollLock = (options) => {
5
- const { containerRef, originRef } = options || {};
6
- const [locked, setLocked] = React.useState(false);
7
- const unlockScrollRef = React.useRef(null);
8
- const handleLockScroll = React.useCallback(() => {
9
- unlockScrollRef.current = lockScroll({
10
- containerEl: containerRef?.current,
11
- originEl: originRef?.current,
12
- callback: () => setLocked(true),
13
- });
14
- }, [containerRef, originRef]);
15
- const handleUnlockScroll = React.useCallback(() => {
16
- unlockScrollRef.current?.({ callback: () => setLocked(false) });
17
- unlockScrollRef.current = null;
18
- }, []);
19
- return React.useMemo(() => ({
20
- scrollLocked: locked,
21
- lockScroll: handleLockScroll,
22
- unlockScroll: handleUnlockScroll,
23
- }), [locked, handleLockScroll, handleUnlockScroll]);
24
- };
25
- export default useScrollLock;
@@ -1,7 +0,0 @@
1
- declare const useToggle: (defaultValue?: boolean) => {
2
- active: boolean;
3
- activate: () => void;
4
- deactivate: () => void;
5
- toggle: (targetValue?: any) => void;
6
- };
7
- export default useToggle;
@@ -1,19 +0,0 @@
1
- "use client";
2
- import React from "react";
3
- const useToggle = (defaultValue) => {
4
- const [active, setActive] = React.useState(defaultValue || false);
5
- const activate = React.useCallback(() => {
6
- setActive(true);
7
- }, []);
8
- const deactivate = React.useCallback(() => {
9
- setActive(false);
10
- }, []);
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- const toggle = React.useCallback((targetValue) => {
13
- // Checking the targetValue type for backwards compatibility if something like handler events
14
- // are passed automatically e.g. onClick={toggle}
15
- setActive(typeof targetValue === "boolean" ? targetValue : (active) => !active);
16
- }, []);
17
- return React.useMemo(() => ({ active, activate, deactivate, toggle }), [activate, deactivate, toggle, active]);
18
- };
19
- export default useToggle;