@launchpad-ui/dropdown 0.6.84 → 0.6.85

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,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 /* @__PURE__ */ 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,35 +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(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
- });
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 = /* @__PURE__ */ 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
- 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
- });
100
+ " ",
101
+ !hideCaret && /* @__PURE__ */ jsx(Icon, { name: "chevron-down", size: "small" })
102
+ ] });
112
103
  });
113
104
  DropdownButton.displayName = "DropdownButton";
114
105
  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,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,CAA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AAEH,SAAA,qBAAA,QAAA;AAAA,IAED,GAAA;AAAA,IAES,gBAAA;AAAA;;;;;;;;"}
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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AO;AAAA,EAAA;AAG9B,QAAA,2BAA2B,CAAC,eAAwB;AACxD,cAAU,UAAU;AAAA,EAAA;AAGtB,QAAM,gBAAgB,MAAM;AAC1B,UAAM,CAAC,aAAa,YAAY,IAAI,SAAS,QAAQ,QAAQ;AACtD,WAAA;AAAA,MACL,QAAQ;AAAA,MAGR,SAAS;AAAA,IAAA;AAAA,EACX;AAGI,QAAA,uBAAuB,GAAG,mBAAmB,eAAe;AAC5D,QAAA,iBAAiB,GAAG,YAAY,gBAAgB;AAGpD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,eAAe,iBAAiB;AAAA,MAChC,gBAAgB;AAAA,MAChB;AAAA,MACA,iBAAiB;AAAA,MACjB,kBAAkB;AAAA,MAClB,gBAAc;AAAA,MACb,GAAG;AAAA,MAEH,UAAA;AAAA,QAAc,cAAA;AAAA,QACd,cAAc;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGrB;AChHA,MAAM,iBAAoE,2BAAA,CAAC,OAAO,QAAQ;AAClF,QAAA,EAAE,UAAU,WAAW,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;"}
package/dist/index.js CHANGED
@@ -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 /* @__PURE__ */ 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,35 +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(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
- });
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 = /* @__PURE__ */ 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
- 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
- });
102
+ " ",
103
+ !hideCaret && /* @__PURE__ */ jsxRuntime.jsx(icons.Icon, { name: "chevron-down", size: "small" })
104
+ ] });
114
105
  });
115
106
  DropdownButton.displayName = "DropdownButton";
116
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 { 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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ources":["../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;AAA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CAAW,MAAM,EAAE,QAAQ,MAAO;AAAA,EAAA;AAG9B,QAAA,2BAA2B,CAAC,eAAwB;AACxD,cAAU,UAAU;AAAA,EAAA;AAGtB,QAAM,gBAAgB,MAAM;AAC1B,UAAM,CAAC,aAAa,YAAY,IAAIC,MAAAA,SAAS,QAAQ,QAAQ;AACtD,WAAA;AAAA,MACL,QAAQ;AAAA,MAGR,SAAS;AAAA,IAAA;AAAA,EACX;AAGI,QAAA,uBAAuBC,QAAAA,GAAG,mBAAmB,eAAe;AAC5D,QAAA,iBAAiBA,QAAAA,GAAG,YAAY,gBAAgB;AAGpD,SAAAC,2BAAA;AAAA,IAACC,QAAA;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,eAAe,iBAAiB;AAAA,MAChC,gBAAgB;AAAA,MAChB;AAAA,MACA,iBAAiB;AAAA,MACjB,kBAAkB;AAAA,MAClB,gBAAc;AAAA,MACb,GAAG;AAAA,MAEH,UAAA;AAAA,QAAc,cAAA;AAAA,QACd,cAAc;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGrB;AChHA,MAAM,iBAAoEC,sBAAA,WAAA,CAAC,OAAO,QAAQ;AAClF,QAAA,EAAE,UAAU,WAAW,gBAAgB,SAAS,mBAAmB,GAAG,KAAS,IAAA;AAErF,yCACGC,OAAQ,QAAA,EAAA,GAAG,MAAM,gBAAc,QAAQ,KACrC,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;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@launchpad-ui/dropdown",
3
- "version": "0.6.84",
3
+ "version": "0.6.85",
4
4
  "status": "beta",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,11 +25,11 @@
25
25
  },
26
26
  "source": "src/index.ts",
27
27
  "dependencies": {
28
- "@react-aria/utils": "3.22.0",
28
+ "@react-aria/utils": "3.23.0",
29
29
  "classix": "2.1.17",
30
30
  "@launchpad-ui/button": "~0.11.9",
31
31
  "@launchpad-ui/icons": "~0.14.9",
32
- "@launchpad-ui/popover": "~0.11.7",
32
+ "@launchpad-ui/popover": "~0.11.8",
33
33
  "@launchpad-ui/tokens": "~0.9.2"
34
34
  },
35
35
  "peerDependencies": {
@@ -41,7 +41,7 @@
41
41
  "react-dom": "18.2.0"
42
42
  },
43
43
  "scripts": {
44
- "build": "vite build -c ../../vite.config.ts && tsc --project tsconfig.build.json",
44
+ "build": "vite build -c ../../vite.config.mts && tsc --project tsconfig.build.json",
45
45
  "clean": "rm -rf dist",
46
46
  "lint": "eslint '**/*.{ts,tsx,js}'",
47
47
  "test": "vitest run --coverage"