@launchpad-ui/dropdown 0.6.48 → 0.6.50
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/Dropdown.d.ts +1 -2
- package/dist/Dropdown.d.ts.map +1 -1
- package/dist/index.es.js +28 -36
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +29 -37
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/Dropdown.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
/// <reference types="react" />
|
2
1
|
import type { PopoverProps } from '@launchpad-ui/popover';
|
3
2
|
type DropdownState = {
|
4
3
|
isOpen?: boolean;
|
@@ -7,7 +6,7 @@ type DropdownProps<T extends string | object | number> = PopoverProps & {
|
|
7
6
|
onSelect?: (item: T, stateChanges: DropdownState) => void;
|
8
7
|
onStateChange?: (state: DropdownState) => void;
|
9
8
|
};
|
10
|
-
declare const Dropdown: <T extends string | number | object>(props: DropdownProps<T>) => JSX.Element;
|
9
|
+
declare const Dropdown: <T extends string | number | object>(props: DropdownProps<T>) => import("react/jsx-runtime").JSX.Element;
|
11
10
|
export { Dropdown };
|
12
11
|
export type { DropdownProps };
|
13
12
|
//# sourceMappingURL=Dropdown.d.ts.map
|
package/dist/Dropdown.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../src/Dropdown.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../src/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAQ1D,KAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,YAAY,GAAG;IACtE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1D,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF,QAAA,MAAM,QAAQ,0GAyGb,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.es.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
1
2
|
import { Popover } from "@launchpad-ui/popover";
|
2
3
|
import { mergeRefs } from "@react-aria/utils";
|
3
4
|
import { cx } from "classix";
|
4
5
|
import { useRef, useState, useEffect, cloneElement, Children, forwardRef } from "react";
|
5
|
-
import { jsxs, jsx } from "react/jsx-runtime";
|
6
6
|
import { Button } from "@launchpad-ui/button";
|
7
7
|
import { ExpandMore } from "@launchpad-ui/icons";
|
8
8
|
const Dropdown = (props) => {
|
@@ -20,7 +20,7 @@ const Dropdown = (props) => {
|
|
20
20
|
...rest
|
21
21
|
} = props;
|
22
22
|
const triggerRef = useRef();
|
23
|
-
const [isOpen, setIsOpen] = useState(isOpenProp
|
23
|
+
const [isOpen, setIsOpen] = useState(isOpenProp ?? false);
|
24
24
|
const [hasOpened, setHasOpened] = useState(isOpen);
|
25
25
|
useEffect(() => {
|
26
26
|
if (isOpenProp !== void 0) {
|
@@ -42,14 +42,10 @@ const Dropdown = (props) => {
|
|
42
42
|
}, [isOpen, hasOpened]);
|
43
43
|
useEffect(() => {
|
44
44
|
setHasOpened(isOpen);
|
45
|
-
onStateChange == null ? void 0 : onStateChange({
|
46
|
-
isOpen
|
47
|
-
});
|
45
|
+
onStateChange == null ? void 0 : onStateChange({ isOpen });
|
48
46
|
}, [isOpen]);
|
49
47
|
const renderTrigger = () => {
|
50
|
-
const {
|
51
|
-
target
|
52
|
-
} = parseChildren();
|
48
|
+
const { target } = parseChildren();
|
53
49
|
return cloneElement(target, {
|
54
50
|
"aria-haspopup": true,
|
55
51
|
"aria-expanded": isOpen ? true : false,
|
@@ -64,9 +60,7 @@ const Dropdown = (props) => {
|
|
64
60
|
};
|
65
61
|
const handleSelect = (item) => {
|
66
62
|
setIsOpen(false);
|
67
|
-
onSelect == null ? void 0 : onSelect(item, {
|
68
|
-
isOpen: false
|
69
|
-
});
|
63
|
+
onSelect == null ? void 0 : onSelect(item, { isOpen: false });
|
70
64
|
};
|
71
65
|
const handlePopoverInteraction = (nextIsOpen) => {
|
72
66
|
setIsOpen(nextIsOpen);
|
@@ -80,34 +74,32 @@ const Dropdown = (props) => {
|
|
80
74
|
};
|
81
75
|
const popoverTargetClasses = cx("Dropdown-target", targetClassName);
|
82
76
|
const popoverClasses = cx("Dropdown", popoverClassName);
|
83
|
-
return /* @__PURE__ */ jsxs(
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
77
|
+
return /* @__PURE__ */ jsxs(
|
78
|
+
Popover,
|
79
|
+
{
|
80
|
+
isOpen,
|
81
|
+
placement,
|
82
|
+
onInteraction: onInteraction || handlePopoverInteraction,
|
83
|
+
restrictHeight: false,
|
84
|
+
disabled,
|
85
|
+
targetClassName: popoverTargetClasses,
|
86
|
+
popoverClassName: popoverClasses,
|
87
|
+
"data-test-id": testId,
|
88
|
+
...rest,
|
89
|
+
children: [
|
90
|
+
renderTrigger(),
|
91
|
+
renderContent()
|
92
|
+
]
|
93
|
+
}
|
94
|
+
);
|
95
95
|
};
|
96
96
|
const DropdownButton = forwardRef((props, ref) => {
|
97
|
-
const {
|
97
|
+
const { children, hideCaret, "data-test-id": testId = "dropdown-button", ...rest } = props;
|
98
|
+
return /* @__PURE__ */ jsxs(Button, { ...rest, "data-test-id": testId, ref, children: [
|
98
99
|
children,
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
} = props;
|
103
|
-
return /* @__PURE__ */ jsxs(Button, {
|
104
|
-
...rest,
|
105
|
-
"data-test-id": testId,
|
106
|
-
ref,
|
107
|
-
children: [children, " ", !hideCaret && /* @__PURE__ */ jsx(ExpandMore, {
|
108
|
-
size: "small"
|
109
|
-
})]
|
110
|
-
});
|
100
|
+
" ",
|
101
|
+
!hideCaret && /* @__PURE__ */ jsx(ExpandMore, { size: "small" })
|
102
|
+
] });
|
111
103
|
});
|
112
104
|
DropdownButton.displayName = "DropdownButton";
|
113
105
|
export {
|
package/dist/index.es.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/Dropdown.tsx","../src/DropdownButton.tsx"],"sourcesContent":["import type { PopoverProps } from '@launchpad-ui/popover';\nimport type { AriaAttributes, ForwardedRef, FunctionComponentElement, ReactElement } from 'react';\n\nimport { Popover } from '@launchpad-ui/popover';\nimport { mergeRefs } from '@react-aria/utils';\nimport { cx } from 'classix';\nimport { Children, cloneElement, useEffect, useRef, useState } from 'react';\n\ntype DropdownState = {\n isOpen?: boolean;\n};\n\ntype DropdownProps<T extends string | object | number> = PopoverProps & {\n onSelect?: (item: T, stateChanges: DropdownState) => void;\n onStateChange?: (state: DropdownState) => void;\n};\n\nconst Dropdown = <T extends string | object | number>(props: DropdownProps<T>) => {\n const {\n placement,\n disabled,\n targetClassName,\n popoverClassName,\n isOpen: isOpenProp,\n onInteraction,\n onSelect,\n onStateChange,\n children,\n 'data-test-id': testId = 'dropdown',\n ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>();\n const [isOpen, setIsOpen] = useState(isOpenProp ?? false);\n const [hasOpened, setHasOpened] = useState(isOpen);\n\n useEffect(() => {\n if (isOpenProp !== undefined) {\n setIsOpen(isOpenProp);\n }\n }, [isOpenProp]);\n\n useEffect(() => {\n // Focus the button upon closing for convenient tabbing\n if (hasOpened && isOpen === false) {\n setTimeout(() => {\n const current = triggerRef.current;\n if (!current) {\n return;\n }\n\n // If a dropdown menu item triggers a modal, we do not want to focus the trigger. Instead\n // we let the modal components control their own focus.\n // Note that this is not ideal since closing the modal will not cause the dropdown trigger\n // to regain focus.\n const hasModal = current.closest?.('.has-overlay');\n\n !hasModal && current.focus?.();\n });\n }\n }, [isOpen, hasOpened]);\n\n useEffect(() => {\n setHasOpened(isOpen);\n onStateChange?.({ isOpen });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n const renderTrigger = () => {\n const { target } = parseChildren();\n return cloneElement(target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: target.ref ? mergeRefs(target.ref, triggerRef) : triggerRef,\n isopen: isOpen?.toString(),\n });\n };\n\n const renderContent = () => {\n return cloneElement(parseChildren().content, {\n onSelect: handleSelect,\n });\n };\n\n const handleSelect = (item: T) => {\n setIsOpen(false);\n onSelect?.(item, { isOpen: false });\n };\n\n const handlePopoverInteraction = (nextIsOpen: boolean) => {\n setIsOpen(nextIsOpen);\n };\n\n const parseChildren = () => {\n const [targetChild, contentChild] = Children.toArray(children);\n return {\n target: targetChild as FunctionComponentElement<\n AriaAttributes & { ref: ForwardedRef<HTMLElement | undefined>; isopen: string }\n >,\n content: contentChild as ReactElement,\n };\n };\n\n const popoverTargetClasses = cx('Dropdown-target', targetClassName);\n const popoverClasses = cx('Dropdown', popoverClassName);\n\n return (\n <Popover\n isOpen={isOpen}\n placement={placement}\n onInteraction={onInteraction || handlePopoverInteraction}\n restrictHeight={false}\n disabled={disabled}\n targetClassName={popoverTargetClasses}\n popoverClassName={popoverClasses}\n data-test-id={testId}\n {...rest}\n >\n {renderTrigger()}\n {renderContent()}\n </Popover>\n );\n};\n\nexport { Dropdown };\nexport type { DropdownProps };\n","import type { ButtonProps } from '@launchpad-ui/button';\n\nimport { Button } from '@launchpad-ui/button';\nimport { ExpandMore } from '@launchpad-ui/icons';\nimport { forwardRef } from 'react';\n\ntype DropdownButtonProps = ButtonProps & {\n hideCaret?: boolean;\n};\n\nconst DropdownButton = forwardRef<HTMLButtonElement, DropdownButtonProps>((props, ref) => {\n const { children, hideCaret, 'data-test-id': testId = 'dropdown-button', ...rest } = props;\n\n return (\n <Button {...rest} data-test-id={testId} ref={ref}>\n {children} {!hideCaret && <ExpandMore size=\"small\" />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":[
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/Dropdown.tsx","../src/DropdownButton.tsx"],"sourcesContent":["import type { PopoverProps } from '@launchpad-ui/popover';\nimport type { AriaAttributes, ForwardedRef, FunctionComponentElement, ReactElement } from 'react';\n\nimport { Popover } from '@launchpad-ui/popover';\nimport { mergeRefs } from '@react-aria/utils';\nimport { cx } from 'classix';\nimport { Children, cloneElement, useEffect, useRef, useState } from 'react';\n\ntype DropdownState = {\n isOpen?: boolean;\n};\n\ntype DropdownProps<T extends string | object | number> = PopoverProps & {\n onSelect?: (item: T, stateChanges: DropdownState) => void;\n onStateChange?: (state: DropdownState) => void;\n};\n\nconst Dropdown = <T extends string | object | number>(props: DropdownProps<T>) => {\n const {\n placement,\n disabled,\n targetClassName,\n popoverClassName,\n isOpen: isOpenProp,\n onInteraction,\n onSelect,\n onStateChange,\n children,\n 'data-test-id': testId = 'dropdown',\n ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>();\n const [isOpen, setIsOpen] = useState(isOpenProp ?? false);\n const [hasOpened, setHasOpened] = useState(isOpen);\n\n useEffect(() => {\n if (isOpenProp !== undefined) {\n setIsOpen(isOpenProp);\n }\n }, [isOpenProp]);\n\n useEffect(() => {\n // Focus the button upon closing for convenient tabbing\n if (hasOpened && isOpen === false) {\n setTimeout(() => {\n const current = triggerRef.current;\n if (!current) {\n return;\n }\n\n // If a dropdown menu item triggers a modal, we do not want to focus the trigger. Instead\n // we let the modal components control their own focus.\n // Note that this is not ideal since closing the modal will not cause the dropdown trigger\n // to regain focus.\n const hasModal = current.closest?.('.has-overlay');\n\n !hasModal && current.focus?.();\n });\n }\n }, [isOpen, hasOpened]);\n\n useEffect(() => {\n setHasOpened(isOpen);\n onStateChange?.({ isOpen });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n const renderTrigger = () => {\n const { target } = parseChildren();\n return cloneElement(target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: target.ref ? mergeRefs(target.ref, triggerRef) : triggerRef,\n isopen: isOpen?.toString(),\n });\n };\n\n const renderContent = () => {\n return cloneElement(parseChildren().content, {\n onSelect: handleSelect,\n });\n };\n\n const handleSelect = (item: T) => {\n setIsOpen(false);\n onSelect?.(item, { isOpen: false });\n };\n\n const handlePopoverInteraction = (nextIsOpen: boolean) => {\n setIsOpen(nextIsOpen);\n };\n\n const parseChildren = () => {\n const [targetChild, contentChild] = Children.toArray(children);\n return {\n target: targetChild as FunctionComponentElement<\n AriaAttributes & { ref: ForwardedRef<HTMLElement | undefined>; isopen: string }\n >,\n content: contentChild as ReactElement,\n };\n };\n\n const popoverTargetClasses = cx('Dropdown-target', targetClassName);\n const popoverClasses = cx('Dropdown', popoverClassName);\n\n return (\n <Popover\n isOpen={isOpen}\n placement={placement}\n onInteraction={onInteraction || handlePopoverInteraction}\n restrictHeight={false}\n disabled={disabled}\n targetClassName={popoverTargetClasses}\n popoverClassName={popoverClasses}\n data-test-id={testId}\n {...rest}\n >\n {renderTrigger()}\n {renderContent()}\n </Popover>\n );\n};\n\nexport { Dropdown };\nexport type { DropdownProps };\n","import type { ButtonProps } from '@launchpad-ui/button';\n\nimport { Button } from '@launchpad-ui/button';\nimport { ExpandMore } from '@launchpad-ui/icons';\nimport { forwardRef } from 'react';\n\ntype DropdownButtonProps = ButtonProps & {\n hideCaret?: boolean;\n};\n\nconst DropdownButton = forwardRef<HTMLButtonElement, DropdownButtonProps>((props, ref) => {\n const { children, hideCaret, 'data-test-id': testId = 'dropdown-button', ...rest } = props;\n\n return (\n <Button {...rest} data-test-id={testId} ref={ref}>\n {children} {!hideCaret && <ExpandMore size=\"small\" />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":[],"mappings":";;;;;;;AAiBM,MAAA,WAAW,CAAqC,UAA4B;AAC1E,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,SAAS;AAAA,IACzB,GAAG;AAAA,EACD,IAAA;AAEJ,QAAM,aAAa;AACnB,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,cAAc,KAAK;AACxD,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,MAAM;AAEjD,YAAU,MAAM;AACd,QAAI,eAAe,QAAW;AAC5B,gBAAU,UAAU;AAAA,IACtB;AAAA,EAAA,GACC,CAAC,UAAU,CAAC;AAEf,YAAU,MAAM;AAEV,QAAA,aAAa,WAAW,OAAO;AACjC,iBAAW,MAAM;;AACf,cAAM,UAAU,WAAW;AAC3B,YAAI,CAAC,SAAS;AACZ;AAAA,QACF;AAMM,cAAA,YAAW,aAAQ,YAAR,iCAAkB;AAElC,SAAA,cAAY,aAAQ,UAAR;AAAA,MAAgB,CAC9B;AAAA,IACH;AAAA,EAAA,GACC,CAAC,QAAQ,SAAS,CAAC;AAEtB,YAAU,MAAM;AACd,iBAAa,MAAM;AACH,mDAAA,EAAE;EAAQ,GAEzB,CAAC,MAAM,CAAC;AAEX,QAAM,gBAAgB,MAAM;AACpB,UAAA,EAAE,WAAW;AACnB,WAAO,aAAa,QAAQ;AAAA,MAC1B,iBAAiB;AAAA,MACjB,iBAAiB,SAAS,OAAO;AAAA,MACjC,KAAK,OAAO,MAAM,UAAU,OAAO,KAAK,UAAU,IAAI;AAAA,MACtD,QAAQ,iCAAQ;AAAA,IAAS,CAC1B;AAAA,EAAA;AAGH,QAAM,gBAAgB,MAA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+
const jsxRuntime = require("react/jsx-runtime");
|
3
4
|
const popover = require("@launchpad-ui/popover");
|
4
5
|
const utils = require("@react-aria/utils");
|
5
6
|
const classix = require("classix");
|
6
7
|
const react = require("react");
|
7
|
-
const jsxRuntime = require("react/jsx-runtime");
|
8
8
|
const button = require("@launchpad-ui/button");
|
9
9
|
const icons = require("@launchpad-ui/icons");
|
10
10
|
const Dropdown = (props) => {
|
@@ -22,7 +22,7 @@ const Dropdown = (props) => {
|
|
22
22
|
...rest
|
23
23
|
} = props;
|
24
24
|
const triggerRef = react.useRef();
|
25
|
-
const [isOpen, setIsOpen] = react.useState(isOpenProp
|
25
|
+
const [isOpen, setIsOpen] = react.useState(isOpenProp ?? false);
|
26
26
|
const [hasOpened, setHasOpened] = react.useState(isOpen);
|
27
27
|
react.useEffect(() => {
|
28
28
|
if (isOpenProp !== void 0) {
|
@@ -44,14 +44,10 @@ const Dropdown = (props) => {
|
|
44
44
|
}, [isOpen, hasOpened]);
|
45
45
|
react.useEffect(() => {
|
46
46
|
setHasOpened(isOpen);
|
47
|
-
onStateChange == null ? void 0 : onStateChange({
|
48
|
-
isOpen
|
49
|
-
});
|
47
|
+
onStateChange == null ? void 0 : onStateChange({ isOpen });
|
50
48
|
}, [isOpen]);
|
51
49
|
const renderTrigger = () => {
|
52
|
-
const {
|
53
|
-
target
|
54
|
-
} = parseChildren();
|
50
|
+
const { target } = parseChildren();
|
55
51
|
return react.cloneElement(target, {
|
56
52
|
"aria-haspopup": true,
|
57
53
|
"aria-expanded": isOpen ? true : false,
|
@@ -66,9 +62,7 @@ const Dropdown = (props) => {
|
|
66
62
|
};
|
67
63
|
const handleSelect = (item) => {
|
68
64
|
setIsOpen(false);
|
69
|
-
onSelect == null ? void 0 : onSelect(item, {
|
70
|
-
isOpen: false
|
71
|
-
});
|
65
|
+
onSelect == null ? void 0 : onSelect(item, { isOpen: false });
|
72
66
|
};
|
73
67
|
const handlePopoverInteraction = (nextIsOpen) => {
|
74
68
|
setIsOpen(nextIsOpen);
|
@@ -82,34 +76,32 @@ const Dropdown = (props) => {
|
|
82
76
|
};
|
83
77
|
const popoverTargetClasses = classix.cx("Dropdown-target", targetClassName);
|
84
78
|
const popoverClasses = classix.cx("Dropdown", popoverClassName);
|
85
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
79
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
80
|
+
popover.Popover,
|
81
|
+
{
|
82
|
+
isOpen,
|
83
|
+
placement,
|
84
|
+
onInteraction: onInteraction || handlePopoverInteraction,
|
85
|
+
restrictHeight: false,
|
86
|
+
disabled,
|
87
|
+
targetClassName: popoverTargetClasses,
|
88
|
+
popoverClassName: popoverClasses,
|
89
|
+
"data-test-id": testId,
|
90
|
+
...rest,
|
91
|
+
children: [
|
92
|
+
renderTrigger(),
|
93
|
+
renderContent()
|
94
|
+
]
|
95
|
+
}
|
96
|
+
);
|
97
97
|
};
|
98
98
|
const DropdownButton = react.forwardRef((props, ref) => {
|
99
|
-
const {
|
99
|
+
const { children, hideCaret, "data-test-id": testId = "dropdown-button", ...rest } = props;
|
100
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(button.Button, { ...rest, "data-test-id": testId, ref, children: [
|
100
101
|
children,
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
} = props;
|
105
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(button.Button, {
|
106
|
-
...rest,
|
107
|
-
"data-test-id": testId,
|
108
|
-
ref,
|
109
|
-
children: [children, " ", !hideCaret && /* @__PURE__ */ jsxRuntime.jsx(icons.ExpandMore, {
|
110
|
-
size: "small"
|
111
|
-
})]
|
112
|
-
});
|
102
|
+
" ",
|
103
|
+
!hideCaret && /* @__PURE__ */ jsxRuntime.jsx(icons.ExpandMore, { size: "small" })
|
104
|
+
] });
|
113
105
|
});
|
114
106
|
DropdownButton.displayName = "DropdownButton";
|
115
107
|
exports.Dropdown = Dropdown;
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/Dropdown.tsx","../src/DropdownButton.tsx"],"sourcesContent":["import type { PopoverProps } from '@launchpad-ui/popover';\nimport type { AriaAttributes, ForwardedRef, FunctionComponentElement, ReactElement } from 'react';\n\nimport { Popover } from '@launchpad-ui/popover';\nimport { mergeRefs } from '@react-aria/utils';\nimport { cx } from 'classix';\nimport { Children, cloneElement, useEffect, useRef, useState } from 'react';\n\ntype DropdownState = {\n isOpen?: boolean;\n};\n\ntype DropdownProps<T extends string | object | number> = PopoverProps & {\n onSelect?: (item: T, stateChanges: DropdownState) => void;\n onStateChange?: (state: DropdownState) => void;\n};\n\nconst Dropdown = <T extends string | object | number>(props: DropdownProps<T>) => {\n const {\n placement,\n disabled,\n targetClassName,\n popoverClassName,\n isOpen: isOpenProp,\n onInteraction,\n onSelect,\n onStateChange,\n children,\n 'data-test-id': testId = 'dropdown',\n ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>();\n const [isOpen, setIsOpen] = useState(isOpenProp ?? false);\n const [hasOpened, setHasOpened] = useState(isOpen);\n\n useEffect(() => {\n if (isOpenProp !== undefined) {\n setIsOpen(isOpenProp);\n }\n }, [isOpenProp]);\n\n useEffect(() => {\n // Focus the button upon closing for convenient tabbing\n if (hasOpened && isOpen === false) {\n setTimeout(() => {\n const current = triggerRef.current;\n if (!current) {\n return;\n }\n\n // If a dropdown menu item triggers a modal, we do not want to focus the trigger. Instead\n // we let the modal components control their own focus.\n // Note that this is not ideal since closing the modal will not cause the dropdown trigger\n // to regain focus.\n const hasModal = current.closest?.('.has-overlay');\n\n !hasModal && current.focus?.();\n });\n }\n }, [isOpen, hasOpened]);\n\n useEffect(() => {\n setHasOpened(isOpen);\n onStateChange?.({ isOpen });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n const renderTrigger = () => {\n const { target } = parseChildren();\n return cloneElement(target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: target.ref ? mergeRefs(target.ref, triggerRef) : triggerRef,\n isopen: isOpen?.toString(),\n });\n };\n\n const renderContent = () => {\n return cloneElement(parseChildren().content, {\n onSelect: handleSelect,\n });\n };\n\n const handleSelect = (item: T) => {\n setIsOpen(false);\n onSelect?.(item, { isOpen: false });\n };\n\n const handlePopoverInteraction = (nextIsOpen: boolean) => {\n setIsOpen(nextIsOpen);\n };\n\n const parseChildren = () => {\n const [targetChild, contentChild] = Children.toArray(children);\n return {\n target: targetChild as FunctionComponentElement<\n AriaAttributes & { ref: ForwardedRef<HTMLElement | undefined>; isopen: string }\n >,\n content: contentChild as ReactElement,\n };\n };\n\n const popoverTargetClasses = cx('Dropdown-target', targetClassName);\n const popoverClasses = cx('Dropdown', popoverClassName);\n\n return (\n <Popover\n isOpen={isOpen}\n placement={placement}\n onInteraction={onInteraction || handlePopoverInteraction}\n restrictHeight={false}\n disabled={disabled}\n targetClassName={popoverTargetClasses}\n popoverClassName={popoverClasses}\n data-test-id={testId}\n {...rest}\n >\n {renderTrigger()}\n {renderContent()}\n </Popover>\n );\n};\n\nexport { Dropdown };\nexport type { DropdownProps };\n","import type { ButtonProps } from '@launchpad-ui/button';\n\nimport { Button } from '@launchpad-ui/button';\nimport { ExpandMore } from '@launchpad-ui/icons';\nimport { forwardRef } from 'react';\n\ntype DropdownButtonProps = ButtonProps & {\n hideCaret?: boolean;\n};\n\nconst DropdownButton = forwardRef<HTMLButtonElement, DropdownButtonProps>((props, ref) => {\n const { children, hideCaret, 'data-test-id': testId = 'dropdown-button', ...rest } = props;\n\n return (\n <Button {...rest} data-test-id={testId} ref={ref}>\n {children} {!hideCaret && <ExpandMore size=\"small\" />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":["
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Dropdown.tsx","../src/DropdownButton.tsx"],"sourcesContent":["import type { PopoverProps } from '@launchpad-ui/popover';\nimport type { AriaAttributes, ForwardedRef, FunctionComponentElement, ReactElement } from 'react';\n\nimport { Popover } from '@launchpad-ui/popover';\nimport { mergeRefs } from '@react-aria/utils';\nimport { cx } from 'classix';\nimport { Children, cloneElement, useEffect, useRef, useState } from 'react';\n\ntype DropdownState = {\n isOpen?: boolean;\n};\n\ntype DropdownProps<T extends string | object | number> = PopoverProps & {\n onSelect?: (item: T, stateChanges: DropdownState) => void;\n onStateChange?: (state: DropdownState) => void;\n};\n\nconst Dropdown = <T extends string | object | number>(props: DropdownProps<T>) => {\n const {\n placement,\n disabled,\n targetClassName,\n popoverClassName,\n isOpen: isOpenProp,\n onInteraction,\n onSelect,\n onStateChange,\n children,\n 'data-test-id': testId = 'dropdown',\n ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>();\n const [isOpen, setIsOpen] = useState(isOpenProp ?? false);\n const [hasOpened, setHasOpened] = useState(isOpen);\n\n useEffect(() => {\n if (isOpenProp !== undefined) {\n setIsOpen(isOpenProp);\n }\n }, [isOpenProp]);\n\n useEffect(() => {\n // Focus the button upon closing for convenient tabbing\n if (hasOpened && isOpen === false) {\n setTimeout(() => {\n const current = triggerRef.current;\n if (!current) {\n return;\n }\n\n // If a dropdown menu item triggers a modal, we do not want to focus the trigger. Instead\n // we let the modal components control their own focus.\n // Note that this is not ideal since closing the modal will not cause the dropdown trigger\n // to regain focus.\n const hasModal = current.closest?.('.has-overlay');\n\n !hasModal && current.focus?.();\n });\n }\n }, [isOpen, hasOpened]);\n\n useEffect(() => {\n setHasOpened(isOpen);\n onStateChange?.({ isOpen });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen]);\n\n const renderTrigger = () => {\n const { target } = parseChildren();\n return cloneElement(target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: target.ref ? mergeRefs(target.ref, triggerRef) : triggerRef,\n isopen: isOpen?.toString(),\n });\n };\n\n const renderContent = () => {\n return cloneElement(parseChildren().content, {\n onSelect: handleSelect,\n });\n };\n\n const handleSelect = (item: T) => {\n setIsOpen(false);\n onSelect?.(item, { isOpen: false });\n };\n\n const handlePopoverInteraction = (nextIsOpen: boolean) => {\n setIsOpen(nextIsOpen);\n };\n\n const parseChildren = () => {\n const [targetChild, contentChild] = Children.toArray(children);\n return {\n target: targetChild as FunctionComponentElement<\n AriaAttributes & { ref: ForwardedRef<HTMLElement | undefined>; isopen: string }\n >,\n content: contentChild as ReactElement,\n };\n };\n\n const popoverTargetClasses = cx('Dropdown-target', targetClassName);\n const popoverClasses = cx('Dropdown', popoverClassName);\n\n return (\n <Popover\n isOpen={isOpen}\n placement={placement}\n onInteraction={onInteraction || handlePopoverInteraction}\n restrictHeight={false}\n disabled={disabled}\n targetClassName={popoverTargetClasses}\n popoverClassName={popoverClasses}\n data-test-id={testId}\n {...rest}\n >\n {renderTrigger()}\n {renderContent()}\n </Popover>\n );\n};\n\nexport { Dropdown };\nexport type { DropdownProps };\n","import type { ButtonProps } from '@launchpad-ui/button';\n\nimport { Button } from '@launchpad-ui/button';\nimport { ExpandMore } from '@launchpad-ui/icons';\nimport { forwardRef } from 'react';\n\ntype DropdownButtonProps = ButtonProps & {\n hideCaret?: boolean;\n};\n\nconst DropdownButton = forwardRef<HTMLButtonElement, DropdownButtonProps>((props, ref) => {\n const { children, hideCaret, 'data-test-id': testId = 'dropdown-button', ...rest } = props;\n\n return (\n <Button {...rest} data-test-id={testId} ref={ref}>\n {children} {!hideCaret && <ExpandMore size=\"small\" />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":["useRef","useState","useEffect","cloneElement","mergeRefs","Children","cx","jsxs","Popover","forwardRef","Button","jsx","ExpandMore"],"mappings":";;;;;;;;;AAiBM,MAAA,WAAW,CAAqC,UAA4B;AA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
|
"access": "public"
|
@@ -25,11 +25,11 @@
|
|
25
25
|
},
|
26
26
|
"source": "src/index.ts",
|
27
27
|
"dependencies": {
|
28
|
-
"@react-aria/utils": "3.
|
28
|
+
"@react-aria/utils": "3.17.0",
|
29
29
|
"classix": "2.1.17",
|
30
30
|
"@launchpad-ui/button": "~0.8.13",
|
31
31
|
"@launchpad-ui/icons": "~0.8.6",
|
32
|
-
"@launchpad-ui/popover": "~0.10.
|
32
|
+
"@launchpad-ui/popover": "~0.10.4",
|
33
33
|
"@launchpad-ui/tokens": "~0.5.6"
|
34
34
|
},
|
35
35
|
"peerDependencies": {
|