@react-fabric/core 1.0.0-beta.22 → 1.0.0-beta.24

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 (66) hide show
  1. package/dist/cjs/components/animations/Animations.js +1 -1
  2. package/dist/cjs/components/avatar/Avatar.js +1 -1
  3. package/dist/cjs/components/button/ButtonGroup.js +3 -2
  4. package/dist/cjs/components/button/ToggleButtonGroup.js +2 -1
  5. package/dist/cjs/components/callout/Callout.js +2 -1
  6. package/dist/cjs/components/card/Card.js +1 -1
  7. package/dist/cjs/components/card/CardCover.js +1 -1
  8. package/dist/cjs/components/chip/Chip.js +1 -1
  9. package/dist/cjs/components/divider/Divider.js +1 -1
  10. package/dist/cjs/components/icon/Icon.js +1 -1
  11. package/dist/cjs/components/menu/Menu.js +31 -27
  12. package/dist/cjs/components/menu/MenuItem.js +20 -12
  13. package/dist/cjs/components/progress/ProgressBar.js +2 -1
  14. package/dist/cjs/components/progress/ProgressCircle.js +2 -1
  15. package/dist/cjs/components/tabpanel/TabPanel.js +1 -1
  16. package/dist/cjs/core/headfoot/HeadFoot.js +2 -1
  17. package/dist/cjs/index.js +4 -0
  18. package/dist/cjs/overlays/alert/Alert.js +1 -1
  19. package/dist/cjs/overlays/message/Message.js +1 -1
  20. package/dist/cjs/overlays/toast/Toast.js +1 -1
  21. package/dist/cjs/overlays/tooltip/Tooltip.js +1 -1
  22. package/dist/cjs/typography/Abbr.js +1 -1
  23. package/dist/cjs/typography/Anchor.js +2 -1
  24. package/dist/cjs/typography/Mark.js +1 -1
  25. package/dist/cjs/typography/Text.js +1 -1
  26. package/dist/cjs/typography/Title.js +2 -1
  27. package/dist/cjs/utils/cloneElement.js +44 -0
  28. package/dist/esm/components/animations/Animations.js +1 -1
  29. package/dist/esm/components/avatar/Avatar.js +1 -1
  30. package/dist/esm/components/button/ButtonGroup.js +2 -1
  31. package/dist/esm/components/button/ToggleButtonGroup.js +2 -1
  32. package/dist/esm/components/callout/Callout.js +2 -1
  33. package/dist/esm/components/card/Card.js +1 -1
  34. package/dist/esm/components/card/CardCover.js +1 -1
  35. package/dist/esm/components/chip/Chip.js +1 -1
  36. package/dist/esm/components/divider/Divider.js +1 -1
  37. package/dist/esm/components/icon/Icon.js +1 -1
  38. package/dist/esm/components/menu/Menu.js +32 -28
  39. package/dist/esm/components/menu/MenuItem.js +14 -6
  40. package/dist/esm/components/progress/ProgressBar.js +2 -1
  41. package/dist/esm/components/progress/ProgressCircle.js +2 -1
  42. package/dist/esm/components/tabpanel/TabPanel.js +1 -1
  43. package/dist/esm/core/headfoot/HeadFoot.js +2 -1
  44. package/dist/esm/index.js +2 -0
  45. package/dist/esm/overlays/alert/Alert.js +1 -1
  46. package/dist/esm/overlays/message/Message.js +1 -1
  47. package/dist/esm/overlays/toast/Toast.js +1 -1
  48. package/dist/esm/overlays/tooltip/Tooltip.js +1 -1
  49. package/dist/esm/typography/Abbr.js +1 -1
  50. package/dist/esm/typography/Anchor.js +2 -1
  51. package/dist/esm/typography/Mark.js +1 -1
  52. package/dist/esm/typography/Text.js +1 -1
  53. package/dist/esm/typography/Title.js +2 -1
  54. package/dist/esm/utils/cloneElement.js +44 -0
  55. package/dist/types/index.d.ts +2 -0
  56. package/dist/types/utils/cloneElement.d.ts +2 -0
  57. package/dist/types/utils/index.d.ts +1 -0
  58. package/package.json +3 -3
  59. package/src/components/button/ButtonGroup.tsx +1 -1
  60. package/src/components/button/ToggleButtonGroup.tsx +2 -1
  61. package/src/components/menu/Menu.tsx +45 -42
  62. package/src/components/menu/MenuItem.tsx +8 -3
  63. package/src/index.ts +3 -0
  64. package/src/overlays/tooltip/Tooltip.tsx +1 -1
  65. package/src/utils/cloneElement.ts +44 -0
  66. package/src/utils/index.ts +1 -0
@@ -45,7 +45,7 @@ import {
45
45
  useRole,
46
46
  useTypeahead,
47
47
  } from "@floating-ui/react";
48
- import { cloneChildren, mergeRefs } from "@react-fabric/utilities";
48
+ import { mergeRefs } from "@react-fabric/utilities";
49
49
  import classNames from "classnames";
50
50
  import {
51
51
  cloneElement,
@@ -55,8 +55,9 @@ import {
55
55
  useRef,
56
56
  useState,
57
57
  } from "react";
58
+ import { HotKeyWrapper } from "../../hotkeys/HotKeyWrapper";
58
59
  import { CoreIcons } from "../../types/icons";
59
- import { nodeCheck } from "../../utils";
60
+ import { cloneChildren, nodeCheck } from "../../utils";
60
61
  import { MenuItem } from "./MenuItem";
61
62
  import { type MenuProps } from "./types";
62
63
 
@@ -219,47 +220,49 @@ const MenuComponent = ({
219
220
  {(!isNested || isOpen) && (
220
221
  <Wrapper {...wrapperProps}>
221
222
  {isNested && <FloatingOverlay />}
222
- <FloatingFocusManager
223
- context={context}
224
- modal={!isNested}
225
- initialFocus={isNested ? -1 : 0}
226
- returnFocus={!isNested}
227
- >
228
- <div
229
- className={classNames(
230
- menuClassName,
231
- "flex flex-col bg-base p-1 menu-list",
232
- isNested &&
233
- "outline shadow-lg rounded-capped max-h-96 overflow-auto scroll-thin z-[var(--z-popover)]",
234
- )}
235
- autoFocus
236
- ref={mergeRefs(isNested ? refs.setFloating : ref)}
237
- {...getFloatingProps({
238
- onClick: isNested ? undefined : handleClick,
239
- })}
240
- // @ts-expect-error ignore
241
- {...{ style: !isNested ? rest.style : floatingStyles }}
223
+ <HotKeyWrapper>
224
+ <FloatingFocusManager
225
+ context={context}
226
+ modal={!isNested}
227
+ initialFocus={isNested ? -1 : 0}
228
+ returnFocus={!isNested}
242
229
  >
243
- {cloneChildren(children, (child: AnyObject, index) => {
244
- labelsRef.current[index] = child.props.label;
245
- return cloneElement(
246
- child,
247
- nodeCheck(child, MenuItem, Menu, MenuComponent)
248
- ? {
249
- minimal: !isNested && minimal,
250
- "data-focus": activeIndex === index,
251
- ref: (el: HTMLElement) =>
252
- (elementsRef.current[index] = el),
253
- ...getItemProps({
254
- onClick: child.props.onClick,
255
- tabIndex: activeIndex === index ? 0 : -1,
256
- }),
257
- }
258
- : {},
259
- );
260
- })}
261
- </div>
262
- </FloatingFocusManager>
230
+ <div
231
+ className={classNames(
232
+ menuClassName,
233
+ "flex flex-col bg-base p-1 menu-list",
234
+ isNested &&
235
+ "outline shadow-lg rounded-capped max-h-96 overflow-auto scroll-thin z-[var(--z-popover)]",
236
+ )}
237
+ autoFocus
238
+ ref={mergeRefs(isNested ? refs.setFloating : ref)}
239
+ {...getFloatingProps({
240
+ onClick: isNested ? undefined : handleClick,
241
+ })}
242
+ // @ts-expect-error ignore
243
+ {...{ style: !isNested ? rest.style : floatingStyles }}
244
+ >
245
+ {cloneChildren(children, (child: AnyObject, index) => {
246
+ labelsRef.current[index] = child.props.label;
247
+ return cloneElement(
248
+ child,
249
+ nodeCheck(child, MenuItem, Menu, MenuComponent)
250
+ ? {
251
+ minimal: !isNested && minimal,
252
+ "data-focus": activeIndex === index,
253
+ ref: (el: HTMLElement) =>
254
+ (elementsRef.current[index] = el),
255
+ ...getItemProps({
256
+ onClick: child.props.onClick,
257
+ tabIndex: activeIndex === index ? 0 : -1,
258
+ }),
259
+ }
260
+ : {},
261
+ );
262
+ })}
263
+ </div>
264
+ </FloatingFocusManager>
265
+ </HotKeyWrapper>
263
266
  </Wrapper>
264
267
  )}
265
268
  </FloatingList>
@@ -22,9 +22,10 @@
22
22
  */
23
23
 
24
24
  import { useFloatingTree } from "@floating-ui/react";
25
- import { iconToken } from "@react-fabric/utilities";
25
+ import { iconToken, mergeRefs } from "@react-fabric/utilities";
26
26
  import classNames from "classnames";
27
- import { Fragment, useCallback, useMemo } from "react";
27
+ import { Fragment, useCallback, useMemo, useRef } from "react";
28
+ import { HotKey } from "../../hotkeys/HotKey";
28
29
  import { HotKeyLabel } from "../../hotkeys/HotKeyLabel";
29
30
  import { Tooltip } from "../../overlays";
30
31
  import { type PolymorphicProps } from "../../types";
@@ -58,6 +59,7 @@ export const MenuItem = <Tag extends React.ElementType = "button">({
58
59
  ref,
59
60
  ...aria
60
61
  }: MenuItemProps & PolymorphicProps<Tag>) => {
62
+ const elRef = useRef<HTMLElement>(null);
61
63
  const tree = useFloatingTree();
62
64
  const badgeProps = useMemo(() => {
63
65
  return getBadgeProps(badge);
@@ -135,7 +137,7 @@ export const MenuItem = <Tag extends React.ElementType = "button">({
135
137
  return (
136
138
  <Wrapper {...aria}>
137
139
  <E
138
- ref={ref}
140
+ ref={mergeRefs(ref, elRef)}
139
141
  data-dropdown-dismiss
140
142
  data-color={color}
141
143
  className={classNames(
@@ -155,6 +157,9 @@ export const MenuItem = <Tag extends React.ElementType = "button">({
155
157
  }}
156
158
  {...(minimal ? {} : aria)}
157
159
  >
160
+ {hotKey && (
161
+ <HotKey keyCombo={hotKey} handler={() => elRef.current?.click?.()} />
162
+ )}
158
163
  {menuLabel}
159
164
  </E>
160
165
  </Wrapper>
package/src/index.ts CHANGED
@@ -40,10 +40,13 @@ export * from "./hooks/useStorage";
40
40
 
41
41
  export { HotKey } from "./hotkeys/HotKey";
42
42
  export { HotKeyLabel } from "./hotkeys/HotKeyLabel";
43
+ export { HotKeyWrapper } from "./hotkeys/HotKeyWrapper";
43
44
 
44
45
  export { type ModalProps } from "./types";
45
46
  export { CoreIcons } from "./types/icons";
46
47
 
48
+ export { cloneChildren } from "./utils";
49
+
47
50
  export {
48
51
  ApplicationProvider,
49
52
  useApplicationContext,
@@ -184,7 +184,7 @@ export const Tooltip = ({
184
184
  >
185
185
  <span
186
186
  className={classNames(
187
- "font-medium text-dimmed flex-1",
187
+ "font-medium text-dimmed flex-1 break-all",
188
188
  isString(content) && "whitespace-pre-wrap mixed-lang",
189
189
  )}
190
190
  >
@@ -0,0 +1,44 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { type ReactNode, Children, isValidElement } from "react";
25
+ import { Fragment } from "react/jsx-runtime";
26
+
27
+ export const cloneChildren = (
28
+ children: ReactNode,
29
+ callback: (child: ReactNode, index: number) => ReactNode,
30
+ ): ReactNode => {
31
+ return Children.map(children, (c: ReactNode) => {
32
+ if (isValidElement(c)) {
33
+ if (c.type === Fragment) {
34
+ // just compare to `Fragment`
35
+ return cloneChildren(c.props?.children, callback);
36
+ }
37
+ return c;
38
+ }
39
+ return c;
40
+ })
41
+ ?.flat()
42
+ .filter(Boolean)
43
+ .map(callback);
44
+ };
@@ -24,5 +24,6 @@
24
24
  /* istanbul ignore file */
25
25
 
26
26
  export * from "./calculateDimensions";
27
+ export * from "./cloneElement";
27
28
  export * from "./getColor";
28
29
  export * from "./nodeCheck";