@basic-ui/core 0.0.45 → 0.0.47
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/build/cjs/index.js +85 -10
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Menu/ContextMenuTrigger.d.ts +11 -0
- package/build/esm/Menu/ContextMenuTrigger.js +51 -0
- package/build/esm/Menu/ContextMenuTrigger.js.map +1 -0
- package/build/esm/Menu/Menu.js +11 -2
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuItem.js +0 -1
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.js +23 -6
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.js +6 -2
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +5 -1
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.d.ts +1 -0
- package/build/esm/Menu/fixtures/countryList.js +2 -0
- package/build/esm/Menu/fixtures/countryList.js.map +1 -0
- package/build/esm/Menu/index.d.ts +1 -0
- package/build/esm/Menu/index.js +1 -0
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/hooks/useControlledState.js +3 -1
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Menu/ContextMenu.story.tsx +73 -0
- package/src/Menu/ContextMenuTrigger.tsx +63 -0
- package/src/Menu/Menu.story.tsx +2 -2
- package/src/Menu/Menu.tsx +14 -1
- package/src/Menu/MenuComplex.story.tsx +58 -0
- package/src/Menu/MenuItem.tsx +0 -1
- package/src/Menu/MenuList.tsx +38 -9
- package/src/Menu/MenuPopover.tsx +9 -2
- package/src/Menu/context.ts +5 -1
- package/src/Menu/fixtures/countryList.ts +198 -0
- package/src/Menu/index.ts +1 -0
- package/src/hooks/useControlledState.ts +7 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ElementType, HTMLAttributes } from 'react';
|
|
2
|
+
export declare type ContextMenuTriggerProps = HTMLAttributes<HTMLElement> & {
|
|
3
|
+
as?: ElementType<any>;
|
|
4
|
+
innerAs?: ElementType<any>;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const ContextMenuTrigger: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLElement> & {
|
|
8
|
+
as?: ElementType<any> | undefined;
|
|
9
|
+
innerAs?: ElementType<any> | undefined;
|
|
10
|
+
disabled?: boolean | undefined;
|
|
11
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["as", "id", "onContextMenu", "disabled"];
|
|
4
|
+
import { forwardRef, useId } from 'react';
|
|
5
|
+
import { useMenuContext } from './context';
|
|
6
|
+
import { wrapEvent } from '../utils/wrap-event';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export var ContextMenuTrigger = /*#__PURE__*/forwardRef(function MenuButton(props, forwardedRef) {
|
|
9
|
+
var _props$as = props.as,
|
|
10
|
+
Comp = _props$as === void 0 ? 'div' : _props$as,
|
|
11
|
+
preferredId = props.id,
|
|
12
|
+
onContextMenu = props.onContextMenu,
|
|
13
|
+
disabled = props.disabled,
|
|
14
|
+
otherProps = _objectWithoutProperties(props, _excluded);
|
|
15
|
+
|
|
16
|
+
var _useMenuContext = useMenuContext(),
|
|
17
|
+
menuListIdRef = _useMenuContext.menuListIdRef,
|
|
18
|
+
open = _useMenuContext.open,
|
|
19
|
+
buttonRef = _useMenuContext.buttonRef,
|
|
20
|
+
onChange = _useMenuContext.onChange,
|
|
21
|
+
offset = _useMenuContext.offset,
|
|
22
|
+
isContextMenu = _useMenuContext.isContextMenu;
|
|
23
|
+
|
|
24
|
+
var idGenerated = useId();
|
|
25
|
+
var id = preferredId || idGenerated;
|
|
26
|
+
|
|
27
|
+
var handleContextMenu = function handleContextMenu(e) {
|
|
28
|
+
if (disabled) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var rect = e.currentTarget.getBoundingClientRect();
|
|
33
|
+
offset.current = [e.nativeEvent.x - rect.x, e.nativeEvent.y - rect.y];
|
|
34
|
+
isContextMenu.current = true;
|
|
35
|
+
buttonRef.current = e.currentTarget;
|
|
36
|
+
onChange && onChange(e, !open);
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return /*#__PURE__*/_jsx(Comp, _extends({
|
|
41
|
+
ref: forwardedRef,
|
|
42
|
+
id: id,
|
|
43
|
+
"aria-haspopup": true,
|
|
44
|
+
"aria-controls": menuListIdRef.current,
|
|
45
|
+
"aria-expanded": open ? true : undefined,
|
|
46
|
+
"data-menu-trigger": "",
|
|
47
|
+
onContextMenu: wrapEvent(onContextMenu, handleContextMenu),
|
|
48
|
+
disabled: disabled
|
|
49
|
+
}, otherProps));
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=ContextMenuTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenuTrigger.js","names":["forwardRef","useId","useMenuContext","wrapEvent","ContextMenuTrigger","MenuButton","props","forwardedRef","as","Comp","preferredId","id","onContextMenu","disabled","otherProps","menuListIdRef","open","buttonRef","onChange","offset","isContextMenu","idGenerated","handleContextMenu","e","rect","currentTarget","getBoundingClientRect","current","nativeEvent","x","y","preventDefault","undefined"],"sources":["../../../src/Menu/ContextMenuTrigger.tsx"],"sourcesContent":["import type {\n ElementType,\n HTMLAttributes,\n MouseEvent as ReactMouseEvent,\n} from 'react';\nimport { forwardRef, useId } from 'react';\n\nimport { useMenuContext } from './context';\nimport { wrapEvent } from '../utils/wrap-event';\n\nexport type ContextMenuTriggerProps = HTMLAttributes<HTMLElement> & {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n disabled?: boolean;\n};\n\nexport const ContextMenuTrigger = forwardRef<\n HTMLElement,\n ContextMenuTriggerProps\n>(function MenuButton(props, forwardedRef) {\n const {\n as: Comp = 'div',\n id: preferredId,\n onContextMenu,\n disabled,\n ...otherProps\n } = props;\n const { menuListIdRef, open, buttonRef, onChange, offset, isContextMenu } =\n useMenuContext();\n\n const idGenerated = useId();\n const id = preferredId || idGenerated;\n\n const handleContextMenu = (e: ReactMouseEvent<HTMLElement>) => {\n if (disabled) {\n return;\n }\n const rect = e.currentTarget.getBoundingClientRect();\n offset.current = [\n (e.nativeEvent as MouseEvent).x - rect.x,\n (e.nativeEvent as MouseEvent).y - rect.y,\n ];\n isContextMenu.current = true;\n\n buttonRef.current = e.currentTarget;\n onChange && onChange(e, !open);\n e.preventDefault();\n };\n\n return (\n <Comp\n ref={forwardedRef}\n id={id}\n aria-haspopup={true}\n aria-controls={menuListIdRef.current}\n aria-expanded={open ? true : undefined}\n data-menu-trigger=\"\"\n onContextMenu={wrapEvent(onContextMenu, handleContextMenu)}\n disabled={disabled}\n {...otherProps}\n />\n );\n});\n"],"mappings":";;;AAKA,SAASA,UAAT,EAAqBC,KAArB,QAAkC,OAAlC;AAEA,SAASC,cAAT,QAA+B,WAA/B;AACA,SAASC,SAAT,QAA0B,qBAA1B;;AAQA,OAAO,IAAMC,kBAAkB,gBAAGJ,UAAU,CAG1C,SAASK,UAAT,CAAoBC,KAApB,EAA2BC,YAA3B,EAAyC;EACzC,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,KADb;EAAA,IAEMC,WAFN,GAMIJ,KANJ,CAEEK,EAFF;EAAA,IAGEC,aAHF,GAMIN,KANJ,CAGEM,aAHF;EAAA,IAIEC,QAJF,GAMIP,KANJ,CAIEO,QAJF;EAAA,IAKKC,UALL,4BAMIR,KANJ;;EAOA,sBACEJ,cAAc,EADhB;EAA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@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["as", "open", "defaultOpen", "onChange"];
|
|
5
|
-
import { forwardRef, useRef, Fragment, useId } from 'react';
|
|
5
|
+
import { useCallback, forwardRef, useRef, Fragment, useId } from 'react';
|
|
6
6
|
import { MenuProvider } from './context';
|
|
7
7
|
import { useControlledState } from '../hooks';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -29,12 +29,21 @@ export var Menu = /*#__PURE__*/forwardRef(function Menu(props, forwardedRef) {
|
|
|
29
29
|
onChange = _useControlledState2[1];
|
|
30
30
|
|
|
31
31
|
menuListIdRef.current = useId();
|
|
32
|
+
var offset = useRef([0, 0]);
|
|
33
|
+
var offsetFn = useCallback(function (_ref) {
|
|
34
|
+
var reference = _ref.reference;
|
|
35
|
+
return [offset.current[0], offset.current[1] - reference.height];
|
|
36
|
+
}, []);
|
|
37
|
+
var isContextMenu = useRef(false);
|
|
32
38
|
var value = {
|
|
33
39
|
menuListIdRef: menuListIdRef,
|
|
34
40
|
openWithArrowKeyRef: openWithArrowKeyRef,
|
|
35
41
|
open: open,
|
|
36
42
|
onChange: onChange,
|
|
37
|
-
buttonRef: buttonRef
|
|
43
|
+
buttonRef: buttonRef,
|
|
44
|
+
offset: offset,
|
|
45
|
+
offsetFn: offsetFn,
|
|
46
|
+
isContextMenu: isContextMenu
|
|
38
47
|
};
|
|
39
48
|
return /*#__PURE__*/_jsx(MenuProvider, {
|
|
40
49
|
value: value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","names":["forwardRef","useRef","Fragment","useId","MenuProvider","useControlledState","Menu","props","forwardedRef","as","Comp","openProp","open","defaultOpen","onChangeProp","onChange","otherProps","menuListIdRef","openWithArrowKeyRef","buttonRef","setState","e","isOpen","current","value"],"sources":["../../../src/Menu/Menu.tsx"],"sourcesContent":["import type {\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ElementType,\n} from 'react';\nimport { forwardRef, useRef, Fragment, useId } from 'react';\n\nimport type { MenuContextProps } from './context';\nimport { MenuProvider } from './context';\nimport { useControlledState } from '../hooks';\n\nexport interface MenuProps {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n onChange?: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open?: boolean;\n defaultOpen?: boolean;\n}\n\nexport const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(\n props,\n forwardedRef\n) {\n const {\n as: Comp = Fragment,\n open: openProp,\n defaultOpen = false,\n onChange: onChangeProp,\n ...otherProps\n } = props;\n const menuListIdRef = useRef<string>();\n const openWithArrowKeyRef = useRef<'ArrowUp' | 'ArrowDown' | null>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [open, onChange] = useControlledState(\n openProp,\n onChangeProp,\n defaultOpen,\n (setState) => (e, isOpen) => {\n setState(isOpen);\n }\n );\n\n menuListIdRef.current = useId();\n\n const value: MenuContextProps = {\n menuListIdRef,\n openWithArrowKeyRef,\n open,\n onChange,\n buttonRef,\n };\n\n return (\n <MenuProvider value={value}>\n <Comp ref={forwardedRef} {...otherProps} />\n </MenuProvider>\n );\n});\n"],"mappings":";;;;AAOA,SAASA,
|
|
1
|
+
{"version":3,"file":"Menu.js","names":["useCallback","forwardRef","useRef","Fragment","useId","MenuProvider","useControlledState","Menu","props","forwardedRef","as","Comp","openProp","open","defaultOpen","onChangeProp","onChange","otherProps","menuListIdRef","openWithArrowKeyRef","buttonRef","setState","e","isOpen","current","offset","offsetFn","reference","height","isContextMenu","value"],"sources":["../../../src/Menu/Menu.tsx"],"sourcesContent":["import type {\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ElementType,\n} from 'react';\nimport { useCallback, forwardRef, useRef, Fragment, useId } from 'react';\n\nimport type { MenuContextProps } from './context';\nimport { MenuProvider } from './context';\nimport { useControlledState } from '../hooks';\nimport type { OffsetsFunction } from '../Popper';\n\nexport interface MenuProps {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n onChange?: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open?: boolean;\n defaultOpen?: boolean;\n}\n\nexport const Menu = forwardRef<HTMLDivElement, MenuProps>(function Menu(\n props,\n forwardedRef\n) {\n const {\n as: Comp = Fragment,\n open: openProp,\n defaultOpen = false,\n onChange: onChangeProp,\n ...otherProps\n } = props;\n const menuListIdRef = useRef<string>();\n const openWithArrowKeyRef = useRef<'ArrowUp' | 'ArrowDown' | null>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const [open, onChange] = useControlledState(\n openProp,\n onChangeProp,\n defaultOpen,\n (setState) => (e, isOpen) => {\n setState(isOpen);\n }\n );\n\n menuListIdRef.current = useId();\n const offset = useRef<[number, number]>([0, 0]);\n const offsetFn = useCallback<OffsetsFunction>(\n ({ reference }) => [\n offset.current[0],\n offset.current[1] - reference.height,\n ],\n []\n );\n const isContextMenu = useRef(false);\n\n const value: MenuContextProps = {\n menuListIdRef,\n openWithArrowKeyRef,\n open,\n onChange,\n buttonRef,\n offset,\n offsetFn,\n isContextMenu,\n };\n\n return (\n <MenuProvider value={value}>\n <Comp ref={forwardedRef} {...otherProps} />\n </MenuProvider>\n );\n});\n"],"mappings":";;;;AAOA,SAASA,WAAT,EAAsBC,UAAtB,EAAkCC,MAAlC,EAA0CC,QAA1C,EAAoDC,KAApD,QAAiE,OAAjE;AAGA,SAASC,YAAT,QAA6B,WAA7B;AACA,SAASC,kBAAT,QAAmC,UAAnC;;AAkBA,OAAO,IAAMC,IAAI,gBAAGN,UAAU,CAA4B,SAASM,IAAT,CACx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AQ,EAARA,QAJ8B;IAK9BI,SAAS,EAATA,SAL8B;IAM9BK,MAAM,EAANA,MAN8B;IAO9BC,QAAQ,EAARA,QAP8B;IAQ9BG,aAAa,EAAbA;EAR8B,CAAhC;EAWA,oBACE,KAAC,YAAD;IAAc,KAAK,EAAEC,KAArB;IAAA,uBACE,KAAC,IAAD;MAAM,GAAG,EAAErB;IAAX,GAA6BQ,UAA7B;EADF,EADF;AAKD,CAlD6B,CAAvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItem.js","names":["forwardRef","useRef","useId","useMenuContext","useMenuListContext","assignMultipleRefs","wrapEvent","MenuItem","props","forwardedRef","as","Comp","disabled","onSelect","onClick","onKeyDown","otherProps","onChange","buttonRef","navigationItem","onNavigate","ref","itemId","isActive","current","handleSelect","e","focus","preventDefault","handleClick","handleKeyDown","key","undefined"],"sources":["../../../src/Menu/MenuItem.tsx"],"sourcesContent":["import type {\n LiHTMLAttributes,\n ElementType,\n MouseEvent,\n KeyboardEvent,\n KeyboardEventHandler,\n} from 'react';\nimport { forwardRef, useRef, useId } from 'react';\n\nimport { useMenuContext, useMenuListContext } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { wrapEvent } from '../utils';\n\nexport interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onSelect?: (\n e: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>\n ) => void;\n disabled?: boolean;\n}\n\nexport const MenuItem = forwardRef<any, MenuItemProps>(function MenuItem(\n props,\n forwardedRef\n) {\n const {\n as: Comp = 'li',\n disabled,\n onSelect,\n onClick,\n onKeyDown,\n ...otherProps\n } = props;\n const { onChange, buttonRef } = useMenuContext();\n const { navigationItem, onNavigate } = useMenuListContext();\n const ref = useRef<HTMLLIElement>();\n const itemId = useId();\n\n const isActive = ref.current && ref.current === navigationItem;\n\n const handleSelect = wrapEvent(\n onSelect,\n (e: KeyboardEvent<HTMLLIElement> | MouseEvent<HTMLLIElement>) => {\n onChange && onChange(e, false);\n buttonRef.current?.focus();\n e.preventDefault();\n }\n );\n\n const handleClick = (e: MouseEvent<HTMLLIElement>) => {\n if (!disabled) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onNavigate && onNavigate(ref.current!);\n handleSelect(e);\n }\n };\n\n const handleKeyDown: KeyboardEventHandler<HTMLLIElement> = (e) => {\n switch (e.key) {\n case 'Enter':\n
|
|
1
|
+
{"version":3,"file":"MenuItem.js","names":["forwardRef","useRef","useId","useMenuContext","useMenuListContext","assignMultipleRefs","wrapEvent","MenuItem","props","forwardedRef","as","Comp","disabled","onSelect","onClick","onKeyDown","otherProps","onChange","buttonRef","navigationItem","onNavigate","ref","itemId","isActive","current","handleSelect","e","focus","preventDefault","handleClick","handleKeyDown","key","undefined"],"sources":["../../../src/Menu/MenuItem.tsx"],"sourcesContent":["import type {\n LiHTMLAttributes,\n ElementType,\n MouseEvent,\n KeyboardEvent,\n KeyboardEventHandler,\n} from 'react';\nimport { forwardRef, useRef, useId } from 'react';\n\nimport { useMenuContext, useMenuListContext } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { wrapEvent } from '../utils';\n\nexport interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onSelect?: (\n e: MouseEvent<HTMLLIElement> | KeyboardEvent<HTMLLIElement>\n ) => void;\n disabled?: boolean;\n}\n\nexport const MenuItem = forwardRef<any, MenuItemProps>(function MenuItem(\n props,\n forwardedRef\n) {\n const {\n as: Comp = 'li',\n disabled,\n onSelect,\n onClick,\n onKeyDown,\n ...otherProps\n } = props;\n const { onChange, buttonRef } = useMenuContext();\n const { navigationItem, onNavigate } = useMenuListContext();\n const ref = useRef<HTMLLIElement>();\n const itemId = useId();\n\n const isActive = ref.current && ref.current === navigationItem;\n\n const handleSelect = wrapEvent(\n onSelect,\n (e: KeyboardEvent<HTMLLIElement> | MouseEvent<HTMLLIElement>) => {\n onChange && onChange(e, false);\n buttonRef.current?.focus();\n e.preventDefault();\n }\n );\n\n const handleClick = (e: MouseEvent<HTMLLIElement>) => {\n if (!disabled) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n onNavigate && onNavigate(ref.current!);\n handleSelect(e);\n }\n };\n\n const handleKeyDown: KeyboardEventHandler<HTMLLIElement> = (e) => {\n switch (e.key) {\n case 'Enter':\n if (!disabled) {\n handleSelect(e);\n }\n break;\n }\n };\n\n return (\n <Comp\n ref={assignMultipleRefs(ref, forwardedRef)}\n id={disabled ? undefined : itemId}\n data-menu-item=\"\"\n data-highlighted={isActive ? '' : undefined}\n role=\"menuitem\"\n onClick={wrapEvent(onClick, handleClick)}\n tabIndex={disabled ? -1 : 0}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n data-disabled={disabled ? '' : undefined}\n aria-disabled={disabled ? '' : undefined}\n disabled={disabled}\n {...otherProps}\n />\n );\n});\n"],"mappings":";;;AAOA,SAASA,UAAT,EAAqBC,MAArB,EAA6BC,KAA7B,QAA0C,OAA1C;AAEA,SAASC,cAAT,EAAyBC,kBAAzB,QAAmD,WAAnD;AACA,SAASC,kBAAT,QAAmC,qBAAnC;AACA,SAASC,SAAT,QAA0B,UAA1B;;AAWA,OAAO,IAAMC,QAAQ,gBAAGP,UAAU,CAAqB,SAASO,QAAT,CACrDC,KADqD,EAErDC,YAFqD,EAGrD;EACA,gBAOID,KAPJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,IADb;EAAA,IAEEC,QAFF,GAOIJ,KAPJ,CAEEI,QAFF;EAAA,IAGEC,QAHF,GAOIL,KAPJ,CAGEK,QAHF;EAAA,IAIEC,OAJF,GAOIN,KAPJ,CAIEM,OAJF;EAAA,IAKEC,SALF,GAOIP,KAPJ,CAKEO,SALF;EAAA,IAMKC,UANL,4BAOIR,KAPJ;;EAQA,sBAAgCL,cAAc,EAA9C;EAAA,IAAQ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AAD,EAAUe,WAAV,CANpB;IAOE,QAAQ,EAAEjB,QAAQ,GAAG,CAAC,CAAJ,GAAQ,CAP5B;IAQE,SAAS,EAAEN,SAAS,CAACS,SAAD,EAAYe,aAAZ,CARtB;IASE,iBAAelB,QAAQ,GAAG,EAAH,GAAQoB,SATjC;IAUE,iBAAepB,QAAQ,GAAG,EAAH,GAAQoB,SAVjC;IAWE,QAAQ,EAAEpB;EAXZ,GAYMI,UAZN,EADF;AAgBD,CA9DiC,CAA3B"}
|
|
@@ -21,12 +21,16 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
|
|
|
21
21
|
defaultActiveItemValue = props.defaultActiveItemValue,
|
|
22
22
|
otherProps = _objectWithoutProperties(props, _excluded);
|
|
23
23
|
|
|
24
|
+
var itemSearchStr = useRef('');
|
|
25
|
+
var itemSearchClearTimeout = useRef();
|
|
26
|
+
|
|
24
27
|
var _useMenuContext = useMenuContext(),
|
|
25
28
|
menuListIdRef = _useMenuContext.menuListIdRef,
|
|
26
29
|
buttonRef = _useMenuContext.buttonRef,
|
|
27
30
|
onChange = _useMenuContext.onChange,
|
|
28
31
|
openWithArrowKeyRef = _useMenuContext.openWithArrowKeyRef,
|
|
29
|
-
open = _useMenuContext.open
|
|
32
|
+
open = _useMenuContext.open,
|
|
33
|
+
isContextMenu = _useMenuContext.isContextMenu;
|
|
30
34
|
|
|
31
35
|
var _useState = useState(),
|
|
32
36
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -72,7 +76,9 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
|
|
|
72
76
|
useOnClickOutside(menuListRef, function (e) {
|
|
73
77
|
var _buttonRef$current;
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
console.log(isContextMenu.current);
|
|
80
|
+
|
|
81
|
+
if (isContextMenu.current || e.target instanceof HTMLElement && e.target !== buttonRef.current && !((_buttonRef$current = buttonRef.current) !== null && _buttonRef$current !== void 0 && _buttonRef$current.contains(e.target))) {
|
|
76
82
|
onChange && onChange(e, false);
|
|
77
83
|
}
|
|
78
84
|
|
|
@@ -89,6 +95,7 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
|
|
|
89
95
|
onChange && onChange(e, false);
|
|
90
96
|
e.preventDefault(); // prevents focusing on next element, because we will be handling it
|
|
91
97
|
|
|
98
|
+
itemSearchStr.current = '';
|
|
92
99
|
(_buttonRef$current2 = buttonRef.current) === null || _buttonRef$current2 === void 0 ? void 0 : _buttonRef$current2.focus();
|
|
93
100
|
break;
|
|
94
101
|
}
|
|
@@ -98,6 +105,7 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
|
|
|
98
105
|
case 'ArrowDown':
|
|
99
106
|
case 'ArrowUp':
|
|
100
107
|
e.preventDefault();
|
|
108
|
+
itemSearchStr.current = '';
|
|
101
109
|
var allItems = scope ? scope.current.queryAllNodes(queryScope) : [];
|
|
102
110
|
var currentIndex = allItems.findIndex(function (e) {
|
|
103
111
|
return e === navigationItem;
|
|
@@ -135,27 +143,36 @@ export var MenuList = /*#__PURE__*/forwardRef(function MenuList(props, forwarded
|
|
|
135
143
|
|
|
136
144
|
default:
|
|
137
145
|
{
|
|
138
|
-
if (e.key.length === 1) {
|
|
146
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {
|
|
139
147
|
// A-Z
|
|
140
148
|
e.preventDefault();
|
|
141
149
|
|
|
150
|
+
if (itemSearchStr.current.length === 0 || itemSearchStr.current.slice(-1) !== e.key) {
|
|
151
|
+
itemSearchStr.current = itemSearchStr.current + e.key;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
clearTimeout(itemSearchClearTimeout.current);
|
|
155
|
+
itemSearchClearTimeout.current = setTimeout(function () {
|
|
156
|
+
itemSearchStr.current = '';
|
|
157
|
+
}, 500);
|
|
158
|
+
|
|
142
159
|
var _allItems = scope ? scope.current.queryAllNodes(queryScope) : [];
|
|
143
160
|
|
|
144
161
|
var _currentIndex = _allItems.findIndex(function (e) {
|
|
145
162
|
return e === navigationItem;
|
|
146
163
|
});
|
|
147
164
|
|
|
148
|
-
var
|
|
165
|
+
var searchStr = itemSearchStr.current;
|
|
149
166
|
|
|
150
167
|
var _nextIndex = -1;
|
|
151
168
|
|
|
152
|
-
for (var i = 1; i < _allItems.length; i++) {
|
|
169
|
+
for (var i = searchStr.length === 1 ? 1 : 0; i < _allItems.length; i++) {
|
|
153
170
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
154
171
|
var idx = getCircularIndex(_currentIndex + i, _allItems.length);
|
|
155
172
|
var dom = _allItems[idx];
|
|
156
173
|
var domText = dom.innerText.toLowerCase();
|
|
157
174
|
|
|
158
|
-
if (domText.length > 0 && domText.
|
|
175
|
+
if (domText.length > 0 && domText.startsWith(searchStr)) {
|
|
159
176
|
_nextIndex = idx;
|
|
160
177
|
break;
|
|
161
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuList.js","names":["forwardRef","useEffect","useRef","useState","useLayoutEffect","useMenuContext","MenuListProvider","assignMultipleRefs","useOnClickOutside","useScope","queryScope","getCircularIndex","wrapEvent","useEnhancedEffect","window","MenuList","props","forwardedRef","as","Comp","onKeyDown","preferredId","id","defaultActiveItemValue","otherProps","menuListIdRef","buttonRef","onChange","openWithArrowKeyRef","open","navigationItem","setNavigationItem","mounted","setMounted","menuListRef","scope","onNavigate","el","focus","current","allItems","queryAllNodes","index","length","i","dataset","value","e","target","HTMLElement","contains","preventDefault","handleKeyDown","key","currentIndex","findIndex","nextIndex","firstLetter","toLowerCase","idx","dom","domText","innerText","charAt"],"sources":["../../../src/Menu/MenuList.tsx"],"sourcesContent":["import type { HTMLAttributes, ElementType, KeyboardEvent } from 'react';\nimport {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n} from 'react';\n\nimport { useMenuContext, MenuListProvider } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { useOnClickOutside } from '../hooks/useOnClickOutside';\nimport { useScope } from '../hooks';\nimport { queryScope } from './scope';\nimport { getCircularIndex, wrapEvent } from '../utils';\n\nconst useEnhancedEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport interface MenuListProps extends HTMLAttributes<HTMLUListElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n defaultActiveItemValue?: string;\n}\n\nexport const MenuList = forwardRef<HTMLUListElement, MenuListProps>(\n function MenuList(props, forwardedRef) {\n const {\n as: Comp = 'ul',\n onKeyDown,\n id: preferredId,\n defaultActiveItemValue,\n ...otherProps\n } = props;\n\n const { menuListIdRef, buttonRef, onChange, openWithArrowKeyRef, open } =\n useMenuContext();\n\n const [navigationItem, setNavigationItem] = useState<\n HTMLElement | undefined\n >();\n\n const [mounted, setMounted] = useState(false);\n\n const menuListRef = useRef<HTMLUListElement>();\n\n const scope = useScope<HTMLLIElement, HTMLUListElement>(menuListRef);\n\n const onNavigate = (el: HTMLElement) => {\n el.focus();\n setNavigationItem(el);\n };\n\n menuListIdRef.current = preferredId || menuListIdRef.current;\n\n useEnhancedEffect(() => {\n if (!mounted) {\n const allItems = scope.current.queryAllNodes(queryScope);\n let index = getCircularIndex(\n openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0,\n allItems.length\n );\n\n if (defaultActiveItemValue) {\n for (let i = 0; i < allItems.length; i++) {\n if (allItems[i].dataset.value === defaultActiveItemValue) {\n index = i;\n break;\n }\n }\n }\n\n if (index !== null) {\n onNavigate && onNavigate(allItems[index]);\n }\n }\n\n openWithArrowKeyRef.current = null;\n setMounted(true);\n }, [\n mounted,\n navigationItem,\n onNavigate,\n openWithArrowKeyRef,\n scope,\n defaultActiveItemValue,\n ]);\n\n useOnClickOutside(\n menuListRef,\n (e) => {\n if (\n e.target instanceof HTMLElement &&\n e.target !== buttonRef.current &&\n !buttonRef.current?.contains(e.target)\n ) {\n onChange && onChange(e as any, false);\n }\n e.preventDefault();\n },\n true\n );\n\n function handleKeyDown(e: KeyboardEvent<HTMLUListElement>) {\n switch (e.key) {\n case 'Escape':\n case 'Tab': {\n onChange && onChange(e, false);\n e.preventDefault(); // prevents focusing on next element, because we will be handling it\n buttonRef.current?.focus();\n break;\n }\n case 'Home':\n case 'End':\n case 'ArrowDown':\n case 'ArrowUp':\n e.preventDefault();\n const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];\n const currentIndex = allItems.findIndex((e) => e === navigationItem);\n if (allItems.length === 0) {\n return;\n }\n let nextIndex: number = currentIndex;\n switch (e.key) {\n case 'ArrowUp':\n nextIndex += -1;\n break;\n case 'ArrowDown':\n nextIndex += 1;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = -1;\n break;\n }\n // We already checked if allItems.length = 0 above\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n nextIndex = getCircularIndex(nextIndex, allItems.length)!;\n onNavigate && onNavigate(allItems[nextIndex]);\n break;\n default: {\n if (e.key.length === 1) {\n // A-Z\n e.preventDefault();\n const allItems = scope\n ? scope.current.queryAllNodes(queryScope)\n : [];\n const currentIndex = allItems.findIndex(\n (e) => e === navigationItem\n );\n const firstLetter = e.key.toLowerCase();\n let nextIndex = -1;\n for (let i = 1; i < allItems.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const idx = getCircularIndex(currentIndex + i, allItems.length)!;\n const dom = allItems[idx];\n const domText = dom.innerText.toLowerCase();\n if (domText.length > 0 && domText.charAt(0) === firstLetter) {\n nextIndex = idx;\n break;\n }\n }\n if (nextIndex >= 0 && nextIndex < allItems.length) {\n onNavigate && onNavigate(allItems[nextIndex]);\n }\n }\n }\n }\n }\n\n if (!open) {\n return null;\n }\n\n return (\n <MenuListProvider\n value={{\n navigationItem,\n onNavigate,\n }}\n >\n <Comp\n ref={assignMultipleRefs(forwardedRef, menuListRef)}\n id={menuListIdRef.current}\n role=\"menu\"\n aria-labelledby={buttonRef.current?.id}\n data-menu-list=\"\"\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AACgB,UAAD,CAAT,CAAxB;YACD;UACF;QACF;IAhEH;EAkED;;EAED,IAAI,CAAC3B,IAAL,EAAW;IACT,OAAO,IAAP;EACD;;EAED,oBACE,KAAC,gBAAD;IACE,KAAK,EAAE;MACLC,cAAc,EAAdA,cADK;MAELM,UAAU,EAAVA;IAFK,CADT;IAAA,uBAME,KAAC,IAAD;MACE,GAAG,EAAE7B,kBAAkB,CAACU,YAAD,EAAeiB,WAAf,CADzB;MAEE,EAAE,EAAET,aAAa,CAACc,OAFpB;MAGE,IAAI,EAAC,MAHP;MAIE,0CAAiBb,SAAS,CAACa,OAA3B,wDAAiB,oBAAmBjB,EAJtC;MAKE,kBAAe,EALjB;MAME,QAAQ,EAAC,IANX;MAOE,SAAS,EAAEV,SAAS,CAACQ,SAAD,EAAYgC,aAAZ;IAPtB,GAQM5B,UARN;EANF,EADF;AAmBD,CA1K+B,CAA3B"}
|
|
1
|
+
{"version":3,"file":"MenuList.js","names":["forwardRef","useEffect","useRef","useState","useLayoutEffect","useMenuContext","MenuListProvider","assignMultipleRefs","useOnClickOutside","useScope","queryScope","getCircularIndex","wrapEvent","useEnhancedEffect","window","MenuList","props","forwardedRef","as","Comp","onKeyDown","preferredId","id","defaultActiveItemValue","otherProps","itemSearchStr","itemSearchClearTimeout","menuListIdRef","buttonRef","onChange","openWithArrowKeyRef","open","isContextMenu","navigationItem","setNavigationItem","mounted","setMounted","menuListRef","scope","onNavigate","el","focus","current","allItems","queryAllNodes","index","length","i","dataset","value","e","console","log","target","HTMLElement","contains","preventDefault","handleKeyDown","key","currentIndex","findIndex","nextIndex","ctrlKey","altKey","slice","clearTimeout","setTimeout","searchStr","idx","dom","domText","innerText","toLowerCase","startsWith"],"sources":["../../../src/Menu/MenuList.tsx"],"sourcesContent":["import type { HTMLAttributes, ElementType, KeyboardEvent } from 'react';\nimport {\n forwardRef,\n useEffect,\n useRef,\n useState,\n useLayoutEffect,\n} from 'react';\n\nimport { useMenuContext, MenuListProvider } from './context';\nimport { assignMultipleRefs } from '../utils/assign-ref';\nimport { useOnClickOutside } from '../hooks/useOnClickOutside';\nimport { useScope } from '../hooks';\nimport { queryScope } from './scope';\nimport { getCircularIndex, wrapEvent } from '../utils';\n\nconst useEnhancedEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport interface MenuListProps extends HTMLAttributes<HTMLUListElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n defaultActiveItemValue?: string;\n}\n\nexport const MenuList = forwardRef<HTMLUListElement, MenuListProps>(\n function MenuList(props, forwardedRef) {\n const {\n as: Comp = 'ul',\n onKeyDown,\n id: preferredId,\n defaultActiveItemValue,\n ...otherProps\n } = props;\n\n const itemSearchStr = useRef('');\n const itemSearchClearTimeout = useRef<ReturnType<typeof setTimeout>>();\n\n const {\n menuListIdRef,\n buttonRef,\n onChange,\n openWithArrowKeyRef,\n open,\n isContextMenu,\n } = useMenuContext();\n\n const [navigationItem, setNavigationItem] = useState<\n HTMLElement | undefined\n >();\n\n const [mounted, setMounted] = useState(false);\n\n const menuListRef = useRef<HTMLUListElement>();\n\n const scope = useScope<HTMLLIElement, HTMLUListElement>(menuListRef);\n\n const onNavigate = (el: HTMLElement) => {\n el.focus();\n setNavigationItem(el);\n };\n\n menuListIdRef.current = preferredId || menuListIdRef.current;\n\n useEnhancedEffect(() => {\n if (!mounted) {\n const allItems = scope.current.queryAllNodes(queryScope);\n let index = getCircularIndex(\n openWithArrowKeyRef.current === 'ArrowUp' ? -1 : 0,\n allItems.length\n );\n\n if (defaultActiveItemValue) {\n for (let i = 0; i < allItems.length; i++) {\n if (allItems[i].dataset.value === defaultActiveItemValue) {\n index = i;\n break;\n }\n }\n }\n\n if (index !== null) {\n onNavigate && onNavigate(allItems[index]);\n }\n }\n\n openWithArrowKeyRef.current = null;\n setMounted(true);\n }, [\n mounted,\n navigationItem,\n onNavigate,\n openWithArrowKeyRef,\n scope,\n defaultActiveItemValue,\n ]);\n\n useOnClickOutside(\n menuListRef,\n (e) => {\n console.log(isContextMenu.current);\n if (\n isContextMenu.current ||\n (e.target instanceof HTMLElement &&\n e.target !== buttonRef.current &&\n !buttonRef.current?.contains(e.target))\n ) {\n onChange && onChange(e as any, false);\n }\n e.preventDefault();\n },\n true\n );\n\n function handleKeyDown(e: KeyboardEvent<HTMLUListElement>) {\n switch (e.key) {\n case 'Escape':\n case 'Tab': {\n onChange && onChange(e, false);\n e.preventDefault(); // prevents focusing on next element, because we will be handling it\n itemSearchStr.current = '';\n buttonRef.current?.focus();\n break;\n }\n case 'Home':\n case 'End':\n case 'ArrowDown':\n case 'ArrowUp':\n e.preventDefault();\n itemSearchStr.current = '';\n const allItems = scope ? scope.current.queryAllNodes(queryScope) : [];\n const currentIndex = allItems.findIndex((e) => e === navigationItem);\n if (allItems.length === 0) {\n return;\n }\n let nextIndex: number = currentIndex;\n switch (e.key) {\n case 'ArrowUp':\n nextIndex += -1;\n break;\n case 'ArrowDown':\n nextIndex += 1;\n break;\n case 'Home':\n nextIndex = 0;\n break;\n case 'End':\n nextIndex = -1;\n break;\n }\n // We already checked if allItems.length = 0 above\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n nextIndex = getCircularIndex(nextIndex, allItems.length)!;\n onNavigate && onNavigate(allItems[nextIndex]);\n break;\n default: {\n if (e.key.length === 1 && !e.ctrlKey && !e.altKey) {\n // A-Z\n e.preventDefault();\n\n if (\n itemSearchStr.current.length === 0 ||\n itemSearchStr.current.slice(-1) !== e.key\n ) {\n itemSearchStr.current = itemSearchStr.current + e.key;\n }\n clearTimeout(itemSearchClearTimeout.current as any);\n itemSearchClearTimeout.current = setTimeout(() => {\n itemSearchStr.current = '';\n }, 500);\n\n const allItems = scope\n ? scope.current.queryAllNodes(queryScope)\n : [];\n const currentIndex = allItems.findIndex(\n (e) => e === navigationItem\n );\n const searchStr = itemSearchStr.current;\n let nextIndex = -1;\n for (\n let i = searchStr.length === 1 ? 1 : 0;\n i < allItems.length;\n i++\n ) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const idx = getCircularIndex(currentIndex + i, allItems.length)!;\n const dom = allItems[idx];\n const domText = dom.innerText.toLowerCase();\n if (domText.length > 0 && domText.startsWith(searchStr)) {\n nextIndex = idx;\n break;\n }\n }\n if (nextIndex >= 0 && nextIndex < allItems.length) {\n onNavigate && onNavigate(allItems[nextIndex]);\n }\n }\n }\n }\n }\n\n if (!open) {\n return null;\n }\n\n return (\n <MenuListProvider\n value={{\n navigationItem,\n onNavigate,\n }}\n >\n <Comp\n ref={assignMultipleRefs(forwardedRef, menuListRef)}\n id={menuListIdRef.current}\n role=\"menu\"\n aria-labelledby={buttonRef.current?.id}\n data-menu-list=\"\"\n tabIndex=\"-1\"\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n {...otherProps}\n />\n </MenuListProvider>\n );\n }\n);\n"],"mappings":";;;;AACA,SACEA,UADF,EAEEC,SAFF,EAGEC,MAHF,EAIEC,QAJF,EAKEC,eALF,QAMO,OANP;AAQA,SAASC,cAAT,EAAyBC,gBAAzB,QAAiD,WAAjD;AACA,SAASC,kBAAT,QAAmC,qBAAnC;AACA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,QAAT,QAAyB,UAAzB;AACA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,gBAAT,EAA2BC,SAA3B,QAA4C,UAA5C;;AAEA,IAAMC,iBAAiB,GACrB,OAAOC,MAAP,KAAkB,WAAlB,GAAgCV,eAAhC,GAAkDH,SADpD;AASA,OAAO,IAAMc,QAAQ,gBAAGf,UAAU,CAChC,SAASe,QAAT,CAAkBC,KAAlB,EAAyBC,YAAzB,EAAuC;EAAA;;EACrC,gBAMID,KANJ,CACEE,EADF;EAAA,IACMC,IADN,0BACa,IADb;EAAA,IAEEC,SAFF,GAMIJ,KANJ,CAEEI,SAFF;EAAA,IAGMC,WAHN,GAMIL,KANJ,CAGEM,EAHF;EAAA,IAIEC,sBAJF,GAMIP,KANJ,CAIEO,sBAJF;E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,UAAD,CAAT,CAAxB;YACD;UACF;QACF;IAlFH;EAoFD;;EAED,IAAI,CAAC9B,IAAL,EAAW;IACT,OAAO,IAAP;EACD;;EAED,oBACE,KAAC,gBAAD;IACE,KAAK,EAAE;MACLE,cAAc,EAAdA,cADK;MAELM,UAAU,EAAVA;IAFK,CADT;IAAA,uBAME,KAAC,IAAD;MACE,GAAG,EAAEhC,kBAAkB,CAACU,YAAD,EAAeoB,WAAf,CADzB;MAEE,EAAE,EAAEV,aAAa,CAACe,OAFpB;MAGE,IAAI,EAAC,MAHP;MAIE,0CAAiBd,SAAS,CAACc,OAA3B,wDAAiB,oBAAmBpB,EAJtC;MAKE,kBAAe,EALjB;MAME,QAAQ,EAAC,IANX;MAOE,SAAS,EAAEV,SAAS,CAACQ,SAAD,EAAYqC,aAAZ;IAPtB,GAQMjC,UARN;EANF,EADF;AAmBD,CAvM+B,CAA3B"}
|
|
@@ -12,7 +12,9 @@ export var MenuPopover = /*#__PURE__*/forwardRef(function MenuPopover(props, for
|
|
|
12
12
|
|
|
13
13
|
var _useMenuContext = useMenuContext(),
|
|
14
14
|
buttonRef = _useMenuContext.buttonRef,
|
|
15
|
-
open = _useMenuContext.open
|
|
15
|
+
open = _useMenuContext.open,
|
|
16
|
+
offsetFn = _useMenuContext.offsetFn,
|
|
17
|
+
isContextMenu = _useMenuContext.isContextMenu;
|
|
16
18
|
|
|
17
19
|
if (!open) {
|
|
18
20
|
return null;
|
|
@@ -21,7 +23,9 @@ export var MenuPopover = /*#__PURE__*/forwardRef(function MenuPopover(props, for
|
|
|
21
23
|
return /*#__PURE__*/_jsx(Popper, _extends({
|
|
22
24
|
as: as,
|
|
23
25
|
ref: forwardedRef,
|
|
24
|
-
anchorEl: buttonRef
|
|
26
|
+
anchorEl: buttonRef,
|
|
27
|
+
offsetFn: offsetFn,
|
|
28
|
+
placement: isContextMenu.current ? 'bottom-start' : undefined
|
|
25
29
|
}, otherProps));
|
|
26
30
|
});
|
|
27
31
|
//# sourceMappingURL=MenuPopover.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuPopover.js","names":["forwardRef","Popper","useMenuContext","MenuPopover","props","forwardedRef","as","otherProps","buttonRef","open"],"sources":["../../../src/Menu/MenuPopover.tsx"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport { forwardRef } from 'react';\n\nimport type { PopperProps } from '../Popper';\nimport { Popper } from '../Popper';\nimport { useMenuContext } from './context';\n\nexport interface MenuPopoverProps extends Omit<PopperProps, 'anchorEl'> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n}\n\nexport const MenuPopover = forwardRef<HTMLDivElement, MenuPopoverProps>(\n function MenuPopover(props, forwardedRef) {\n const { as = 'div', ...otherProps } = props;\n const { buttonRef, open } = useMenuContext();\n\n if (!open) {\n return null;\n }\n\n return (\n <Popper
|
|
1
|
+
{"version":3,"file":"MenuPopover.js","names":["forwardRef","Popper","useMenuContext","MenuPopover","props","forwardedRef","as","otherProps","buttonRef","open","offsetFn","isContextMenu","current","undefined"],"sources":["../../../src/Menu/MenuPopover.tsx"],"sourcesContent":["import type { ElementType, ReactNode } from 'react';\nimport { forwardRef } from 'react';\n\nimport type { PopperProps } from '../Popper';\nimport { Popper } from '../Popper';\nimport { useMenuContext } from './context';\n\nexport interface MenuPopoverProps extends Omit<PopperProps, 'anchorEl'> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n children?: ReactNode;\n}\n\nexport const MenuPopover = forwardRef<HTMLDivElement, MenuPopoverProps>(\n function MenuPopover(props, forwardedRef) {\n const { as = 'div', ...otherProps } = props;\n const { buttonRef, open, offsetFn, isContextMenu } = useMenuContext();\n\n if (!open) {\n return null;\n }\n\n return (\n <Popper\n as={as}\n ref={forwardedRef}\n anchorEl={buttonRef}\n offsetFn={offsetFn}\n placement={isContextMenu.current ? 'bottom-start' : undefined}\n {...otherProps}\n />\n );\n }\n);\n"],"mappings":";;;AACA,SAASA,UAAT,QAA2B,OAA3B;AAGA,SAASC,MAAT,QAAuB,WAAvB;AACA,SAASC,cAAT,QAA+B,WAA/B;;AAQA,OAAO,IAAMC,WAAW,gBAAGH,UAAU,CACnC,SAASG,WAAT,CAAqBC,KAArB,EAA4BC,YAA5B,EAA0C;EACxC,gBAAsCD,KAAtC,CAAQE,EAAR;EAAA,IAAQA,EAAR,0BAAa,KAAb;EAAA,IAAuBC,UAAvB,4BAAsCH,KAAtC;;EACA,sBAAqDF,cAAc,EAAnE;EAAA,IAAQM,SAAR,mBAAQA,SAAR;EAAA,IAAmBC,IAAnB,mBAAmBA,IAAnB;EAAA,IAAyBC,QAAzB,mBAAyBA,QAAzB;EAAA,IAAmCC,aAAnC,mBAAmCA,aAAnC;;EAEA,IAAI,CAACF,IAAL,EAAW;IACT,OAAO,IAAP;EACD;;EAED,oBACE,KAAC,MAAD;IACE,EAAE,EAAEH,EADN;IAEE,GAAG,EAAED,YAFP;IAGE,QAAQ,EAAEG,SAHZ;IAIE,QAAQ,EAAEE,QAJZ;IAKE,SAAS,EAAEC,aAAa,CAACC,OAAd,GAAwB,cAAxB,GAAyCC;EALtD,GAMMN,UANN,EADF;AAUD,CAnBkC,CAA9B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OffsetsFunction } from '@popperjs/core/lib/modifiers/offset';
|
|
1
2
|
import type { KeyboardEvent, MouseEvent, MutableRefObject, PointerEvent } from 'react';
|
|
2
3
|
export declare type ItemObject = {
|
|
3
4
|
text: string;
|
|
@@ -5,11 +6,14 @@ export declare type ItemObject = {
|
|
|
5
6
|
id: string | undefined;
|
|
6
7
|
};
|
|
7
8
|
export interface MenuContextProps {
|
|
8
|
-
buttonRef: MutableRefObject<
|
|
9
|
+
buttonRef: MutableRefObject<HTMLElement | null>;
|
|
9
10
|
menuListIdRef: MutableRefObject<undefined | string>;
|
|
10
11
|
openWithArrowKeyRef: MutableRefObject<string | null>;
|
|
11
12
|
onChange?: (e: KeyboardEvent<HTMLElement> | MouseEvent<HTMLElement> | PointerEvent<HTMLElement>, isOpen: boolean) => void;
|
|
12
13
|
open: boolean;
|
|
14
|
+
offset: MutableRefObject<[number, number]>;
|
|
15
|
+
offsetFn: OffsetsFunction;
|
|
16
|
+
isContextMenu: MutableRefObject<boolean>;
|
|
13
17
|
}
|
|
14
18
|
export declare const MenuProvider: import("react").Provider<MenuContextProps>;
|
|
15
19
|
export declare const useMenuContext: () => MenuContextProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["createContext","useContext","menuContext","MenuProvider","Provider","useMenuContext","menuListContext","MenuListProvider","useMenuListContext"],"sources":["../../../src/Menu/context.ts"],"sourcesContent":["import type {\n KeyboardEvent,\n MouseEvent,\n MutableRefObject,\n PointerEvent,\n} from 'react';\nimport { createContext, useContext } from 'react';\n\nexport type ItemObject = { text: string; value: any; id: string | undefined };\n\n// MenuRoot\nexport interface MenuContextProps {\n buttonRef: MutableRefObject<
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","useContext","menuContext","MenuProvider","Provider","useMenuContext","menuListContext","MenuListProvider","useMenuListContext"],"sources":["../../../src/Menu/context.ts"],"sourcesContent":["import type { OffsetsFunction } from '@popperjs/core/lib/modifiers/offset';\nimport type {\n KeyboardEvent,\n MouseEvent,\n MutableRefObject,\n PointerEvent,\n} from 'react';\nimport { createContext, useContext } from 'react';\n\nexport type ItemObject = { text: string; value: any; id: string | undefined };\n\n// MenuRoot\nexport interface MenuContextProps {\n buttonRef: MutableRefObject<HTMLElement | null>;\n menuListIdRef: MutableRefObject<undefined | string>;\n openWithArrowKeyRef: MutableRefObject<string | null>;\n onChange?: (\n e:\n | KeyboardEvent<HTMLElement>\n | MouseEvent<HTMLElement>\n | PointerEvent<HTMLElement>,\n isOpen: boolean\n ) => void;\n open: boolean;\n offset: MutableRefObject<[number, number]>;\n offsetFn: OffsetsFunction;\n isContextMenu: MutableRefObject<boolean>;\n}\n\nconst menuContext = createContext<MenuContextProps>(null as any);\nexport const { Provider: MenuProvider } = menuContext;\nexport const useMenuContext = () => useContext(menuContext);\n\n// MenuList\nexport interface MenuListContextProps {\n navigationItem: HTMLElement | undefined;\n onNavigate: undefined | ((idx: HTMLElement) => void);\n}\n\nconst menuListContext = createContext<MenuListContextProps>(null as any);\nexport const MenuListProvider = menuListContext.Provider;\nexport const useMenuListContext = () => useContext(menuListContext);\n"],"mappings":"AAOA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAsBA,IAAMC,WAAW,gBAAGF,aAAa,CAAmB,IAAnB,CAAjC;AACO,IAAkBG,YAAlB,GAAmCD,WAAnC,CAAQE,QAAR;;AACP,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB;EAAA,OAAMJ,UAAU,CAACC,WAAD,CAAhB;AAAA,CAAvB,C,CAEP;;AAMA,IAAMI,eAAe,gBAAGN,aAAa,CAAuB,IAAvB,CAArC;AACA,OAAO,IAAMO,gBAAgB,GAAGD,eAAe,CAACF,QAAzC;AACP,OAAO,IAAMI,kBAAkB,GAAG,SAArBA,kBAAqB;EAAA,OAAMP,UAAU,CAACK,eAAD,CAAhB;AAAA,CAA3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const countryList: string[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export var countryList = ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', "Côte d'Ivoire", 'Cabo Verde', 'Cambodia', 'Cameroon', 'Canada', 'Central African Republic', 'Central American Republic', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros', 'Congo (Congo-Brazzaville)', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czechia (Czech Republic)', 'Democratic Republic of the Congo', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Eswatini (fmr. "Swaziland")', 'Ethiopia', 'Fiji', 'Finland', 'France', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Holy See', 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Mauritania', 'Mauritius', 'Mexico', 'Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique', 'Myanmar (formerly Burma)', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'North Korea', 'North Macedonia', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestine State', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', 'Romania', 'Russia', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Korea', 'South Sudan', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Sweden', 'Switzerland', 'Syria', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States of America', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'];
|
|
2
|
+
//# sourceMappingURL=countryList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countryList.js","names":["countryList"],"sources":["../../../../src/Menu/fixtures/countryList.ts"],"sourcesContent":["export const countryList = [\n 'Afghanistan',\n 'Albania',\n 'Algeria',\n 'Andorra',\n 'Angola',\n 'Antigua and Barbuda',\n 'Argentina',\n 'Armenia',\n 'Australia',\n 'Austria',\n 'Azerbaijan',\n 'Bahamas',\n 'Bahrain',\n 'Bangladesh',\n 'Barbados',\n 'Belarus',\n 'Belgium',\n 'Belize',\n 'Benin',\n 'Bhutan',\n 'Bolivia',\n 'Bosnia and Herzegovina',\n 'Botswana',\n 'Brazil',\n 'Brunei',\n 'Bulgaria',\n 'Burkina Faso',\n 'Burundi',\n \"Côte d'Ivoire\",\n 'Cabo Verde',\n 'Cambodia',\n 'Cameroon',\n 'Canada',\n 'Central African Republic',\n 'Central American Republic',\n 'Chad',\n 'Chile',\n 'China',\n 'Colombia',\n 'Comoros',\n 'Congo (Congo-Brazzaville)',\n 'Costa Rica',\n 'Croatia',\n 'Cuba',\n 'Cyprus',\n 'Czechia (Czech Republic)',\n 'Democratic Republic of the Congo',\n 'Denmark',\n 'Djibouti',\n 'Dominica',\n 'Dominican Republic',\n 'Ecuador',\n 'Egypt',\n 'El Salvador',\n 'Equatorial Guinea',\n 'Eritrea',\n 'Estonia',\n 'Eswatini (fmr. \"Swaziland\")',\n 'Ethiopia',\n 'Fiji',\n 'Finland',\n 'France',\n 'Gabon',\n 'Gambia',\n 'Georgia',\n 'Germany',\n 'Ghana',\n 'Greece',\n 'Grenada',\n 'Guatemala',\n 'Guinea',\n 'Guinea-Bissau',\n 'Guyana',\n 'Haiti',\n 'Holy See',\n 'Honduras',\n 'Hungary',\n 'Iceland',\n 'India',\n 'Indonesia',\n 'Iran',\n 'Iraq',\n 'Ireland',\n 'Israel',\n 'Italy',\n 'Jamaica',\n 'Japan',\n 'Jordan',\n 'Kazakhstan',\n 'Kenya',\n 'Kiribati',\n 'Kuwait',\n 'Kyrgyzstan',\n 'Laos',\n 'Latvia',\n 'Lebanon',\n 'Lesotho',\n 'Liberia',\n 'Libya',\n 'Liechtenstein',\n 'Lithuania',\n 'Luxembourg',\n 'Madagascar',\n 'Malawi',\n 'Malaysia',\n 'Maldives',\n 'Mali',\n 'Malta',\n 'Marshall Islands',\n 'Mauritania',\n 'Mauritius',\n 'Mexico',\n 'Micronesia',\n 'Moldova',\n 'Monaco',\n 'Mongolia',\n 'Montenegro',\n 'Morocco',\n 'Mozambique',\n 'Myanmar (formerly Burma)',\n 'Namibia',\n 'Nauru',\n 'Nepal',\n 'Netherlands',\n 'New Zealand',\n 'Nicaragua',\n 'Niger',\n 'Nigeria',\n 'North Korea',\n 'North Macedonia',\n 'Norway',\n 'Oman',\n 'Pakistan',\n 'Palau',\n 'Palestine State',\n 'Panama',\n 'Papua New Guinea',\n 'Paraguay',\n 'Peru',\n 'Philippines',\n 'Poland',\n 'Portugal',\n 'Qatar',\n 'Romania',\n 'Russia',\n 'Rwanda',\n 'Saint Kitts and Nevis',\n 'Saint Lucia',\n 'Saint Vincent and the Grenadines',\n 'Samoa',\n 'San Marino',\n 'Sao Tome and Principe',\n 'Saudi Arabia',\n 'Senegal',\n 'Serbia',\n 'Seychelles',\n 'Sierra Leone',\n 'Singapore',\n 'Slovakia',\n 'Slovenia',\n 'Solomon Islands',\n 'Somalia',\n 'South Africa',\n 'South Korea',\n 'South Sudan',\n 'Spain',\n 'Sri Lanka',\n 'Sudan',\n 'Suriname',\n 'Sweden',\n 'Switzerland',\n 'Syria',\n 'Tajikistan',\n 'Tanzania',\n 'Thailand',\n 'Timor-Leste',\n 'Togo',\n 'Tonga',\n 'Trinidad and Tobago',\n 'Tunisia',\n 'Turkey',\n 'Turkmenistan',\n 'Tuvalu',\n 'Uganda',\n 'Ukraine',\n 'United Arab Emirates',\n 'United Kingdom',\n 'United States of America',\n 'Uruguay',\n 'Uzbekistan',\n 'Vanuatu',\n 'Venezuela',\n 'Vietnam',\n 'Yemen',\n 'Zambia',\n 'Zimbabwe',\n];\n"],"mappings":"AAAA,OAAO,IAAMA,WAAW,GAAG,CACzB,aADyB,EAEzB,SAFyB,EAGzB,SAHyB,EAIzB,SAJyB,EAKzB,QALyB,EAMzB,qBANyB,EAOzB,WAPyB,EAQzB,SARyB,EASzB,WATyB,EAUzB,SAVyB,EAWzB,YAXyB,EAYzB,SAZyB,EAazB,SAbyB,EAczB,YAdyB,EAezB,UAfyB,EAgBzB,SAhByB,EAiBzB,SAjByB,EAkBzB,QAlByB,EAmBzB,OAnByB,EAoBzB,QApByB,EAqBzB,SArByB,EAsBzB,wBAtByB,EAuBzB,UAvByB,EAwBzB,QAxByB,EAyBzB,QAzByB,EA0BzB,UA1ByB,EA2BzB,cA3ByB,EA4BzB,SA5ByB,EA6BzB,eA7ByB,EA8BzB,YA9ByB,EA+BzB,UA/ByB,EAgCzB,UAhCyB,EAiCzB,QAjCyB,EAkCzB,0BAlCyB,EAmCzB,2BAnCyB,EAoCzB,MApCyB,EAqCzB,OArCyB,EAsCzB,OAtCyB,EAuCzB,UAvCyB,EAwCzB,SAxCyB,EAyCzB,2BAzCyB,EA0CzB,YA1CyB,EA2CzB,SA3CyB,EA4CzB,MA5CyB,EA6CzB,QA7CyB,EA8CzB,0BA9CyB,EA+CzB,kCA/CyB,EAgDzB,SAhDyB,EAiDzB,UAjDyB,EAkDzB,UAlDyB,EAmDzB,oBAnDyB,EAoDzB,SApDyB,EAqDzB,OArDyB,EAsDzB,aAtDyB,EAuDzB,mBAvDyB,EAwDzB,S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menu/index.ts"],"sourcesContent":["export * from './Menu';\nexport * from './MenuButton';\nexport * from './MenuItem';\nexport * from './MenuList';\nexport * from './MenuPopover';\n"],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,cAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd;AACA,cAAc,eAAd"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/Menu/index.ts"],"sourcesContent":["export * from './Menu';\nexport * from './MenuButton';\nexport * from './ContextMenuTrigger';\nexport * from './MenuItem';\nexport * from './MenuList';\nexport * from './MenuPopover';\n"],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,cAAd;AACA,cAAc,sBAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd;AACA,cAAc,eAAd"}
|
|
@@ -4,6 +4,7 @@ import { wrapEvent } from '../utils';
|
|
|
4
4
|
export function useControlledState(valueProp, onChangeProp, defaultValue, defaultOnChange) {
|
|
5
5
|
var isControlled = valueProp !== undefined;
|
|
6
6
|
var wasControlled = useRef(isControlled);
|
|
7
|
+
var hasWarned = useRef(false);
|
|
7
8
|
|
|
8
9
|
var _useState = useState(defaultValue),
|
|
9
10
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -11,8 +12,9 @@ export function useControlledState(valueProp, onChangeProp, defaultValue, defaul
|
|
|
11
12
|
setValueState = _useState2[1];
|
|
12
13
|
|
|
13
14
|
if (isControlled) {
|
|
14
|
-
if (wasControlled.current && process.env.NODE_ENV !== 'production') {
|
|
15
|
+
if (wasControlled.current && process.env.NODE_ENV !== 'production' && !hasWarned.current) {
|
|
15
16
|
console.warn('Trying to change from controlled to uncontrolled.');
|
|
17
|
+
hasWarned.current = true;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
return [// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (wasControlled.current
|
|
1
|
+
{"version":3,"file":"useControlledState.js","names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","wasControlled","hasWarned","valueState","setValueState","current","process","env","NODE_ENV","console","warn"],"sources":["../../../src/hooks/useControlledState.ts"],"sourcesContent":["import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';\nimport { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends SyntheticEvent<any> | Event,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V | (() => V),\n defaultOnChange: (\n setValue: Dispatch<SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [V, CustomEventHandler<E, H>] {\n const isControlled = valueProp !== undefined;\n const wasControlled = useRef(isControlled);\n const hasWarned = useRef(false);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled) {\n if (\n wasControlled.current &&\n process.env.NODE_ENV !== 'production' &&\n !hasWarned.current\n ) {\n console.warn('Trying to change from controlled to uncontrolled.');\n hasWarned.current = true;\n }\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueProp!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n }\n\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueState!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n ];\n}\n"],"mappings":";AACA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;AAGA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAO,SAASC,kBAAT,CAKLC,SALK,EAMLC,YANK,EAOLC,YAPK,EAQLC,eARK,EAW0B;EAC/B,IAAMC,YAAY,GAAGJ,SAAS,KAAKK,SAAnC;EACA,IAAMC,aAAa,GAAGV,MAAM,CAACQ,YAAD,CAA5B;EACA,IAAMG,SAAS,GAAGX,MAAM,CAAC,KAAD,CAAxB;;EACA,gBAAoCC,QAAQ,CAAIK,YAAJ,CAA5C;EAAA;EAAA,IAAOM,UAAP;EAAA,IAAmBC,aAAnB;;EAEA,IAAIL,YAAJ,EAAkB;IAChB,IACEE,aAAa,CAACI,OAAd,IACAC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YADzB,IAEA,CAACN,SAAS,CAACG,OAHb,EAIE;MACAI,OAAO,CAACC,IAAR,CAAa,mDAAb;MACAR,SAAS,CAACG,OAAV,GAAoB,IAApB;IACD;;IACD,OAAO,CACL;IACAV,SAFK,EAGLF,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;EAKD;;EAED,OAAO,CACL;EACAD,UAFK,EAGLV,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACM,aAAD,CAA9B,CAHJ,CAAP;AAKD"}
|