@launchpad-ui/dropdown 0.6.57 → 0.6.59

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
@@ -46,7 +46,7 @@ const Dropdown = (props) => {
46
46
  }, [isOpen]);
47
47
  const renderTrigger = () => {
48
48
  const { target } = parseChildren();
49
- return cloneElement(target, {
49
+ return /* @__PURE__ */ cloneElement(target, {
50
50
  "aria-haspopup": true,
51
51
  "aria-expanded": isOpen ? true : false,
52
52
  ref: target.ref ? mergeRefs(target.ref, triggerRef) : triggerRef,
@@ -54,7 +54,7 @@ const Dropdown = (props) => {
54
54
  });
55
55
  };
56
56
  const renderContent = () => {
57
- return cloneElement(parseChildren().content, {
57
+ return /* @__PURE__ */ cloneElement(parseChildren().content, {
58
58
  onSelect: handleSelect
59
59
  });
60
60
  };
@@ -93,7 +93,7 @@ const Dropdown = (props) => {
93
93
  }
94
94
  );
95
95
  };
96
- const DropdownButton = forwardRef((props, ref) => {
96
+ const DropdownButton = /* @__PURE__ */ forwardRef((props, ref) => {
97
97
  const { children, hideCaret, "data-test-id": testId = "dropdown-button", ...rest } = props;
98
98
  return /* @__PURE__ */ jsxs(Button, { ...rest, "data-test-id": testId, ref, children: [
99
99
  children,
@@ -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=\"expand-more\" 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,c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A,MACb,GAAG;AAAA,MAEH,UAAA;AAAA,QAAc,cAAA;AAAA,QACd,cAAc;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGrB;AChHA,MAAM,iBAAiB,WAAmD,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,eAAc,MAAK,SAAQ;AAAA,EAClE,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=\"expand-more\" 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,WAAoB,6BAAA,QAAQ;AAAA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;AAAA,EAClE,EAAA,CAAA;AAEJ,CAAC;AAED,eAAe,cAAc;"}
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ const Dropdown = (props) => {
48
48
  }, [isOpen]);
49
49
  const renderTrigger = () => {
50
50
  const { target } = parseChildren();
51
- return react.cloneElement(target, {
51
+ return /* @__PURE__ */ react.cloneElement(target, {
52
52
  "aria-haspopup": true,
53
53
  "aria-expanded": isOpen ? true : false,
54
54
  ref: target.ref ? utils.mergeRefs(target.ref, triggerRef) : triggerRef,
@@ -56,7 +56,7 @@ const Dropdown = (props) => {
56
56
  });
57
57
  };
58
58
  const renderContent = () => {
59
- return react.cloneElement(parseChildren().content, {
59
+ return /* @__PURE__ */ react.cloneElement(parseChildren().content, {
60
60
  onSelect: handleSelect
61
61
  });
62
62
  };
@@ -95,7 +95,7 @@ const Dropdown = (props) => {
95
95
  }
96
96
  );
97
97
  };
98
- const DropdownButton = react.forwardRef((props, ref) => {
98
+ const DropdownButton = /* @__PURE__ */ react.forwardRef((props, ref) => {
99
99
  const { children, hideCaret, "data-test-id": testId = "dropdown-button", ...rest } = props;
100
100
  return /* @__PURE__ */ jsxRuntime.jsxs(button.Button, { ...rest, "data-test-id": testId, ref, children: [
101
101
  children,
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=\"expand-more\" 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,UA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AACC,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,iBAAiBC,MAAA,WAAmD,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,eAAc,MAAK,SAAQ;AAAA,EAClE,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=\"expand-more\" 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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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,eAAc,MAAK,SAAQ;AAAA,EAClE,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.57",
3
+ "version": "0.6.59",
4
4
  "status": "beta",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,9 +27,9 @@
27
27
  "dependencies": {
28
28
  "@react-aria/utils": "3.18.0",
29
29
  "classix": "2.1.17",
30
- "@launchpad-ui/button": "~0.9.2",
31
- "@launchpad-ui/icons": "~0.9.2",
32
- "@launchpad-ui/popover": "~0.10.9",
30
+ "@launchpad-ui/button": "~0.9.4",
31
+ "@launchpad-ui/icons": "~0.9.4",
32
+ "@launchpad-ui/popover": "~0.10.10",
33
33
  "@launchpad-ui/tokens": "~0.6.0"
34
34
  },
35
35
  "peerDependencies": {