@langchain/macaw-components 1.1.0 → 1.1.1
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/catalog.json +524 -482
- package/dist/components/Accordion/Accordion.d.ts +63 -0
- package/dist/components/Accordion/Accordion.js +170 -0
- package/dist/components/Accordion/Accordion.js.map +1 -0
- package/dist/components/Accordion/index.d.ts +2 -0
- package/dist/components/Accordion/index.js +2 -0
- package/dist/components/Attachment/Attachment.js +3 -3
- package/dist/components/Avatar/Avatar.js +1 -1
- package/dist/components/Banner/Banner.js +2 -2
- package/dist/components/Button/Button.js +2 -2
- package/dist/components/ChartCard/ChartCard.js +2 -2
- package/dist/components/ChartLegend/ChartLegend.js +1 -1
- package/dist/components/Checkbox/Checkbox.js +1 -1
- package/dist/components/Code/CodeLite.js +2 -2
- package/dist/components/Code/index.js +1 -1
- package/dist/components/Command/CommandMenu.js +1 -1
- package/dist/components/CopyButton/CopyButton.js +2 -2
- package/dist/components/Dialog/index.js +3 -3
- package/dist/components/ErrorMessage/ErrorMessage.js +3 -3
- package/dist/components/IconButton/IconButton.js +2 -2
- package/dist/components/Input/Input.js +1 -1
- package/dist/components/Pane/Pane.js +2 -2
- package/dist/components/Select/Select.d.ts +8 -0
- package/dist/components/Select/Select.js +4 -4
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/SelectPrimitive.js +1 -1
- package/dist/components/Select/index.d.ts +1 -1
- package/dist/components/SplitViewPane/SplitViewPaneHeader.js +2 -2
- package/dist/components/StatusBadge/StatusBadge.d.ts +27 -0
- package/dist/components/StatusBadge/StatusBadge.js +42 -0
- package/dist/components/StatusBadge/StatusBadge.js.map +1 -0
- package/dist/components/StatusBadge/index.d.ts +2 -0
- package/dist/components/StatusBadge/index.js +2 -0
- package/dist/components/Toast/index.js +2 -2
- package/dist/components/Tooltip/Tooltip.js +1 -1
- package/dist/components/Typeahead/TypeaheadParts.js +2 -2
- package/dist/components/Typeahead/TypeaheadView.js +1 -1
- package/dist/components/UnsavedChangesDialog.js +2 -2
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +7 -6
- package/dist/icons/LongTailPhosphorIcons.js +1 -1
- package/dist/icons/PaddedPhosphorIcons.js +2 -2
- package/dist/index.js +7 -6
- package/dist/utilities.css +1 -1
- package/package.json +20 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface AccordionProps {
|
|
3
|
+
title?: ReactNode;
|
|
4
|
+
description?: ReactNode;
|
|
5
|
+
/** Sits right of the title, such as a button to add another item. */
|
|
6
|
+
action?: ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* `AccordionItem`s, or the list's empty or loading content, such as an
|
|
9
|
+
* `EmptyState`, which fills the card as-is. Without children it's just the
|
|
10
|
+
* header, for a section of plain fields.
|
|
11
|
+
*/
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A section of `AccordionItem`s in one bordered card, with an optional title,
|
|
17
|
+
* description, and action above.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Accordion({ title, description, action, children, className, }: AccordionProps): import("react").JSX.Element;
|
|
20
|
+
/** One entry in an `AccordionItem`'s overflow menu. */
|
|
21
|
+
export interface AccordionItemMenuItem {
|
|
22
|
+
/** The entry's name, in Title Case, such as Remove. */
|
|
23
|
+
label: string;
|
|
24
|
+
/** A quiet line under the label, such as what the entry does. */
|
|
25
|
+
description?: string;
|
|
26
|
+
/** Called when the viewer picks the entry; the menu then closes. */
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
/** `destructive` marks an entry that removes or revokes something. */
|
|
29
|
+
tone?: 'default' | 'destructive';
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface AccordionItemProps {
|
|
33
|
+
/** A mark at 16px, which the item puts in a tile. */
|
|
34
|
+
icon?: ReactNode;
|
|
35
|
+
/** A person's or account's name, shown as an avatar in place of `icon`. */
|
|
36
|
+
avatar?: string;
|
|
37
|
+
title: ReactNode;
|
|
38
|
+
/** Sits beside the title, such as a `StatusBadge`. */
|
|
39
|
+
badge?: ReactNode;
|
|
40
|
+
/** A quiet line under the title. */
|
|
41
|
+
description?: ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* The item's own action, kept on its header whether or not it's expanded,
|
|
44
|
+
* such as a `Switch`, a `Select` with `variant="plain"`, or a button.
|
|
45
|
+
*/
|
|
46
|
+
action?: ReactNode;
|
|
47
|
+
/** Entries for the item's overflow menu, such as Rename or Remove. */
|
|
48
|
+
menuItems?: AccordionItemMenuItem[];
|
|
49
|
+
/**
|
|
50
|
+
* The item's expandable body, shown below the header when expanded. Without
|
|
51
|
+
* it the item doesn't expand.
|
|
52
|
+
*/
|
|
53
|
+
contents?: ReactNode;
|
|
54
|
+
defaultExpanded?: boolean;
|
|
55
|
+
/** Called when the viewer expands or collapses the item. */
|
|
56
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
57
|
+
className?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* One item in an `Accordion`: a header with a title, its action, and an
|
|
61
|
+
* overflow menu, which expands to show its `contents` when it has any.
|
|
62
|
+
*/
|
|
63
|
+
export declare function AccordionItem({ icon: iconProp, avatar, title, badge, description, action, menuItems, contents, defaultExpanded, onExpandedChange, className, }: AccordionItemProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { CaretDownIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
2
|
+
import { animation } from "../../utils/animation.js";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
import { Text } from "../Text/Text.js";
|
|
5
|
+
import { Avatar } from "../Avatar/Avatar.js";
|
|
6
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../DropdownMenu/DropdownMenu.js";
|
|
7
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
8
|
+
import { Children, Fragment, isValidElement, useId, useState } from "react";
|
|
9
|
+
import { DotsThreeIcon } from "@phosphor-icons/react/dist/ssr/DotsThree";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
//#region packages/components/src/components/Accordion/Accordion.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Whether a node renders anything, with fragments opened up, so a fragment of
|
|
14
|
+
* only `false` or `null` children counts as empty.
|
|
15
|
+
*/
|
|
16
|
+
function hasContent(node) {
|
|
17
|
+
return Children.toArray(node).some((child) => isValidElement(child) && child.type === Fragment ? hasContent(child.props.children) : true);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A section of `AccordionItem`s in one bordered card, with an optional title,
|
|
21
|
+
* description, and action above.
|
|
22
|
+
*/
|
|
23
|
+
function Accordion({ title, description, action, children, className }) {
|
|
24
|
+
const titleId = useId();
|
|
25
|
+
const hasHeader = title != null || description != null || action != null;
|
|
26
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
27
|
+
"aria-labelledby": title != null ? titleId : void 0,
|
|
28
|
+
className: cn("flex flex-col gap-space-3", className),
|
|
29
|
+
children: [hasHeader && /* @__PURE__ */ jsxs("div", {
|
|
30
|
+
className: "flex flex-col gap-space-1",
|
|
31
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
32
|
+
className: "flex items-center justify-between gap-space-3",
|
|
33
|
+
children: [title != null && /* @__PURE__ */ jsx(Text, {
|
|
34
|
+
as: "h3",
|
|
35
|
+
variant: "h3",
|
|
36
|
+
id: titleId,
|
|
37
|
+
children: title
|
|
38
|
+
}), action != null && /* @__PURE__ */ jsx("div", {
|
|
39
|
+
className: "ml-auto flex shrink-0 items-center gap-space-2",
|
|
40
|
+
children: action
|
|
41
|
+
})]
|
|
42
|
+
}), description != null && /* @__PURE__ */ jsx(Text, {
|
|
43
|
+
as: "p",
|
|
44
|
+
variant: "sm",
|
|
45
|
+
color: "tertiary",
|
|
46
|
+
children: description
|
|
47
|
+
})]
|
|
48
|
+
}), hasContent(children) && /* @__PURE__ */ jsx("div", {
|
|
49
|
+
className: "flex flex-col divide-y divide-subtle overflow-hidden rounded-md border border-default bg-surface-level-1",
|
|
50
|
+
children
|
|
51
|
+
})]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One item in an `Accordion`: a header with a title, its action, and an
|
|
56
|
+
* overflow menu, which expands to show its `contents` when it has any.
|
|
57
|
+
*/
|
|
58
|
+
function AccordionItem({ icon: iconProp, avatar, title, badge, description, action, menuItems, contents, defaultExpanded = false, onExpandedChange, className }) {
|
|
59
|
+
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
60
|
+
function toggle() {
|
|
61
|
+
setExpanded(!expanded);
|
|
62
|
+
onExpandedChange?.(!expanded);
|
|
63
|
+
}
|
|
64
|
+
const bodyId = useId();
|
|
65
|
+
const icon = avatar != null ? /* @__PURE__ */ jsx(Avatar, {
|
|
66
|
+
label: avatar,
|
|
67
|
+
size: "sm",
|
|
68
|
+
shape: "circle"
|
|
69
|
+
}) : iconProp;
|
|
70
|
+
const label = typeof title === "string" ? title : "item";
|
|
71
|
+
const hasBody = hasContent(contents);
|
|
72
|
+
const hasMenu = menuItems != null && menuItems.length > 0;
|
|
73
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
74
|
+
className: cn("flex flex-col", className),
|
|
75
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
76
|
+
className: "flex items-center gap-space-2 px-space-3 py-space-2",
|
|
77
|
+
children: [
|
|
78
|
+
icon != null && /* @__PURE__ */ jsx("span", {
|
|
79
|
+
className: cn("flex size-6 shrink-0 items-center justify-center", avatar == null && "rounded-sm bg-surface-level-2 text-icon-secondary [&>*]:size-4"),
|
|
80
|
+
children: icon
|
|
81
|
+
}),
|
|
82
|
+
/* @__PURE__ */ jsxs("div", {
|
|
83
|
+
className: "flex min-w-0 flex-1 flex-wrap items-center justify-between gap-x-space-3 gap-y-space-2",
|
|
84
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
85
|
+
className: cn("flex min-h-6 min-w-0 flex-1 basis-16 flex-col justify-center", hasBody && "cursor-pointer"),
|
|
86
|
+
onClick: hasBody ? toggle : void 0,
|
|
87
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
88
|
+
className: "flex min-w-0 items-center gap-space-2",
|
|
89
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
90
|
+
as: "span",
|
|
91
|
+
variant: "sm",
|
|
92
|
+
weight: "medium",
|
|
93
|
+
className: "truncate text-primary",
|
|
94
|
+
children: title
|
|
95
|
+
}), badge]
|
|
96
|
+
}), description != null && /* @__PURE__ */ jsx(Text, {
|
|
97
|
+
as: "span",
|
|
98
|
+
variant: "xs",
|
|
99
|
+
color: "tertiary",
|
|
100
|
+
className: "truncate",
|
|
101
|
+
children: description
|
|
102
|
+
})]
|
|
103
|
+
}), action != null && /* @__PURE__ */ jsx("div", {
|
|
104
|
+
className: "flex min-h-6 shrink-0 items-center gap-space-2",
|
|
105
|
+
children: action
|
|
106
|
+
})]
|
|
107
|
+
}),
|
|
108
|
+
(hasMenu || hasBody) && /* @__PURE__ */ jsxs("div", {
|
|
109
|
+
className: "flex shrink-0 items-center gap-space-2",
|
|
110
|
+
children: [hasMenu && /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
|
|
111
|
+
asChild: true,
|
|
112
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
113
|
+
icon: DotsThreeIcon,
|
|
114
|
+
iconWeight: "regular",
|
|
115
|
+
label: `${label} options`,
|
|
116
|
+
variant: "plain",
|
|
117
|
+
color: "secondary",
|
|
118
|
+
size: "sm"
|
|
119
|
+
})
|
|
120
|
+
}), /* @__PURE__ */ jsx(DropdownMenuContent, {
|
|
121
|
+
align: "end",
|
|
122
|
+
className: "max-w-xs",
|
|
123
|
+
children: menuItems.map((item) => /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
124
|
+
disabled: item.disabled,
|
|
125
|
+
onSelect: item.onSelect,
|
|
126
|
+
className: "flex-col items-start justify-center",
|
|
127
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
128
|
+
as: "span",
|
|
129
|
+
variant: "sm",
|
|
130
|
+
color: item.tone === "destructive" ? "error" : "primary",
|
|
131
|
+
children: item.label
|
|
132
|
+
}), item.description != null && /* @__PURE__ */ jsx(Text, {
|
|
133
|
+
as: "span",
|
|
134
|
+
variant: "xs",
|
|
135
|
+
color: "tertiary",
|
|
136
|
+
children: item.description
|
|
137
|
+
})]
|
|
138
|
+
}, item.label))
|
|
139
|
+
})] }), hasBody && /* @__PURE__ */ jsx(IconButton, {
|
|
140
|
+
icon: CaretDownIcon,
|
|
141
|
+
iconWeight: "regular",
|
|
142
|
+
label: expanded ? `Hide ${label}` : `Show ${label}`,
|
|
143
|
+
variant: "plain",
|
|
144
|
+
color: "secondary",
|
|
145
|
+
size: "sm",
|
|
146
|
+
"aria-expanded": expanded,
|
|
147
|
+
"aria-controls": bodyId,
|
|
148
|
+
onClick: toggle,
|
|
149
|
+
className: cn("[&_svg]:transition-transform [&_svg]:duration-normal motion-reduce:[&_svg]:transition-none", !expanded && "[&_svg]:-rotate-90")
|
|
150
|
+
})]
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
}), hasBody && /* @__PURE__ */ jsx("div", {
|
|
154
|
+
id: bodyId,
|
|
155
|
+
className: cn(animation.contentResize, "motion-reduce:transition-none", expanded ? "grid-rows-[1fr]" : "grid-rows-[0fr]"),
|
|
156
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
157
|
+
className: "overflow-hidden",
|
|
158
|
+
inert: !expanded,
|
|
159
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
160
|
+
className: "border-t border-subtle px-space-3 py-space-2",
|
|
161
|
+
children: contents
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
})]
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
export { Accordion, AccordionItem };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=Accordion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Accordion.js","names":[],"sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["import {\n Children,\n Fragment,\n isValidElement,\n type ReactNode,\n useId,\n useState,\n} from 'react';\n\nimport { DotsThreeIcon } from '@phosphor-icons/react/dist/ssr/DotsThree';\n\nimport { CaretDownIcon } from '../../icons/PaddedPhosphorIcons';\nimport { animation } from '../../utils/animation';\nimport { cn } from '../../utils/cn';\nimport { Avatar } from '../Avatar';\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from '../DropdownMenu';\nimport { IconButton } from '../IconButton';\nimport { Text } from '../Text';\n\n/**\n * Whether a node renders anything, with fragments opened up, so a fragment of\n * only `false` or `null` children counts as empty.\n */\nfunction hasContent(node: ReactNode): boolean {\n return Children.toArray(node).some((child) =>\n isValidElement<{ children?: ReactNode }>(child) && child.type === Fragment\n ? hasContent(child.props.children)\n : true\n );\n}\n\nexport interface AccordionProps {\n title?: ReactNode;\n description?: ReactNode;\n /** Sits right of the title, such as a button to add another item. */\n action?: ReactNode;\n /**\n * `AccordionItem`s, or the list's empty or loading content, such as an\n * `EmptyState`, which fills the card as-is. Without children it's just the\n * header, for a section of plain fields.\n */\n children?: ReactNode;\n className?: string;\n}\n\n/**\n * A section of `AccordionItem`s in one bordered card, with an optional title,\n * description, and action above.\n */\nexport function Accordion({\n title,\n description,\n action,\n children,\n className,\n}: AccordionProps) {\n const titleId = useId();\n const hasHeader = title != null || description != null || action != null;\n return (\n <section\n // Names the section after its title, so it reads as a landmark.\n aria-labelledby={title != null ? titleId : undefined}\n className={cn('flex flex-col gap-space-3', className)}\n >\n {hasHeader && (\n <div className=\"flex flex-col gap-space-1\">\n {/* The action centers on the title's line, so it stays put however\n far the description wraps. */}\n <div className=\"flex items-center justify-between gap-space-3\">\n {title != null && (\n <Text as=\"h3\" variant=\"h3\" id={titleId}>\n {title}\n </Text>\n )}\n {action != null && (\n <div className=\"ml-auto flex shrink-0 items-center gap-space-2\">\n {action}\n </div>\n )}\n </div>\n {description != null && (\n <Text as=\"p\" variant=\"sm\" color=\"tertiary\">\n {description}\n </Text>\n )}\n </div>\n )}\n {hasContent(children) && (\n <div className=\"flex flex-col divide-y divide-subtle overflow-hidden rounded-md border border-default bg-surface-level-1\">\n {children}\n </div>\n )}\n </section>\n );\n}\n\n/** One entry in an `AccordionItem`'s overflow menu. */\nexport interface AccordionItemMenuItem {\n /** The entry's name, in Title Case, such as Remove. */\n label: string;\n /** A quiet line under the label, such as what the entry does. */\n description?: string;\n /** Called when the viewer picks the entry; the menu then closes. */\n onSelect: () => void;\n /** `destructive` marks an entry that removes or revokes something. */\n tone?: 'default' | 'destructive';\n disabled?: boolean;\n}\n\nexport interface AccordionItemProps {\n /** A mark at 16px, which the item puts in a tile. */\n icon?: ReactNode;\n /** A person's or account's name, shown as an avatar in place of `icon`. */\n avatar?: string;\n title: ReactNode;\n /** Sits beside the title, such as a `StatusBadge`. */\n badge?: ReactNode;\n /** A quiet line under the title. */\n description?: ReactNode;\n /**\n * The item's own action, kept on its header whether or not it's expanded,\n * such as a `Switch`, a `Select` with `variant=\"plain\"`, or a button.\n */\n action?: ReactNode;\n /** Entries for the item's overflow menu, such as Rename or Remove. */\n menuItems?: AccordionItemMenuItem[];\n /**\n * The item's expandable body, shown below the header when expanded. Without\n * it the item doesn't expand.\n */\n contents?: ReactNode;\n defaultExpanded?: boolean;\n /** Called when the viewer expands or collapses the item. */\n onExpandedChange?: (expanded: boolean) => void;\n className?: string;\n}\n\n/**\n * One item in an `Accordion`: a header with a title, its action, and an\n * overflow menu, which expands to show its `contents` when it has any.\n */\nexport function AccordionItem({\n icon: iconProp,\n avatar,\n title,\n badge,\n description,\n action,\n menuItems,\n contents,\n defaultExpanded = false,\n onExpandedChange,\n className,\n}: AccordionItemProps) {\n const [expanded, setExpanded] = useState(defaultExpanded);\n function toggle() {\n setExpanded(!expanded);\n onExpandedChange?.(!expanded);\n }\n const bodyId = useId();\n const icon =\n avatar != null ? (\n <Avatar label={avatar} size=\"sm\" shape=\"circle\" />\n ) : (\n iconProp\n );\n const label = typeof title === 'string' ? title : 'item';\n const hasBody = hasContent(contents);\n\n const hasMenu = menuItems != null && menuItems.length > 0;\n\n return (\n <div className={cn('flex flex-col', className)}>\n {/* Everything centers on the header row, so the icon tile, the action,\n the menu, and the caret share one axis with or without a\n description. The tile and the trailing control are both 24px and\n inset by the row's px-space-3, mirroring each other. */}\n <div className=\"flex items-center gap-space-2 px-space-3 py-space-2\">\n {icon != null && (\n <span\n className={cn(\n 'flex size-6 shrink-0 items-center justify-center',\n // An avatar is its own shape, so it goes without the tile.\n avatar == null &&\n 'rounded-sm bg-surface-level-2 text-icon-secondary [&>*]:size-4'\n )}\n >\n {icon}\n </span>\n )}\n\n <div className=\"flex min-w-0 flex-1 flex-wrap items-center justify-between gap-x-space-3 gap-y-space-2\">\n {/* The title also toggles the item for a pointer; the caret is the\n control a keyboard or screen reader uses. */}\n <div\n className={cn(\n 'flex min-h-6 min-w-0 flex-1 basis-16 flex-col justify-center',\n hasBody && 'cursor-pointer'\n )}\n onClick={hasBody ? toggle : undefined}\n >\n <span className=\"flex min-w-0 items-center gap-space-2\">\n <Text\n as=\"span\"\n variant=\"sm\"\n weight=\"medium\"\n className=\"truncate text-primary\"\n >\n {title}\n </Text>\n {badge}\n </span>\n {description != null && (\n <Text\n as=\"span\"\n variant=\"xs\"\n color=\"tertiary\"\n className=\"truncate\"\n >\n {description}\n </Text>\n )}\n </div>\n\n {/* The title grows to fill the header, which keeps the action on\n the right until it wraps under the title. */}\n {action != null && (\n <div className=\"flex min-h-6 shrink-0 items-center gap-space-2\">\n {action}\n </div>\n )}\n </div>\n\n {/* Kept out of the wrapping area, so the menu and caret stay pinned\n to the row's right edge, opposite the icon tile. */}\n {(hasMenu || hasBody) && (\n <div className=\"flex shrink-0 items-center gap-space-2\">\n {hasMenu && (\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <IconButton\n icon={DotsThreeIcon}\n iconWeight=\"regular\"\n label={`${label} options`}\n variant=\"plain\"\n color=\"secondary\"\n size=\"sm\"\n />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"max-w-xs\">\n {menuItems.map((item) => (\n <DropdownMenuItem\n key={item.label}\n disabled={item.disabled}\n onSelect={item.onSelect}\n className=\"flex-col items-start justify-center\"\n >\n <Text\n as=\"span\"\n variant=\"sm\"\n color={\n item.tone === 'destructive' ? 'error' : 'primary'\n }\n >\n {item.label}\n </Text>\n {item.description != null && (\n <Text as=\"span\" variant=\"xs\" color=\"tertiary\">\n {item.description}\n </Text>\n )}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n )}\n {hasBody && (\n <IconButton\n icon={CaretDownIcon}\n iconWeight=\"regular\"\n label={expanded ? `Hide ${label}` : `Show ${label}`}\n variant=\"plain\"\n color=\"secondary\"\n size=\"sm\"\n aria-expanded={expanded}\n aria-controls={bodyId}\n onClick={toggle}\n className={cn(\n '[&_svg]:transition-transform [&_svg]:duration-normal motion-reduce:[&_svg]:transition-none',\n !expanded && '[&_svg]:-rotate-90'\n )}\n />\n )}\n </div>\n )}\n </div>\n\n {hasBody && (\n <div\n id={bodyId}\n className={cn(\n animation.contentResize,\n 'motion-reduce:transition-none',\n expanded ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]'\n )}\n >\n <div className=\"overflow-hidden\" inert={!expanded}>\n <div className=\"border-t border-subtle px-space-3 py-space-2\">\n {contents}\n </div>\n </div>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,SAAS,WAAW,MAA0B;CAC5C,OAAO,SAAS,QAAQ,IAAI,CAAC,CAAC,MAAM,UAClC,eAAyC,K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M,IAAG;QAAO,SAAQ;QAAK,OAAM;QAChC,UAAA,KAAK;OACF,CAAA,CAEQ;MAnBX,GAAA,KAAK,KAmBM,CACnB;KACkB,CAAA,CACT,EAAA,CAAA,GAEf,WACC,oBAAC,YAAD;MACE,MAAM;MACN,YAAW;MACX,OAAO,WAAW,QAAQ,UAAU,QAAQ;MAC5C,SAAQ;MACR,OAAM;MACN,MAAK;MACL,iBAAe;MACf,iBAAe;MACf,SAAS;MACT,WAAW,GACT,8FACA,CAAC,YAAY,oBACf;KACD,CAAA,CAEA;;GAEJ;EAEJ,CAAA,GAAA,WACC,oBAAC,OAAD;GACE,IAAI;GACJ,WAAW,GACT,UAAU,eACV,iCACA,WAAW,oBAAoB,iBACjC;GAEA,UAAA,oBAAC,OAAD;IAAK,WAAU;IAAkB,OAAO,CAAC;IACvC,UAAA,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA;IACE,CAAA;GACF,CAAA;EACF,CAAA,CAEJ;;AAET"}
|
|
@@ -2,15 +2,15 @@ import { cn } from "../../utils/cn.js";
|
|
|
2
2
|
import { CONTROL_SIZES, VISUAL_ELEMENT_SIZES } from "../../utils/componentSizes.js";
|
|
3
3
|
import { Text } from "../Text/Text.js";
|
|
4
4
|
import { SpinnerIcon } from "../Spinner/Spinner.js";
|
|
5
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
6
|
import { Button } from "../Button/Button.js";
|
|
6
7
|
import { Icon } from "../Icon/Icon.js";
|
|
7
|
-
import { IconButton } from "../IconButton/IconButton.js";
|
|
8
8
|
import { t as getAttachmentIcon } from "../../_chunks/render-attachment-icon-BWBEMxXZ.js";
|
|
9
9
|
import { forwardRef, useId } from "react";
|
|
10
|
-
import { FileIcon } from "@phosphor-icons/react/dist/ssr/File";
|
|
11
|
-
import { WarningCircleIcon } from "@phosphor-icons/react/dist/ssr/WarningCircle";
|
|
12
10
|
import { XIcon } from "@phosphor-icons/react/dist/ssr/X";
|
|
13
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { FileIcon } from "@phosphor-icons/react/dist/ssr/File";
|
|
13
|
+
import { WarningCircleIcon } from "@phosphor-icons/react/dist/ssr/WarningCircle";
|
|
14
14
|
//#region packages/components/src/components/Attachment/Attachment.tsx
|
|
15
15
|
var SIZE_STYLES = {
|
|
16
16
|
sm: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
2
|
import { VISUAL_ELEMENT_SIZES } from "../../utils/componentSizes.js";
|
|
3
|
-
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
4
3
|
import { getColorByString } from "../../utils/get-color-by-string.js";
|
|
4
|
+
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
5
5
|
import { forwardRef } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { sanitizeUrl } from "@braintree/sanitize-url";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { XIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { Text } from "../Text/Text.js";
|
|
3
|
-
import { Icon } from "../Icon/Icon.js";
|
|
4
4
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Icon } from "../Icon/Icon.js";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { CheckCircleIcon } from "@phosphor-icons/react/dist/ssr/CheckCircle";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
2
|
import { CONTROL_SIZES } from "../../utils/componentSizes.js";
|
|
3
3
|
import { Text } from "../Text/Text.js";
|
|
4
|
-
import { Badge } from "../Badge/Badge.js";
|
|
5
|
-
import { Spinner } from "../Spinner/Spinner.js";
|
|
6
4
|
import { buttonStyleMap } from "./constants.js";
|
|
5
|
+
import { Spinner } from "../Spinner/Spinner.js";
|
|
6
|
+
import { Badge } from "../Badge/Badge.js";
|
|
7
7
|
import { cloneElement, forwardRef, isValidElement } from "react";
|
|
8
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
//#region packages/components/src/components/Button/Button.tsx
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { DotsSixVerticalIcon, XCloseIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { Text } from "../Text/Text.js";
|
|
3
|
-
import { IconButton } from "../IconButton/IconButton.js";
|
|
4
|
-
import { DotsSixVerticalIcon, XCloseIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
5
4
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "../DropdownMenu/DropdownMenu.js";
|
|
5
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
6
6
|
import { EmptyState } from "../EmptyState/EmptyState.js";
|
|
7
7
|
import { Skeleton } from "../Skeleton/Skeleton.js";
|
|
8
8
|
import { ChartCardSkeleton } from "./ChartCardSkeleton.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
2
3
|
import { Badge } from "../Badge/Badge.js";
|
|
3
4
|
import { Button } from "../Button/Button.js";
|
|
4
|
-
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
5
5
|
import { SPACE_SCALE_PX } from "../../utils/spacing.js";
|
|
6
6
|
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../Popover/Popover.js";
|
|
7
7
|
import { getChartLegendListColumns, getChartLegendListGridTemplate, widthsMatch } from "./utils.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CheckIcon, MinusIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { SELECTION_CONTROL_HIT_AREA_STYLES } from "../../utils/componentSizes.js";
|
|
3
4
|
import { Text } from "../Text/Text.js";
|
|
4
|
-
import { CheckIcon, MinusIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
5
5
|
import { checkboxBaseStyles, checkboxFocusStyles, checkboxIconSizes, checkboxIndicatorStyles, checkboxRootStateStyles, checkboxSizeStyles } from "./constants.js";
|
|
6
6
|
import { forwardRef, useId } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { CaretDownIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { Text } from "../Text/Text.js";
|
|
3
4
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
4
|
-
import { CaretDownIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
5
5
|
import { useCodeMirror } from "../../utils/useCodeMirror.js";
|
|
6
6
|
import { CopyIconButton } from "../CopyButton/CopyButton.js";
|
|
7
7
|
import { convertFile, getVisibleLines, parseFile } from "./CodeLite.utils.js";
|
|
8
8
|
import { CodeToolbar } from "./CodeToolbar.js";
|
|
9
9
|
import { Suspense, lazy, memo, useEffect, useRef, useState } from "react";
|
|
10
|
+
import { DotsThreeIcon } from "@phosphor-icons/react/dist/ssr/DotsThree";
|
|
10
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
import { TableVirtuoso } from "react-virtuoso";
|
|
12
|
-
import { DotsThreeIcon } from "@phosphor-icons/react/dist/ssr/DotsThree";
|
|
13
13
|
//#region packages/components/src/components/Code/CodeLite.tsx
|
|
14
14
|
var LazyCodeLiteDiff = lazy(() => import("./CodeLiteDiff.js").then((module) => ({ default: module.CodeLiteDiff })));
|
|
15
15
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
|
-
import { Button } from "../Button/Button.js";
|
|
3
2
|
import zIndices from "../../utils/zIndices.js";
|
|
4
3
|
import { useZIndex } from "../../utils/useZIndex.js";
|
|
4
|
+
import { Button } from "../Button/Button.js";
|
|
5
5
|
import { Banner } from "../Banner/Banner.js";
|
|
6
6
|
import "../Banner/index.js";
|
|
7
7
|
import { useColorScheme } from "../../hooks/useColorScheme.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { CheckIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { OPTION_ROW_SIZES } from "../../utils/componentSizes.js";
|
|
3
4
|
import { Text } from "../Text/Text.js";
|
|
4
5
|
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
6
|
-
import { CheckIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
7
7
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from "./Command.js";
|
|
8
8
|
import { Fragment, useCallback, useEffect, useRef, useState } from "react";
|
|
9
9
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CheckIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { Text } from "../Text/Text.js";
|
|
2
|
-
import { Button } from "../Button/Button.js";
|
|
3
3
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Button } from "../Button/Button.js";
|
|
5
5
|
import { pickDataAttributes } from "../../utils/dataAttributes.js";
|
|
6
6
|
import { useCopy } from "./useCopy.js";
|
|
7
7
|
import { useState } from "react";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { XIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
|
-
import { Text } from "../Text/Text.js";
|
|
3
3
|
import zIndices from "../../utils/zIndices.js";
|
|
4
4
|
import { useZIndex } from "../../utils/useZIndex.js";
|
|
5
5
|
import { ZIndexProvider } from "../../utils/ZIndexContext.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Text } from "../Text/Text.js";
|
|
7
7
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
8
|
-
import {
|
|
8
|
+
import { Icon } from "../Icon/Icon.js";
|
|
9
9
|
import { pickDataAttributes } from "../../utils/dataAttributes.js";
|
|
10
10
|
import { mergeRefs } from "../../utils/merge-refs.js";
|
|
11
11
|
import { ModalLayerProvider, ModalProvider, useCurrentModalLayer, useModalLayer } from "../../utils/ModalLayerContext.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { CaretRightIcon, XCloseIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { Text } from "../Text/Text.js";
|
|
3
|
-
import { Icon } from "../Icon/Icon.js";
|
|
4
4
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Icon } from "../Icon/Icon.js";
|
|
6
6
|
import { CopyIconButton } from "../CopyButton/CopyButton.js";
|
|
7
7
|
import { prettifyErrorPayload } from "../../utils/prettify-error-payload.js";
|
|
8
8
|
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { ExclamationMarkIcon } from "@phosphor-icons/react/dist/ssr/ExclamationMark";
|
|
11
10
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
11
|
+
import { ExclamationMarkIcon } from "@phosphor-icons/react/dist/ssr/ExclamationMark";
|
|
12
12
|
//#region packages/components/src/components/ErrorMessage/ErrorMessage.tsx
|
|
13
13
|
var sizeStyles = {
|
|
14
14
|
sm: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
2
|
import { CONTROL_SIZES } from "../../utils/componentSizes.js";
|
|
3
|
-
import { Spinner } from "../Spinner/Spinner.js";
|
|
4
|
-
import { buttonStyleMap } from "../Button/constants.js";
|
|
5
3
|
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
4
|
+
import { buttonStyleMap } from "../Button/constants.js";
|
|
5
|
+
import { Spinner } from "../Spinner/Spinner.js";
|
|
6
6
|
import { cloneElement, forwardRef, isValidElement } from "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
//#region packages/components/src/components/IconButton/IconButton.tsx
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
2
|
import { Text } from "../Text/Text.js";
|
|
3
|
-
import { Icon } from "../Icon/Icon.js";
|
|
4
3
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
4
|
+
import { Icon } from "../Icon/Icon.js";
|
|
5
5
|
import { mergeRefs } from "../../utils/merge-refs.js";
|
|
6
6
|
import { CONTROL_ICON_SIZES } from "../../utils/controlIconSizes.js";
|
|
7
7
|
import { INPUT_TEXT_CLASSES, getInputContainerClasses, getInputElementClasses } from "./inputStyles.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { CaretDoubleRightIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
|
-
import { Text } from "../Text/Text.js";
|
|
3
3
|
import zIndices from "../../utils/zIndices.js";
|
|
4
4
|
import { useZIndex } from "../../utils/useZIndex.js";
|
|
5
5
|
import { ZIndexProvider } from "../../utils/ZIndexContext.js";
|
|
6
|
+
import { Text } from "../Text/Text.js";
|
|
6
7
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
7
|
-
import { CaretDoubleRightIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
8
8
|
import { pickDataAttributes } from "../../utils/dataAttributes.js";
|
|
9
9
|
import { mergeRefs } from "../../utils/merge-refs.js";
|
|
10
10
|
import { ModalLayerProvider, useCurrentModalLayer, useModalLayer } from "../../utils/ModalLayerContext.js";
|
|
@@ -18,6 +18,7 @@ export interface SelectGroup<T extends string = string> {
|
|
|
18
18
|
options: SelectOption<T>[];
|
|
19
19
|
}
|
|
20
20
|
export type SelectSize = ControlSize;
|
|
21
|
+
export type SelectVariant = 'outlined' | 'plain';
|
|
21
22
|
interface SelectBaseProps<T extends string = string> extends DataAttributes {
|
|
22
23
|
/** The currently selected value */
|
|
23
24
|
value?: T;
|
|
@@ -51,6 +52,13 @@ interface SelectBaseProps<T extends string = string> extends DataAttributes {
|
|
|
51
52
|
endReachedThresholdPx?: number;
|
|
52
53
|
/** Additional class name for the trigger button */
|
|
53
54
|
triggerClassName?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Trigger appearance. `outlined` (default) is a full-width form field.
|
|
57
|
+
* `plain` drops the field fill and border and sizes the trigger to its
|
|
58
|
+
* value, so it reads as text until hovered — for an inline setting in a row,
|
|
59
|
+
* such as a member's role, where a field box would crowd it.
|
|
60
|
+
*/
|
|
61
|
+
variant?: SelectVariant;
|
|
54
62
|
/** Additional class name for the popover content */
|
|
55
63
|
contentClassName?: string;
|
|
56
64
|
/** Custom render function for the selected value in the trigger */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { CaretDownIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { CONTROL_SIZES } from "../../utils/componentSizes.js";
|
|
3
4
|
import { Text } from "../Text/Text.js";
|
|
4
5
|
import { Button } from "../Button/Button.js";
|
|
5
6
|
import { Icon } from "../Icon/Icon.js";
|
|
6
|
-
import { CaretDownIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
7
7
|
import { pickDataAttributes } from "../../utils/dataAttributes.js";
|
|
8
8
|
import { Popover, PopoverContent, PopoverTrigger } from "../Popover/Popover.js";
|
|
9
9
|
import { CONTROL_ICON_SIZES } from "../../utils/controlIconSizes.js";
|
|
@@ -21,7 +21,7 @@ function optionToItem(opt) {
|
|
|
21
21
|
keywords: opt.label ? [opt.label] : void 0
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function OptionSelect({ value, onChange, options, groups, placeholder = "Select...", searchPlaceholder = "Search...", disabled = false, size = "sm", emptyText = "No results found.", open: controlledOpen, onOpenChange: controlledOnOpenChange, allowDeselect, hideSearch = true, disableFilter, onSearchChange, loading, loadingRows, onEndReached, endReachedThresholdPx, triggerClassName, contentClassName, renderValue, renderOption, side, align = "start", "aria-label": ariaLabel, "data-testid": dataTestId, ...rest }) {
|
|
24
|
+
function OptionSelect({ value, onChange, options, groups, placeholder = "Select...", searchPlaceholder = "Search...", disabled = false, size = "sm", emptyText = "No results found.", open: controlledOpen, onOpenChange: controlledOnOpenChange, allowDeselect, hideSearch = true, disableFilter, onSearchChange, loading, loadingRows, onEndReached, endReachedThresholdPx, triggerClassName, variant = "outlined", contentClassName, renderValue, renderOption, side, align = "start", "aria-label": ariaLabel, "data-testid": dataTestId, ...rest }) {
|
|
25
25
|
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
26
26
|
const isControlled = controlledOpen !== void 0;
|
|
27
27
|
const open = isControlled ? controlledOpen : uncontrolledOpen;
|
|
@@ -85,10 +85,10 @@ function OptionSelect({ value, onChange, options, groups, placeholder = "Select.
|
|
|
85
85
|
role: "combobox",
|
|
86
86
|
"aria-expanded": open,
|
|
87
87
|
"aria-label": ariaLabel ?? placeholder,
|
|
88
|
-
variant
|
|
88
|
+
variant,
|
|
89
89
|
color: "secondary",
|
|
90
90
|
size: triggerButtonSize,
|
|
91
|
-
className: cn("box-border
|
|
91
|
+
className: cn("box-border justify-between py-0", CONTROL_SIZES[size].heightClassName, variant === "plain" ? cn("w-auto max-w-full gap-space-1 px-space-1", disabled && "bg-disabled text-disabled dark:bg-disabled") : cn("w-full", disabled ? "border-muted bg-input-disabled text-disabled dark:bg-input-disabled" : "bg-input border-muted hover:border-subtle focus-visible:border-focus focus-visible:shadow-[0_0_0_1px_var(--border-focus)] focus-visible:outline-none"), triggerClassName),
|
|
92
92
|
disabled,
|
|
93
93
|
"data-testid": dataTestId,
|
|
94
94
|
children: [triggerContent, /* @__PURE__ */ jsx(Icon, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","names":[],"sources":["../../../src/components/Select/Select.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { CaretDownIcon } from '../../icons/PaddedPhosphorIcons';\nimport { cn } from '../../utils/cn';\nimport {\n CONTROL_SIZES,\n type ControlSize,\n type OptionRowSize,\n} from '../../utils/componentSizes';\nimport { CONTROL_ICON_SIZES } from '../../utils/controlIconSizes';\nimport {\n type DataAttributes,\n pickDataAttributes,\n} from '../../utils/dataAttributes';\nimport { Button } from '../Button';\nimport { CommandMenu } from '../Command/CommandMenu';\nimport type { CommandMenuGroup, CommandMenuItem } from '../Command/CommandMenu';\nimport { Icon } from '../Icon';\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover';\nimport { Text } from '../Text';\n\nexport interface SelectOption<T extends string = string> {\n /** The value used for selection and filtering */\n value: T;\n /** Display label (defaults to value if not provided) */\n label?: string;\n /** Secondary description text displayed below the label */\n description?: string;\n /** Element displayed on the right side of the item (e.g. badge, shortcut) */\n rightDecorator?: ReactNode;\n /** Whether this option is disabled */\n disabled?: boolean;\n}\n\nexport interface SelectGroup<T extends string = string> {\n heading?: string;\n options: SelectOption<T>[];\n}\n\nexport type SelectSize = ControlSize;\n\ninterface SelectBaseProps<T extends string = string> extends DataAttributes {\n /** The currently selected value */\n value?: T;\n /** Callback when selection changes. Receives undefined when deselected. */\n onChange: (value: T | undefined) => void;\n /** Placeholder text when no value is selected */\n placeholder?: string;\n /** Placeholder text for the search input */\n searchPlaceholder?: string;\n /** Whether the select is disabled */\n disabled?: boolean;\n /** Exact trigger height: xs=20px, sm=24px, md=32px, lg=40px. */\n size?: SelectSize;\n /** Text to show when no options match the search */\n emptyText?: string;\n /** Allow deselecting the current value by clicking it again (default: false) */\n allowDeselect?: boolean;\n /** Hide the search input (default: true, search is hidden) */\n hideSearch?: boolean;\n /** Disable client-side filtering by cmdk (default: false). Set true for server-side filtering. */\n disableFilter?: boolean;\n /** Callback when the search input value changes. Useful for server-side filtering. */\n onSearchChange?: (query: string) => void;\n /** Whether more items are currently being loaded */\n loading?: boolean;\n /** Number of skeleton rows to show while loading (default: 5) */\n loadingRows?: number;\n /** Callback when the user scrolls near the end of the list. Use for infinite loading. */\n onEndReached?: () => void;\n /** Distance in pixels from the bottom to trigger onEndReached (default: 50) */\n endReachedThresholdPx?: number;\n /** Additional class name for the trigger button */\n triggerClassName?: string;\n /** Additional class name for the popover content */\n contentClassName?: string;\n /** Custom render function for the selected value in the trigger */\n renderValue?: (option: SelectOption<T>) => ReactNode;\n /** Custom render function for each option in the list */\n renderOption?: (option: SelectOption<T>, isSelected: boolean) => ReactNode;\n /** Side of the trigger to align the popover */\n side?: 'top' | 'bottom' | 'left' | 'right';\n /** Alignment of the popover relative to the trigger */\n align?: 'start' | 'center' | 'end';\n /** aria-label for the trigger button */\n 'aria-label'?: string;\n /** Test id for the trigger button */\n 'data-testid'?: string;\n}\n\nexport type SelectProps<T extends string = string> = SelectBaseProps<T> &\n (\n | {\n options: SelectOption<T>[];\n groups?: never;\n }\n | {\n groups: SelectGroup<T>[];\n options?: never;\n }\n ) &\n (\n | {\n /** Controlled open state */\n open: boolean;\n /** Callback when open state changes (required when `open` is provided) */\n onOpenChange: (open: boolean) => void;\n }\n | {\n open?: never;\n onOpenChange?: never;\n }\n );\n\nfunction optionToItem(opt: SelectOption): CommandMenuItem {\n return {\n value: opt.value,\n label: opt.label,\n description: opt.description,\n rightDecorator: opt.rightDecorator,\n disabled: opt.disabled,\n keywords: opt.label ? [opt.label] : undefined,\n };\n}\n\nfunction OptionSelect<T extends string = string>({\n value,\n onChange,\n options,\n groups,\n placeholder = 'Select...',\n searchPlaceholder = 'Search...',\n disabled = false,\n size = 'sm',\n emptyText = 'No results found.',\n open: controlledOpen,\n onOpenChange: controlledOnOpenChange,\n allowDeselect,\n hideSearch = true,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n triggerClassName,\n contentClassName,\n renderValue,\n renderOption,\n side,\n align = 'start',\n 'aria-label': ariaLabel,\n 'data-testid': dataTestId,\n ...rest\n}: SelectProps<T>) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n const isControlled = controlledOpen !== undefined;\n const open = isControlled ? controlledOpen : uncontrolledOpen;\n const setOpen = isControlled ? controlledOnOpenChange : setUncontrolledOpen;\n\n const allOptions = useMemo<SelectOption<T>[]>(\n () => (groups ? groups.flatMap((g) => g.options) : (options ?? [])),\n [groups, options]\n );\n\n const selectedOption = useMemo(\n () => allOptions.find((opt) => opt.value === value),\n [allOptions, value]\n );\n\n const handleSelect = useCallback(\n (optionValue: string) => {\n const match = allOptions.find((o) => o.value === optionValue);\n if (!match) return;\n if (allowDeselect && match.value === value) {\n onChange(undefined);\n } else {\n onChange(match.value);\n }\n setOpen(false);\n },\n [allowDeselect, value, onChange, setOpen, allOptions]\n );\n\n const items: CommandMenuItem[] = useMemo(\n () => (options ?? []).map(optionToItem),\n [options]\n );\n\n const commandGroups: CommandMenuGroup[] | undefined = useMemo(\n () =>\n groups?.map((g) => ({\n heading: g.heading,\n items: g.options.map(optionToItem),\n })),\n [groups]\n );\n\n const renderItem = renderOption\n ? (item: CommandMenuItem, isSelected: boolean) => {\n const option = allOptions.find((o) => o.value === item.value);\n return option ? renderOption(option, isSelected) : null;\n }\n : undefined;\n const searchInputSize = size === 'xs' ? 'sm' : size === 'lg' ? 'md' : size;\n const triggerButtonSize = size === 'lg' ? 'md' : size;\n const itemRowSize: OptionRowSize =\n size === 'xs' || size === 'sm' ? 'sm' : 'md';\n\n const commandMenuSharedProps = {\n value,\n onSelect: handleSelect,\n placeholder: searchPlaceholder,\n emptyText,\n hideSearch,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n renderItem,\n inputSize: searchInputSize,\n itemRowSize,\n };\n\n const triggerContent =\n selectedOption && renderValue ? (\n renderValue(selectedOption)\n ) : (\n <Text\n as=\"span\"\n variant={triggerButtonSize}\n weight=\"normal\"\n className=\"min-w-0 truncate text-left\"\n >\n {selectedOption\n ? (selectedOption.label ?? selectedOption.value)\n : placeholder}\n </Text>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n {...pickDataAttributes(rest)}\n role=\"combobox\"\n aria-expanded={open}\n aria-label={ariaLabel ?? placeholder}\n variant=\"outlined\"\n color=\"secondary\"\n size={triggerButtonSize}\n className={cn(\n 'box-border w-full justify-between py-0',\n CONTROL_SIZES[size].heightClassName,\n disabled\n ? 'border-muted bg-input-disabled text-disabled dark:bg-input-disabled'\n : 'bg-input border-muted hover:border-subtle focus-visible:border-focus focus-visible:shadow-[0_0_0_1px_var(--border-focus)] focus-visible:outline-none',\n triggerClassName\n )}\n disabled={disabled}\n data-testid={dataTestId}\n >\n {triggerContent}\n <Icon\n aria-hidden\n icon={CaretDownIcon}\n iconClassName={CONTROL_ICON_SIZES[size].iconClassName}\n className={disabled ? 'text-icon-disabled' : 'text-inherit'}\n weight=\"regular\"\n />\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className={cn(\n 'w-max min-w-[var(--radix-popover-trigger-width)] max-w-[min(24rem,calc(100vw-1rem))] p-0 text-primary',\n contentClassName\n )}\n side={side}\n align={align}\n >\n {commandGroups ? (\n <CommandMenu groups={commandGroups} {...commandMenuSharedProps} />\n ) : (\n <CommandMenu items={items} {...commandMenuSharedProps} />\n )}\n </PopoverContent>\n </Popover>\n );\n}\n\nexport function Select<T extends string = string>(\n props: SelectProps<T>\n): React.ReactElement<unknown> {\n return <OptionSelect {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;AAmHA,SAAS,aAAa,KAAoC;CACxD,O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AA,CACT;;AAEb;AAEA,SAAgB,OACd,OAC6B;CAC7B,OAAO,oBAAC,cAAD,EAAc,GAAI,MAAQ,CAAA;AACnC"}
|
|
1
|
+
{"version":3,"file":"Select.js","names":[],"sources":["../../../src/components/Select/Select.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { CaretDownIcon } from '../../icons/PaddedPhosphorIcons';\nimport { cn } from '../../utils/cn';\nimport {\n CONTROL_SIZES,\n type ControlSize,\n type OptionRowSize,\n} from '../../utils/componentSizes';\nimport { CONTROL_ICON_SIZES } from '../../utils/controlIconSizes';\nimport {\n type DataAttributes,\n pickDataAttributes,\n} from '../../utils/dataAttributes';\nimport { Button } from '../Button';\nimport { CommandMenu } from '../Command/CommandMenu';\nimport type { CommandMenuGroup, CommandMenuItem } from '../Command/CommandMenu';\nimport { Icon } from '../Icon';\nimport { Popover, PopoverContent, PopoverTrigger } from '../Popover';\nimport { Text } from '../Text';\n\nexport interface SelectOption<T extends string = string> {\n /** The value used for selection and filtering */\n value: T;\n /** Display label (defaults to value if not provided) */\n label?: string;\n /** Secondary description text displayed below the label */\n description?: string;\n /** Element displayed on the right side of the item (e.g. badge, shortcut) */\n rightDecorator?: ReactNode;\n /** Whether this option is disabled */\n disabled?: boolean;\n}\n\nexport interface SelectGroup<T extends string = string> {\n heading?: string;\n options: SelectOption<T>[];\n}\n\nexport type SelectSize = ControlSize;\n\nexport type SelectVariant = 'outlined' | 'plain';\n\ninterface SelectBaseProps<T extends string = string> extends DataAttributes {\n /** The currently selected value */\n value?: T;\n /** Callback when selection changes. Receives undefined when deselected. */\n onChange: (value: T | undefined) => void;\n /** Placeholder text when no value is selected */\n placeholder?: string;\n /** Placeholder text for the search input */\n searchPlaceholder?: string;\n /** Whether the select is disabled */\n disabled?: boolean;\n /** Exact trigger height: xs=20px, sm=24px, md=32px, lg=40px. */\n size?: SelectSize;\n /** Text to show when no options match the search */\n emptyText?: string;\n /** Allow deselecting the current value by clicking it again (default: false) */\n allowDeselect?: boolean;\n /** Hide the search input (default: true, search is hidden) */\n hideSearch?: boolean;\n /** Disable client-side filtering by cmdk (default: false). Set true for server-side filtering. */\n disableFilter?: boolean;\n /** Callback when the search input value changes. Useful for server-side filtering. */\n onSearchChange?: (query: string) => void;\n /** Whether more items are currently being loaded */\n loading?: boolean;\n /** Number of skeleton rows to show while loading (default: 5) */\n loadingRows?: number;\n /** Callback when the user scrolls near the end of the list. Use for infinite loading. */\n onEndReached?: () => void;\n /** Distance in pixels from the bottom to trigger onEndReached (default: 50) */\n endReachedThresholdPx?: number;\n /** Additional class name for the trigger button */\n triggerClassName?: string;\n /**\n * Trigger appearance. `outlined` (default) is a full-width form field.\n * `plain` drops the field fill and border and sizes the trigger to its\n * value, so it reads as text until hovered — for an inline setting in a row,\n * such as a member's role, where a field box would crowd it.\n */\n variant?: SelectVariant;\n /** Additional class name for the popover content */\n contentClassName?: string;\n /** Custom render function for the selected value in the trigger */\n renderValue?: (option: SelectOption<T>) => ReactNode;\n /** Custom render function for each option in the list */\n renderOption?: (option: SelectOption<T>, isSelected: boolean) => ReactNode;\n /** Side of the trigger to align the popover */\n side?: 'top' | 'bottom' | 'left' | 'right';\n /** Alignment of the popover relative to the trigger */\n align?: 'start' | 'center' | 'end';\n /** aria-label for the trigger button */\n 'aria-label'?: string;\n /** Test id for the trigger button */\n 'data-testid'?: string;\n}\n\nexport type SelectProps<T extends string = string> = SelectBaseProps<T> &\n (\n | {\n options: SelectOption<T>[];\n groups?: never;\n }\n | {\n groups: SelectGroup<T>[];\n options?: never;\n }\n ) &\n (\n | {\n /** Controlled open state */\n open: boolean;\n /** Callback when open state changes (required when `open` is provided) */\n onOpenChange: (open: boolean) => void;\n }\n | {\n open?: never;\n onOpenChange?: never;\n }\n );\n\nfunction optionToItem(opt: SelectOption): CommandMenuItem {\n return {\n value: opt.value,\n label: opt.label,\n description: opt.description,\n rightDecorator: opt.rightDecorator,\n disabled: opt.disabled,\n keywords: opt.label ? [opt.label] : undefined,\n };\n}\n\nfunction OptionSelect<T extends string = string>({\n value,\n onChange,\n options,\n groups,\n placeholder = 'Select...',\n searchPlaceholder = 'Search...',\n disabled = false,\n size = 'sm',\n emptyText = 'No results found.',\n open: controlledOpen,\n onOpenChange: controlledOnOpenChange,\n allowDeselect,\n hideSearch = true,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n triggerClassName,\n variant = 'outlined',\n contentClassName,\n renderValue,\n renderOption,\n side,\n align = 'start',\n 'aria-label': ariaLabel,\n 'data-testid': dataTestId,\n ...rest\n}: SelectProps<T>) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n const isControlled = controlledOpen !== undefined;\n const open = isControlled ? controlledOpen : uncontrolledOpen;\n const setOpen = isControlled ? controlledOnOpenChange : setUncontrolledOpen;\n\n const allOptions = useMemo<SelectOption<T>[]>(\n () => (groups ? groups.flatMap((g) => g.options) : (options ?? [])),\n [groups, options]\n );\n\n const selectedOption = useMemo(\n () => allOptions.find((opt) => opt.value === value),\n [allOptions, value]\n );\n\n const handleSelect = useCallback(\n (optionValue: string) => {\n const match = allOptions.find((o) => o.value === optionValue);\n if (!match) return;\n if (allowDeselect && match.value === value) {\n onChange(undefined);\n } else {\n onChange(match.value);\n }\n setOpen(false);\n },\n [allowDeselect, value, onChange, setOpen, allOptions]\n );\n\n const items: CommandMenuItem[] = useMemo(\n () => (options ?? []).map(optionToItem),\n [options]\n );\n\n const commandGroups: CommandMenuGroup[] | undefined = useMemo(\n () =>\n groups?.map((g) => ({\n heading: g.heading,\n items: g.options.map(optionToItem),\n })),\n [groups]\n );\n\n const renderItem = renderOption\n ? (item: CommandMenuItem, isSelected: boolean) => {\n const option = allOptions.find((o) => o.value === item.value);\n return option ? renderOption(option, isSelected) : null;\n }\n : undefined;\n const searchInputSize = size === 'xs' ? 'sm' : size === 'lg' ? 'md' : size;\n const triggerButtonSize = size === 'lg' ? 'md' : size;\n const itemRowSize: OptionRowSize =\n size === 'xs' || size === 'sm' ? 'sm' : 'md';\n\n const commandMenuSharedProps = {\n value,\n onSelect: handleSelect,\n placeholder: searchPlaceholder,\n emptyText,\n hideSearch,\n disableFilter,\n onSearchChange,\n loading,\n loadingRows,\n onEndReached,\n endReachedThresholdPx,\n renderItem,\n inputSize: searchInputSize,\n itemRowSize,\n };\n\n const triggerContent =\n selectedOption && renderValue ? (\n renderValue(selectedOption)\n ) : (\n <Text\n as=\"span\"\n variant={triggerButtonSize}\n weight=\"normal\"\n className=\"min-w-0 truncate text-left\"\n >\n {selectedOption\n ? (selectedOption.label ?? selectedOption.value)\n : placeholder}\n </Text>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n {...pickDataAttributes(rest)}\n role=\"combobox\"\n aria-expanded={open}\n aria-label={ariaLabel ?? placeholder}\n variant={variant}\n color=\"secondary\"\n size={triggerButtonSize}\n className={cn(\n 'box-border justify-between py-0',\n CONTROL_SIZES[size].heightClassName,\n variant === 'plain'\n ? cn(\n 'w-auto max-w-full gap-space-1 px-space-1',\n // The shared disabled fill, in both themes.\n disabled && 'bg-disabled text-disabled dark:bg-disabled'\n )\n : cn(\n 'w-full',\n disabled\n ? 'border-muted bg-input-disabled text-disabled dark:bg-input-disabled'\n : 'bg-input border-muted hover:border-subtle focus-visible:border-focus focus-visible:shadow-[0_0_0_1px_var(--border-focus)] focus-visible:outline-none'\n ),\n triggerClassName\n )}\n disabled={disabled}\n data-testid={dataTestId}\n >\n {triggerContent}\n <Icon\n aria-hidden\n icon={CaretDownIcon}\n iconClassName={CONTROL_ICON_SIZES[size].iconClassName}\n className={disabled ? 'text-icon-disabled' : 'text-inherit'}\n weight=\"regular\"\n />\n </Button>\n </PopoverTrigger>\n <PopoverContent\n className={cn(\n 'w-max min-w-[var(--radix-popover-trigger-width)] max-w-[min(24rem,calc(100vw-1rem))] p-0 text-primary',\n contentClassName\n )}\n side={side}\n align={align}\n >\n {commandGroups ? (\n <CommandMenu groups={commandGroups} {...commandMenuSharedProps} />\n ) : (\n <CommandMenu items={items} {...commandMenuSharedProps} />\n )}\n </PopoverContent>\n </Popover>\n );\n}\n\nexport function Select<T extends string = string>(\n props: SelectProps<T>\n): React.ReactElement<unknown> {\n return <OptionSelect {...props} />;\n}\n"],"mappings":";;;;;;;;;;;;;AA4HA,SAAS,aAAa,KAAoC;CACxD,OAAO;EACL,OAAO,IAAI;EACX,OAAO,IAAI;EACX,aAAa,IAAI;EACjB,gBAAgB,IAAI;EACpB,UAAU,IAAI;EACd,UAAU,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,KAAA;CACtC;AACF;AAEA,SAAS,aAAwC,EAC/C,OACA,UACA,SACA,QACA,cAAc,aACd,oBAAoB,aACpB,WAAW,OACX,OAAO,MACP,YAAY,qBACZ,MAAM,gBACN,cAAc,wBACd,eACA,aAAa,MACb,eACA,gBACA,SACA,aACA,cACA,uBACA,kBACA,UAAU,YACV,kBACA,aACA,cACA,MACA,QAAQ,SACR,cAAc,WACd,eAAe,YACf,GAAG,QACc;CACjB,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,KAAK;CAC9D,MAAM,eAAe,mBAAmB,KAAA;CACxC,MAAM,OAAO,eAAe,iBAAiB;CAC7C,MAAM,UAAU,eAAe,yBAAyB;CAExD,MAAM,aAAa,cACV,SAAS,OAAO,SAAS,MAAM,EAAE,OAAO,IAAK,WAAW,CAAC,GAChE,CAAC,QAAQ,OAAO,CAClB;CAEA,MAAM,iBAAiB,cACf,WAAW,MAAM,QAAQ,IAAI,UAAU,KAAK,GAClD,CAAC,YAAY,KAAK,CACpB;CAEA,MAAM,eAAe,aAClB,gBAAwB;EACvB,MAAM,QAAQ,WAAW,MAAM,MAAM,EAAE,UAAU,WAAW;EAC5D,IAAI,CAAC,OAAO;EACZ,IAAI,iBAAiB,MAAM,UAAU,OACnC,SAAS,KAAA,CAAS;OAElB,SAAS,MAAM,KAAK;EAEtB,QAAQ,K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MAAD;KACE,eAAA;KACA,MAAM;KACN,eAAe,mBAAmB,KAAK,CAAC;KACxC,WAAW,WAAW,uBAAuB;KAC7C,QAAO;IACR,CAAA,CACK;;EACM,CAAA,GAChB,oBAAC,gBAAD;GACE,WAAW,GACT,yGACA,gBACF;GACM;GACC;GAEN,UAAA,gBACC,oBAAC,aAAD;IAAa,QAAQ;IAAe,GAAI;GAAyB,CAAA,IAEjE,oBAAC,aAAD;IAAoB;IAAO,GAAI;GAAyB,CAAA;EAE5C,CAAA,CACT;;AAEb;AAEA,SAAgB,OACd,OAC6B;CAC7B,OAAO,oBAAC,cAAD,EAAc,GAAI,MAAQ,CAAA;AACnC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { CaretDownIcon, CaretUpIcon, CheckIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
1
2
|
import { cn } from "../../utils/cn.js";
|
|
2
3
|
import { OPTION_ROW_SIZES } from "../../utils/componentSizes.js";
|
|
3
4
|
import zIndices from "../../utils/zIndices.js";
|
|
4
5
|
import { useZIndex } from "../../utils/useZIndex.js";
|
|
5
6
|
import { ZIndexProvider } from "../../utils/ZIndexContext.js";
|
|
6
|
-
import { CaretDownIcon, CaretUpIcon, CheckIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
7
7
|
import * as React$1 from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|