@launchpad-ui/dropdown 0.6.81 → 0.6.82

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/index.es.js CHANGED
@@ -42,10 +42,14 @@ const Dropdown = (props) => {
42
42
  }, [isOpen, hasOpened]);
43
43
  useEffect(() => {
44
44
  setHasOpened(isOpen);
45
- onStateChange == null ? void 0 : onStateChange({ isOpen });
45
+ onStateChange == null ? void 0 : onStateChange({
46
+ isOpen
47
+ });
46
48
  }, [isOpen]);
47
49
  const renderTrigger = () => {
48
- const { target } = parseChildren();
50
+ const {
51
+ target
52
+ } = parseChildren();
49
53
  return /* @__PURE__ */ cloneElement(target, {
50
54
  "aria-haspopup": true,
51
55
  "aria-expanded": isOpen ? true : false,
@@ -60,7 +64,9 @@ const Dropdown = (props) => {
60
64
  };
61
65
  const handleSelect = (item) => {
62
66
  setIsOpen(false);
63
- onSelect == null ? void 0 : onSelect(item, { isOpen: false });
67
+ onSelect == null ? void 0 : onSelect(item, {
68
+ isOpen: false
69
+ });
64
70
  };
65
71
  const handlePopoverInteraction = (nextIsOpen) => {
66
72
  setIsOpen(nextIsOpen);
@@ -74,32 +80,35 @@ const Dropdown = (props) => {
74
80
  };
75
81
  const popoverTargetClasses = cx("Dropdown-target", targetClassName);
76
82
  const popoverClasses = cx("Dropdown", popoverClassName);
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
- );
83
+ return /* @__PURE__ */ jsxs(Popover, {
84
+ isOpen,
85
+ placement,
86
+ onInteraction: onInteraction || handlePopoverInteraction,
87
+ restrictHeight: false,
88
+ disabled,
89
+ targetClassName: popoverTargetClasses,
90
+ popoverClassName: popoverClasses,
91
+ "data-test-id": testId,
92
+ ...rest,
93
+ children: [renderTrigger(), renderContent()]
94
+ });
95
95
  };
96
96
  const DropdownButton = /* @__PURE__ */ forwardRef((props, ref) => {
97
- const { children, hideCaret, "data-test-id": testId = "dropdown-button", ...rest } = props;
98
- return /* @__PURE__ */ jsxs(Button, { ...rest, "data-test-id": testId, ref, children: [
97
+ const {
99
98
  children,
100
- " ",
101
- !hideCaret && /* @__PURE__ */ jsx(Icon, { name: "chevron-down", size: "small" })
102
- ] });
99
+ hideCaret,
100
+ "data-test-id": testId = "dropdown-button",
101
+ ...rest
102
+ } = props;
103
+ return /* @__PURE__ */ jsxs(Button, {
104
+ ...rest,
105
+ "data-test-id": testId,
106
+ ref,
107
+ children: [children, " ", !hideCaret && /* @__PURE__ */ jsx(Icon, {
108
+ name: "chevron-down",
109
+ size: "small"
110
+ })]
111
+ });
103
112
  });
104
113
  DropdownButton.displayName = "DropdownButton";
105
114
  export {
@@ -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 { Icon } 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 && <Icon name=\"chevron-down\" 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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,gBAAgB,SAAS,mBAAmB,GAAG,KAAS,IAAA;AAErF,8BACG,QAAQ,EAAA,GAAG,MAAM,gBAAc,QAAQ,KACrC,UAAA;AAAA,IAAA;AAAA,IAAS;AAAA,IAAE,CAAC,aAAa,oBAAC,QAAK,MAAK,gBAAe,MAAK,SAAQ;AAAA,EACnE,EAAA,CAAA;AAEJ,CAAC;AAED,eAAe,cAAc;"}
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 { Icon } 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 && <Icon name=\"chevron-down\" size=\"small\" />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":[],"mappings":";;;;;;;AAiBM,MAAA,WAAW,WAAiE;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;AAAA,MAEd;AAAA,IAEJ;AAAA,EACE,GAAM,CAAA,MAAE,CAAO;AACf,QAAA,gBAAoB,MAAQ;AAAA,UACT;AAAA,MACjB;AAAA,IAAiC,kBACrB;AACZ,WAAyB,6BAAA,QAAA;AAAA,MAC1B,iBAAA;AAAA,MACH,iBAAA,SAAA,OAAA;AAAA,MAEA,kBAAsB,UAAM,OAAA,KAAA,UAAA,IAAA;AAAA,MACnB,QAAA,iCAAA;AAAA,IAAsC,CAAA;AAAA,EACjC;AAEd,QAAA,gBAAA,MAAA;AAEM,wCAAgB,cAAY,EAAA,SAAA;AAAA,MAChC,UAAe;AAAA,IACf,CAAA;AAAA,EAAkC;AAG9B,QAAA,eAAA,UAAA;AACJ,cAAU,KAAU;AACtB,yCAAA,MAAA;AAAA,MAEA;IACE;AAAA,EACA;AAAO,QACG,2BAAA,gBAAA;AAAA,cAGC,UAAA;AAAA,EAAA;AAEb,QAAA,gBAAA,MAAA;AAEM,UAAA,CAAA,aAAA,YAA0B,IAAA,SAAA,QAAkC,QAAA;AAC5D,WAAA;AAAA,MAGJ,QAAA;AAAA,MAAC,SAAA;AAAA,IAAA;AAAA,EAAA;AAEC,QAAA,uBAAA,GAAA,mBAAA,eAAA;AAAA,yBACgC,GAAA,YAAA,gBAAA;AAAA,SAChB,qBAAA,SAAA;AAAA,IAChB;AAAA,IAAA;AAAA,IACiB,eACC,iBAAA;AAAA,IAAA,gBACJ;AAAA,IAAA;AAAA,IAGb,iBAAA;AAAA,IAAc,kBAAA;AAAA,IAAA,gBACA;AAAA,IAAA,GAAA;AAAA,IAAA,UAAA,CAAA,iBAAA,eAAA;AAAA,EAAA,CACjB;AAEJ;AChHA,MAAM,iBAAoE,2BAAA,CAAC,OAAO,QAAQ;AAClF,QAAA;AAAA,IAEN;AAAA,IAEK;AAAA,IAAS,gBAAA,SAAA;AAAA,IAAE,GAAc;AAAA,EAC5B,IAAA;AAEH,SAAA,qBAAA,QAAA;AAAA,IAED,GAAA;AAAA,IAES,gBAAA;AAAA;;;;;;;;"}
package/dist/index.js CHANGED
@@ -44,10 +44,14 @@ const Dropdown = (props) => {
44
44
  }, [isOpen, hasOpened]);
45
45
  react.useEffect(() => {
46
46
  setHasOpened(isOpen);
47
- onStateChange == null ? void 0 : onStateChange({ isOpen });
47
+ onStateChange == null ? void 0 : onStateChange({
48
+ isOpen
49
+ });
48
50
  }, [isOpen]);
49
51
  const renderTrigger = () => {
50
- const { target } = parseChildren();
52
+ const {
53
+ target
54
+ } = parseChildren();
51
55
  return /* @__PURE__ */ react.cloneElement(target, {
52
56
  "aria-haspopup": true,
53
57
  "aria-expanded": isOpen ? true : false,
@@ -62,7 +66,9 @@ const Dropdown = (props) => {
62
66
  };
63
67
  const handleSelect = (item) => {
64
68
  setIsOpen(false);
65
- onSelect == null ? void 0 : onSelect(item, { isOpen: false });
69
+ onSelect == null ? void 0 : onSelect(item, {
70
+ isOpen: false
71
+ });
66
72
  };
67
73
  const handlePopoverInteraction = (nextIsOpen) => {
68
74
  setIsOpen(nextIsOpen);
@@ -76,32 +82,35 @@ const Dropdown = (props) => {
76
82
  };
77
83
  const popoverTargetClasses = classix.cx("Dropdown-target", targetClassName);
78
84
  const popoverClasses = classix.cx("Dropdown", popoverClassName);
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
- );
85
+ return /* @__PURE__ */ jsxRuntime.jsxs(popover.Popover, {
86
+ isOpen,
87
+ placement,
88
+ onInteraction: onInteraction || handlePopoverInteraction,
89
+ restrictHeight: false,
90
+ disabled,
91
+ targetClassName: popoverTargetClasses,
92
+ popoverClassName: popoverClasses,
93
+ "data-test-id": testId,
94
+ ...rest,
95
+ children: [renderTrigger(), renderContent()]
96
+ });
97
97
  };
98
98
  const DropdownButton = /* @__PURE__ */ react.forwardRef((props, ref) => {
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: [
99
+ const {
101
100
  children,
102
- " ",
103
- !hideCaret && /* @__PURE__ */ jsxRuntime.jsx(icons.Icon, { name: "chevron-down", size: "small" })
104
- ] });
101
+ hideCaret,
102
+ "data-test-id": testId = "dropdown-button",
103
+ ...rest
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.Icon, {
110
+ name: "chevron-down",
111
+ size: "small"
112
+ })]
113
+ });
105
114
  });
106
115
  DropdownButton.displayName = "DropdownButton";
107
116
  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 { Icon } 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 && <Icon name=\"chevron-down\" 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","Icon"],"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,aAAaA,MAAAA;AACnB,QAAM,CAAC,QAAQ,SAAS,IAAIC,MAAAA,SAAS,cAAc,KAAK;AACxD,QAAM,CAAC,WAAW,YAAY,IAAIA,eAAS,MAAM;AAEjDC,QAAAA,UAAU,MAAM;AACd,QAAI,eAAe,QAAW;AAC5B,gBAAU,UAAU;AAAA,IACtB;AAAA,EAAA,GACC,CAAC,UAAU,CAAC;AAEfA,QAAAA,UAAU,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;AAEtBA,QAAAA,UAAU,MAAM;AACd,iBAAa,MAAM;AACH,mDAAA,EAAE;EAAQ,GAEzB,CAAC,MAAM,CAAC;AAEX,QAAM,gBAAgB,MAAM;AACpB,UAAA,EAAE,WAAW;AACnB,W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ACrC,UAAA;AAAA,IAAA;AAAA,IAAS;AAAA,IAAE,CAAC,aAAaC,2BAAA,IAACC,cAAK,MAAK,gBAAe,MAAK,SAAQ;AAAA,EACnE,EAAA,CAAA;AAEJ,CAAC;AAED,eAAe,cAAc;;;"}
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 { Icon } 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 && <Icon name=\"chevron-down\" 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"],"mappings":";;;;;;;;;AAiBM,MAAA,WAAW,WAAiE;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,aAAaA,MAAAA;AACnB,QAAM,CAAC,QAAQ,SAAS,IAAIC,MAAAA,SAAS,cAAc,KAAK;AACxD,QAAM,CAAC,WAAW,YAAY,IAAIA,eAAS,MAAM;AAEjDC,QAAAA,UAAU,MAAM;AACd,QAAI,eAAe,QAAW;AAC5B,gBAAU,UAAU;AAAA,IACtB;AAAA,EAAA,GACC,CAAC,UAAU,CAAC;AAEfA,QAAAA,UAAU,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;AAEtBA,QAAAA,UAAU,MAAM;AACd,iBAAa,MAAM;AACH,mDAAA;AAAA,MAEd;AAAA,IAEJ;AAAA,EACE,GAAM,CAAA,MAAE,CAAO;AACf,QAAA,gBAAoB,MAAQ;AAAA,UACT;AAAA,MACjB;AAAA,IAAiC,kBACrB;AACZ,WAAyBC,sBAAAA,aAAA,QAAA;AAAA,MAC1B,iBAAA;AAAA,MACH,iBAAA,SAAA,OAAA;AAAA,MAEA,kBAAsBC,MAAAA,UAAM,OAAA,KAAA,UAAA,IAAA;AAAA,MACnB,QAAA,iCAAA;AAAA,IAAsC,CAAA;AAAA,EACjC;AAEd,QAAA,gBAAA,MAAA;AAEM,8CAAgB,cAAY,EAAA,SAAA;AAAA,MAChC,UAAe;AAAA,IACf,CAAA;AAAA,EAAkC;AAG9B,QAAA,eAAA,UAAA;AACJ,cAAU,KAAU;AACtB,yCAAA,MAAA;AAAA,MAEA;IACE;AAAA,EACA;AAAO,QACG,2BAAA,gBAAA;AAAA,cAGC,UAAA;AAAA,EAAA;AAEb,QAAA,gBAAA,MAAA;AAEM,UAAA,CAAA,aAAA,YAA0B,IAAAC,MAAAA,SAAA,QAAkC,QAAA;AAC5D,WAAA;AAAA,MAGJ,QAAA;AAAA,MAAC,SAAA;AAAA,IAAA;AAAA,EAAA;AAEC,QAAA,uBAAAC,QAAAA,GAAA,mBAAA,eAAA;AAAA,yBACgCA,QAAAA,GAAA,YAAA,gBAAA;AAAA,SAChBC,2BAAAA,KAAAC,QAAAA,SAAA;AAAA,IAChB;AAAA,IAAA;AAAA,IACiB,eACC,iBAAA;AAAA,IAAA,gBACJ;AAAA,IAAA;AAAA,IAGb,iBAAA;AAAA,IAAc,kBAAA;AAAA,IAAA,gBACA;AAAA,IAAA,GAAA;AAAA,IAAA,UAAA,CAAA,iBAAA,eAAA;AAAA,EAAA,CACjB;AAEJ;AChHA,MAAM,iBAAoEC,sBAAA,WAAA,CAAC,OAAO,QAAQ;AAClF,QAAA;AAAA,IAEN;AAAA,IAEK;AAAA,IAAS,gBAAA,SAAA;AAAA,IAAE,GAAc;AAAA,EAC5B,IAAA;AAEH,SAAAF,2BAAAA,KAAAG,OAAAA,QAAA;AAAA,IAED,GAAA;AAAA,IAES,gBAAA;AAAA;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@launchpad-ui/dropdown",
3
- "version": "0.6.81",
3
+ "version": "0.6.82",
4
4
  "status": "beta",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,10 +27,10 @@
27
27
  "dependencies": {
28
28
  "@react-aria/utils": "3.22.0",
29
29
  "classix": "2.1.17",
30
- "@launchpad-ui/button": "~0.11.6",
31
- "@launchpad-ui/icons": "~0.14.6",
32
- "@launchpad-ui/popover": "~0.11.6",
33
- "@launchpad-ui/tokens": "~0.9.1"
30
+ "@launchpad-ui/button": "~0.11.7",
31
+ "@launchpad-ui/icons": "~0.14.7",
32
+ "@launchpad-ui/popover": "~0.11.7",
33
+ "@launchpad-ui/tokens": "~0.9.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": "18.2.0",