@doist/reactist 26.0.0 → 26.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/reactist.cjs.development.js +36 -9
- package/dist/reactist.cjs.development.js.map +1 -1
- package/dist/reactist.cjs.production.min.js +1 -1
- package/dist/reactist.cjs.production.min.js.map +1 -1
- package/es/alert/alert.js +6 -3
- package/es/alert/alert.js.map +1 -1
- package/es/alert/alert.module.css.js +1 -1
- package/es/menu/menu.js +17 -4
- package/es/menu/menu.js.map +1 -1
- package/es/tooltip/tooltip.js +14 -3
- package/es/tooltip/tooltip.js.map +1 -1
- package/lib/alert/alert.js +1 -1
- package/lib/alert/alert.js.map +1 -1
- package/lib/alert/alert.module.css.js +1 -1
- package/lib/menu/menu.js +1 -1
- package/lib/menu/menu.js.map +1 -1
- package/lib/tooltip/tooltip.d.ts +19 -2
- package/lib/tooltip/tooltip.js +1 -1
- package/lib/tooltip/tooltip.js.map +1 -1
- package/package.json +1 -1
- package/styles/alert.css +1 -1
- package/styles/alert.module.css.css +1 -1
- package/styles/index.css +1 -3
- package/styles/reactist.css +1 -1
package/es/alert/alert.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { getClassNames } from '../utils/responsive-props.js';
|
|
3
3
|
import { Box } from '../box/box.js';
|
|
4
|
-
import {
|
|
4
|
+
import { IconButton } from '../button/button.js';
|
|
5
5
|
import { Columns, Column } from '../columns/columns.js';
|
|
6
6
|
import { AlertIcon } from '../icons/alert-icon.js';
|
|
7
7
|
import { CloseIcon } from '../icons/close-icon.js';
|
|
@@ -30,10 +30,13 @@ function Alert({
|
|
|
30
30
|
className: modules_6205a58e.icon
|
|
31
31
|
})), /*#__PURE__*/React.createElement(Column, null, /*#__PURE__*/React.createElement(Box, {
|
|
32
32
|
paddingY: "xsmall",
|
|
33
|
-
paddingRight: onClose != null && closeLabel != null ? undefined : 'small'
|
|
33
|
+
paddingRight: onClose != null && closeLabel != null ? undefined : 'small',
|
|
34
|
+
display: "flex",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
className: modules_6205a58e.content
|
|
34
37
|
}, children)), onClose != null && closeLabel != null ? /*#__PURE__*/React.createElement(Column, {
|
|
35
38
|
width: "content"
|
|
36
|
-
}, /*#__PURE__*/React.createElement(
|
|
39
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
37
40
|
variant: "quaternary",
|
|
38
41
|
size: "small",
|
|
39
42
|
onClick: onClose,
|
package/es/alert/alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert.js","sources":["../../src/alert/alert.tsx"],"sourcesContent":["import * as React from 'react'\nimport { getClassNames } from '../utils/responsive-props'\nimport { Box } from '../box'\nimport {
|
|
1
|
+
{"version":3,"file":"alert.js","sources":["../../src/alert/alert.tsx"],"sourcesContent":["import * as React from 'react'\nimport { getClassNames } from '../utils/responsive-props'\nimport { Box } from '../box'\nimport { IconButton } from '../button'\nimport { Columns, Column } from '../columns'\n\nimport { AlertIcon } from '../icons/alert-icon'\nimport { CloseIcon } from '../icons/close-icon'\n\nimport styles from './alert.module.css'\n\nimport type { AlertTone } from '../utils/common-types'\n\ntype AllOrNone<T> = T | { [K in keyof T]?: never }\n\ntype AlertCloseProps = AllOrNone<{\n closeLabel: string\n onClose: () => void\n}>\n\ntype AlertProps = {\n id?: string\n children: React.ReactNode\n tone: AlertTone\n} & AlertCloseProps\n\nfunction Alert({ id, children, tone, closeLabel, onClose }: AlertProps) {\n return (\n <Box\n id={id}\n role=\"alert\"\n aria-live=\"polite\"\n borderRadius=\"full\"\n className={[styles.container, getClassNames(styles, 'tone', tone)]}\n >\n <Columns space=\"small\" alignY=\"center\">\n <Column width=\"content\">\n <AlertIcon tone={tone} className={styles.icon} />\n </Column>\n <Column>\n <Box\n paddingY=\"xsmall\"\n paddingRight={onClose != null && closeLabel != null ? undefined : 'small'}\n display=\"flex\"\n alignItems=\"center\"\n className={styles.content}\n >\n {children}\n </Box>\n </Column>\n {onClose != null && closeLabel != null ? (\n <Column width=\"content\">\n <IconButton\n variant=\"quaternary\"\n size=\"small\"\n onClick={onClose}\n aria-label={closeLabel}\n icon={<CloseIcon />}\n style={{\n // @ts-expect-error not sure how to make TypeScript understand custom CSS properties\n '--reactist-btn-hover-fill': 'transparent',\n }}\n />\n </Column>\n ) : null}\n </Columns>\n </Box>\n )\n}\n\nexport { Alert }\nexport type { AlertProps }\n"],"names":["Alert","id","children","tone","closeLabel","onClose","React","createElement","Box","role","borderRadius","className","styles","container","getClassNames","Columns","space","alignY","Column","width","AlertIcon","icon","paddingY","paddingRight","undefined","display","alignItems","content","IconButton","variant","size","onClick","CloseIcon","style"],"mappings":";;;;;;;;;AA0BA,SAASA,KAAT,CAAe;EAAEC,EAAF;EAAMC,QAAN;EAAgBC,IAAhB;EAAsBC,UAAtB;AAAkCC,EAAAA,OAAAA;AAAlC,CAAf,EAAsE;AAClE,EAAA,oBACIC,KAAA,CAAAC,aAAA,CAACC,GAAD,EAAI;AACAP,IAAAA,EAAE,EAAEA,EADJ;AAEAQ,IAAAA,IAAI,EAAC,OAFL;AAGU,IAAA,WAAA,EAAA,QAHV;AAIAC,IAAAA,YAAY,EAAC,MAJb;AAKAC,IAAAA,SAAS,EAAE,CAACC,gBAAM,CAACC,SAAR,EAAmBC,aAAa,CAACF,gBAAD,EAAS,MAAT,EAAiBT,IAAjB,CAAhC,CAAA;AALX,GAAJ,eAOIG,KAAC,CAAAC,aAAD,CAACQ,OAAD;AAASC,IAAAA,KAAK,EAAC;AAAQC,IAAAA,MAAM,EAAC,QAAA;GAA9B,eACIX,KAAA,CAAAC,aAAA,CAACW,MAAD,EAAO;AAACC,IAAAA,KAAK,EAAC,SAAA;AAAP,GAAP,eACIb,KAAA,CAAAC,aAAA,CAACa,SAAD,EAAU;AAACjB,IAAAA,IAAI,EAAEA,IAAP;IAAaQ,SAAS,EAAEC,gBAAM,CAACS,IAAAA;AAA/B,GAAV,CADJ,CADJ,eAIIf,KAAA,CAAAC,aAAA,CAACW,MAAD,EAAO,IAAP,eACIZ,KAAA,CAAAC,aAAA,CAACC,GAAD,EACI;AAAAc,IAAAA,QAAQ,EAAC,QAAT;IACAC,YAAY,EAAElB,OAAO,IAAI,IAAX,IAAmBD,UAAU,IAAI,IAAjC,GAAwCoB,SAAxC,GAAoD,OADlE;AAEAC,IAAAA,OAAO,EAAC,MAFR;AAGAC,IAAAA,UAAU,EAAC,QAHX;IAIAf,SAAS,EAAEC,gBAAM,CAACe,OAAAA;AAJlB,GADJ,EAOKzB,QAPL,CADJ,CAJJ,EAeKG,OAAO,IAAI,IAAX,IAAmBD,UAAU,IAAI,IAAjC,gBACGE,KAAC,CAAAC,aAAD,CAACW,MAAD,EAAQ;AAAAC,IAAAA,KAAK,EAAC,SAAA;AAAN,GAAR,eACIb,KAAC,CAAAC,aAAD,CAACqB,UAAD;AACIC,IAAAA,OAAO,EAAC;AACRC,IAAAA,IAAI,EAAC;AACLC,IAAAA,OAAO,EAAE1B;AAAO,IAAA,YAAA,EACJD;IACZiB,IAAI,eAAEf,mBAAA,CAAC0B,SAAD,EAAU,IAAV;AACNC,IAAAA,KAAK,EAAE;AACH;MACA,2BAA6B,EAAA,aAAA;AAF1B,KAAA;GANX,CADJ,CADH,GAcG,IA7BR,CAPJ,CADJ,CAAA;AAyCH;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var modules_6205a58e = {"container":"
|
|
1
|
+
var modules_6205a58e = {"container":"d6be7fe9","content":"ad8ace2f","icon":"ab71a9dc","tone-info":"_043941a6","tone-positive":"f34b89d4","tone-caution":"a069ea07","tone-critical":"e505aabb"};
|
|
2
2
|
|
|
3
3
|
export { modules_6205a58e as default };
|
|
4
4
|
//# sourceMappingURL=alert.module.css.js.map
|
package/es/menu/menu.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useMenuStore, MenuButton as MenuButton$1, Role, Portal, Menu as Menu$1,
|
|
|
6
6
|
const _excluded = ["children", "onItemSelect"],
|
|
7
7
|
_excluded2 = ["exceptionallySetClassName"],
|
|
8
8
|
_excluded3 = ["render"],
|
|
9
|
-
_excluded4 = ["exceptionallySetClassName", "modal"],
|
|
9
|
+
_excluded4 = ["exceptionallySetClassName", "modal", "flip"],
|
|
10
10
|
_excluded5 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName"],
|
|
11
11
|
_excluded6 = ["label", "children", "exceptionallySetClassName"];
|
|
12
12
|
const MenuContext = /*#__PURE__*/React.createContext({
|
|
@@ -15,6 +15,9 @@ const MenuContext = /*#__PURE__*/React.createContext({
|
|
|
15
15
|
getAnchorRect: null,
|
|
16
16
|
setAnchorRect: () => undefined
|
|
17
17
|
});
|
|
18
|
+
const SubMenuContext = /*#__PURE__*/React.createContext({
|
|
19
|
+
isSubMenu: false
|
|
20
|
+
});
|
|
18
21
|
/**
|
|
19
22
|
* Wrapper component to control a menu. It does not render anything, only providing the state
|
|
20
23
|
* management for the menu components inside it.
|
|
@@ -107,7 +110,8 @@ const ContextMenuTrigger = /*#__PURE__*/React.forwardRef(function ContextMenuTri
|
|
|
107
110
|
const MenuList = /*#__PURE__*/React.forwardRef(function MenuList(_ref4, ref) {
|
|
108
111
|
let {
|
|
109
112
|
exceptionallySetClassName,
|
|
110
|
-
modal = true
|
|
113
|
+
modal = true,
|
|
114
|
+
flip
|
|
111
115
|
} = _ref4,
|
|
112
116
|
props = _objectWithoutProperties(_ref4, _excluded4);
|
|
113
117
|
|
|
@@ -120,6 +124,9 @@ const MenuList = /*#__PURE__*/React.forwardRef(function MenuList(_ref4, ref) {
|
|
|
120
124
|
throw new Error('MenuList must be wrapped in <Menu/>');
|
|
121
125
|
}
|
|
122
126
|
|
|
127
|
+
const {
|
|
128
|
+
isSubMenu
|
|
129
|
+
} = React.useContext(SubMenuContext);
|
|
123
130
|
const isOpen = menuStore.useState('open');
|
|
124
131
|
return isOpen ? /*#__PURE__*/React.createElement(Portal, {
|
|
125
132
|
preserveTabOrder: true
|
|
@@ -130,7 +137,8 @@ const MenuList = /*#__PURE__*/React.forwardRef(function MenuList(_ref4, ref) {
|
|
|
130
137
|
ref: ref,
|
|
131
138
|
className: classNames('reactist_menulist', exceptionallySetClassName),
|
|
132
139
|
getAnchorRect: getAnchorRect != null ? getAnchorRect : undefined,
|
|
133
|
-
modal: modal
|
|
140
|
+
modal: modal,
|
|
141
|
+
flip: flip != null ? flip : isSubMenu ? 'bottom' : undefined
|
|
134
142
|
}))) : null;
|
|
135
143
|
});
|
|
136
144
|
/**
|
|
@@ -221,6 +229,9 @@ const SubMenu = /*#__PURE__*/React.forwardRef(function SubMenu({
|
|
|
221
229
|
}, [parentMenuHide, parentMenuItemSelect, onItemSelect]);
|
|
222
230
|
const [button, list] = React.Children.toArray(children);
|
|
223
231
|
const buttonElement = button;
|
|
232
|
+
const subMenuContextValue = React.useMemo(() => ({
|
|
233
|
+
isSubMenu: true
|
|
234
|
+
}), []);
|
|
224
235
|
return /*#__PURE__*/React.createElement(Menu, {
|
|
225
236
|
onItemSelect: handleSubItemSelect
|
|
226
237
|
}, /*#__PURE__*/React.createElement(MenuItem$1, {
|
|
@@ -228,7 +239,9 @@ const SubMenu = /*#__PURE__*/React.forwardRef(function SubMenu({
|
|
|
228
239
|
ref: ref,
|
|
229
240
|
hideOnClick: false,
|
|
230
241
|
render: buttonElement
|
|
231
|
-
}, buttonElement.props.children),
|
|
242
|
+
}, buttonElement.props.children), /*#__PURE__*/React.createElement(SubMenuContext.Provider, {
|
|
243
|
+
value: subMenuContextValue
|
|
244
|
+
}, list));
|
|
232
245
|
});
|
|
233
246
|
/**
|
|
234
247
|
* A way to semantically group some menu items.
|
package/es/menu/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","sources":["../../src/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\nimport {\n Portal,\n MenuStore,\n MenuStoreProps,\n useMenuStore,\n MenuProps as AriakitMenuProps,\n Menu as AriakitMenu,\n MenuGroup as AriakitMenuGroup,\n MenuItem as AriakitMenuItem,\n MenuItemProps as AriakitMenuItemProps,\n MenuButton as AriakitMenuButton,\n MenuButtonProps as AriakitMenuButtonProps,\n Role,\n RoleProps,\n} from '@ariakit/react'\n\nimport './menu.less'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype MenuContextState = {\n menuStore: MenuStore | null\n handleItemSelect?: (value: string | null | undefined) => void\n getAnchorRect: (() => { x: number; y: number }) | null\n setAnchorRect: (rect: { x: number; y: number } | null) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>({\n menuStore: null,\n handleItemSelect: () => undefined,\n getAnchorRect: null,\n setAnchorRect: () => undefined,\n})\n\n//\n// Menu\n//\n\ninterface MenuProps extends Omit<MenuStoreProps, 'visible'> {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const [anchorRect, setAnchorRect] = React.useState<{ x: number; y: number } | null>(null)\n const getAnchorRect = React.useMemo(() => (anchorRect ? () => anchorRect : null), [anchorRect])\n const menuStore = useMenuStore({ focusLoop: true, ...props })\n\n const value: MenuContextState = React.useMemo(\n () => ({ menuStore, handleItemSelect: onItemSelect, getAnchorRect, setAnchorRect }),\n [menuStore, onItemSelect, getAnchorRect, setAnchorRect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ninterface MenuButtonProps\n extends Omit<AriakitMenuButtonProps, 'store' | 'className' | 'as'>,\n ObfuscatedClassName {}\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuButton must be wrapped in <Menu/>')\n }\n return (\n <AriakitMenuButton\n {...props}\n store={menuStore}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// ContextMenuTrigger\n//\n\ninterface ContextMenuTriggerProps\n extends ObfuscatedClassName,\n React.HTMLAttributes<HTMLDivElement>,\n Pick<RoleProps, 'render'> {}\n\nconst ContextMenuTrigger = React.forwardRef<HTMLDivElement, ContextMenuTriggerProps>(\n function ContextMenuTrigger({ render, ...props }, ref) {\n const { setAnchorRect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('ContextMenuTrigger must be wrapped in <Menu/>')\n }\n\n const handleContextMenu = React.useCallback(\n function handleContextMenu(event: React.MouseEvent) {\n event.preventDefault()\n setAnchorRect({ x: event.clientX, y: event.clientY })\n menuStore.show()\n },\n [setAnchorRect, menuStore],\n )\n\n const isOpen = menuStore.useState('open')\n React.useEffect(() => {\n if (!isOpen) setAnchorRect(null)\n }, [isOpen, setAnchorRect])\n\n return <Role.div {...props} onContextMenu={handleContextMenu} ref={ref} render={render} />\n },\n)\n\n//\n// MenuList\n//\n\ninterface MenuListProps\n extends Omit<AriakitMenuProps, 'store' | 'className'>,\n ObfuscatedClassName {}\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuList(\n { exceptionallySetClassName, modal = true, ...props },\n ref,\n) {\n const { menuStore, getAnchorRect } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuList must be wrapped in <Menu/>')\n }\n\n const isOpen = menuStore.useState('open')\n\n return isOpen ? (\n <Portal preserveTabOrder>\n <AriakitMenu\n {...props}\n store={menuStore}\n gutter={8}\n shift={4}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n getAnchorRect={getAnchorRect ?? undefined}\n modal={modal}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ninterface MenuItemProps extends AriakitMenuItemProps, ObfuscatedClassName {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuItem must be wrapped in <Menu/>')\n }\n\n const { hide } = menuStore\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect?.(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <AriakitMenuItem\n {...props}\n store={menuStore}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </AriakitMenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('SubMenu must be wrapped in <Menu/>')\n }\n\n const { hide: parentMenuHide } = menuStore\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n onItemSelect?.(value)\n parentMenuItemSelect?.(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n const buttonElement = button as React.ReactElement<MenuButtonProps>\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n <AriakitMenuItem store={menuStore} ref={ref} hideOnClick={false} render={buttonElement}>\n {buttonElement.props.children}\n </AriakitMenuItem>\n {list}\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ninterface MenuGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>,\n ObfuscatedClassName {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = React.forwardRef<HTMLDivElement, MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuGroup must be wrapped in <Menu/>')\n }\n\n return (\n <AriakitMenuGroup\n {...props}\n ref={ref}\n store={menuStore}\n className={exceptionallySetClassName}\n >\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </AriakitMenuGroup>\n )\n})\n\nexport { ContextMenuTrigger, Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, MenuGroupProps }\n"],"names":["MenuContext","React","createContext","menuStore","handleItemSelect","undefined","getAnchorRect","setAnchorRect","Menu","children","onItemSelect","props","anchorRect","useState","useMemo","useMenuStore","_objectSpread","focusLoop","value","createElement","Provider","MenuButton","forwardRef","ref","exceptionallySetClassName","useContext","Error","AriakitMenuButton","store","className","classNames","ContextMenuTrigger","render","handleContextMenu","useCallback","event","preventDefault","x","clientX","y","clientY","show","isOpen","useEffect","Role","div","onContextMenu","MenuList","modal","Portal","preserveTabOrder","AriakitMenu","gutter","shift","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","onSelectResult","defaultPrevented","shouldClose","AriakitMenuItem","hideOnClick","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","button","list","Children","toArray","buttonElement","MenuGroup","label","AriakitMenuGroup","role"],"mappings":";;;;;;;;;;;AA6BA,MAAMA,WAAW,gBAAGC,KAAK,CAACC,aAAN,CAAsC;AACtDC,EAAAA,SAAS,EAAE,IAD2C;EAEtDC,gBAAgB,EAAE,MAAMC,SAF8B;AAGtDC,EAAAA,aAAa,EAAE,IAHuC;AAItDC,EAAAA,aAAa,EAAE,MAAMF,SAAAA;AAJiC,CAAtC,CAApB,CAAA;AA4BA;;;AAGG;;AACH,SAASG,IAAT,CAA6D,IAAA,EAAA;EAAA,IAA/C;IAAEC,QAAF;AAAYC,IAAAA,YAAAA;GAAmC,GAAA,IAAA;AAAA,MAAlBC,KAAkB,GAAA,wBAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;EACzD,MAAM,CAACC,UAAD,EAAaL,aAAb,CAAA,GAA8BN,KAAK,CAACY,QAAN,CAAgD,IAAhD,CAApC,CAAA;AACA,EAAA,MAAMP,aAAa,GAAGL,KAAK,CAACa,OAAN,CAAc,MAAOF,UAAU,GAAG,MAAMA,UAAT,GAAsB,IAArD,EAA4D,CAACA,UAAD,CAA5D,CAAtB,CAAA;EACA,MAAMT,SAAS,GAAGY,YAAY,CAAAC,cAAA,CAAA;AAAGC,IAAAA,SAAS,EAAE,IAAA;AAAd,GAAA,EAAuBN,KAAvB,CAA9B,CAAA,CAAA;AAEA,EAAA,MAAMO,KAAK,GAAqBjB,KAAK,CAACa,OAAN,CAC5B,OAAO;IAAEX,SAAF;AAAaC,IAAAA,gBAAgB,EAAEM,YAA/B;IAA6CJ,aAA7C;AAA4DC,IAAAA,aAAAA;GAAnE,CAD4B,EAE5B,CAACJ,SAAD,EAAYO,YAAZ,EAA0BJ,aAA1B,EAAyCC,aAAzC,CAF4B,CAAhC,CAAA;AAKA,EAAA,oBAAON,KAAA,CAAAkB,aAAA,CAACnB,WAAW,CAACoB,QAAb,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;AAAKyC,IAAAA,WAAW,EAAE;AAAOhC,IAAAA,MAAM,EAAEyC,aAAAA;GAAzE,EACKA,aAAa,CAAC9D,KAAd,CAAoBF,QADzB,CADJ,EAIK6D,IAJL,CADJ,CAAA;AAQH,CA9Be,EAAhB;AA6CA;;;;;AAKG;;AACGI,MAAAA,SAAS,gBAAGzE,KAAK,CAACqB,UAAN,CAAiD,SAASoD,SAAT,CAE/DnD,KAAAA,EAAAA,GAF+D,EAE5D;EAAA,IADH;IAAEoD,KAAF;IAASlE,QAAT;AAAmBe,IAAAA,yBAAAA;GAChB,GAAA,KAAA;AAAA,MAD8Cb,KAC9C,GAAA,wBAAA,CAAA,KAAA,EAAA,UAAA,CAAA,CAAA;;EAEH,MAAM;AAAER,IAAAA,SAAAA;AAAF,GAAA,GAAgBF,KAAK,CAACwB,UAAN,CAAiBzB,WAAjB,CAAtB,CAAA;;EACA,IAAI,CAACG,SAAL,EAAgB;AACZ,IAAA,MAAM,IAAIuB,KAAJ,CAAU,sCAAV,CAAN,CAAA;AACH,GAAA;;AAED,EAAA,oBACIzB,KAAC,CAAAkB,aAAD,CAACyD,WAAD,oCACQjE,KADR,CAAA,EAAA,EAAA,EAAA;AAEIY,IAAAA,GAAG,EAAEA,GAFT;AAGIK,IAAAA,KAAK,EAAEzB,SAHX;AAII0B,IAAAA,SAAS,EAAEL,yBAAAA;AAJf,GAAA,CAAA,EAMKmD,KAAK,gBACF1E,KAAK,CAAAkB,aAAL,CAAK,KAAL,EAAK;AAAA0D,IAAAA,IAAI,EAAC,cAAL;AAAoBhD,IAAAA,SAAS,EAAC,2BAAA;AAA9B,GAAL,EACK8C,KADL,CADE,GAIF,IAVR,EAWKlE,QAXL,CADJ,CAAA;AAeH,CAxBiB;;;;"}
|
|
1
|
+
{"version":3,"file":"menu.js","sources":["../../src/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\nimport {\n Portal,\n MenuStore,\n MenuStoreProps,\n useMenuStore,\n MenuProps as AriakitMenuProps,\n Menu as AriakitMenu,\n MenuGroup as AriakitMenuGroup,\n MenuItem as AriakitMenuItem,\n MenuItemProps as AriakitMenuItemProps,\n MenuButton as AriakitMenuButton,\n MenuButtonProps as AriakitMenuButtonProps,\n Role,\n RoleProps,\n} from '@ariakit/react'\n\nimport './menu.less'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype MenuContextState = {\n menuStore: MenuStore | null\n handleItemSelect?: (value: string | null | undefined) => void\n getAnchorRect: (() => { x: number; y: number }) | null\n setAnchorRect: (rect: { x: number; y: number } | null) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>({\n menuStore: null,\n handleItemSelect: () => undefined,\n getAnchorRect: null,\n setAnchorRect: () => undefined,\n})\n\nconst SubMenuContext = React.createContext<{ isSubMenu: boolean }>({ isSubMenu: false })\n\n//\n// Menu\n//\n\ninterface MenuProps extends Omit<MenuStoreProps, 'visible'> {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const [anchorRect, setAnchorRect] = React.useState<{ x: number; y: number } | null>(null)\n const getAnchorRect = React.useMemo(() => (anchorRect ? () => anchorRect : null), [anchorRect])\n const menuStore = useMenuStore({ focusLoop: true, ...props })\n\n const value: MenuContextState = React.useMemo(\n () => ({ menuStore, handleItemSelect: onItemSelect, getAnchorRect, setAnchorRect }),\n [menuStore, onItemSelect, getAnchorRect, setAnchorRect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ninterface MenuButtonProps\n extends Omit<AriakitMenuButtonProps, 'store' | 'className' | 'as'>,\n ObfuscatedClassName {}\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuButton must be wrapped in <Menu/>')\n }\n return (\n <AriakitMenuButton\n {...props}\n store={menuStore}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// ContextMenuTrigger\n//\n\ninterface ContextMenuTriggerProps\n extends ObfuscatedClassName,\n React.HTMLAttributes<HTMLDivElement>,\n Pick<RoleProps, 'render'> {}\n\nconst ContextMenuTrigger = React.forwardRef<HTMLDivElement, ContextMenuTriggerProps>(\n function ContextMenuTrigger({ render, ...props }, ref) {\n const { setAnchorRect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('ContextMenuTrigger must be wrapped in <Menu/>')\n }\n\n const handleContextMenu = React.useCallback(\n function handleContextMenu(event: React.MouseEvent) {\n event.preventDefault()\n setAnchorRect({ x: event.clientX, y: event.clientY })\n menuStore.show()\n },\n [setAnchorRect, menuStore],\n )\n\n const isOpen = menuStore.useState('open')\n React.useEffect(() => {\n if (!isOpen) setAnchorRect(null)\n }, [isOpen, setAnchorRect])\n\n return <Role.div {...props} onContextMenu={handleContextMenu} ref={ref} render={render} />\n },\n)\n\n//\n// MenuList\n//\n\ninterface MenuListProps\n extends Omit<AriakitMenuProps, 'store' | 'className'>,\n ObfuscatedClassName {}\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuList(\n { exceptionallySetClassName, modal = true, flip, ...props },\n ref,\n) {\n const { menuStore, getAnchorRect } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuList must be wrapped in <Menu/>')\n }\n\n const { isSubMenu } = React.useContext(SubMenuContext)\n\n const isOpen = menuStore.useState('open')\n\n return isOpen ? (\n <Portal preserveTabOrder>\n <AriakitMenu\n {...props}\n store={menuStore}\n gutter={8}\n shift={4}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n getAnchorRect={getAnchorRect ?? undefined}\n modal={modal}\n flip={flip ?? (isSubMenu ? 'bottom' : undefined)}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ninterface MenuItemProps extends AriakitMenuItemProps, ObfuscatedClassName {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuItem must be wrapped in <Menu/>')\n }\n\n const { hide } = menuStore\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect?.(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <AriakitMenuItem\n {...props}\n store={menuStore}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </AriakitMenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('SubMenu must be wrapped in <Menu/>')\n }\n\n const { hide: parentMenuHide } = menuStore\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n onItemSelect?.(value)\n parentMenuItemSelect?.(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n const buttonElement = button as React.ReactElement<MenuButtonProps>\n const subMenuContextValue = React.useMemo(() => ({ isSubMenu: true }), [])\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n <AriakitMenuItem store={menuStore} ref={ref} hideOnClick={false} render={buttonElement}>\n {buttonElement.props.children}\n </AriakitMenuItem>\n <SubMenuContext.Provider value={subMenuContextValue}>{list}</SubMenuContext.Provider>\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ninterface MenuGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>,\n ObfuscatedClassName {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = React.forwardRef<HTMLDivElement, MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuGroup must be wrapped in <Menu/>')\n }\n\n return (\n <AriakitMenuGroup\n {...props}\n ref={ref}\n store={menuStore}\n className={exceptionallySetClassName}\n >\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </AriakitMenuGroup>\n )\n})\n\nexport { ContextMenuTrigger, Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, MenuGroupProps }\n"],"names":["MenuContext","React","createContext","menuStore","handleItemSelect","undefined","getAnchorRect","setAnchorRect","SubMenuContext","isSubMenu","Menu","children","onItemSelect","props","anchorRect","useState","useMemo","useMenuStore","_objectSpread","focusLoop","value","createElement","Provider","MenuButton","forwardRef","ref","exceptionallySetClassName","useContext","Error","AriakitMenuButton","store","className","classNames","ContextMenuTrigger","render","handleContextMenu","useCallback","event","preventDefault","x","clientX","y","clientY","show","isOpen","useEffect","Role","div","onContextMenu","MenuList","modal","flip","Portal","preserveTabOrder","AriakitMenu","gutter","shift","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","onSelectResult","defaultPrevented","shouldClose","AriakitMenuItem","hideOnClick","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","button","list","Children","toArray","buttonElement","subMenuContextValue","MenuGroup","label","AriakitMenuGroup","role"],"mappings":";;;;;;;;;;;AA6BA,MAAMA,WAAW,gBAAGC,KAAK,CAACC,aAAN,CAAsC;AACtDC,EAAAA,SAAS,EAAE,IAD2C;EAEtDC,gBAAgB,EAAE,MAAMC,SAF8B;AAGtDC,EAAAA,aAAa,EAAE,IAHuC;AAItDC,EAAAA,aAAa,EAAE,MAAMF,SAAAA;AAJiC,CAAtC,CAApB,CAAA;AAOA,MAAMG,cAAc,gBAAGP,KAAK,CAACC,aAAN,CAA4C;AAAEO,EAAAA,SAAS,EAAE,KAAA;AAAb,CAA5C,CAAvB,CAAA;AAuBA;;;AAGG;;AACH,SAASC,IAAT,CAA6D,IAAA,EAAA;EAAA,IAA/C;IAAEC,QAAF;AAAYC,IAAAA,YAAAA;GAAmC,GAAA,IAAA;AAAA,MAAlBC,KAAkB,GAAA,wBAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;EACzD,MAAM,CAACC,UAAD,EAAaP,aAAb,CAAA,GAA8BN,KAAK,CAACc,QAAN,CAAgD,IAAhD,CAApC,CAAA;AACA,EAAA,MAAMT,aAAa,GAAGL,KAAK,CAACe,OAAN,CAAc,MAAOF,UAAU,GAAG,MAAMA,UAAT,GAAsB,IAArD,EAA4D,CAACA,UAAD,CAA5D,CAAtB,CAAA;EACA,MAAMX,SAAS,GAAGc,YAAY,CAAAC,cAAA,CAAA;AAAGC,IAAAA,SAAS,EAAE,IAAA;AAAd,GAAA,EAAuBN,KAAvB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,CAAA,KAAA,EAAA,UAAA,CAAA,CAAA;;EAEH,MAAM;AAAEV,IAAAA,SAAAA;AAAF,GAAA,GAAgBF,KAAK,CAAC0B,UAAN,CAAiB3B,WAAjB,CAAtB,CAAA;;EACA,IAAI,CAACG,SAAL,EAAgB;AACZ,IAAA,MAAM,IAAIyB,KAAJ,CAAU,sCAAV,CAAN,CAAA;AACH,GAAA;;AAED,EAAA,oBACI3B,KAAC,CAAAoB,aAAD,CAAC2D,WAAD,oCACQnE,KADR,CAAA,EAAA,EAAA,EAAA;AAEIY,IAAAA,GAAG,EAAEA,GAFT;AAGIK,IAAAA,KAAK,EAAE3B,SAHX;AAII4B,IAAAA,SAAS,EAAEL,yBAAAA;AAJf,GAAA,CAAA,EAMKqD,KAAK,gBACF9E,KAAK,CAAAoB,aAAL,CAAK,KAAL,EAAK;AAAA4D,IAAAA,IAAI,EAAC,cAAL;AAAoBlD,IAAAA,SAAS,EAAC,2BAAA;AAA9B,GAAL,EACKgD,KADL,CADE,GAIF,IAVR,EAWKpE,QAXL,CADJ,CAAA;AAeH,CAxBiB;;;;"}
|
package/es/tooltip/tooltip.js
CHANGED
|
@@ -3,18 +3,29 @@ import { useTooltipStore, TooltipAnchor, Tooltip as Tooltip$1, TooltipArrow } fr
|
|
|
3
3
|
import { Box } from '../box/box.js';
|
|
4
4
|
import modules_95f1407a from './tooltip.module.css.js';
|
|
5
5
|
|
|
6
|
+
const TooltipContext = /*#__PURE__*/React.createContext({
|
|
7
|
+
showTimeout: 500,
|
|
8
|
+
hideTimeout: 100
|
|
9
|
+
});
|
|
10
|
+
|
|
6
11
|
function Tooltip({
|
|
7
12
|
children,
|
|
8
13
|
content,
|
|
9
14
|
position = 'top',
|
|
10
15
|
gapSize = 3,
|
|
11
16
|
withArrow = false,
|
|
17
|
+
showTimeout,
|
|
18
|
+
hideTimeout,
|
|
12
19
|
exceptionallySetClassName
|
|
13
20
|
}) {
|
|
21
|
+
const {
|
|
22
|
+
showTimeout: globalShowTimeout,
|
|
23
|
+
hideTimeout: globalHideTimeout
|
|
24
|
+
} = React.useContext(TooltipContext);
|
|
14
25
|
const tooltip = useTooltipStore({
|
|
15
26
|
placement: position,
|
|
16
|
-
showTimeout:
|
|
17
|
-
hideTimeout:
|
|
27
|
+
showTimeout: showTimeout != null ? showTimeout : globalShowTimeout,
|
|
28
|
+
hideTimeout: hideTimeout != null ? hideTimeout : globalHideTimeout
|
|
18
29
|
});
|
|
19
30
|
const isOpen = tooltip.useState('open');
|
|
20
31
|
const child = React.Children.only(children);
|
|
@@ -48,5 +59,5 @@ function Tooltip({
|
|
|
48
59
|
}, withArrow ? /*#__PURE__*/React.createElement(TooltipArrow, null) : null, typeof content === 'function' ? content() : content) : null);
|
|
49
60
|
}
|
|
50
61
|
|
|
51
|
-
export { Tooltip };
|
|
62
|
+
export { Tooltip, TooltipContext };
|
|
52
63
|
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sources":["../../src/tooltip/tooltip.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n useTooltipStore,\n Tooltip as AriakitTooltip,\n TooltipAnchor,\n TooltipArrow,\n} from '@ariakit/react'\nimport { Box } from '../box'\n\nimport type { TooltipStoreState } from '@ariakit/react'\n\nimport styles from './tooltip.module.css'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ninterface TooltipProps extends ObfuscatedClassName {\n /**\n * The element that triggers the tooltip. Generally a button or link.\n *\n * It should be an interactive element accessible both via mouse and keyboard interactions.\n */\n children: React.ReactNode\n\n /**\n * The content to show in the tooltip.\n *\n * It can be rich content provided via React elements, or string content. It should not include\n * interactive elements inside it. This includes links or buttons.\n *\n * You can provide a function instead of the content itself. In this case, the function should\n * return the desired content. This is useful if the content is expensive to generate. It can\n * also be useful if the content dynamically changes often, so every time you trigger the\n * tooltip the content may have changed (e.g. if you show a ticking time clock in the tooltip).\n *\n * The trigger element will be associated to this content via `aria-describedby`. This means\n * that the tooltip content will be read by assistive technologies such as screen readers. It\n * will likely read this content right after reading the trigger element label.\n */\n content: React.ReactNode | (() => React.ReactNode)\n\n /**\n * How to place the tooltip relative to its trigger element.\n *\n * The possible values are \"top\", \"bottom\", \"left\", \"right\". Additionally, any of these values\n * can be combined with `-start` or `-end` for even more control. For instance `top-start` will\n * place the tooltip at the top, but with the start (e.g. left) side of the toolip and the\n * trigger aligned. If neither `-start` or `-end` are provided, the tooltip is centered along\n * the vertical or horizontal axis with the trigger.\n *\n * The position is enforced whenever possible, but tooltips can appear in different positions\n * if the specified one would make the tooltip intersect with the viewport edges.\n *\n * @default 'top'\n */\n position?: TooltipStoreState['placement']\n\n /**\n * The separation (in pixels) between the trigger element and the tooltip.\n * @default 3\n */\n gapSize?: number\n\n /**\n * Whether to show an arrow-like element attached to the tooltip, and pointing towards the\n * trigger element.\n * @default false\n */\n withArrow?: boolean\n}\n\nfunction Tooltip({\n children,\n content,\n position = 'top',\n gapSize = 3,\n withArrow = false,\n exceptionallySetClassName,\n}: TooltipProps) {\n const tooltip = useTooltipStore({
|
|
1
|
+
{"version":3,"file":"tooltip.js","sources":["../../src/tooltip/tooltip.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n useTooltipStore,\n Tooltip as AriakitTooltip,\n TooltipAnchor,\n TooltipArrow,\n} from '@ariakit/react'\nimport { Box } from '../box'\n\nimport type { TooltipStoreState } from '@ariakit/react'\n\nimport styles from './tooltip.module.css'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype TooltipContextState = {\n showTimeout: number\n hideTimeout: number\n}\n\nconst TooltipContext = React.createContext<TooltipContextState>({\n showTimeout: 500,\n hideTimeout: 100,\n})\n\ninterface TooltipProps extends ObfuscatedClassName {\n /**\n * The element that triggers the tooltip. Generally a button or link.\n *\n * It should be an interactive element accessible both via mouse and keyboard interactions.\n */\n children: React.ReactNode\n\n /**\n * The content to show in the tooltip.\n *\n * It can be rich content provided via React elements, or string content. It should not include\n * interactive elements inside it. This includes links or buttons.\n *\n * You can provide a function instead of the content itself. In this case, the function should\n * return the desired content. This is useful if the content is expensive to generate. It can\n * also be useful if the content dynamically changes often, so every time you trigger the\n * tooltip the content may have changed (e.g. if you show a ticking time clock in the tooltip).\n *\n * The trigger element will be associated to this content via `aria-describedby`. This means\n * that the tooltip content will be read by assistive technologies such as screen readers. It\n * will likely read this content right after reading the trigger element label.\n */\n content: React.ReactNode | (() => React.ReactNode)\n\n /**\n * How to place the tooltip relative to its trigger element.\n *\n * The possible values are \"top\", \"bottom\", \"left\", \"right\". Additionally, any of these values\n * can be combined with `-start` or `-end` for even more control. For instance `top-start` will\n * place the tooltip at the top, but with the start (e.g. left) side of the toolip and the\n * trigger aligned. If neither `-start` or `-end` are provided, the tooltip is centered along\n * the vertical or horizontal axis with the trigger.\n *\n * The position is enforced whenever possible, but tooltips can appear in different positions\n * if the specified one would make the tooltip intersect with the viewport edges.\n *\n * @default 'top'\n */\n position?: TooltipStoreState['placement']\n\n /**\n * The separation (in pixels) between the trigger element and the tooltip.\n * @default 3\n */\n gapSize?: number\n\n /**\n * Whether to show an arrow-like element attached to the tooltip, and pointing towards the\n * trigger element.\n * @default false\n */\n withArrow?: boolean\n\n /**\n * The amount of time in milliseconds to wait before showing the tooltip\n * Use `<TooltipContext.Provider>` to set a global value for all tooltips\n * @default 500\n */\n showTimeout?: number\n\n /**\n * The amount of time in milliseconds to wait before hiding the tooltip\n * Use `<TooltipContext.Provider>` to set a global value for all tooltips\n * @default 100\n */\n hideTimeout?: number\n}\n\nfunction Tooltip({\n children,\n content,\n position = 'top',\n gapSize = 3,\n withArrow = false,\n showTimeout,\n hideTimeout,\n exceptionallySetClassName,\n}: TooltipProps) {\n const { showTimeout: globalShowTimeout, hideTimeout: globalHideTimeout } = React.useContext(\n TooltipContext,\n )\n const tooltip = useTooltipStore({\n placement: position,\n showTimeout: showTimeout ?? globalShowTimeout,\n hideTimeout: hideTimeout ?? globalHideTimeout,\n })\n const isOpen = tooltip.useState('open')\n\n const child = React.Children.only(\n children as React.FunctionComponentElement<JSX.IntrinsicElements['div']> | null,\n )\n\n if (!child) {\n return child\n }\n\n if (typeof child.ref === 'string') {\n throw new Error('Tooltip: String refs cannot be used as they cannot be forwarded')\n }\n\n return (\n <>\n <TooltipAnchor render={child} store={tooltip} ref={child.ref} />\n {isOpen && content ? (\n <AriakitTooltip\n store={tooltip}\n gutter={gapSize}\n render={\n <Box\n className={[styles.tooltip, exceptionallySetClassName]}\n background=\"toast\"\n borderRadius=\"standard\"\n paddingX=\"small\"\n paddingY=\"xsmall\"\n maxWidth=\"medium\"\n width=\"fitContent\"\n overflow=\"hidden\"\n textAlign=\"center\"\n />\n }\n >\n {withArrow ? <TooltipArrow /> : null}\n {typeof content === 'function' ? content() : content}\n </AriakitTooltip>\n ) : null}\n </>\n )\n}\n\nexport type { TooltipProps }\nexport { Tooltip, TooltipContext }\n"],"names":["TooltipContext","React","createContext","showTimeout","hideTimeout","Tooltip","children","content","position","gapSize","withArrow","exceptionallySetClassName","globalShowTimeout","globalHideTimeout","useContext","tooltip","useTooltipStore","placement","isOpen","useState","child","Children","only","ref","Error","createElement","Fragment","TooltipAnchor","render","store","AriakitTooltip","gutter","Box","className","styles","background","borderRadius","paddingX","paddingY","maxWidth","width","overflow","textAlign","TooltipArrow"],"mappings":";;;;;AAoBA,MAAMA,cAAc,gBAAGC,KAAK,CAACC,aAAN,CAAyC;AAC5DC,EAAAA,WAAW,EAAE,GAD+C;AAE5DC,EAAAA,WAAW,EAAE,GAAA;AAF+C,CAAzC,EAAvB;;AA0EA,SAASC,OAAT,CAAiB;EACbC,QADa;EAEbC,OAFa;AAGbC,EAAAA,QAAQ,GAAG,KAHE;AAIbC,EAAAA,OAAO,GAAG,CAJG;AAKbC,EAAAA,SAAS,GAAG,KALC;EAMbP,WANa;EAObC,WAPa;AAQbO,EAAAA,yBAAAA;AARa,CAAjB,EASe;EACX,MAAM;AAAER,IAAAA,WAAW,EAAES,iBAAf;AAAkCR,IAAAA,WA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B,CADX;AAEAwB,MAAAA,UAAU,EAAC,OAFX;AAGAC,MAAAA,YAAY,EAAC,UAHb;AAIAC,MAAAA,QAAQ,EAAC,OAJT;AAKAC,MAAAA,QAAQ,EAAC,QALT;AAMAC,MAAAA,QAAQ,EAAC,QANT;AAOAC,MAAAA,KAAK,EAAC,YAPN;AAQAC,MAAAA,QAAQ,EAAC,QART;AASAC,MAAAA,SAAS,EAAC,QAAA;KATd,CAAA;GAJR,EAiBKhC,SAAS,gBAAGT,KAAA,CAAAwB,aAAA,CAACkB,YAAD,EAAgB,IAAhB,CAAH,GAAsB,IAjBpC,EAkBK,OAAOpC,OAAP,KAAmB,UAAnB,GAAgCA,OAAO,EAAvC,GAA4CA,OAlBjD,CADH,GAqBG,IAvBR,CADJ,CAAA;AA2BH;;;;"}
|
package/lib/alert/alert.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../utils/responsive-props.js"),l=require("../box/box.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../utils/responsive-props.js"),l=require("../box/box.js"),n=require("../button/button.js"),r=require("../columns/columns.js"),a=require("../icons/alert-icon.js"),o=require("../icons/close-icon.js"),s=require("./alert.module.css.js");function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(l){if("default"!==l){var n=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(t,l,n.get?n:{enumerable:!0,get:function(){return e[l]}})}})),t.default=e,t}var i=c(e);exports.Alert=function({id:e,children:c,tone:u,closeLabel:m,onClose:d}){return i.createElement(l.Box,{id:e,role:"alert","aria-live":"polite",borderRadius:"full",className:[s.default.container,t.getClassNames(s.default,"tone",u)]},i.createElement(r.Columns,{space:"small",alignY:"center"},i.createElement(r.Column,{width:"content"},i.createElement(a.AlertIcon,{tone:u,className:s.default.icon})),i.createElement(r.Column,null,i.createElement(l.Box,{paddingY:"xsmall",paddingRight:null!=d&&null!=m?void 0:"small",display:"flex",alignItems:"center",className:s.default.content},c)),null!=d&&null!=m?i.createElement(r.Column,{width:"content"},i.createElement(n.IconButton,{variant:"quaternary",size:"small",onClick:d,"aria-label":m,icon:i.createElement(o.CloseIcon,null),style:{"--reactist-btn-hover-fill":"transparent"}})):null))};
|
|
2
2
|
//# sourceMappingURL=alert.js.map
|
package/lib/alert/alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alert.js","sources":["../../src/alert/alert.tsx"],"sourcesContent":["import * as React from 'react'\nimport { getClassNames } from '../utils/responsive-props'\nimport { Box } from '../box'\nimport {
|
|
1
|
+
{"version":3,"file":"alert.js","sources":["../../src/alert/alert.tsx"],"sourcesContent":["import * as React from 'react'\nimport { getClassNames } from '../utils/responsive-props'\nimport { Box } from '../box'\nimport { IconButton } from '../button'\nimport { Columns, Column } from '../columns'\n\nimport { AlertIcon } from '../icons/alert-icon'\nimport { CloseIcon } from '../icons/close-icon'\n\nimport styles from './alert.module.css'\n\nimport type { AlertTone } from '../utils/common-types'\n\ntype AllOrNone<T> = T | { [K in keyof T]?: never }\n\ntype AlertCloseProps = AllOrNone<{\n closeLabel: string\n onClose: () => void\n}>\n\ntype AlertProps = {\n id?: string\n children: React.ReactNode\n tone: AlertTone\n} & AlertCloseProps\n\nfunction Alert({ id, children, tone, closeLabel, onClose }: AlertProps) {\n return (\n <Box\n id={id}\n role=\"alert\"\n aria-live=\"polite\"\n borderRadius=\"full\"\n className={[styles.container, getClassNames(styles, 'tone', tone)]}\n >\n <Columns space=\"small\" alignY=\"center\">\n <Column width=\"content\">\n <AlertIcon tone={tone} className={styles.icon} />\n </Column>\n <Column>\n <Box\n paddingY=\"xsmall\"\n paddingRight={onClose != null && closeLabel != null ? undefined : 'small'}\n display=\"flex\"\n alignItems=\"center\"\n className={styles.content}\n >\n {children}\n </Box>\n </Column>\n {onClose != null && closeLabel != null ? (\n <Column width=\"content\">\n <IconButton\n variant=\"quaternary\"\n size=\"small\"\n onClick={onClose}\n aria-label={closeLabel}\n icon={<CloseIcon />}\n style={{\n // @ts-expect-error not sure how to make TypeScript understand custom CSS properties\n '--reactist-btn-hover-fill': 'transparent',\n }}\n />\n </Column>\n ) : null}\n </Columns>\n </Box>\n )\n}\n\nexport { Alert }\nexport type { AlertProps }\n"],"names":["id","children","tone","closeLabel","onClose","React","createElement","Box","role","aria-live","borderRadius","className","styles","container","getClassNames","Columns","space","alignY","Column","width","AlertIcon","icon","paddingY","paddingRight","undefined","display","alignItems","content","IconButton","variant","size","onClick","aria-label","CloseIcon","style","--reactist-btn-hover-fill"],"mappings":"wnBA0BA,UAAeA,GAAEA,EAAFC,SAAMA,EAANC,KAAgBA,EAAhBC,WAAsBA,EAAtBC,QAAkCA,IAC7C,OACIC,EAAAC,cAACC,MAAG,CACAP,GAAIA,EACJQ,KAAK,QACKC,YAAA,SACVC,aAAa,OACbC,UAAW,CAACC,EAAAA,QAAOC,UAAWC,EAAaA,cAACF,UAAQ,OAAQV,KAE5DG,EAACC,cAAAS,WAAQC,MAAM,QAAQC,OAAO,UAC1BZ,EAAAC,cAACY,SAAM,CAACC,MAAM,WACVd,EAAAC,cAACc,YAAS,CAAClB,KAAMA,EAAMS,UAAWC,EAAM,QAACS,QAE7ChB,EAAAC,cAACY,EAAAA,OAAM,KACHb,EAAAC,cAACC,MACG,CAAAe,SAAS,SACTC,aAAyB,MAAXnB,GAAiC,MAAdD,OAAqBqB,EAAY,QAClEC,QAAQ,OACRC,WAAW,SACXf,UAAWC,EAAM,QAACe,SAEjB1B,IAGG,MAAXG,GAAiC,MAAdD,EAChBE,EAACC,cAAAY,SAAO,CAAAC,MAAM,WACVd,EAACC,cAAAsB,cACGC,QAAQ,aACRC,KAAK,QACLC,QAAS3B,EAAO4B,aACJ7B,EACZkB,KAAMhB,gBAAC4B,EAAAA,UAAS,MAChBC,MAAO,CAEHC,4BAA6B,kBAIzC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={container:"
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={container:"d6be7fe9",content:"ad8ace2f",icon:"ab71a9dc","tone-info":"_043941a6","tone-positive":"f34b89d4","tone-caution":"a069ea07","tone-critical":"e505aabb"};
|
|
2
2
|
//# sourceMappingURL=alert.module.css.js.map
|
package/lib/menu/menu.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),t=require("react"),r=require("classnames"),n=require("@ariakit/react");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,t}var u=l(t),c=o(r);const a=["children","onItemSelect"],s=["exceptionallySetClassName"],i=["render"],d=["exceptionallySetClassName","modal"],p=["value","children","onSelect","hideOnSelect","onClick","exceptionallySetClassName"],m=["label","children","exceptionallySetClassName"],f=u.createContext({menuStore:null,handleItemSelect:()=>{},getAnchorRect:null,setAnchorRect:()=>{}});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),t=require("react"),r=require("classnames"),n=require("@ariakit/react");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,t}var u=l(t),c=o(r);const a=["children","onItemSelect"],s=["exceptionallySetClassName"],i=["render"],d=["exceptionallySetClassName","modal","flip"],p=["value","children","onSelect","hideOnSelect","onClick","exceptionallySetClassName"],m=["label","children","exceptionallySetClassName"],f=u.createContext({menuStore:null,handleItemSelect:()=>{},getAnchorRect:null,setAnchorRect:()=>{}}),S=u.createContext({isSubMenu:!1});function b(t){let{children:r,onItemSelect:o}=t,l=e.objectWithoutProperties(t,a);const[c,s]=u.useState(null),i=u.useMemo(()=>c?()=>c:null,[c]),d=n.useMenuStore(e.objectSpread2({focusLoop:!0},l)),p=u.useMemo(()=>({menuStore:d,handleItemSelect:o,getAnchorRect:i,setAnchorRect:s}),[d,o,i,s]);return u.createElement(f.Provider,{value:p},r)}const h=u.forwardRef((function(t,r){let{exceptionallySetClassName:o}=t,l=e.objectWithoutProperties(t,s);const{menuStore:a}=u.useContext(f);if(!a)throw new Error("MenuButton must be wrapped in <Menu/>");return u.createElement(n.MenuButton,e.objectSpread2(e.objectSpread2({},l),{},{store:a,ref:r,className:c.default("reactist_menubutton",o)}))})),M=u.forwardRef((function(t,r){let{render:o}=t,l=e.objectWithoutProperties(t,i);const{setAnchorRect:c,menuStore:a}=u.useContext(f);if(!a)throw new Error("ContextMenuTrigger must be wrapped in <Menu/>");const s=u.useCallback((function(e){e.preventDefault(),c({x:e.clientX,y:e.clientY}),a.show()}),[c,a]),d=a.useState("open");return u.useEffect(()=>{d||c(null)},[d,c]),u.createElement(n.Role.div,e.objectSpread2(e.objectSpread2({},l),{},{onContextMenu:s,ref:r,render:o}))})),x=u.forwardRef((function(t,r){let{exceptionallySetClassName:o,modal:l=!0,flip:a}=t,s=e.objectWithoutProperties(t,d);const{menuStore:i,getAnchorRect:p}=u.useContext(f);if(!i)throw new Error("MenuList must be wrapped in <Menu/>");const{isSubMenu:m}=u.useContext(S);return i.useState("open")?u.createElement(n.Portal,{preserveTabOrder:!0},u.createElement(n.Menu,e.objectSpread2(e.objectSpread2({},s),{},{store:i,gutter:8,shift:4,ref:r,className:c.default("reactist_menulist",o),getAnchorRect:null!=p?p:void 0,modal:l,flip:null!=a?a:m?"bottom":void 0}))):null})),C=u.forwardRef((function(t,r){let{value:o,children:l,onSelect:c,hideOnSelect:a=!0,onClick:s,exceptionallySetClassName:i}=t,d=e.objectWithoutProperties(t,p);const{handleItemSelect:m,menuStore:S}=u.useContext(f);if(!S)throw new Error("MenuItem must be wrapped in <Menu/>");const{hide:b}=S,h=u.useCallback((function(e){null==s||s(e);const t=!1!==(c&&!e.defaultPrevented?c():void 0)&&a;null==m||m(o),t&&b()}),[c,s,m,a,b,o]);return u.createElement(n.MenuItem,e.objectSpread2(e.objectSpread2({},d),{},{store:S,ref:r,onClick:h,className:i,hideOnClick:!1}),l)})),w=u.forwardRef((function({children:e,onItemSelect:t},r){const{handleItemSelect:o,menuStore:l}=u.useContext(f);if(!l)throw new Error("SubMenu must be wrapped in <Menu/>");const{hide:c}=l,a=u.useCallback((function(e){null==t||t(e),null==o||o(e),c()}),[c,o,t]),[s,i]=u.Children.toArray(e),d=s,p=u.useMemo(()=>({isSubMenu:!0}),[]);return u.createElement(b,{onItemSelect:a},u.createElement(n.MenuItem,{store:l,ref:r,hideOnClick:!1,render:d},d.props.children),u.createElement(S.Provider,{value:p},i))})),j=u.forwardRef((function(t,r){let{label:o,children:l,exceptionallySetClassName:c}=t,a=e.objectWithoutProperties(t,m);const{menuStore:s}=u.useContext(f);if(!s)throw new Error("MenuGroup must be wrapped in <Menu/>");return u.createElement(n.MenuGroup,e.objectSpread2(e.objectSpread2({},a),{},{ref:r,store:s,className:c}),o?u.createElement("div",{role:"presentation",className:"reactist_menugroup__label"},o):null,l)}));exports.ContextMenuTrigger=M,exports.Menu=b,exports.MenuButton=h,exports.MenuGroup=j,exports.MenuItem=C,exports.MenuList=x,exports.SubMenu=w;
|
|
2
2
|
//# sourceMappingURL=menu.js.map
|
package/lib/menu/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","sources":["../../src/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\nimport {\n Portal,\n MenuStore,\n MenuStoreProps,\n useMenuStore,\n MenuProps as AriakitMenuProps,\n Menu as AriakitMenu,\n MenuGroup as AriakitMenuGroup,\n MenuItem as AriakitMenuItem,\n MenuItemProps as AriakitMenuItemProps,\n MenuButton as AriakitMenuButton,\n MenuButtonProps as AriakitMenuButtonProps,\n Role,\n RoleProps,\n} from '@ariakit/react'\n\nimport './menu.less'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype MenuContextState = {\n menuStore: MenuStore | null\n handleItemSelect?: (value: string | null | undefined) => void\n getAnchorRect: (() => { x: number; y: number }) | null\n setAnchorRect: (rect: { x: number; y: number } | null) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>({\n menuStore: null,\n handleItemSelect: () => undefined,\n getAnchorRect: null,\n setAnchorRect: () => undefined,\n})\n\n//\n// Menu\n//\n\ninterface MenuProps extends Omit<MenuStoreProps, 'visible'> {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const [anchorRect, setAnchorRect] = React.useState<{ x: number; y: number } | null>(null)\n const getAnchorRect = React.useMemo(() => (anchorRect ? () => anchorRect : null), [anchorRect])\n const menuStore = useMenuStore({ focusLoop: true, ...props })\n\n const value: MenuContextState = React.useMemo(\n () => ({ menuStore, handleItemSelect: onItemSelect, getAnchorRect, setAnchorRect }),\n [menuStore, onItemSelect, getAnchorRect, setAnchorRect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ninterface MenuButtonProps\n extends Omit<AriakitMenuButtonProps, 'store' | 'className' | 'as'>,\n ObfuscatedClassName {}\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuButton must be wrapped in <Menu/>')\n }\n return (\n <AriakitMenuButton\n {...props}\n store={menuStore}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// ContextMenuTrigger\n//\n\ninterface ContextMenuTriggerProps\n extends ObfuscatedClassName,\n React.HTMLAttributes<HTMLDivElement>,\n Pick<RoleProps, 'render'> {}\n\nconst ContextMenuTrigger = React.forwardRef<HTMLDivElement, ContextMenuTriggerProps>(\n function ContextMenuTrigger({ render, ...props }, ref) {\n const { setAnchorRect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('ContextMenuTrigger must be wrapped in <Menu/>')\n }\n\n const handleContextMenu = React.useCallback(\n function handleContextMenu(event: React.MouseEvent) {\n event.preventDefault()\n setAnchorRect({ x: event.clientX, y: event.clientY })\n menuStore.show()\n },\n [setAnchorRect, menuStore],\n )\n\n const isOpen = menuStore.useState('open')\n React.useEffect(() => {\n if (!isOpen) setAnchorRect(null)\n }, [isOpen, setAnchorRect])\n\n return <Role.div {...props} onContextMenu={handleContextMenu} ref={ref} render={render} />\n },\n)\n\n//\n// MenuList\n//\n\ninterface MenuListProps\n extends Omit<AriakitMenuProps, 'store' | 'className'>,\n ObfuscatedClassName {}\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuList(\n { exceptionallySetClassName, modal = true, ...props },\n ref,\n) {\n const { menuStore, getAnchorRect } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuList must be wrapped in <Menu/>')\n }\n\n const isOpen = menuStore.useState('open')\n\n return isOpen ? (\n <Portal preserveTabOrder>\n <AriakitMenu\n {...props}\n store={menuStore}\n gutter={8}\n shift={4}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n getAnchorRect={getAnchorRect ?? undefined}\n modal={modal}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ninterface MenuItemProps extends AriakitMenuItemProps, ObfuscatedClassName {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuItem must be wrapped in <Menu/>')\n }\n\n const { hide } = menuStore\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect?.(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <AriakitMenuItem\n {...props}\n store={menuStore}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </AriakitMenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('SubMenu must be wrapped in <Menu/>')\n }\n\n const { hide: parentMenuHide } = menuStore\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n onItemSelect?.(value)\n parentMenuItemSelect?.(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n const buttonElement = button as React.ReactElement<MenuButtonProps>\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n <AriakitMenuItem store={menuStore} ref={ref} hideOnClick={false} render={buttonElement}>\n {buttonElement.props.children}\n </AriakitMenuItem>\n {list}\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ninterface MenuGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>,\n ObfuscatedClassName {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = React.forwardRef<HTMLDivElement, MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuGroup must be wrapped in <Menu/>')\n }\n\n return (\n <AriakitMenuGroup\n {...props}\n ref={ref}\n store={menuStore}\n className={exceptionallySetClassName}\n >\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </AriakitMenuGroup>\n )\n})\n\nexport { ContextMenuTrigger, Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, MenuGroupProps }\n"],"names":["MenuContext","React","createContext","menuStore","handleItemSelect","getAnchorRect","setAnchorRect","Menu","_ref","children","onItemSelect","props","_objectWithoutProperties","objectWithoutProperties","_excluded","anchorRect","useState","useMemo","useMenuStore","_objectSpread","focusLoop","value","createElement","Provider","MenuButton","forwardRef","ref","exceptionallySetClassName","_ref2","_excluded2","useContext","Error","AriakitMenuButton","store","className","classNames","ContextMenuTrigger","render","_ref3","_excluded3","handleContextMenu","useCallback","event","preventDefault","x","clientX","y","clientY","show","isOpen","useEffect","Role","div","onContextMenu","MenuList","modal","_ref4","_excluded4","Portal","preserveTabOrder","AriakitMenu","gutter","shift","undefined","MenuItem","onSelect","hideOnSelect","onClick","_ref5","_excluded5","hide","handleClick","shouldClose","defaultPrevented","AriakitMenuItem","hideOnClick","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","button","list","Children","toArray","MenuGroup","label","_ref6","_excluded6","AriakitMenuGroup","role"],"mappings":"kzBA6BMA,EAAcC,EAAMC,cAAgC,CACtDC,UAAW,KACXC,iBAAkB,OAClBC,cAAe,KACfC,cAAe,SA4BnB,SAASC,EAAoDC,GAAA,IAA/CC,SAAEA,EAAFC,aAAYA,GAAmCF,EAAlBG,EAAkBC,EAAAC,wBAAAL,EAAAM,GACzD,MAAOC,EAAYT,GAAiBL,EAAMe,SAA0C,MAC9EX,EAAgBJ,EAAMgB,QAAQ,IAAOF,EAAa,IAAMA,EAAa,KAAO,CAACA,IAC7EZ,EAAYe,EAAYA,aAAAC,gBAAA,CAAGC,WAAW,GAAST,IAE/CU,EAA0BpB,EAAMgB,QAClC,KAAO,CAAEd,UAAAA,EAAWC,iBAAkBM,EAAcL,cAAAA,EAAeC,cAAAA,IACnE,CAACH,EAAWO,EAAcL,EAAeC,IAG7C,OAAOL,EAAAqB,cAACtB,EAAYuB,SAAQ,CAACF,MAAOA,GAAQZ,GAc1Ce,MAAAA,EAAavB,EAAMwB,YAA+C,SAEpEC,EAAAA,GAAG,IADHC,0BAAEA,GACCC,EAD6BjB,EAC7BC,EAAAC,wBAAAe,EAAAC,GAEH,MAAM1B,UAAEA,GAAcF,EAAM6B,WAAW9B,GACvC,IAAKG,EACD,MAAM,IAAI4B,MAAM,yCAEpB,OACI9B,EAACqB,cAAAU,gDACOrB,GADR,GAAA,CAEIsB,MAAO9B,EACPuB,IAAKA,EACLQ,UAAWC,EAAAA,QAAW,sBAAuBR,SAcnDS,EAAqBnC,EAAMwB,YAC7B,SAAkDC,EAAAA,GAAG,IAAzBW,OAAEA,GAAuBC,EAAZ3B,EAAYC,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vC,IAAKG,EACD,MAAM,IAAI4B,MAAM,wCAGpB,OACI9B,EAACqB,cAAAkE,+CACO7E,GADR,GAAA,CAEIe,IAAKA,EACLO,MAAO9B,EACP+B,UAAWP,IAEV0D,EACGpF,EAAKqB,cAAA,MAAA,CAAAmE,KAAK,eAAevD,UAAU,6BAC9BmD,GAEL,KACH5E"}
|
|
1
|
+
{"version":3,"file":"menu.js","sources":["../../src/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\nimport {\n Portal,\n MenuStore,\n MenuStoreProps,\n useMenuStore,\n MenuProps as AriakitMenuProps,\n Menu as AriakitMenu,\n MenuGroup as AriakitMenuGroup,\n MenuItem as AriakitMenuItem,\n MenuItemProps as AriakitMenuItemProps,\n MenuButton as AriakitMenuButton,\n MenuButtonProps as AriakitMenuButtonProps,\n Role,\n RoleProps,\n} from '@ariakit/react'\n\nimport './menu.less'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype MenuContextState = {\n menuStore: MenuStore | null\n handleItemSelect?: (value: string | null | undefined) => void\n getAnchorRect: (() => { x: number; y: number }) | null\n setAnchorRect: (rect: { x: number; y: number } | null) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>({\n menuStore: null,\n handleItemSelect: () => undefined,\n getAnchorRect: null,\n setAnchorRect: () => undefined,\n})\n\nconst SubMenuContext = React.createContext<{ isSubMenu: boolean }>({ isSubMenu: false })\n\n//\n// Menu\n//\n\ninterface MenuProps extends Omit<MenuStoreProps, 'visible'> {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const [anchorRect, setAnchorRect] = React.useState<{ x: number; y: number } | null>(null)\n const getAnchorRect = React.useMemo(() => (anchorRect ? () => anchorRect : null), [anchorRect])\n const menuStore = useMenuStore({ focusLoop: true, ...props })\n\n const value: MenuContextState = React.useMemo(\n () => ({ menuStore, handleItemSelect: onItemSelect, getAnchorRect, setAnchorRect }),\n [menuStore, onItemSelect, getAnchorRect, setAnchorRect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ninterface MenuButtonProps\n extends Omit<AriakitMenuButtonProps, 'store' | 'className' | 'as'>,\n ObfuscatedClassName {}\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuButton must be wrapped in <Menu/>')\n }\n return (\n <AriakitMenuButton\n {...props}\n store={menuStore}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// ContextMenuTrigger\n//\n\ninterface ContextMenuTriggerProps\n extends ObfuscatedClassName,\n React.HTMLAttributes<HTMLDivElement>,\n Pick<RoleProps, 'render'> {}\n\nconst ContextMenuTrigger = React.forwardRef<HTMLDivElement, ContextMenuTriggerProps>(\n function ContextMenuTrigger({ render, ...props }, ref) {\n const { setAnchorRect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('ContextMenuTrigger must be wrapped in <Menu/>')\n }\n\n const handleContextMenu = React.useCallback(\n function handleContextMenu(event: React.MouseEvent) {\n event.preventDefault()\n setAnchorRect({ x: event.clientX, y: event.clientY })\n menuStore.show()\n },\n [setAnchorRect, menuStore],\n )\n\n const isOpen = menuStore.useState('open')\n React.useEffect(() => {\n if (!isOpen) setAnchorRect(null)\n }, [isOpen, setAnchorRect])\n\n return <Role.div {...props} onContextMenu={handleContextMenu} ref={ref} render={render} />\n },\n)\n\n//\n// MenuList\n//\n\ninterface MenuListProps\n extends Omit<AriakitMenuProps, 'store' | 'className'>,\n ObfuscatedClassName {}\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = React.forwardRef<HTMLDivElement, MenuListProps>(function MenuList(\n { exceptionallySetClassName, modal = true, flip, ...props },\n ref,\n) {\n const { menuStore, getAnchorRect } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuList must be wrapped in <Menu/>')\n }\n\n const { isSubMenu } = React.useContext(SubMenuContext)\n\n const isOpen = menuStore.useState('open')\n\n return isOpen ? (\n <Portal preserveTabOrder>\n <AriakitMenu\n {...props}\n store={menuStore}\n gutter={8}\n shift={4}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n getAnchorRect={getAnchorRect ?? undefined}\n modal={modal}\n flip={flip ?? (isSubMenu ? 'bottom' : undefined)}\n />\n </Portal>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ninterface MenuItemProps extends AriakitMenuItemProps, ObfuscatedClassName {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuItem must be wrapped in <Menu/>')\n }\n\n const { hide } = menuStore\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect?.(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <AriakitMenuItem\n {...props}\n store={menuStore}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n hideOnClick={false}\n >\n {children}\n </AriakitMenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLDivElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('SubMenu must be wrapped in <Menu/>')\n }\n\n const { hide: parentMenuHide } = menuStore\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value: string | null | undefined) {\n onItemSelect?.(value)\n parentMenuItemSelect?.(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n const buttonElement = button as React.ReactElement<MenuButtonProps>\n const subMenuContextValue = React.useMemo(() => ({ isSubMenu: true }), [])\n\n return (\n <Menu onItemSelect={handleSubItemSelect}>\n <AriakitMenuItem store={menuStore} ref={ref} hideOnClick={false} render={buttonElement}>\n {buttonElement.props.children}\n </AriakitMenuItem>\n <SubMenuContext.Provider value={subMenuContextValue}>{list}</SubMenuContext.Provider>\n </Menu>\n )\n})\n\n//\n// MenuGroup\n//\n\ninterface MenuGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'className'>,\n ObfuscatedClassName {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = React.forwardRef<HTMLDivElement, MenuGroupProps>(function MenuGroup(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { menuStore } = React.useContext(MenuContext)\n if (!menuStore) {\n throw new Error('MenuGroup must be wrapped in <Menu/>')\n }\n\n return (\n <AriakitMenuGroup\n {...props}\n ref={ref}\n store={menuStore}\n className={exceptionallySetClassName}\n >\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </AriakitMenuGroup>\n )\n})\n\nexport { ContextMenuTrigger, Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, MenuGroupProps }\n"],"names":["MenuContext","React","createContext","menuStore","handleItemSelect","getAnchorRect","setAnchorRect","SubMenuContext","isSubMenu","Menu","_ref","children","onItemSelect","props","_objectWithoutProperties","objectWithoutProperties","_excluded","anchorRect","useState","useMemo","useMenuStore","_objectSpread","focusLoop","value","createElement","Provider","MenuButton","forwardRef","ref","exceptionallySetClassName","_ref2","_excluded2","useContext","Error","AriakitMenuButton","store","className","classNames","ContextMenuTrigger","render","_ref3","_excluded3","handleContextMenu","useCallback","event","preventDefault","x","clientX","y","clientY","show","isOpen","useEffect","Role","div","onContextMenu","MenuList","modal","flip","_ref4","_excluded4","Portal","preserveTabOrder","AriakitMenu","gutter","shift","undefined","MenuItem","onSelect","hideOnSelect","onClick","_ref5","_excluded5","hide","handleClick","shouldClose","defaultPrevented","AriakitMenuItem","hideOnClick","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","button","list","Children","toArray","buttonElement","subMenuContextValue","MenuGroup","label","_ref6","_excluded6","AriakitMenuGroup","role"],"mappings":"yzBA6BMA,EAAcC,EAAMC,cAAgC,CACtDC,UAAW,KACXC,iBAAkB,OAClBC,cAAe,KACfC,cAAe,SAGbC,EAAiBN,EAAMC,cAAsC,CAAEM,WAAW,IA2BhF,SAASC,EAAoDC,GAAA,IAA/CC,SAAEA,EAAFC,aAAYA,GAAmCF,EAAlBG,EAAkBC,EAAAC,wBAAAL,EAAAM,GACzD,MAAOC,EAAYX,GAAiBL,EAAMiB,SAA0C,MAC9Eb,EAAgBJ,EAAMkB,QAAQ,IAAOF,EAAa,IAAMA,EAAa,KAAO,CAACA,IAC7Ed,EAAYiB,EAAYA,aAAAC,gBAAA,CAAGC,WAAW,GAAST,IAE/CU,EAA0BtB,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C,aAAYA,GACZgB,GAEA,MAAQxB,iBAAkB4E,EAApB7E,UAA0CA,GAAcF,EAAM+B,WAAWhC,GAC/E,IAAKG,EACD,MAAM,IAAI8B,MAAM,sCAGpB,MAAQwC,KAAMQ,GAAmB9E,EAC3B+E,EAAsBjF,EAAM0C,aAC9B,SAA6BpB,GACzB,MAAAX,GAAAA,EAAeW,GACf,MAAAyD,GAAAA,EAAuBzD,GACvB0D,MAEJ,CAACA,EAAgBD,EAAsBpE,KAGpCuE,EAAQC,GAAQnF,EAAMoF,SAASC,QAAQ3E,GACxC4E,EAAgBJ,EAChBK,EAAsBvF,EAAMkB,QAAQ,KAAO,CAAEX,WAAW,IAAS,IAEvE,OACIP,EAACuB,cAAAf,EAAK,CAAAG,aAAcsE,GAChBjF,EAACuB,cAAAqD,YAAgB1C,MAAOhC,EAAWyB,IAAKA,EAAKkD,aAAa,EAAOvC,OAAQgD,GACpEA,EAAc1E,MAAMF,UAEzBV,EAAAuB,cAACjB,EAAekB,SAAQ,CAACF,MAAOiE,GAAsBJ,OAwB5DK,EAAYxF,EAAM0B,YAA2C,SAE/DC,EAAAA,GAAG,IADH8D,MAAEA,EAAF/E,SAASA,EAATkB,0BAAmBA,GAChB8D,EAD8C9E,EAC9CC,EAAAC,wBAAA4E,EAAAC,GAEH,MAAMzF,UAAEA,GAAcF,EAAM+B,WAAWhC,GACvC,IAAKG,EACD,MAAM,IAAI8B,MAAM,wCAGpB,OACIhC,EAACuB,cAAAqE,+CACOhF,GADR,GAAA,CAEIe,IAAKA,EACLO,MAAOhC,EACPiC,UAAWP,IAEV6D,EACGzF,EAAKuB,cAAA,MAAA,CAAAsE,KAAK,eAAe1D,UAAU,6BAC9BsD,GAEL,KACH/E"}
|
package/lib/tooltip/tooltip.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { TooltipStoreState } from '@ariakit/react';
|
|
3
3
|
import type { ObfuscatedClassName } from '../utils/common-types';
|
|
4
|
+
type TooltipContextState = {
|
|
5
|
+
showTimeout: number;
|
|
6
|
+
hideTimeout: number;
|
|
7
|
+
};
|
|
8
|
+
declare const TooltipContext: React.Context<TooltipContextState>;
|
|
4
9
|
interface TooltipProps extends ObfuscatedClassName {
|
|
5
10
|
/**
|
|
6
11
|
* The element that triggers the tooltip. Generally a button or link.
|
|
@@ -50,7 +55,19 @@ interface TooltipProps extends ObfuscatedClassName {
|
|
|
50
55
|
* @default false
|
|
51
56
|
*/
|
|
52
57
|
withArrow?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The amount of time in milliseconds to wait before showing the tooltip
|
|
60
|
+
* Use `<TooltipContext.Provider>` to set a global value for all tooltips
|
|
61
|
+
* @default 500
|
|
62
|
+
*/
|
|
63
|
+
showTimeout?: number;
|
|
64
|
+
/**
|
|
65
|
+
* The amount of time in milliseconds to wait before hiding the tooltip
|
|
66
|
+
* Use `<TooltipContext.Provider>` to set a global value for all tooltips
|
|
67
|
+
* @default 100
|
|
68
|
+
*/
|
|
69
|
+
hideTimeout?: number;
|
|
53
70
|
}
|
|
54
|
-
declare function Tooltip({ children, content, position, gapSize, withArrow, exceptionallySetClassName, }: TooltipProps): React.JSX.Element | null;
|
|
71
|
+
declare function Tooltip({ children, content, position, gapSize, withArrow, showTimeout, hideTimeout, exceptionallySetClassName, }: TooltipProps): React.JSX.Element | null;
|
|
55
72
|
export type { TooltipProps };
|
|
56
|
-
export { Tooltip };
|
|
73
|
+
export { Tooltip, TooltipContext };
|
package/lib/tooltip/tooltip.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@ariakit/react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@ariakit/react"),o=require("../box/box.js"),r=require("./tooltip.module.css.js");function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,t}var i=n(e);const l=i.createContext({showTimeout:500,hideTimeout:100});exports.Tooltip=function({children:e,content:n,position:u="top",gapSize:a=3,withArrow:s=!1,showTimeout:c,hideTimeout:d,exceptionallySetClassName:p}){const{showTimeout:f,hideTimeout:m}=i.useContext(l),h=t.useTooltipStore({placement:u,showTimeout:null!=c?c:f,hideTimeout:null!=d?d:m}),T=h.useState("open"),w=i.Children.only(e);if(!w)return w;if("string"==typeof w.ref)throw new Error("Tooltip: String refs cannot be used as they cannot be forwarded");return i.createElement(i.Fragment,null,i.createElement(t.TooltipAnchor,{render:w,store:h,ref:w.ref}),T&&n?i.createElement(t.Tooltip,{store:h,gutter:a,render:i.createElement(o.Box,{className:[r.default.tooltip,p],background:"toast",borderRadius:"standard",paddingX:"small",paddingY:"xsmall",maxWidth:"medium",width:"fitContent",overflow:"hidden",textAlign:"center"})},s?i.createElement(t.TooltipArrow,null):null,"function"==typeof n?n():n):null)},exports.TooltipContext=l;
|
|
2
2
|
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sources":["../../src/tooltip/tooltip.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n useTooltipStore,\n Tooltip as AriakitTooltip,\n TooltipAnchor,\n TooltipArrow,\n} from '@ariakit/react'\nimport { Box } from '../box'\n\nimport type { TooltipStoreState } from '@ariakit/react'\n\nimport styles from './tooltip.module.css'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ninterface TooltipProps extends ObfuscatedClassName {\n /**\n * The element that triggers the tooltip. Generally a button or link.\n *\n * It should be an interactive element accessible both via mouse and keyboard interactions.\n */\n children: React.ReactNode\n\n /**\n * The content to show in the tooltip.\n *\n * It can be rich content provided via React elements, or string content. It should not include\n * interactive elements inside it. This includes links or buttons.\n *\n * You can provide a function instead of the content itself. In this case, the function should\n * return the desired content. This is useful if the content is expensive to generate. It can\n * also be useful if the content dynamically changes often, so every time you trigger the\n * tooltip the content may have changed (e.g. if you show a ticking time clock in the tooltip).\n *\n * The trigger element will be associated to this content via `aria-describedby`. This means\n * that the tooltip content will be read by assistive technologies such as screen readers. It\n * will likely read this content right after reading the trigger element label.\n */\n content: React.ReactNode | (() => React.ReactNode)\n\n /**\n * How to place the tooltip relative to its trigger element.\n *\n * The possible values are \"top\", \"bottom\", \"left\", \"right\". Additionally, any of these values\n * can be combined with `-start` or `-end` for even more control. For instance `top-start` will\n * place the tooltip at the top, but with the start (e.g. left) side of the toolip and the\n * trigger aligned. If neither `-start` or `-end` are provided, the tooltip is centered along\n * the vertical or horizontal axis with the trigger.\n *\n * The position is enforced whenever possible, but tooltips can appear in different positions\n * if the specified one would make the tooltip intersect with the viewport edges.\n *\n * @default 'top'\n */\n position?: TooltipStoreState['placement']\n\n /**\n * The separation (in pixels) between the trigger element and the tooltip.\n * @default 3\n */\n gapSize?: number\n\n /**\n * Whether to show an arrow-like element attached to the tooltip, and pointing towards the\n * trigger element.\n * @default false\n */\n withArrow?: boolean\n}\n\nfunction Tooltip({\n children,\n content,\n position = 'top',\n gapSize = 3,\n withArrow = false,\n exceptionallySetClassName,\n}: TooltipProps) {\n const tooltip = useTooltipStore({
|
|
1
|
+
{"version":3,"file":"tooltip.js","sources":["../../src/tooltip/tooltip.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n useTooltipStore,\n Tooltip as AriakitTooltip,\n TooltipAnchor,\n TooltipArrow,\n} from '@ariakit/react'\nimport { Box } from '../box'\n\nimport type { TooltipStoreState } from '@ariakit/react'\n\nimport styles from './tooltip.module.css'\nimport type { ObfuscatedClassName } from '../utils/common-types'\n\ntype TooltipContextState = {\n showTimeout: number\n hideTimeout: number\n}\n\nconst TooltipContext = React.createContext<TooltipContextState>({\n showTimeout: 500,\n hideTimeout: 100,\n})\n\ninterface TooltipProps extends ObfuscatedClassName {\n /**\n * The element that triggers the tooltip. Generally a button or link.\n *\n * It should be an interactive element accessible both via mouse and keyboard interactions.\n */\n children: React.ReactNode\n\n /**\n * The content to show in the tooltip.\n *\n * It can be rich content provided via React elements, or string content. It should not include\n * interactive elements inside it. This includes links or buttons.\n *\n * You can provide a function instead of the content itself. In this case, the function should\n * return the desired content. This is useful if the content is expensive to generate. It can\n * also be useful if the content dynamically changes often, so every time you trigger the\n * tooltip the content may have changed (e.g. if you show a ticking time clock in the tooltip).\n *\n * The trigger element will be associated to this content via `aria-describedby`. This means\n * that the tooltip content will be read by assistive technologies such as screen readers. It\n * will likely read this content right after reading the trigger element label.\n */\n content: React.ReactNode | (() => React.ReactNode)\n\n /**\n * How to place the tooltip relative to its trigger element.\n *\n * The possible values are \"top\", \"bottom\", \"left\", \"right\". Additionally, any of these values\n * can be combined with `-start` or `-end` for even more control. For instance `top-start` will\n * place the tooltip at the top, but with the start (e.g. left) side of the toolip and the\n * trigger aligned. If neither `-start` or `-end` are provided, the tooltip is centered along\n * the vertical or horizontal axis with the trigger.\n *\n * The position is enforced whenever possible, but tooltips can appear in different positions\n * if the specified one would make the tooltip intersect with the viewport edges.\n *\n * @default 'top'\n */\n position?: TooltipStoreState['placement']\n\n /**\n * The separation (in pixels) between the trigger element and the tooltip.\n * @default 3\n */\n gapSize?: number\n\n /**\n * Whether to show an arrow-like element attached to the tooltip, and pointing towards the\n * trigger element.\n * @default false\n */\n withArrow?: boolean\n\n /**\n * The amount of time in milliseconds to wait before showing the tooltip\n * Use `<TooltipContext.Provider>` to set a global value for all tooltips\n * @default 500\n */\n showTimeout?: number\n\n /**\n * The amount of time in milliseconds to wait before hiding the tooltip\n * Use `<TooltipContext.Provider>` to set a global value for all tooltips\n * @default 100\n */\n hideTimeout?: number\n}\n\nfunction Tooltip({\n children,\n content,\n position = 'top',\n gapSize = 3,\n withArrow = false,\n showTimeout,\n hideTimeout,\n exceptionallySetClassName,\n}: TooltipProps) {\n const { showTimeout: globalShowTimeout, hideTimeout: globalHideTimeout } = React.useContext(\n TooltipContext,\n )\n const tooltip = useTooltipStore({\n placement: position,\n showTimeout: showTimeout ?? globalShowTimeout,\n hideTimeout: hideTimeout ?? globalHideTimeout,\n })\n const isOpen = tooltip.useState('open')\n\n const child = React.Children.only(\n children as React.FunctionComponentElement<JSX.IntrinsicElements['div']> | null,\n )\n\n if (!child) {\n return child\n }\n\n if (typeof child.ref === 'string') {\n throw new Error('Tooltip: String refs cannot be used as they cannot be forwarded')\n }\n\n return (\n <>\n <TooltipAnchor render={child} store={tooltip} ref={child.ref} />\n {isOpen && content ? (\n <AriakitTooltip\n store={tooltip}\n gutter={gapSize}\n render={\n <Box\n className={[styles.tooltip, exceptionallySetClassName]}\n background=\"toast\"\n borderRadius=\"standard\"\n paddingX=\"small\"\n paddingY=\"xsmall\"\n maxWidth=\"medium\"\n width=\"fitContent\"\n overflow=\"hidden\"\n textAlign=\"center\"\n />\n }\n >\n {withArrow ? <TooltipArrow /> : null}\n {typeof content === 'function' ? content() : content}\n </AriakitTooltip>\n ) : null}\n </>\n )\n}\n\nexport type { TooltipProps }\nexport { Tooltip, TooltipContext }\n"],"names":["TooltipContext","React","createContext","showTimeout","hideTimeout","children","content","position","gapSize","withArrow","exceptionallySetClassName","globalShowTimeout","globalHideTimeout","useContext","tooltip","useTooltipStore","placement","isOpen","useState","child","Children","only","ref","Error","createElement","Fragment","TooltipAnchor","render","store","AriakitTooltip","gutter","Box","className","styles","background","borderRadius","paddingX","paddingY","maxWidth","width","overflow","textAlign","TooltipArrow"],"mappings":"kdAoBA,MAAMA,EAAiBC,EAAMC,cAAmC,CAC5DC,YAAa,IACbC,YAAa,sBAwEjB,UAAiBC,SACbA,EADaC,QAEbA,EAFaC,SAGbA,EAAW,MAHEC,QAIbA,EAAU,EAJGC,UAKbA,GAAY,EALCN,YAMbA,EANaC,YAObA,EAPaM,0BAQbA,IAEA,MAAQP,YAAaQ,EAAmBP,YAAaQ,GAAsBX,EAAMY,WAC7Eb,GAEEc,EAAUC,EAAAA,gBAAgB,CAC5BC,UAAWT,EACXJ,YAAaA,MAAAA,EAAAA,EAAeQ,EAC5BP,YAAaA,MAAAA,EAAAA,EAAeQ,IAE1BK,EAASH,EAAQI,SAAS,QAE1BC,EAAQlB,EAAMmB,SAASC,KACzBhB,GAGJ,IAAKc,EACD,OAAOA,EAGX,GAAyB,iBAAdA,EAAMG,IACb,MAAM,IAAIC,MAAM,mEAGpB,OACItB,EAAAuB,cAAAvB,EAAAwB,SAAA,KACIxB,EAAAuB,cAACE,gBAAa,CAACC,OAAQR,EAAOS,MAAOd,EAASQ,IAAKH,EAAMG,MACxDL,GAAUX,EACPL,EAACuB,cAAAK,EAAAA,QACG,CAAAD,MAAOd,EACPgB,OAAQtB,EACRmB,OACI1B,EAAAuB,cAACO,MAAG,CACAC,UAAW,CAACC,EAAAA,QAAOnB,QAASJ,GAC5BwB,WAAW,QACXC,aAAa,WACbC,SAAS,QACTC,SAAS,SACTC,SAAS,SACTC,MAAM,aACNC,SAAS,SACTC,UAAU,YAIjBhC,EAAYR,EAAAuB,cAACkB,EAADA,aAAgB,MAAG,KACZ,mBAAZpC,EAAyBA,IAAYA,GAEjD"}
|