@launchpad-ui/dropdown 0.3.5 → 0.3.6
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 +1 -4
- package/dist/index.es.js.map +3 -3
- package/dist/index.js +3 -12
- package/dist/index.js.map +4 -4
- package/package.json +5 -5
package/dist/index.es.js
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
// ../../scripts/react-shim.js
|
2
|
-
import * as React from "react";
|
3
|
-
|
4
1
|
// src/Dropdown.tsx
|
5
2
|
import { Popover } from "@launchpad-ui/popover";
|
6
|
-
import cx from "
|
3
|
+
import { cx } from "classix";
|
7
4
|
import { Children, cloneElement, useEffect, useRef, useState } from "react";
|
8
5
|
import { jsxs } from "react/jsx-runtime";
|
9
6
|
var Dropdown = (props) => {
|
package/dist/index.es.js.map
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
|
-
"sources": ["
|
4
|
-
"sourcesContent": ["import
|
5
|
-
"mappings": ";
|
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;AAAA,QACF;AAMA,cAAM,WAAW,QAAQ,UAAU,YAAY;AAE/C,SAAC,YAAY,QAAQ,QAAQ;AAAA,MAC/B,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,QAAQ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U,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
6
|
"names": ["jsxs"]
|
7
7
|
}
|
package/dist/index.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name in all)
|
@@ -17,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
-
mod
|
23
|
-
));
|
24
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
25
19
|
|
26
20
|
// src/index.ts
|
@@ -31,12 +25,9 @@ __export(src_exports, {
|
|
31
25
|
});
|
32
26
|
module.exports = __toCommonJS(src_exports);
|
33
27
|
|
34
|
-
// ../../scripts/react-shim.js
|
35
|
-
var React = __toESM(require("react"));
|
36
|
-
|
37
28
|
// src/Dropdown.tsx
|
38
29
|
var import_popover = require("@launchpad-ui/popover");
|
39
|
-
var
|
30
|
+
var import_classix = require("classix");
|
40
31
|
var import_react = require("react");
|
41
32
|
var import_jsx_runtime = require("react/jsx-runtime");
|
42
33
|
var Dropdown = (props) => {
|
@@ -103,8 +94,8 @@ var Dropdown = (props) => {
|
|
103
94
|
content: contentChild
|
104
95
|
};
|
105
96
|
};
|
106
|
-
const popoverTargetClasses = (0,
|
107
|
-
const popoverClasses = (0,
|
97
|
+
const popoverTargetClasses = (0, import_classix.cx)("Dropdown-target", targetClassName);
|
98
|
+
const popoverClasses = (0, import_classix.cx)("Dropdown", popoverClassName);
|
108
99
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_popover.Popover, {
|
109
100
|
isOpen,
|
110
101
|
placement,
|
package/dist/index.js.map
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
|
-
"sources": ["../src/index.ts", "
|
4
|
-
"sourcesContent": ["export type { DropdownProps } from './Dropdown';\nexport type { DropdownButtonProps } from './DropdownButton';\nexport { Dropdown } from './Dropdown';\nexport { DropdownButton } from './DropdownButton';\n", "import
|
5
|
-
"mappings": "
|
6
|
-
"names": ["
|
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;AAM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AA,gBAA2B;AAmBrB;AALN,IAAM,qBAAiB;AAAA,EACrB,CAAC,OAAO,QAAQ;AACd,UAAM,EAAE,UAAU,cAAc,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
7
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@launchpad-ui/dropdown",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.6",
|
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
|
-
"@launchpad-ui/button": "~0.4.
|
29
|
-
"@launchpad-ui/icons": "~0.3.
|
30
|
-
"@launchpad-ui/popover": "~0.6.
|
28
|
+
"@launchpad-ui/button": "~0.4.1",
|
29
|
+
"@launchpad-ui/icons": "~0.3.3",
|
30
|
+
"@launchpad-ui/popover": "~0.6.5",
|
31
31
|
"@launchpad-ui/tokens": "~0.1.5",
|
32
|
-
"
|
32
|
+
"classix": "^2.1.13"
|
33
33
|
},
|
34
34
|
"peerDependencies": {
|
35
35
|
"react": "^18.0.0",
|