@basic-ui/core 0.0.28 → 0.0.32

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 (132) hide show
  1. package/build/cjs/index.js +44 -21
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/FocusLock/useFocusLock.js +21 -7
  4. package/build/esm/FocusLock/useFocusLock.js.map +1 -1
  5. package/build/esm/Menu/Menu.js +0 -3
  6. package/build/esm/Menu/Menu.js.map +1 -1
  7. package/build/esm/Menu/MenuButton.js +7 -5
  8. package/build/esm/Menu/MenuButton.js.map +1 -1
  9. package/build/esm/Menu/MenuList.js +8 -5
  10. package/build/esm/Menu/MenuList.js.map +1 -1
  11. package/build/esm/Menu/context.d.ts +0 -1
  12. package/build/esm/Menu/context.js.map +1 -1
  13. package/build/esm/Tooltip/Tooltip.d.ts +1 -0
  14. package/build/esm/Tooltip/Tooltip.js +10 -3
  15. package/build/esm/Tooltip/Tooltip.js.map +1 -1
  16. package/build/esm/hooks/useId.d.ts +1 -0
  17. package/build/esm/hooks/useId.js.map +1 -1
  18. package/build/tsconfig.tsbuildinfo +11 -11
  19. package/package.json +4 -3
  20. package/src/Accordion/Accordion.story.tsx +72 -0
  21. package/src/Accordion/Accordion.tsx +51 -0
  22. package/src/Accordion/AccordionBody.tsx +53 -0
  23. package/src/Accordion/AccordionHeader.tsx +165 -0
  24. package/src/Accordion/AccordionItem.tsx +43 -0
  25. package/src/Accordion/context.ts +35 -0
  26. package/src/Accordion/index.ts +4 -0
  27. package/src/Accordion/scopeQuery.ts +7 -0
  28. package/src/Accordion/styles.css +21 -0
  29. package/src/CheckBox/CheckBox.tsx +41 -0
  30. package/src/CheckBox/index.ts +1 -0
  31. package/src/ComboBox/ComboBox.story.tsx +118 -0
  32. package/src/ComboBox/Combobox.tsx +153 -0
  33. package/src/ComboBox/ComboboxButton.tsx +60 -0
  34. package/src/ComboBox/ComboboxInput.tsx +178 -0
  35. package/src/ComboBox/ComboboxLabel.tsx +32 -0
  36. package/src/ComboBox/ComboboxList.tsx +47 -0
  37. package/src/ComboBox/ComboboxOption.tsx +107 -0
  38. package/src/ComboBox/ComboboxPopover.tsx +58 -0
  39. package/src/ComboBox/cities.ts +23194 -0
  40. package/src/ComboBox/context.ts +33 -0
  41. package/src/ComboBox/hooks.tsx +428 -0
  42. package/src/ComboBox/index.ts +8 -0
  43. package/src/ComboBox/makeHash.ts +19 -0
  44. package/src/ComboBox/scopeQuery.ts +6 -0
  45. package/src/ComboBox/styles.css +30 -0
  46. package/src/FocusLock/FocusLock.tsx +59 -0
  47. package/src/FocusLock/index.ts +1 -0
  48. package/src/FocusLock/tabUtils.ts +28 -0
  49. package/src/FocusLock/useFocusLock.ts +61 -0
  50. package/src/List/List.story.tsx +17 -0
  51. package/src/List/List.tsx +17 -0
  52. package/src/List/ListItem.tsx +23 -0
  53. package/src/List/context.ts +19 -0
  54. package/src/List/index.ts +2 -0
  55. package/src/Menu/.gitkeep +0 -0
  56. package/src/Menu/Menu.story.tsx +158 -0
  57. package/src/Menu/Menu.tsx +60 -0
  58. package/src/Menu/MenuButton.tsx +83 -0
  59. package/src/Menu/MenuItem.tsx +83 -0
  60. package/src/Menu/MenuList.tsx +201 -0
  61. package/src/Menu/MenuPopover.tsx +25 -0
  62. package/src/Menu/context.ts +32 -0
  63. package/src/Menu/index.ts +5 -0
  64. package/src/Menu/scope.ts +7 -0
  65. package/src/Menu/styles.css +42 -0
  66. package/src/Modal/Modal.story.tsx +242 -0
  67. package/src/Modal/Modal.tsx +42 -0
  68. package/src/Modal/ModalBackdrop.tsx +72 -0
  69. package/src/Modal/NavDrawer.story.tsx +157 -0
  70. package/src/Modal/index.ts +2 -0
  71. package/src/Modal/styles.css +46 -0
  72. package/src/Popover/.gitkeep +0 -0
  73. package/src/Popper/Popper.story.tsx +267 -0
  74. package/src/Popper/Popper.tsx +149 -0
  75. package/src/Popper/PopperArrow.tsx +36 -0
  76. package/src/Popper/context.ts +9 -0
  77. package/src/Popper/index.ts +3 -0
  78. package/src/Popper/styles.css +60 -0
  79. package/src/Portal/Portal.tsx +20 -0
  80. package/src/Portal/index.ts +1 -0
  81. package/src/RadioButton/RadioButton.story.tsx +73 -0
  82. package/src/RadioButton/RadioButton.tsx +48 -0
  83. package/src/RadioButton/RadioGroup.tsx +56 -0
  84. package/src/RadioButton/context.ts +19 -0
  85. package/src/RadioButton/index.ts +2 -0
  86. package/src/SkipNav/SkipNav.tsx +16 -0
  87. package/src/SkipNav/index.tsx +1 -0
  88. package/src/Spinner/Spinner.story.tsx +30 -0
  89. package/src/Spinner/Spinner.tsx +112 -0
  90. package/src/Spinner/SpinnerButton.tsx +48 -0
  91. package/src/Spinner/context.ts +21 -0
  92. package/src/Spinner/index.ts +2 -0
  93. package/src/Spinner/styles.css +23 -0
  94. package/src/Tabs/Tab.story.tsx +78 -0
  95. package/src/Tabs/Tab.tsx +131 -0
  96. package/src/Tabs/TabList.tsx +63 -0
  97. package/src/Tabs/TabPanel.tsx +52 -0
  98. package/src/Tabs/TabPanels.tsx +30 -0
  99. package/src/Tabs/Tabs.tsx +47 -0
  100. package/src/Tabs/context.ts +30 -0
  101. package/src/Tabs/index.tsx +5 -0
  102. package/src/Tabs/scopeQuery.ts +6 -0
  103. package/src/Tabs/styles.css +0 -0
  104. package/src/Tooltip/.gitkeep +0 -0
  105. package/src/Tooltip/Tooltip.story.tsx +43 -0
  106. package/src/Tooltip/Tooltip.tsx +48 -0
  107. package/src/Tooltip/index.ts +1 -0
  108. package/src/Tooltip/stateMachine.ts +185 -0
  109. package/src/Tooltip/useTooltip.ts +121 -0
  110. package/src/hooks/index.ts +14 -0
  111. package/src/hooks/useAutoFocus.ts +13 -0
  112. package/src/hooks/useChildrenCounter.ts +50 -0
  113. package/src/hooks/useControlledState.ts +37 -0
  114. package/src/hooks/useFocusReturn.ts +23 -0
  115. package/src/hooks/useFocusState.ts +28 -0
  116. package/src/hooks/useGestureHandlers.ts +217 -0
  117. package/src/hooks/useId.ts +18 -0
  118. package/src/hooks/useMeasure.ts +33 -0
  119. package/src/hooks/useOnClickOutside.ts +32 -0
  120. package/src/hooks/useOnKeyDown.ts +18 -0
  121. package/src/hooks/useReducerMachine.ts +59 -0
  122. package/src/hooks/useRemoveBodyScroll.ts +37 -0
  123. package/src/hooks/useScope.ts +51 -0
  124. package/src/hooks/useThrottle.ts +19 -0
  125. package/src/index.ts +19 -0
  126. package/src/utils/assignRef.ts +27 -0
  127. package/src/utils/clamp.ts +3 -0
  128. package/src/utils/createSubscription.ts +16 -0
  129. package/src/utils/getCircularIndex.ts +7 -0
  130. package/src/utils/index.ts +4 -0
  131. package/src/utils/rubberBandClamp.ts +25 -0
  132. package/src/utils/wrapEvent.ts +20 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Menu/MenuButton.tsx"],"names":["forwardRef","useMenuContext","wrapEvent","assignMultipleRefs","MenuButton","props","forwardedRef","as","Comp","id","preferredId","onClick","onKeyDown","disabled","otherProps","menuListIdRef","buttonIdRef","openWithArrowKeyRef","open","buttonRef","onChange","current","handleKeyDown","e","isArrowKey","includes","key","isEnterKey","openedWithArrow","preventDefault","handleClick","undefined"],"mappings":";;AAAA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,cAAT,QAA+B,WAA/B;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SAASC,kBAAT,QAAmC,UAAnC;;AAYA,OAAO,MAAMC,UAAU,gBAAGJ,UAAU,CAClC,SAASI,UAAT,CAAoBC,KAApB,EAA2BC,YAA3B,EAAyC;AACvC,QAAM;AACJC,IAAAA,EAAE,EAAEC,IAAI,GAAG,QADP;AAEJC,IAAAA,EAAE,EAAEC,WAFA;AAGJC,IAAAA,OAHI;AAIJC,IAAAA,SAJI;AAKJC,IAAAA;AALI,MAOFR,KAPJ;AAAA,QAMKS,UANL,iCAOIT,KAPJ;;AAQA,QAAM;AACJU,IAAAA,aADI;AAEJC,IAAAA,WAFI;AAGJC,IAAAA,mBAHI;AAI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AAE7B,SAAS,CAACS,OAAD,EAAUmB,WAAV,CATpB;AAUE,IAAA,SAAS,EAAE5B,SAAS,CAACU,SAAD,EAAYU,aAAZ,CAVtB;AAWE,IAAA,QAAQ,EAAET;AAXZ,KAYMC,UAZN,EADF;AAgBD,CAhEiC,CAA7B","sourcesContent":["import { forwardRef } from 'react';\nimport type * as React from 'react';\nimport { useMenuContext } from './context';\nimport { wrapEvent } from '../utils/wrapEvent';\nimport { assignMultipleRefs } from '../utils';\n\nexport type MenuButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n onClick?: (\n e:\n | React.MouseEvent<HTMLButtonElement>\n | React.KeyboardEvent<HTMLButtonElement>\n ) => void;\n};\n\nexport const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(\n function MenuButton(props, forwardedRef) {\n const {\n as: Comp = 'button',\n id: preferredId,\n onClick,\n onKeyDown,\n disabled,\n ...otherProps\n } = props;\n const {\n menuListIdRef,\n buttonIdRef,\n openWithArrowKeyRef,\n open,\n buttonRef,\n onChange,\n } = useMenuContext();\n\n buttonIdRef.current = preferredId || buttonIdRef.current;\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n\n const isArrowKey = () => ['ArrowUp', 'ArrowDown'].includes(e.key);\n const isEnterKey = () => [' ', 'Enter'].includes(e.key);\n\n const openedWithArrow = isArrowKey();\n if (openedWithArrow || isEnterKey()) {\n if (openedWithArrow) {\n // Used to make it open at the end or begining of the list\n openWithArrowKeyRef.current = e.key;\n }\n onChange && onChange(e, true);\n e.preventDefault();\n }\n };\n\n const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n\n onChange && onChange(e, !open);\n };\n\n return (\n <Comp\n ref={assignMultipleRefs(forwardedRef, buttonRef)}\n id={buttonIdRef.current}\n role=\"button\"\n type=\"button\"\n aria-haspopup={true}\n aria-controls={menuListIdRef.current}\n aria-expanded={open ? true : undefined}\n data-menu-button=\"\"\n onClick={wrapEvent(onClick, handleClick)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n disabled={disabled}\n {...otherProps}\n />\n );\n }\n);\n"],"file":"MenuButton.js"}
1
+ {"version":3,"sources":["../../../src/Menu/MenuButton.tsx"],"names":["forwardRef","useMenuContext","wrapEvent","useId","MenuButton","props","forwardedRef","as","Comp","id","preferredId","onClick","onKeyDown","disabled","otherProps","menuListIdRef","openWithArrowKeyRef","open","buttonRef","onChange","buttonId","handleKeyDown","e","current","currentTarget","isArrowKey","includes","key","isEnterKey","openedWithArrow","preventDefault","handleClick","undefined"],"mappings":";;AAAA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,cAAT,QAA+B,WAA/B;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SAASC,KAAT,QAAsB,UAAtB;;AAYA,OAAO,MAAMC,UAAU,gBAAGJ,UAAU,CAClC,SAASI,UAAT,CAAoBC,KAApB,EAA2BC,YAA3B,EAAyC;AACvC,QAAM;AACJC,IAAAA,EAAE,EAAEC,IAAI,GAAG,QADP;AAEJC,IAAAA,EAAE,EAAEC,WAFA;AAGJC,IAAAA,OAHI;AAIJC,IAAAA,SAJI;AAKJC,IAAAA;AALI,MAOFR,KAPJ;AAAA,QAMKS,UANL,iCAOIT,KAPJ;;AAQA,QAAM;AACJU,IAAAA,aADI;AAEJC,IAAAA,mBAFI;AAGJC,IAAAA,IAHI;AAIJC,IAAAA,SAJI;AAKJC,IAAAA;AALI,MAMFlB,cAAc,EANlB;AAQA,QAAMmB,QAAQ,GAAGjB,KAAK,CAACO,WAAD,CAAtB;;AAEA,QAAMW,aAAa,GAAIC,CAAD,IAA+C;AACnE,QAAIT,QAAJ,EAAc;AACZ;AACD;;AACDK,IAAAA,SAAS,CAACK,OAAV,GAAoBD,CAAC,CAACE,aAAtB;;AAEA,UAAMC,UAAU,GAAG,MAAM,CAAC,SAAD,EAAY,WAAZ,EAAyBC,QAAzB,CAAkCJ,CAAC,CAACK,GAApC,CAAzB;;AACA,UAAMC,UAAU,GAAG,MAAM,CAAC,GAAD,EAAM,OAAN,EAAeF,QAAf,CAAwBJ,CAAC,CAACK,GAA1B,CAAzB;;AAEA,UAAME,eAAe,GAAGJ,UAAU,EAAlC;;AACA,QAAII,eAAe,IAAID,UAAU,EAAjC,EAAqC;AACnC,UAAIC,eAAJ,EAAqB;AACnB;AACAb,QAAAA,mBAAmB,CAACO,OAApB,GAA8BD,CAAC,CAACK,GAAhC;AACD;;AACDR,MAAAA,QAAQ,IAAIA,QAAQ,CAACG,CAAD,EAAI,IAAJ,CAApB;AACAA,MAAAA,CAAC,CAACQ,cAAF;AACD;AACF,GAlBD;;AAoBA,QAAMC,WAAW,GAAIT,CAAD,IAA4C;AAC9D,QAAIT,QAAJ,EAAc;AACZ;AACD;;AACDK,IAAAA,SAAS,CAACK,OAAV,GAAoBD,CAAC,CAACE,aAAtB;AAEAL,IAAAA,QAAQ,IAAIA,QAAQ,CAACG,CAAD,EAAI,CAACL,IAAL,CAApB;AACD,GAPD;;AASA,sBACE,KAAC,IAAD;AACE,IAAA,GAAG,EAAEX,YADP;AAEE,IAAA,EAAE,EAAEc,QAFN;AAGE,IAAA,IAAI,EAAC,QAHP;AAIE,IAAA,IAAI,EAAC,QAJP;AAKE,qBAAe,IALjB;AAME,qBAAeL,aAAa,CAACQ,OAN/B;AAOE,qBAAeN,IAAI,GAAG,IAAH,GAAUe,SAP/B;AAQE,wBAAiB,EARnB;AASE,IAAA,OAAO,EAAE9B,SAAS,CAACS,OAAD,EAAUoB,WAAV,CATpB;AAUE,IAAA,SAAS,EAAE7B,SAAS,CAACU,SAAD,EAAYS,aAAZ,CAVtB;AAWE,IAAA,QAAQ,EAAER;AAXZ,KAYMC,UAZN,EADF;AAgBD,CAjEiC,CAA7B","sourcesContent":["import { forwardRef } from 'react';\nimport type * as React from 'react';\nimport { useMenuContext } from './context';\nimport { wrapEvent } from '../utils/wrapEvent';\nimport { useId } from '../hooks';\n\nexport type MenuButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n onClick?: (\n e:\n | React.MouseEvent<HTMLButtonElement>\n | React.KeyboardEvent<HTMLButtonElement>\n ) => void;\n};\n\nexport const MenuButton = forwardRef<HTMLButtonElement, MenuButtonProps>(\n function MenuButton(props, forwardedRef) {\n const {\n as: Comp = 'button',\n id: preferredId,\n onClick,\n onKeyDown,\n disabled,\n ...otherProps\n } = props;\n const {\n menuListIdRef,\n openWithArrowKeyRef,\n open,\n buttonRef,\n onChange,\n } = useMenuContext();\n\n const buttonId = useId(preferredId);\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n buttonRef.current = e.currentTarget;\n\n const isArrowKey = () => ['ArrowUp', 'ArrowDown'].includes(e.key);\n const isEnterKey = () => [' ', 'Enter'].includes(e.key);\n\n const openedWithArrow = isArrowKey();\n if (openedWithArrow || isEnterKey()) {\n if (openedWithArrow) {\n // Used to make it open at the end or begining of the list\n openWithArrowKeyRef.current = e.key;\n }\n onChange && onChange(e, true);\n e.preventDefault();\n }\n };\n\n const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n return;\n }\n buttonRef.current = e.currentTarget;\n\n onChange && onChange(e, !open);\n };\n\n return (\n <Comp\n ref={forwardedRef}\n id={buttonId}\n role=\"button\"\n type=\"button\"\n aria-haspopup={true}\n aria-controls={menuListIdRef.current}\n aria-expanded={open ? true : undefined}\n data-menu-button=\"\"\n onClick={wrapEvent(onClick, handleClick)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n disabled={disabled}\n {...otherProps}\n />\n );\n }\n);\n"],"file":"MenuButton.js"}
@@ -10,6 +10,8 @@ import { getCircularIndex, wrapEvent } from '../utils';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  const useEnhancedEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
12
12
  export const MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwardedRef) {
13
+ var _buttonRef$current3;
14
+
13
15
  const {
14
16
  as: Comp = 'ul',
15
17
  onKeyDown,
@@ -20,7 +22,6 @@ export const MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forward
20
22
 
21
23
  const {
22
24
  menuListIdRef,
23
- buttonIdRef,
24
25
  buttonRef,
25
26
  onChange,
26
27
  openWithArrowKeyRef,
@@ -60,7 +61,9 @@ export const MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forward
60
61
  setMounted(true);
61
62
  }, [mounted, navigationItem, onNavigate, openWithArrowKeyRef, scope, defaultActiveItemValue]);
62
63
  useOnClickOutside(menuListRef, e => {
63
- if (e.target !== buttonRef.current) {
64
+ var _buttonRef$current;
65
+
66
+ if (e.target instanceof HTMLElement && e.target !== buttonRef.current && !((_buttonRef$current = buttonRef.current) != null && _buttonRef$current.contains(e.target))) {
64
67
  onChange && onChange(e, false);
65
68
  }
66
69
 
@@ -72,12 +75,12 @@ export const MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forward
72
75
  case 'Escape':
73
76
  case 'Tab':
74
77
  {
75
- var _buttonRef$current;
78
+ var _buttonRef$current2;
76
79
 
77
80
  onChange && onChange(e, false);
78
81
  e.preventDefault(); // prevents focusing on next element, because we will be handling it
79
82
 
80
- (_buttonRef$current = buttonRef.current) == null ? void 0 : _buttonRef$current.focus();
83
+ (_buttonRef$current2 = buttonRef.current) == null ? void 0 : _buttonRef$current2.focus();
81
84
  break;
82
85
  }
83
86
 
@@ -162,7 +165,7 @@ export const MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forward
162
165
  ref: assignMultipleRefs(forwardedRef, menuListRef),
163
166
  id: menuListIdRef.current,
164
167
  role: "menu",
165
- "aria-labelledby": buttonIdRef.current,
168
+ "aria-labelledby": (_buttonRef$current3 = buttonRef.current) == null ? void 0 : _buttonRef$current3.id,
166
169
  "data-menu-list": "",
167
170
  tabIndex: "-1",
168
171
  onKeyDown: wrapEvent(onKeyDown, handleKeyDown)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Menu/MenuList.tsx"],"names":["forwardRef","useEffect","useRef","useState","useLayoutEffect","useMenuContext","MenuListProvider","assignMultipleRefs","useOnClickOutside","useScope","queryScope","getCircularIndex","wrapEvent","useEnhancedEffect","window","MenuList","props","forwardedRef","as","Comp","onKeyDown","id","preferredId","defaultActiveItemValue","otherProps","menuListIdRef","buttonIdRef","buttonRef","onChange","openWithArrowKeyRef","open","navigationItem","setNavigationItem","mounted","setMounted","menuListRef","scope","onNavigate","el","focus","current","allItems","queryAllNodes","index","length","i","dataset","value","e","target","preventDefault","handleKeyDown","key","currentIndex","findIndex","nextIndex","firstLetter","toLowerCase","idx","dom","domText","innerText","charAt"],"mappings":";;AAAA,SACEA,UADF,EAEEC,SAFF,EAGEC,MAHF,EAIEC,QAJF,EAKEC,eALF,QAMO,OANP;AAQA,SAASC,cAAT,EAAyBC,gBAAzB,QAAiD,WAAjD;AACA,SAASC,kBAAT,QAAmC,oBAAnC;AACA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,QAAT,QAAyB,UAAzB;AACA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,UAA5C;;AAEA,MAAMC,iBAAiB,GACrB,OAAOC,MAAP,KAAkB,WAAlB,GAAgCV,eAAhC,GAAkDH,SADpD;AASA,OAAO,MAAMc,QAAQ,gBAAGf,UAAU,CAChC,SAASe,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;AACrC,QAAM;AACJC,IAAAA,EAAE,EAAEC,IAAI,GAAG,IADP;AAEJC,IAAAA,SAFI;AAGJC,IAAAA,EAAE,EAAEC,WAHA;AAIJC,IAAAA;AAJI,MAMFP,KANJ;AAAA,QAKKQ,UALL,iCAMIR,KANJ;;AAQA,QAAM;AACJS,IAAAA,aADI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AAO,CAACE,MAAR,CAAe,CAAf,MAAsBN,WAAhD,EAA6D;AAC3DD,gBAAAA,SAAS,GAAGG,GAAZ;AACA;AACD;AACF;;AACD,gBAAIH,SAAS,IAAI,CAAb,IAAkBA,SAAS,GAAGd,QAAQ,CAACG,MAA3C,EAAmD;AACjDP,cAAAA,UAAU,IAAIA,UAAU,CAACI,QAAQ,CAACc,SAAD,CAAT,CAAxB;AACD;AACF;AACF;AAhEH;AAkED;;AAED,MAAI,CAACzB,IAAL,EAAW;AACT,WAAO,IAAP;AACD;;AAED,sBACE,KAAC,gBAAD;AACE,IAAA,KAAK,EAAE;AACLC,MAAAA,cADK;AAELM,MAAAA;AAFK,KADT;AAAA,2BAME,KAAC,IAAD;AACE,MAAA,GAAG,EAAE9B,kBAAkB,CAACU,YAAD,EAAekB,WAAf,CADzB;AAEE,MAAA,EAAE,EAAEV,aAAa,CAACe,OAFpB;AAGE,MAAA,IAAI,EAAC,MAHP;AAIE,yBAAiBd,WAAW,CAACc,OAJ/B;AAKE,wBAAe,EALjB;AAME,MAAA,QAAQ,EAAC,IANX;AAOE,MAAA,SAAS,EAAE5B,SAAS,CAACQ,SAAD,EAAY+B,aAAZ;AAPtB,OAQM3B,UARN;AANF,IADF;AAmBD,CA5K+B,CAA3B","sourcesContent":["import {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n} from 'react';\nimport type * as React from 'react';\nimport { useMenuContext, MenuListProvider } from './context';\nimport { assignMultipleRefs } from '../utils/assignRef';\nimport { useOnClickOutside } from '../hooks/useOnClickOutside';\nimport { useScope } from '../hooks';\nimport { queryScope } from './scope';\nimport { getCircularIndex, wrapEvent } from '../utils';\n\nconst useEnhancedEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport interface MenuListProps extends React.HTMLAttributes<HTMLUListElement> {\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n defaultActiveItemValue?: string;\n}\n\nexport const MenuList = forwardRef<HTMLUListElement, MenuListProps>(\n function MenuList(props, forwardedRef) {\n const {\n as: Comp = 'ul',\n onKeyDown,\n id: preferredId,\n defaultActiveItemValue,\n ...otherProps\n } = props;\n\n const {\n menuListIdRef,\n buttonIdRef,\n buttonRef,\n onChange,\n openWithArrowKeyRef,\n open,\n } = useMenuContext();\n\n const [navigationItem, setNavigationItem] = useState<\n HTMLElement | undefined\n >();\n\n const [mounted, setMounted] = useState(false);\n\n const menuListRef = useRef<HTMLUListElement>();\n\n const scope = useScope<HTMLLIElement, HTMLUListElement>(menuListRef);\n\n const onNavigate = (el: HTMLElement) => {\n el.focus();\n setNavigationItem(el);\n };\n\n menuListIdRef.current = preferredId || menuListIdRef.current;\n\n useEnhancedEffect(() => {\n if (!mounted) {\n const allItems = scope.current.queryAllNodes(queryScope);\n let index = getCircularIndex(\n openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0,\n allItems.length\n );\n\n if (defaultActiveItemValue) {\n for (let i = 0; i < allItems.length; i++) {\n if (allItems[i].dataset.value === defaultActiveItemValue) {\n index = i;\n break;\n }\n }\n }\n\n if (index !== null) {\n onNavigate && onNavigate(allItems[index]);\n }\n }\n\n openWithArrowKeyRef.current = null;\n setMounted(true);\n }, [\n mounted,\n navigationItem,\n onNavigate,\n openWithArrowKeyRef,\n scope,\n defaultActiveItemValue,\n ]);\n\n useOnClickOutside(\n menuListRef,\n (e) => {\n if (e.target !== buttonRef.current) {\n onChange && onChange(e as any, false);\n }\n e.preventDefault();\n },\n true\n );\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLUListElement>) {\n switch (e.key) {\n case 'Escape':\n case 'Tab': {\n onChange && onChange(e, false);\n e.preventDefault(); // prevents focusing on next element, because we will be handling it\n buttonRef.current?.focus();\n break;\n }\n case 'Home':\n case 'End':\n case 'ArrowDown':\n case 'ArrowUp':\n e.preventDefault();\n const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];\n const currentIndex = allItems.findIndex((e) => e === navigationItem);\n if (allItems.length === 0) {\n return;\n }\n let nextIndex: number = currentIndex;\n switch (e.key) {\n case 'ArrowUp':\n nextIndex += -1;\n break;\n case 'ArrowDown':\n nextIndex += 1;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = -1;\n break;\n }\n // We already checked if allItems.length = 0 above\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n nextIndex = getCircularIndex(nextIndex, allItems.length)!;\n onNavigate && onNavigate(allItems[nextIndex]);\n break;\n default: {\n if (e.key.length === 1) {\n // A-Z\n e.preventDefault();\n const allItems = scope\n ? scope.current.queryAllNodes(queryScope)\n : [];\n const currentIndex = allItems.findIndex(\n (e) => e === navigationItem\n );\n const firstLetter = e.key.toLowerCase();\n let nextIndex = -1;\n for (let i = 1; i < allItems.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const idx = getCircularIndex(currentIndex + i, allItems.length)!;\n const dom = allItems[idx];\n const domText = dom.innerText.toLowerCase();\n if (domText.length > 0 && domText.charAt(0) === firstLetter) {\n nextIndex = idx;\n break;\n }\n }\n if (nextIndex >= 0 && nextIndex < allItems.length) {\n onNavigate && onNavigate(allItems[nextIndex]);\n }\n }\n }\n }\n }\n\n if (!open) {\n return null;\n }\n\n return (\n <MenuListProvider\n value={{\n navigationItem,\n onNavigate,\n }}\n >\n <Comp\n ref={assignMultipleRefs(forwardedRef, menuListRef)}\n id={menuListIdRef.current}\n role=\"menu\"\n aria-labelledby={buttonIdRef.current}\n data-menu-list=\"\"\n tabIndex=\"-1\"\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n {...otherProps}\n />\n </MenuListProvider>\n );\n }\n);\n"],"file":"MenuList.js"}
1
+ {"version":3,"sources":["../../../src/Menu/MenuList.tsx"],"names":["forwardRef","useEffect","useRef","useState","useLayoutEffect","useMenuContext","MenuListProvider","assignMultipleRefs","useOnClickOutside","useScope","queryScope","getCircularIndex","wrapEvent","useEnhancedEffect","window","MenuList","props","forwardedRef","as","Comp","onKeyDown","id","preferredId","defaultActiveItemValue","otherProps","menuListIdRef","buttonRef","onChange","openWithArrowKeyRef","open","navigationItem","setNavigationItem","mounted","setMounted","menuListRef","scope","onNavigate","el","focus","current","allItems","queryAllNodes","index","length","i","dataset","value","e","target","HTMLElement","contains","preventDefault","handleKeyDown","key","currentIndex","findIndex","nextIndex","firstLetter","toLowerCase","idx","dom","domText","innerText","charAt"],"mappings":";;AAAA,SACEA,UADF,EAEEC,SAFF,EAGEC,MAHF,EAIEC,QAJF,EAKEC,eALF,QAMO,OANP;AAQA,SAASC,cAAT,EAAyBC,gBAAzB,QAAiD,WAAjD;AACA,SAASC,kBAAT,QAAmC,oBAAnC;AACA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,QAAT,QAAyB,UAAzB;AACA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,UAA5C;;AAEA,MAAMC,iBAAiB,GACrB,OAAOC,MAAP,KAAkB,WAAlB,GAAgCV,eAAhC,GAAkDH,SADpD;AASA,OAAO,MAAMc,QAAQ,gBAAGf,UAAU,CAChC,SAASe,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;AAAA;;AACrC,QAAM;AACJC,IAAAA,EAAE,EAAEC,IAAI,GAAG,IADP;AAEJC,IAAAA,SAFI;AAGJC,IAAAA,EAAE,EAAEC,WAHA;AAIJC,IAAAA;AAJI,MAMFP,KANJ;AAAA,QAKKQ,UALL,iCAMIR,KANJ;;AAQA,QAAM;AACJS,IAAAA,aADI;AAEJC,IAAAA,SAFI;AAGJC,IAAAA,QAHI;AAIJC,IAAAA,mBAJI;AAKJC,IAAAA;AALI,MAMFxB,cAAc,EANlB;AAQA,QAAM,CAACyB,cAAD,EAAiBC,iBAAjB,IAAsC5B,QAAQ,EAApD;AAIA,QAAM,CAAC6B,OAAD,EAAUC,UAAV,IAAwB9B,QAAQ,CAAC,KAAD,CAAtC;AAEA,QAAM+B,WAAW,GAAGhC,MAA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,QAAQ,CAACG,MAA3C,EAAmD;AACjDP,cAAAA,UAAU,IAAIA,UAAU,CAACI,QAAQ,CAACgB,SAAD,CAAT,CAAxB;AACD;AACF;AACF;AAhEH;AAkED;;AAED,MAAI,CAAC3B,IAAL,EAAW;AACT,WAAO,IAAP;AACD;;AAED,sBACE,KAAC,gBAAD;AACE,IAAA,KAAK,EAAE;AACLC,MAAAA,cADK;AAELM,MAAAA;AAFK,KADT;AAAA,2BAME,KAAC,IAAD;AACE,MAAA,GAAG,EAAE7B,kBAAkB,CAACU,YAAD,EAAeiB,WAAf,CADzB;AAEE,MAAA,EAAE,EAAET,aAAa,CAACc,OAFpB;AAGE,MAAA,IAAI,EAAC,MAHP;AAIE,gDAAiBb,SAAS,CAACa,OAA3B,qBAAiB,oBAAmBlB,EAJtC;AAKE,wBAAe,EALjB;AAME,MAAA,QAAQ,EAAC,IANX;AAOE,MAAA,SAAS,EAAET,SAAS,CAACQ,SAAD,EAAYgC,aAAZ;AAPtB,OAQM5B,UARN;AANF,IADF;AAmBD,CA/K+B,CAA3B","sourcesContent":["import {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n} from 'react';\nimport type * as React from 'react';\nimport { useMenuContext, MenuListProvider } from './context';\nimport { assignMultipleRefs } from '../utils/assignRef';\nimport { useOnClickOutside } from '../hooks/useOnClickOutside';\nimport { useScope } from '../hooks';\nimport { queryScope } from './scope';\nimport { getCircularIndex, wrapEvent } from '../utils';\n\nconst useEnhancedEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport interface MenuListProps extends React.HTMLAttributes<HTMLUListElement> {\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n defaultActiveItemValue?: string;\n}\n\nexport const MenuList = forwardRef<HTMLUListElement, MenuListProps>(\n function MenuList(props, forwardedRef) {\n const {\n as: Comp = 'ul',\n onKeyDown,\n id: preferredId,\n defaultActiveItemValue,\n ...otherProps\n } = props;\n\n const {\n menuListIdRef,\n buttonRef,\n onChange,\n openWithArrowKeyRef,\n open,\n } = useMenuContext();\n\n const [navigationItem, setNavigationItem] = useState<\n HTMLElement | undefined\n >();\n\n const [mounted, setMounted] = useState(false);\n\n const menuListRef = useRef<HTMLUListElement>();\n\n const scope = useScope<HTMLLIElement, HTMLUListElement>(menuListRef);\n\n const onNavigate = (el: HTMLElement) => {\n el.focus();\n setNavigationItem(el);\n };\n\n menuListIdRef.current = preferredId || menuListIdRef.current;\n\n useEnhancedEffect(() => {\n if (!mounted) {\n const allItems = scope.current.queryAllNodes(queryScope);\n let index = getCircularIndex(\n openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0,\n allItems.length\n );\n\n if (defaultActiveItemValue) {\n for (let i = 0; i < allItems.length; i++) {\n if (allItems[i].dataset.value === defaultActiveItemValue) {\n index = i;\n break;\n }\n }\n }\n\n if (index !== null) {\n onNavigate && onNavigate(allItems[index]);\n }\n }\n\n openWithArrowKeyRef.current = null;\n setMounted(true);\n }, [\n mounted,\n navigationItem,\n onNavigate,\n openWithArrowKeyRef,\n scope,\n defaultActiveItemValue,\n ]);\n\n useOnClickOutside(\n menuListRef,\n (e) => {\n if (\n e.target instanceof HTMLElement &&\n e.target !== buttonRef.current &&\n !buttonRef.current?.contains(e.target)\n ) {\n onChange && onChange(e as any, false);\n }\n e.preventDefault();\n },\n true\n );\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLUListElement>) {\n switch (e.key) {\n case 'Escape':\n case 'Tab': {\n onChange && onChange(e, false);\n e.preventDefault(); // prevents focusing on next element, because we will be handling it\n buttonRef.current?.focus();\n break;\n }\n case 'Home':\n case 'End':\n case 'ArrowDown':\n case 'ArrowUp':\n e.preventDefault();\n const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];\n const currentIndex = allItems.findIndex((e) => e === navigationItem);\n if (allItems.length === 0) {\n return;\n }\n let nextIndex: number = currentIndex;\n switch (e.key) {\n case 'ArrowUp':\n nextIndex += -1;\n break;\n case 'ArrowDown':\n nextIndex += 1;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = -1;\n break;\n }\n // We already checked if allItems.length = 0 above\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n nextIndex = getCircularIndex(nextIndex, allItems.length)!;\n onNavigate && onNavigate(allItems[nextIndex]);\n break;\n default: {\n if (e.key.length === 1) {\n // A-Z\n e.preventDefault();\n const allItems = scope\n ? scope.current.queryAllNodes(queryScope)\n : [];\n const currentIndex = allItems.findIndex(\n (e) => e === navigationItem\n );\n const firstLetter = e.key.toLowerCase();\n let nextIndex = -1;\n for (let i = 1; i < allItems.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const idx = getCircularIndex(currentIndex + i, allItems.length)!;\n const dom = allItems[idx];\n const domText = dom.innerText.toLowerCase();\n if (domText.length > 0 && domText.charAt(0) === firstLetter) {\n nextIndex = idx;\n break;\n }\n }\n if (nextIndex >= 0 && nextIndex < allItems.length) {\n onNavigate && onNavigate(allItems[nextIndex]);\n }\n }\n }\n }\n }\n\n if (!open) {\n return null;\n }\n\n return (\n <MenuListProvider\n value={{\n navigationItem,\n onNavigate,\n }}\n >\n <Comp\n ref={assignMultipleRefs(forwardedRef, menuListRef)}\n id={menuListIdRef.current}\n role=\"menu\"\n aria-labelledby={buttonRef.current?.id}\n data-menu-list=\"\"\n tabIndex=\"-1\"\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n {...otherProps}\n />\n </MenuListProvider>\n );\n }\n);\n"],"file":"MenuList.js"}
@@ -5,7 +5,6 @@ export declare type ItemObject = {
5
5
  id: string | undefined;
6
6
  };
7
7
  export interface MenuContextProps {
8
- buttonIdRef: MutableRefObject<undefined | string>;
9
8
  buttonRef: MutableRefObject<HTMLButtonElement | null>;
10
9
  menuListIdRef: MutableRefObject<undefined | string>;
11
10
  openWithArrowKeyRef: MutableRefObject<string | null>;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Menu/context.ts"],"names":["createContext","useContext","menuContext","Provider","MenuProvider","useMenuContext","menuListContext","MenuListProvider","useMenuListContext"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA4D,OAA5D;AAoBA,MAAMC,WAAW,gBAAGF,aAAa,CAAmB,IAAnB,CAAjC;AACA,OAAO,MAAM;AAAEG,EAAAA,QAAQ,EAAEC;AAAZ,IAA6BF,WAAnC;AACP,OAAO,MAAMG,cAAc,GAAG,MAAMJ,UAAU,CAACC,WAAD,CAAvC,C,CAEP;;AAMA,MAAMI,eAAe,gBAAGN,aAAa,CAAuB,IAAvB,CAArC;AACA,OAAO,MAAMO,gBAAgB,GAAGD,eAAe,CAACH,QAAzC;AACP,OAAO,MAAMK,kBAAkB,GAAG,MAAMP,UAAU,CAACK,eAAD,CAA3C","sourcesContent":["import { createContext, useContext, MutableRefObject } from 'react';\n\nexport type ItemObject = { text: string; value: any; id: string | undefined };\n\n// MenuRoot\nexport interface MenuContextProps {\n buttonIdRef: MutableRefObject<undefined | string>;\n buttonRef: MutableRefObject<HTMLButtonElement | null>;\n menuListIdRef: MutableRefObject<undefined | string>;\n openWithArrowKeyRef: MutableRefObject<string | null>;\n onChange?: (\n e:\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>\n | React.PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open: boolean;\n}\n\nconst menuContext = createContext<MenuContextProps>(null as any);\nexport const { Provider: MenuProvider } = menuContext;\nexport const useMenuContext = () => useContext(menuContext);\n\n// MenuList\nexport interface MenuListContextProps {\n navigationItem: HTMLElement | undefined;\n onNavigate: undefined | ((idx: HTMLElement) => void);\n}\n\nconst menuListContext = createContext<MenuListContextProps>(null as any);\nexport const MenuListProvider = menuListContext.Provider;\nexport const useMenuListContext = () => useContext(menuListContext);\n"],"file":"context.js"}
1
+ {"version":3,"sources":["../../../src/Menu/context.ts"],"names":["createContext","useContext","menuContext","Provider","MenuProvider","useMenuContext","menuListContext","MenuListProvider","useMenuListContext"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA4D,OAA5D;AAmBA,MAAMC,WAAW,gBAAGF,aAAa,CAAmB,IAAnB,CAAjC;AACA,OAAO,MAAM;AAAEG,EAAAA,QAAQ,EAAEC;AAAZ,IAA6BF,WAAnC;AACP,OAAO,MAAMG,cAAc,GAAG,MAAMJ,UAAU,CAACC,WAAD,CAAvC,C,CAEP;;AAMA,MAAMI,eAAe,gBAAGN,aAAa,CAAuB,IAAvB,CAArC;AACA,OAAO,MAAMO,gBAAgB,GAAGD,eAAe,CAACH,QAAzC;AACP,OAAO,MAAMK,kBAAkB,GAAG,MAAMP,UAAU,CAACK,eAAD,CAA3C","sourcesContent":["import { createContext, useContext, MutableRefObject } from 'react';\n\nexport type ItemObject = { text: string; value: any; id: string | undefined };\n\n// MenuRoot\nexport interface MenuContextProps {\n buttonRef: MutableRefObject<HTMLButtonElement | null>;\n menuListIdRef: MutableRefObject<undefined | string>;\n openWithArrowKeyRef: MutableRefObject<string | null>;\n onChange?: (\n e:\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>\n | React.PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open: boolean;\n}\n\nconst menuContext = createContext<MenuContextProps>(null as any);\nexport const { Provider: MenuProvider } = menuContext;\nexport const useMenuContext = () => useContext(menuContext);\n\n// MenuList\nexport interface MenuListContextProps {\n navigationItem: HTMLElement | undefined;\n onNavigate: undefined | ((idx: HTMLElement) => void);\n}\n\nconst menuListContext = createContext<MenuListContextProps>(null as any);\nexport const MenuListProvider = menuListContext.Provider;\nexport const useMenuListContext = () => useContext(menuListContext);\n"],"file":"context.js"}
@@ -5,5 +5,6 @@ export interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {
5
5
  innerAs?: React.ElementType<any>;
6
6
  children?: React.ReactNode;
7
7
  label: React.ReactNode;
8
+ disabled?: boolean;
8
9
  }
9
10
  export declare const Tooltip: React.ForwardRefExoticComponent<TooltipProps & React.RefAttributes<HTMLDivElement>>;
@@ -2,16 +2,17 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
3
  import React, { forwardRef, cloneElement, Children } from 'react';
4
4
  import { useTooltip } from './useTooltip';
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
5
  import { Fragment as _Fragment } from "react/jsx-runtime";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
7
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
8
  export const Tooltip = /*#__PURE__*/forwardRef(function Tooltip(props, forwardedRef) {
9
9
  const {
10
10
  as: Comp = 'div',
11
11
  innerAs,
12
- children
12
+ children,
13
+ disabled = false
13
14
  } = props,
14
- otherProps = _objectWithoutPropertiesLoose(props, ["as", "innerAs", "children"]);
15
+ otherProps = _objectWithoutPropertiesLoose(props, ["as", "innerAs", "children", "disabled"]);
15
16
 
16
17
  const child = Children.only(children);
17
18
  const [childProps, _ref] = useTooltip(child.props, child.ref, otherProps);
@@ -21,6 +22,12 @@ export const Tooltip = /*#__PURE__*/forwardRef(function Tooltip(props, forwarded
21
22
  } = _ref,
22
23
  tooltipProps = _objectWithoutPropertiesLoose(_ref, ["visible"]);
23
24
 
25
+ if (disabled) {
26
+ return /*#__PURE__*/_jsx(_Fragment, {
27
+ children: child
28
+ });
29
+ }
30
+
24
31
  return /*#__PURE__*/_jsxs(_Fragment, {
25
32
  children: [/*#__PURE__*/cloneElement(child, childProps), visible && /*#__PURE__*/_jsx(Comp, _extends({
26
33
  as: innerAs,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Tooltip/Tooltip.tsx"],"names":["React","forwardRef","cloneElement","Children","useTooltip","Tooltip","props","forwardedRef","as","Comp","innerAs","children","otherProps","child","only","childProps","ref","visible","tooltipProps"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,UADF,EAEEC,YAFF,EAGEC,QAHF,QAMO,OANP;AAOA,SAASC,UAAT,QAA2B,cAA3B;;;;AAUA,OAAO,MAAMC,OAAO,gBAAGJ,UAAU,CAC/B,SAASI,OAAT,CAAiBC,KAAjB,EAAwBC,YAAxB,EAAsC;AACpC,QAAM;AAAEC,IAAAA,EAAE,EAAEC,IAAI,GAAG,KAAb;AAAoBC,IAAAA,OAApB;AAA6BC,IAAAA;AAA7B,MAAyDL,KAA/D;AAAA,QAAgDM,UAAhD,iCAA+DN,KAA/D;;AACA,QAAMO,KAAwC,GAAGV,QAAQ,CAACW,IAAT,CAC/CH,QAD+C,CAAjD;AAGA,QAAM,CAACI,UAAD,UAA6CX,UAAU,CAC3DS,KAAK,CAACP,KADqD,EAE3DO,KAAK,CAACG,GAFqD,EAG3DJ,UAH2D,CAA7D;;AALoC,QAKjB;AAAEK,IAAAA;AAAF,GALiB;AAAA,QAKHC,YALG;;AAWpC,sBACE;AAAA,4BACGhB,YAAY,CAACW,KAAD,EAAQE,UAAR,CADf,EAEGE,OAAO,iBAAI,KAAC,IAAD;AAAM,MAAA,EAAE,EAAEP,OAAV;AAAmB,MAAA,GAAG,EAAEH;AAAxB,OAA0CW,YAA1C,EAFd;AAAA,IADF;AAMD,CAlB8B,CAA1B","sourcesContent":["import React, {\n forwardRef,\n cloneElement,\n Children,\n ReactElement,\n RefAttributes,\n} from 'react';\nimport { useTooltip } from './useTooltip';\nexport type { InjectedTooltipProps } from './useTooltip';\n\nexport interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n children?: React.ReactNode;\n label: React.ReactNode;\n}\n\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(\n function Tooltip(props, forwardedRef) {\n const { as: Comp = 'div', innerAs, children, ...otherProps } = props;\n const child: ReactElement & RefAttributes<any> = Children.only(\n children\n ) as any;\n const [childProps, { visible, ...tooltipProps }] = useTooltip(\n child.props,\n child.ref,\n otherProps\n );\n\n return (\n <>\n {cloneElement(child, childProps)}\n {visible && <Comp as={innerAs} ref={forwardedRef} {...tooltipProps} />}\n </>\n );\n }\n);\n"],"file":"Tooltip.js"}
1
+ {"version":3,"sources":["../../../src/Tooltip/Tooltip.tsx"],"names":["React","forwardRef","cloneElement","Children","useTooltip","Tooltip","props","forwardedRef","as","Comp","innerAs","children","disabled","otherProps","child","only","childProps","ref","visible","tooltipProps"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,UADF,EAEEC,YAFF,EAGEC,QAHF,QAMO,OANP;AAOA,SAASC,UAAT,QAA2B,cAA3B;;;;AAWA,OAAO,MAAMC,OAAO,gBAAGJ,UAAU,CAC/B,SAASI,OAAT,CAAiBC,KAAjB,EAAwBC,YAAxB,EAAsC;AACpC,QAAM;AACJC,IAAAA,EAAE,EAAEC,IAAI,GAAG,KADP;AAEJC,IAAAA,OAFI;AAGJC,IAAAA,QAHI;AAIJC,IAAAA,QAAQ,GAAG;AAJP,MAMFN,KANJ;AAAA,QAKKO,UALL,iCAMIP,KANJ;;AAOA,QAAMQ,KAAwC,GAAGX,QAAQ,CAACY,IAAT,CAC/CJ,QAD+C,CAAjD;AAGA,QAAM,CAACK,UAAD,UAA6CZ,UAAU,CAC3DU,KAAK,CAACR,KADqD,EAE3DQ,KAAK,CAACG,GAFqD,EAG3DJ,UAH2D,CAA7D;;AAXoC,QAWjB;AAAEK,IAAAA;AAAF,GAXiB;AAAA,QAWHC,YAXG;;AAiBpC,MAAIP,QAAJ,EAAc;AACZ,wBAAO;AAAA,gBAAGE;AAAH,MAAP;AACD;;AAED,sBACE;AAAA,4BACGZ,YAAY,CAACY,KAAD,EAAQE,UAAR,CADf,EAEGE,OAAO,iBAAI,KAAC,IAAD;AAAM,MAAA,EAAE,EAAER,OAAV;AAAmB,MAAA,GAAG,EAAEH;AAAxB,OAA0CY,YAA1C,EAFd;AAAA,IADF;AAMD,CA5B8B,CAA1B","sourcesContent":["import React, {\n forwardRef,\n cloneElement,\n Children,\n ReactElement,\n RefAttributes,\n} from 'react';\nimport { useTooltip } from './useTooltip';\nexport type { InjectedTooltipProps } from './useTooltip';\n\nexport interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n children?: React.ReactNode;\n label: React.ReactNode;\n disabled?: boolean;\n}\n\nexport const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(\n function Tooltip(props, forwardedRef) {\n const {\n as: Comp = 'div',\n innerAs,\n children,\n disabled = false,\n ...otherProps\n } = props;\n const child: ReactElement & RefAttributes<any> = Children.only(\n children\n ) as any;\n const [childProps, { visible, ...tooltipProps }] = useTooltip(\n child.props,\n child.ref,\n otherProps\n );\n\n if (disabled) {\n return <>{child}</>;\n }\n\n return (\n <>\n {cloneElement(child, childProps)}\n {visible && <Comp as={innerAs} ref={forwardedRef} {...tooltipProps} />}\n </>\n );\n }\n);\n"],"file":"Tooltip.js"}
@@ -1,2 +1,3 @@
1
1
  export declare function useId(): string | undefined;
2
2
  export declare function useId(preferredId: string): string;
3
+ export declare function useId(preferredId: string | undefined): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useId.ts"],"names":["useEffect","useState","id","genId","useId","preferredId","setId"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC,C,CAEA;AACA;AACA;AACA;AACA;;AACA,IAAIC,EAAE,GAAG,CAAT;;AACA,MAAMC,KAAK,GAAG,gBAAS,EAAED,EAAX,CAAd;;AAIA,OAAO,SAASE,KAAT,CAAeC,WAAf,EAAyD;AAC9D,QAAM,CAACH,EAAD,EAAKI,KAAL,IAAcL,QAAQ,CAAqBI,WAArB,CAA5B;AACAL,EAAAA,SAAS,CAAC,MAAMM,KAAK,CAACH,KAAK,EAAN,CAAZ,EAAuB,EAAvB,CAAT;AACA,SAAOD,EAAP;AACD","sourcesContent":["import { useEffect, useState } from 'react';\n\n// Could use UUID but if we hit 9,007,199,254,740,991 unique components over\n// the lifetime of the app before it gets reloaded, I mean ... come on.\n// I don't even know what xillion that is.\n// /me googles\n// Oh duh, quadrillion. Nine quadrillion components. I think we're okay.\nlet id = 0;\nconst genId = () => `${++id}`;\n\nexport function useId(): string | undefined;\nexport function useId(preferredId: string): string;\nexport function useId(preferredId?: string): string | undefined {\n const [id, setId] = useState<string | undefined>(preferredId);\n useEffect(() => setId(genId()), []);\n return id;\n}\n"],"file":"useId.js"}
1
+ {"version":3,"sources":["../../../src/hooks/useId.ts"],"names":["useEffect","useState","id","genId","useId","preferredId","setId"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC,C,CAEA;AACA;AACA;AACA;AACA;;AACA,IAAIC,EAAE,GAAG,CAAT;;AACA,MAAMC,KAAK,GAAG,gBAAS,EAAED,EAAX,CAAd;;AAKA,OAAO,SAASE,KAAT,CAAeC,WAAf,EAAyD;AAC9D,QAAM,CAACH,EAAD,EAAKI,KAAL,IAAcL,QAAQ,CAAqBI,WAArB,CAA5B;AACAL,EAAAA,SAAS,CAAC,MAAMM,KAAK,CAACH,KAAK,EAAN,CAAZ,EAAuB,EAAvB,CAAT;AACA,SAAOD,EAAP;AACD","sourcesContent":["import { useEffect, useState } from 'react';\n\n// Could use UUID but if we hit 9,007,199,254,740,991 unique components over\n// the lifetime of the app before it gets reloaded, I mean ... come on.\n// I don't even know what xillion that is.\n// /me googles\n// Oh duh, quadrillion. Nine quadrillion components. I think we're okay.\nlet id = 0;\nconst genId = () => `${++id}`;\n\nexport function useId(): string | undefined;\nexport function useId(preferredId: string): string;\nexport function useId(preferredId: string | undefined): string | undefined;\nexport function useId(preferredId?: string): string | undefined {\n const [id, setId] = useState<string | undefined>(preferredId);\n useEffect(() => setId(genId()), []);\n return id;\n}\n"],"file":"useId.js"}
@@ -222,8 +222,8 @@
222
222
  "affectsGlobalScope": false
223
223
  },
224
224
  "../src/hooks/useId.ts": {
225
- "version": "3aff8f1b9d28a3f133f11ea23c9aa7e83dc051f0557c1a47bf5a27513a9359ba",
226
- "signature": "5f753254eec61774a16b087084c079d71fb3ed3e94fdec26d73bd554f3745694",
225
+ "version": "1a7828479e27b318235c2f8a8e191e2edea9699f0acf9187a539fd3e615217fd",
226
+ "signature": "d0039ab8d0f11055fe9b2797bce2c23bff51da16208a37b3468a053375f899c6",
227
227
  "affectsGlobalScope": false
228
228
  },
229
229
  "../src/hooks/useOnClickOutside.ts": {
@@ -377,7 +377,7 @@
377
377
  "affectsGlobalScope": false
378
378
  },
379
379
  "../src/FocusLock/useFocusLock.ts": {
380
- "version": "6af3eeda5891692678d5eb525846aeea71bb74a4e7a604e54699268047156cd5",
380
+ "version": "2e745a2d3bc594f57ee246139928d964f911bee65a600962b29e4d6ff4bc8bb9",
381
381
  "signature": "0e995946ab172b19c89aa7cae99b3621caf512baf3329b498af4ea5815364bd6",
382
382
  "affectsGlobalScope": false
383
383
  },
@@ -392,17 +392,17 @@
392
392
  "affectsGlobalScope": false
393
393
  },
394
394
  "../src/Menu/context.ts": {
395
- "version": "87a8f14255b6c1f0d7ff9544bec2b72c9d9dc9c596c2a8ad2638429835e572f0",
396
- "signature": "dd617fc2bf1dfc2b927ea0057d78011d45691aa611e0a19571f0763359c958d9",
395
+ "version": "98e1e4b4a113aa179de7b3540dffc374df0c464a2166a06fd2ea44b7cb0cb21c",
396
+ "signature": "0b45fab4552426ea20b40f69ba47bc1e4fbc01d3baf52cec4a155c002ac4d301",
397
397
  "affectsGlobalScope": false
398
398
  },
399
399
  "../src/Menu/Menu.tsx": {
400
- "version": "c456fbbaacddef01aba571bd24cd345332f99331196195391ae5a918b280b97a",
400
+ "version": "25bb03d525ae49b2b3b1867fb29df3d2d438c7ca63da8b56b4d556f2f07702cb",
401
401
  "signature": "de10bde1e882e042e2a6622b8cd3cc0b537677d8e78295e3d4d17b4492cbf8ef",
402
402
  "affectsGlobalScope": false
403
403
  },
404
404
  "../src/Menu/MenuButton.tsx": {
405
- "version": "b297806c4dcc5a26e1293a77d2d771dd24fe83343077b9f2e1a75c0ec2c8bb46",
405
+ "version": "4e542d0919ebf866e3bb668062328ee4b4abe3ed2a9e9070f20315a25a874a43",
406
406
  "signature": "c6e623e83418f6aa4970466032bef7ad0f9224f9137fde0633af29af5f352f96",
407
407
  "affectsGlobalScope": false
408
408
  },
@@ -417,7 +417,7 @@
417
417
  "affectsGlobalScope": false
418
418
  },
419
419
  "../src/Menu/MenuList.tsx": {
420
- "version": "dbf67ebb277a3cf2bcafe01b4b09f1874c545f3e223d43cfbea713e5bad7b9a2",
420
+ "version": "5dd9324e4ff07cd1b88d4df006aaaf96e78c93a4c9ff5e8fcef1de6ef379d992",
421
421
  "signature": "6a91df64c0e2f254a1b2d91dc53dca3b254365386a92e41c31e4171b06b5394c",
422
422
  "affectsGlobalScope": false
423
423
  },
@@ -667,8 +667,8 @@
667
667
  "affectsGlobalScope": false
668
668
  },
669
669
  "../src/Tooltip/Tooltip.tsx": {
670
- "version": "bf5ffe2d730baba8e9dfcc42c5df71332a824400b939622d58ffa6e8084e9fde",
671
- "signature": "c3ecbe9381c1aeeeef3343dd37ad2b80f8cc7fa2238ff8dd7ac60561587ee4af",
670
+ "version": "14279edaf9fca3ea5c1b5343281d6faea57697c15b21ec1447c3ca066d2d607d",
671
+ "signature": "7fddbed0e18f235aee9a915c705119570cc946ac13c740a64f2e0493690ee5e7",
672
672
  "affectsGlobalScope": false
673
673
  },
674
674
  "../src/Tooltip/index.ts": {
@@ -3768,7 +3768,7 @@
3768
3768
  "../../../node_modules/@types/node/util.d.ts",
3769
3769
  "../../../node_modules/@types/react/index.d.ts",
3770
3770
  "../src/Menu/context.ts",
3771
- "../src/utils/index.ts",
3771
+ "../src/hooks/index.ts",
3772
3772
  "../src/utils/wrapEvent.ts"
3773
3773
  ],
3774
3774
  "../src/Menu/MenuItem.tsx": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basic-ui/core",
3
- "version": "0.0.28",
3
+ "version": "0.0.32",
4
4
  "description": "Accessible React Components used as building blocks for UI patterns",
5
5
  "author": "Lucas Terra <lucasterra7@gmail.com>",
6
6
  "license": "MIT",
@@ -10,7 +10,8 @@
10
10
  "jsnext:main": "./build/esm/index.js",
11
11
  "types": "./build/esm/index.d.ts",
12
12
  "files": [
13
- "/build"
13
+ "/build",
14
+ "/src"
14
15
  ],
15
16
  "sideEffects": false,
16
17
  "scripts": {
@@ -36,5 +37,5 @@
36
37
  "react": ">=16.14.0 || >=17.0.0",
37
38
  "react-dom": ">=16.14.0 || >=17.0.0"
38
39
  },
39
- "gitHead": "4c51654a7aee5da72a9a716a86f10d3127002391"
40
+ "gitHead": "5d730ab4bfea19ceb7fb52d09139c81cb4c3863f"
40
41
  }
@@ -0,0 +1,72 @@
1
+ import { useState } from 'react';
2
+ import { Accordion, AccordionBody, AccordionHeader, AccordionItem } from './';
3
+ import { storiesOf } from '@storybook/react';
4
+ import './styles.css';
5
+
6
+ const stories = storiesOf('Components/Accordion', module);
7
+
8
+ function AccordionControlled() {
9
+ const [expandedId, setExpandedId] = useState(0);
10
+
11
+ return (
12
+ <Accordion
13
+ expandedIndex={expandedId}
14
+ onChange={(e, idx) => setExpandedId(idx)}
15
+ >
16
+ <AccordionItem>
17
+ <AccordionHeader>Personal information</AccordionHeader>
18
+ <AccordionBody>
19
+ <input type="text" placeholder="name" />
20
+ <input type="text" placeholder="email" />
21
+ <input type="text" placeholder="phone" />
22
+ <input type="text" placeholder="extension" />
23
+ <input type="text" placeholder="country" />
24
+ </AccordionBody>
25
+ </AccordionItem>
26
+ <AccordionItem>
27
+ <AccordionHeader>Billing address</AccordionHeader>
28
+ <AccordionBody>
29
+ <input type="text" placeholder="address" />
30
+ <input type="text" placeholder="address 2" />
31
+ <input type="text" placeholder="city" />
32
+ <input type="text" placeholder="state" />
33
+ <input type="text" placeholder="zip code" />
34
+ </AccordionBody>
35
+ </AccordionItem>
36
+ <AccordionItem>
37
+ <AccordionHeader>Shipping address</AccordionHeader>
38
+ <AccordionBody>
39
+ <input type="text" placeholder="address" />
40
+ <input type="text" placeholder="address 2" />
41
+ <input type="text" placeholder="city" />
42
+ <input type="text" placeholder="state" />
43
+ <input type="text" placeholder="zip code" />
44
+ </AccordionBody>
45
+ </AccordionItem>
46
+ </Accordion>
47
+ );
48
+ }
49
+
50
+ function SingleAccordionItem() {
51
+ const [expanded, setExpanded] = useState(false);
52
+
53
+ return (
54
+ <AccordionItem
55
+ expanded={expanded}
56
+ onChange={(e, value) => setExpanded(value)}
57
+ >
58
+ <AccordionHeader>Personal information</AccordionHeader>
59
+ <AccordionBody>
60
+ <input type="text" placeholder="name" />
61
+ <input type="text" placeholder="email" />
62
+ <input type="text" placeholder="phone" />
63
+ <input type="text" placeholder="extension" />
64
+ <input type="text" placeholder="country" />
65
+ </AccordionBody>
66
+ </AccordionItem>
67
+ );
68
+ }
69
+
70
+ stories.add('controlled', () => <AccordionControlled />);
71
+
72
+ stories.add('single accordion, controlled', () => <SingleAccordionItem />);
@@ -0,0 +1,51 @@
1
+ import { forwardRef, useRef, useState } from 'react';
2
+ import type * as React from 'react';
3
+ import { AccordionContextProps, AccordionProvider } from './context';
4
+ import { useScope } from '../hooks';
5
+ import { assignMultipleRefs } from '../utils';
6
+
7
+ export interface AccordionProps
8
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
9
+ as?: React.ElementType<any>;
10
+ innerAs?: React.ElementType<any>;
11
+ children?: React.ReactNode;
12
+ expandedIndex?: number;
13
+ onChange?: (
14
+ e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,
15
+ index: number
16
+ ) => void;
17
+ }
18
+
19
+ export const Accordion = forwardRef<HTMLDivElement, AccordionProps>(
20
+ function Accordion(props, forwardedRef) {
21
+ const {
22
+ as: Comp = 'div',
23
+ expandedIndex = -1,
24
+ onChange,
25
+ ...otherProps
26
+ } = props;
27
+ const [childrenHeaderHasFocus, setChildrenHeaderHasFocus] = useState(false);
28
+ const ref = useRef<HTMLDivElement>();
29
+
30
+ const scope = useScope(ref);
31
+
32
+ const contextValue: AccordionContextProps = {
33
+ childrenHeaderHasFocus,
34
+ setChildrenHeaderHasFocus,
35
+ scope,
36
+ expandedIndex,
37
+ onChange,
38
+ };
39
+
40
+ return (
41
+ <AccordionProvider value={contextValue}>
42
+ <Comp
43
+ ref={assignMultipleRefs(forwardedRef, ref)}
44
+ {...otherProps}
45
+ data-accordion-root=""
46
+ data-children-has-focus={childrenHeaderHasFocus}
47
+ />
48
+ </AccordionProvider>
49
+ );
50
+ }
51
+ );
@@ -0,0 +1,53 @@
1
+ import { forwardRef, useState, useEffect, useRef } from 'react';
2
+ import type * as React from 'react';
3
+ import { useAccordionItemContext, useAccordionContext } from './context';
4
+ import { bodyScopeQuery as scopeQuery } from './scopeQuery';
5
+ import { assignMultipleRefs } from '../utils';
6
+
7
+ export interface AccordionBodyProps
8
+ extends React.HTMLAttributes<HTMLDivElement> {
9
+ as?: React.ElementType<any>;
10
+ innerAs?: React.ElementType<any>;
11
+ }
12
+
13
+ export const AccordionBody = forwardRef<HTMLDivElement, AccordionBodyProps>(
14
+ function AccordionBody(props, forwardedRef) {
15
+ const { as: Comp = 'div', ...otherProps } = props;
16
+ const accordionItemContext = useAccordionItemContext();
17
+ const accordionContext = useAccordionContext();
18
+ const ref = useRef<HTMLDivElement>();
19
+ const [index, setIndex] = useState<number>();
20
+
21
+ if (!accordionItemContext) {
22
+ throw new Error('Missing parent <Accordion /> component');
23
+ }
24
+
25
+ useEffect(() => {
26
+ if (accordionContext) {
27
+ const allHeaders = accordionContext.scope.current.queryAllNodes(
28
+ scopeQuery
29
+ );
30
+
31
+ const index = allHeaders.findIndex((e) => e === ref.current);
32
+ setIndex(index);
33
+ }
34
+ }, [accordionContext]);
35
+
36
+ const expanded = Boolean(
37
+ accordionItemContext.expanded ||
38
+ (accordionContext && accordionContext.expandedIndex === index)
39
+ );
40
+
41
+ return (
42
+ <Comp
43
+ ref={assignMultipleRefs(forwardedRef, ref)}
44
+ {...otherProps}
45
+ aria-labelledby={accordionItemContext.headerId}
46
+ id={accordionItemContext.bodyId}
47
+ role="region"
48
+ data-accordion-body=""
49
+ hidden={expanded ? undefined : 'hidden'}
50
+ />
51
+ );
52
+ }
53
+ );