@launchpad-ui/dropdown 0.3.7 → 0.4.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../src/Dropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAM1D,aAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,aAAK,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,8EAoGb,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,YAAY,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../src/Dropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAO1D,aAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,aAAK,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,8EAoGb,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,YAAY,EAAE,aAAa,EAAE,CAAC"}
@@ -1,17 +1,25 @@
1
1
  /// <reference types="react" />
2
- import type { ButtonKind, ButtonSize } from '@launchpad-ui/button';
3
- declare type DropdownButtonProps = {
2
+ import type { ButtonProps } from '@launchpad-ui/button';
3
+ declare type DropdownButtonProps = ButtonProps & {
4
4
  hideCaret?: boolean;
5
- kind?: ButtonKind;
6
- size?: ButtonSize;
7
- className?: string;
8
- disabled?: boolean;
9
- children?: React.ReactNode;
10
- onClick?(v: React.MouseEvent): void;
11
- testId?: string;
12
- 'aria-label'?: string;
13
5
  };
14
- declare const DropdownButton: import("react").ForwardRefExoticComponent<DropdownButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
6
+ declare const DropdownButton: import("react").ForwardRefExoticComponent<import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
7
+ isLoading?: boolean | undefined;
8
+ loadingText?: string | JSX.Element | undefined;
9
+ size?: import("@launchpad-ui/button/dist/types").ButtonSize | undefined;
10
+ kind?: import("@launchpad-ui/button/dist/types").ButtonKind | undefined;
11
+ fit?: boolean | undefined;
12
+ disabled?: boolean | undefined;
13
+ icon?: import("react").ReactElement<{
14
+ size?: string | undefined;
15
+ key: string;
16
+ 'aria-hidden': boolean;
17
+ }, string | import("react").JSXElementConstructor<any>> | undefined;
18
+ renderIconFirst?: boolean | undefined;
19
+ asChild?: boolean | undefined;
20
+ } & {
21
+ hideCaret?: boolean | undefined;
22
+ } & import("react").RefAttributes<HTMLButtonElement>>;
15
23
  export { DropdownButton };
16
24
  export type { DropdownButtonProps };
17
25
  //# sourceMappingURL=DropdownButton.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownButton.d.ts","sourceRoot":"","sources":["../src/DropdownButton.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAMnE,aAAK,mBAAmB,GAAG;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,QAAA,MAAM,cAAc,mHAUnB,CAAC;AAIF,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"DropdownButton.d.ts","sourceRoot":"","sources":["../src/DropdownButton.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMxD,aAAK,mBAAmB,GAAG,WAAW,GAAG;IACvC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,cAAc;;;;;;;;;;;;;;;;qDAQlB,CAAC;AAIH,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,9 +1,10 @@
1
- // src/Dropdown.tsx
2
1
  import { Popover } from "@launchpad-ui/popover";
3
2
  import { cx } from "classix";
4
- import { Children, cloneElement, useEffect, useRef, useState } from "react";
5
- import { jsxs } from "react/jsx-runtime";
6
- var Dropdown = (props) => {
3
+ import { useRef, useState, useEffect, cloneElement, Children, forwardRef } from "react";
4
+ import { jsxs, jsx } from "react/jsx-runtime";
5
+ import { Button } from "@launchpad-ui/button";
6
+ import { ExpandMore, IconSize } from "@launchpad-ui/icons";
7
+ const Dropdown = (props) => {
7
8
  const {
8
9
  placement,
9
10
  disabled,
@@ -17,7 +18,7 @@ var Dropdown = (props) => {
17
18
  ...rest
18
19
  } = props;
19
20
  const triggerRef = useRef(null);
20
- const [isOpen, setIsOpen] = useState(isOpenProp ?? false);
21
+ const [isOpen, setIsOpen] = useState(isOpenProp != null ? isOpenProp : false);
21
22
  const [hasOpened, setHasOpened] = useState(isOpen);
22
23
  useEffect(() => {
23
24
  if (isOpenProp !== void 0) {
@@ -27,25 +28,28 @@ var Dropdown = (props) => {
27
28
  useEffect(() => {
28
29
  if (hasOpened && isOpen === false) {
29
30
  setTimeout(() => {
31
+ var _a, _b;
30
32
  const current = triggerRef.current;
31
33
  if (!current) {
32
34
  return;
33
35
  }
34
- const hasModal = current.closest?.(".has-modal");
35
- !hasModal && current.focus?.();
36
+ const hasModal = (_a = current.closest) == null ? void 0 : _a.call(current, ".has-modal");
37
+ !hasModal && ((_b = current.focus) == null ? void 0 : _b.call(current));
36
38
  });
37
39
  }
38
40
  }, [isOpen, hasOpened]);
39
41
  useEffect(() => {
40
42
  setHasOpened(isOpen);
41
- onStateChange?.({ isOpen });
43
+ onStateChange == null ? void 0 : onStateChange({
44
+ isOpen
45
+ });
42
46
  }, [isOpen]);
43
47
  const renderTrigger = () => {
44
48
  return cloneElement(parseChildren().target, {
45
49
  "aria-haspopup": true,
46
50
  "aria-expanded": isOpen ? true : false,
47
51
  ref: triggerRef,
48
- isopen: isOpen?.toString()
52
+ isopen: isOpen == null ? void 0 : isOpen.toString()
49
53
  });
50
54
  };
51
55
  const renderContent = () => {
@@ -55,7 +59,9 @@ var Dropdown = (props) => {
55
59
  };
56
60
  const handleSelect = (item) => {
57
61
  setIsOpen(false);
58
- onSelect?.(item, { isOpen: false });
62
+ onSelect == null ? void 0 : onSelect(item, {
63
+ isOpen: false
64
+ });
59
65
  };
60
66
  const handlePopoverInteraction = (nextIsOpen) => {
61
67
  setIsOpen(nextIsOpen);
@@ -78,34 +84,23 @@ var Dropdown = (props) => {
78
84
  targetClassName: popoverTargetClasses,
79
85
  popoverClassName: popoverClasses,
80
86
  ...rest,
81
- children: [
82
- renderTrigger(),
83
- renderContent()
84
- ]
87
+ children: [renderTrigger(), renderContent()]
85
88
  });
86
89
  };
87
-
88
- // src/DropdownButton.tsx
89
- import { Button } from "@launchpad-ui/button";
90
- import { ExpandMore, IconSize } from "@launchpad-ui/icons";
91
- import { forwardRef } from "react";
92
- import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
93
- var DropdownButton = forwardRef(
94
- (props, ref) => {
95
- const { children, hideCaret, ...rest } = props;
96
- return /* @__PURE__ */ jsxs2(Button, {
97
- ...rest,
98
- ref,
99
- children: [
100
- children,
101
- " ",
102
- !hideCaret && /* @__PURE__ */ jsx(ExpandMore, {
103
- size: IconSize.SMALL
104
- })
105
- ]
106
- });
107
- }
108
- );
90
+ const DropdownButton = forwardRef((props, ref) => {
91
+ const {
92
+ children,
93
+ hideCaret,
94
+ ...rest
95
+ } = props;
96
+ return /* @__PURE__ */ jsxs(Button, {
97
+ ...rest,
98
+ ref,
99
+ children: [children, " ", !hideCaret && /* @__PURE__ */ jsx(ExpandMore, {
100
+ size: IconSize.SMALL
101
+ })]
102
+ });
103
+ });
109
104
  DropdownButton.displayName = "DropdownButton";
110
105
  export {
111
106
  Dropdown,
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/Dropdown.tsx", "../src/DropdownButton.tsx"],
4
- "sourcesContent": ["import type { PopoverProps } from '@launchpad-ui/popover';\n\nimport { Popover } from '@launchpad-ui/popover';\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 ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>(null);\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-modal');\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 return cloneElement(parseChildren().target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: 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 React.ReactElement,\n content: contentChild as React.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 {...rest}\n >\n {renderTrigger()}\n {renderContent()}\n </Popover>\n );\n};\n\nexport { Dropdown };\nexport type { DropdownProps };\n", "import type { ButtonKind, ButtonSize } from '@launchpad-ui/button';\n\nimport { Button } from '@launchpad-ui/button';\nimport { ExpandMore, IconSize } from '@launchpad-ui/icons';\nimport { forwardRef } from 'react';\n\ntype DropdownButtonProps = {\n hideCaret?: boolean;\n kind?: ButtonKind;\n size?: ButtonSize;\n className?: string;\n disabled?: boolean;\n children?: React.ReactNode;\n onClick?(v: React.MouseEvent): void;\n testId?: string;\n 'aria-label'?: string;\n};\n\nconst DropdownButton = forwardRef<React.ElementRef<typeof Button>, DropdownButtonProps>(\n (props, ref) => {\n const { children, hideCaret, ...rest } = props;\n\n return (\n <Button {...rest} ref={ref}>\n {children} {!hideCaret && <ExpandMore size={IconSize.SMALL} />}\n </Button>\n );\n }\n);\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],
5
- "mappings": ";AAEA,SAAS,eAAe;AACxB,SAAS,UAAU;AACnB,SAAS,UAAU,cAAc,WAAW,QAAQ,gBAAgB;AAiGhE;AAtFJ,IAAM,WAAW,CAAqC,UAA4B;AAChF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,OACG;AAAA,EACL,IAAI;AAEJ,QAAM,aAAa,OAAoB,IAAI;AAC3C,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,EACF,GAAG,CAAC,UAAU,CAAC;AAEf,YAAU,MAAM;AAEd,QAAI,aAAa,WAAW,OAAO;AACjC,iBAAW,MAAM;AACf,cAAM,UAAU,WAAW;AAC3B,YAAI,CAAC,SAAS;AACZ;AAA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,gBAAgB;AACrC,SAAS,kBAAkB;AAmBrB,SAC4B,KAD5B,QAAAA,aAAA;AALN,IAAM,iBAAiB;AAAA,EACrB,CAAC,OAAO,QAAQ;AACd,UAAM,EAAE,UAAU,cAAc,KAAK,IAAI;AAEzC,WACE,gBAAAA,MAAC;AAAA,MAAQ,GAAG;AAAA,MAAM;AAAA,MACf;AAAA;AAAA,QAAS;AAAA,QAAE,CAAC,aAAa,oBAAC;AAAA,UAAW,MAAM,SAAS;AAAA,SAAO;AAAA;AAAA,KAC9D;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;",
6
- "names": ["jsxs"]
7
- }
1
+ {"version":3,"file":"index.es.js","sources":["../src/Dropdown.tsx","../src/DropdownButton.tsx"],"sourcesContent":["import type { PopoverProps } from '@launchpad-ui/popover';\nimport type { ReactElement } from 'react';\n\nimport { Popover } from '@launchpad-ui/popover';\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 ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>(null);\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-modal');\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 return cloneElement(parseChildren().target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: 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 ReactElement,\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 {...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, IconSize } 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, ...rest } = props;\n\n return (\n <Button {...rest} ref={ref}>\n {children} {!hideCaret && <ExpandMore size={IconSize.SMALL} />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":["Dropdown","props","placement","disabled","targetClassName","popoverClassName","isOpen","isOpenProp","onInteraction","onSelect","onStateChange","children","rest","triggerRef","useRef","setIsOpen","useState","hasOpened","setHasOpened","useEffect","undefined","setTimeout","current","hasModal","closest","focus","renderTrigger","cloneElement","parseChildren","target","ref","isopen","toString","renderContent","content","handleSelect","item","handlePopoverInteraction","nextIsOpen","targetChild","contentChild","Children","toArray","popoverTargetClasses","cx","popoverClasses","DropdownButton","forwardRef","hideCaret","IconSize","SMALL","displayName"],"mappings":";;;;;;AAgBMA,MAAAA,WAAW,CAAqCC,UAA4B;AAC1E,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,QAAQC;AAAAA,IACRC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,MACDX;AAEEY,QAAAA,aAAaC,OAAoB,IAAd;AACzB,QAAM,CAACR,QAAQS,aAAaC,SAAST,kCAAc,KAAf;AACpC,QAAM,CAACU,WAAWC,gBAAgBF,SAASV,MAAD;AAE1Ca,YAAU,MAAM;AACd,QAAIZ,eAAea,QAAW;AAC5BL,gBAAUR,UAAD;AAAA,IACV;AAAA,EAAA,GACA,CAACA,UAAD,CAJM;AAMTY,YAAU,MAAM;AAEVF,QAAAA,aAAaX,WAAW,OAAO;AACjCe,iBAAW,MAAM;;AACf,cAAMC,UAAUT,WAAWS;AAC3B,YAAI,CAACA,SAAS;AACZ;AAAA,QACD;AAMKC,cAAAA,WAAWD,cAAQE,YAARF,iCAAkB;AAElCC,SAAAA,YAAYD,eAAQG,UAARH;AAAAA,MAAb,CAZQ;AAAA,IAcX;AAAA,EAAA,GACA,CAAChB,QAAQW,SAAT,CAlBM;AAoBTE,YAAU,MAAM;AACdD,iBAAaZ,MAAD;AACI,mDAAA;AAAA,MAAEA;AAAAA,IAAAA;AAAAA,EAAL,G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AA,IAAlB,UAAA,CACGD,UAAW,KAAA,CAACqC,iCAAc,YAAD;AAAA,MAAY,MAAMC,SAASC;AAAAA,IAAAA,CADvD,CAAA;AAAA,EAAA,CADF;AAKD,CARgC;AAUjCJ,eAAeK,cAAc;"}
package/dist/index.js CHANGED
@@ -1,36 +1,12 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- Dropdown: () => Dropdown,
24
- DropdownButton: () => DropdownButton
25
- });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/Dropdown.tsx
29
- var import_popover = require("@launchpad-ui/popover");
30
- var import_classix = require("classix");
31
- var import_react = require("react");
32
- var import_jsx_runtime = require("react/jsx-runtime");
33
- var Dropdown = (props) => {
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const popover = require("@launchpad-ui/popover");
4
+ const classix = require("classix");
5
+ const react = require("react");
6
+ const jsxRuntime = require("react/jsx-runtime");
7
+ const button = require("@launchpad-ui/button");
8
+ const icons = require("@launchpad-ui/icons");
9
+ const Dropdown = (props) => {
34
10
  const {
35
11
  placement,
36
12
  disabled,
@@ -43,60 +19,65 @@ var Dropdown = (props) => {
43
19
  children,
44
20
  ...rest
45
21
  } = props;
46
- const triggerRef = (0, import_react.useRef)(null);
47
- const [isOpen, setIsOpen] = (0, import_react.useState)(isOpenProp ?? false);
48
- const [hasOpened, setHasOpened] = (0, import_react.useState)(isOpen);
49
- (0, import_react.useEffect)(() => {
22
+ const triggerRef = react.useRef(null);
23
+ const [isOpen, setIsOpen] = react.useState(isOpenProp != null ? isOpenProp : false);
24
+ const [hasOpened, setHasOpened] = react.useState(isOpen);
25
+ react.useEffect(() => {
50
26
  if (isOpenProp !== void 0) {
51
27
  setIsOpen(isOpenProp);
52
28
  }
53
29
  }, [isOpenProp]);
54
- (0, import_react.useEffect)(() => {
30
+ react.useEffect(() => {
55
31
  if (hasOpened && isOpen === false) {
56
32
  setTimeout(() => {
33
+ var _a, _b;
57
34
  const current = triggerRef.current;
58
35
  if (!current) {
59
36
  return;
60
37
  }
61
- const hasModal = current.closest?.(".has-modal");
62
- !hasModal && current.focus?.();
38
+ const hasModal = (_a = current.closest) == null ? void 0 : _a.call(current, ".has-modal");
39
+ !hasModal && ((_b = current.focus) == null ? void 0 : _b.call(current));
63
40
  });
64
41
  }
65
42
  }, [isOpen, hasOpened]);
66
- (0, import_react.useEffect)(() => {
43
+ react.useEffect(() => {
67
44
  setHasOpened(isOpen);
68
- onStateChange?.({ isOpen });
45
+ onStateChange == null ? void 0 : onStateChange({
46
+ isOpen
47
+ });
69
48
  }, [isOpen]);
70
49
  const renderTrigger = () => {
71
- return (0, import_react.cloneElement)(parseChildren().target, {
50
+ return react.cloneElement(parseChildren().target, {
72
51
  "aria-haspopup": true,
73
52
  "aria-expanded": isOpen ? true : false,
74
53
  ref: triggerRef,
75
- isopen: isOpen?.toString()
54
+ isopen: isOpen == null ? void 0 : isOpen.toString()
76
55
  });
77
56
  };
78
57
  const renderContent = () => {
79
- return (0, import_react.cloneElement)(parseChildren().content, {
58
+ return react.cloneElement(parseChildren().content, {
80
59
  onSelect: handleSelect
81
60
  });
82
61
  };
83
62
  const handleSelect = (item) => {
84
63
  setIsOpen(false);
85
- onSelect?.(item, { isOpen: false });
64
+ onSelect == null ? void 0 : onSelect(item, {
65
+ isOpen: false
66
+ });
86
67
  };
87
68
  const handlePopoverInteraction = (nextIsOpen) => {
88
69
  setIsOpen(nextIsOpen);
89
70
  };
90
71
  const parseChildren = () => {
91
- const [targetChild, contentChild] = import_react.Children.toArray(children);
72
+ const [targetChild, contentChild] = react.Children.toArray(children);
92
73
  return {
93
74
  target: targetChild,
94
75
  content: contentChild
95
76
  };
96
77
  };
97
- const popoverTargetClasses = (0, import_classix.cx)("Dropdown-target", targetClassName);
98
- const popoverClasses = (0, import_classix.cx)("Dropdown", popoverClassName);
99
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_popover.Popover, {
78
+ const popoverTargetClasses = classix.cx("Dropdown-target", targetClassName);
79
+ const popoverClasses = classix.cx("Dropdown", popoverClassName);
80
+ return /* @__PURE__ */ jsxRuntime.jsxs(popover.Popover, {
100
81
  isOpen,
101
82
  placement,
102
83
  onInteraction: onInteraction || handlePopoverInteraction,
@@ -105,38 +86,24 @@ var Dropdown = (props) => {
105
86
  targetClassName: popoverTargetClasses,
106
87
  popoverClassName: popoverClasses,
107
88
  ...rest,
108
- children: [
109
- renderTrigger(),
110
- renderContent()
111
- ]
89
+ children: [renderTrigger(), renderContent()]
112
90
  });
113
91
  };
114
-
115
- // src/DropdownButton.tsx
116
- var import_button = require("@launchpad-ui/button");
117
- var import_icons = require("@launchpad-ui/icons");
118
- var import_react2 = require("react");
119
- var import_jsx_runtime = require("react/jsx-runtime");
120
- var DropdownButton = (0, import_react2.forwardRef)(
121
- (props, ref) => {
122
- const { children, hideCaret, ...rest } = props;
123
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_button.Button, {
124
- ...rest,
125
- ref,
126
- children: [
127
- children,
128
- " ",
129
- !hideCaret && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ExpandMore, {
130
- size: import_icons.IconSize.SMALL
131
- })
132
- ]
133
- });
134
- }
135
- );
136
- DropdownButton.displayName = "DropdownButton";
137
- // Annotate the CommonJS export names for ESM import in node:
138
- 0 && (module.exports = {
139
- Dropdown,
140
- DropdownButton
92
+ const DropdownButton = react.forwardRef((props, ref) => {
93
+ const {
94
+ children,
95
+ hideCaret,
96
+ ...rest
97
+ } = props;
98
+ return /* @__PURE__ */ jsxRuntime.jsxs(button.Button, {
99
+ ...rest,
100
+ ref,
101
+ children: [children, " ", !hideCaret && /* @__PURE__ */ jsxRuntime.jsx(icons.ExpandMore, {
102
+ size: icons.IconSize.SMALL
103
+ })]
104
+ });
141
105
  });
106
+ DropdownButton.displayName = "DropdownButton";
107
+ exports.Dropdown = Dropdown;
108
+ exports.DropdownButton = DropdownButton;
142
109
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts", "../src/Dropdown.tsx", "../src/DropdownButton.tsx"],
4
- "sourcesContent": ["export type { DropdownProps } from './Dropdown';\nexport type { DropdownButtonProps } from './DropdownButton';\nexport { Dropdown } from './Dropdown';\nexport { DropdownButton } from './DropdownButton';\n", "import type { PopoverProps } from '@launchpad-ui/popover';\n\nimport { Popover } from '@launchpad-ui/popover';\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 ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>(null);\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-modal');\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 return cloneElement(parseChildren().target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: 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 React.ReactElement,\n content: contentChild as React.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 {...rest}\n >\n {renderTrigger()}\n {renderContent()}\n </Popover>\n );\n};\n\nexport { Dropdown };\nexport type { DropdownProps };\n", "import type { ButtonKind, ButtonSize } from '@launchpad-ui/button';\n\nimport { Button } from '@launchpad-ui/button';\nimport { ExpandMore, IconSize } from '@launchpad-ui/icons';\nimport { forwardRef } from 'react';\n\ntype DropdownButtonProps = {\n hideCaret?: boolean;\n kind?: ButtonKind;\n size?: ButtonSize;\n className?: string;\n disabled?: boolean;\n children?: React.ReactNode;\n onClick?(v: React.MouseEvent): void;\n testId?: string;\n 'aria-label'?: string;\n};\n\nconst DropdownButton = forwardRef<React.ElementRef<typeof Button>, DropdownButtonProps>(\n (props, ref) => {\n const { children, hideCaret, ...rest } = props;\n\n return (\n <Button {...rest} ref={ref}>\n {children} {!hideCaret && <ExpandMore size={IconSize.SMALL} />}\n </Button>\n );\n }\n);\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,qBAAwB;AACxB,qBAAmB;AACnB,mBAAoE;AAiGhE;AAtFJ,IAAM,WAAW,CAAqC,UAA4B;AAChF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,OACG;AAAA,EACL,IAAI;AAEJ,QAAM,iBAAa,qBAAoB,IAAI;AAC3C,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAS,cAAc,KAAK;AACxD,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,MAAM;AAEjD,8BAAU,MAAM;AACd,QAAI,eAAe,QAAW;AAC5B,gBAAU,UAAU;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AAEf,8BAAU,MAAM;AAEd,QAAI,aAAa,WAAW,OAAO;AACjC,iBAAW,MAAM;AACf,cAAM,UAAU,WAAW;AAC3B,YAAI,CAAC,SAAS;AACZ;AAAA,QACF;AAMA,cAAM,WAAW,QAAQ,UAAU,YAAY;AAE/C,SAAC,YAAY,QAAQ,QAAQ;AAAA,MAC/B,CAAC;AAAA,IAC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AAc,KAAK,IAAI;AAEzC,WACE,6CAAC;AAAA,MAAQ,GAAG;AAAA,MAAM;AAAA,MACf;AAAA;AAAA,QAAS;AAAA,QAAE,CAAC,aAAa,4CAAC;AAAA,UAAW,MAAM,sBAAS;AAAA,SAAO;AAAA;AAAA,KAC9D;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;",
6
- "names": ["import_react"]
7
- }
1
+ {"version":3,"file":"index.js","sources":["../src/Dropdown.tsx","../src/DropdownButton.tsx"],"sourcesContent":["import type { PopoverProps } from '@launchpad-ui/popover';\nimport type { ReactElement } from 'react';\n\nimport { Popover } from '@launchpad-ui/popover';\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 ...rest\n } = props;\n\n const triggerRef = useRef<HTMLElement>(null);\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-modal');\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 return cloneElement(parseChildren().target, {\n 'aria-haspopup': true,\n 'aria-expanded': isOpen ? true : false,\n ref: 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 ReactElement,\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 {...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, IconSize } 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, ...rest } = props;\n\n return (\n <Button {...rest} ref={ref}>\n {children} {!hideCaret && <ExpandMore size={IconSize.SMALL} />}\n </Button>\n );\n});\n\nDropdownButton.displayName = 'DropdownButton';\n\nexport { DropdownButton };\nexport type { DropdownButtonProps };\n"],"names":["Dropdown","props","placement","disabled","targetClassName","popoverClassName","isOpen","isOpenProp","onInteraction","onSelect","onStateChange","children","rest","triggerRef","useRef","setIsOpen","useState","hasOpened","setHasOpened","useEffect","undefined","setTimeout","current","hasModal","closest","focus","renderTrigger","cloneElement","parseChildren","target","ref","isopen","toString","renderContent","content","handleSelect","item","handlePopoverInteraction","nextIsOpen","targetChild","contentChild","Children","toArray","popoverTargetClasses","cx","popoverClasses","Popover","DropdownButton","forwardRef","hideCaret","Button","ExpandMore","IconSize","SMALL","displayName"],"mappings":";;;;;;;;AAgBMA,MAAAA,WAAW,CAAqCC,UAA4B;AAC1E,QAAA;AAAA,IACJC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC,QAAQC;AAAAA,IACRC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAC;AAAAA,OACGC;AAAAA,MACDX;AAEEY,QAAAA,aAAaC,aAAoB,IAAd;AACzB,QAAM,CAACR,QAAQS,aAAaC,MAAAA,SAAST,kCAAc,KAAf;AACpC,QAAM,CAACU,WAAWC,gBAAgBF,MAAAA,SAASV,MAAD;AAE1Ca,QAAAA,UAAU,MAAM;AACd,QAAIZ,eAAea,QAAW;AAC5BL,gBAAUR,UAAD;AAAA,IACV;AAAA,EAAA,GACA,CAACA,UAAD,CAJM;AAMTY,QAAAA,UAAU,MAAM;AAEVF,QAAAA,aAAaX,WAAW,OAAO;AACjCe,iBAAW,MAAM;;AACf,cAAMC,UAAUT,WAAWS;AAC3B,YAAI,CAACA,SAAS;AACZ;AAAA,QACD;AAMKC,cAAAA,WAAWD,cAAQE,YAARF,iCAAkB;AAElCC,SAAAA,YAAYD,eAAQG,UAARH;AAAAA,MAAb,CAZQ;AAAA,IAcX;AAAA,EAAA,GACA,CAAChB,QAAQW,SAAT,CAlBM;AAoBTE,QAAAA,UAAU,MAAM;AACdD,iBAAaZ,MAAD;AACI,mDAAA;AAAA,MAAEA;AAAAA,IAAAA;AAAAA,EAAL,GAEZ,CAACA,MAAD,CAJM;AAMT,QAAMoB,gBAAgB,MAAM;AACnBC,WAAAA,MAAAA,aAAaC,cAAa,EAAGC,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AA,CAACsC,4CAAcE,kBAAD;AAAA,MAAY,MAAMC,MAASC,SAAAA;AAAAA,IAAAA,CADvD,CAAA;AAAA,EAAA,CADF;AAKD,CARgC;AAUjCN,eAAeO,cAAc;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@launchpad-ui/dropdown",
3
- "version": "0.3.7",
3
+ "version": "0.4.2",
4
4
  "status": "beta",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,9 +25,9 @@
25
25
  },
26
26
  "source": "src/index.ts",
27
27
  "dependencies": {
28
- "@launchpad-ui/button": "~0.5.0",
29
- "@launchpad-ui/icons": "~0.3.3",
30
- "@launchpad-ui/popover": "~0.6.6",
28
+ "@launchpad-ui/button": "~0.6.1",
29
+ "@launchpad-ui/icons": "~0.4.0",
30
+ "@launchpad-ui/popover": "~0.7.1",
31
31
  "@launchpad-ui/tokens": "~0.1.5",
32
32
  "classix": "^2.1.13"
33
33
  },
@@ -40,7 +40,7 @@
40
40
  "react-dom": "^18.2.0"
41
41
  },
42
42
  "scripts": {
43
- "build": "tsc --project tsconfig.build.json && node ../../scripts/build.js",
43
+ "build": "vite build -c ../../vite.config.ts && tsc --project tsconfig.build.json",
44
44
  "clean": "rm -rf dist",
45
45
  "e2e": "playwright test --config=../../playwright.config.ct.ts",
46
46
  "lint": "eslint '**/*.{ts,tsx,js}'",