@langchain/macaw-components 1.3.3 → 1.3.4
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 +568 -517
- package/dist/components/Accordion/Accordion.js +2 -8
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/ChatConversationList/ChatConversationList.d.ts +26 -0
- package/dist/components/ChatConversationList/ChatConversationList.js +83 -0
- package/dist/components/ChatConversationList/ChatConversationList.js.map +1 -0
- package/dist/components/ChatConversationList/ChatConversationListActions.d.ts +22 -0
- package/dist/components/ChatConversationList/ChatConversationListActions.js +61 -0
- package/dist/components/ChatConversationList/ChatConversationListActions.js.map +1 -0
- package/dist/components/ChatConversationList/ChatConversationListGroup.d.ts +27 -0
- package/dist/components/ChatConversationList/ChatConversationListGroup.js +96 -0
- package/dist/components/ChatConversationList/ChatConversationListGroup.js.map +1 -0
- package/dist/components/ChatConversationList/ChatConversationListItem.d.ts +40 -0
- package/dist/components/ChatConversationList/ChatConversationListItem.js +83 -0
- package/dist/components/ChatConversationList/ChatConversationListItem.js.map +1 -0
- package/dist/components/ChatConversationList/index.d.ts +6 -0
- package/dist/components/ChatConversationList/index.js +4 -0
- package/dist/components/ChatMessage/ChatMessage.js +1 -1
- package/dist/icons/LongTailPhosphorIcons.js +1 -1
- package/dist/utilities.css +1 -1
- package/dist/utils/hasContent.d.ts +3 -0
- package/dist/utils/hasContent.js +10 -0
- package/dist/utils/hasContent.js.map +1 -0
- package/package.json +10 -2
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { CaretDownIcon } from "../../icons/PaddedPhosphorIcons.js";
|
|
2
2
|
import { animation } from "../../utils/animation.js";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
|
+
import { hasContent } from "../../utils/hasContent.js";
|
|
4
5
|
import { Text } from "../Text/Text.js";
|
|
5
6
|
import { Avatar } from "../Avatar/Avatar.js";
|
|
6
7
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../DropdownMenu/DropdownMenu.js";
|
|
7
8
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
8
|
-
import {
|
|
9
|
+
import { useId, useState } from "react";
|
|
9
10
|
import { DotsThreeIcon } from "@phosphor-icons/react/dist/ssr/DotsThree";
|
|
10
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
//#region packages/components/src/components/Accordion/Accordion.tsx
|
|
12
13
|
/**
|
|
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
14
|
* A section of `AccordionItem`s in one bordered card, with an optional title,
|
|
21
15
|
* description, and action above.
|
|
22
16
|
*/
|
|
@@ -1 +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":"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"}
|
|
1
|
+
{"version":3,"file":"Accordion.js","names":[],"sources":["../../../src/components/Accordion/Accordion.tsx"],"sourcesContent":["import { type ReactNode, useId, useState } 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 { hasContent } from '../../utils/hasContent';\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\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":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface ChatConversationListProps {
|
|
3
|
+
/** Names the list and its loading status. */
|
|
4
|
+
'aria-label': string;
|
|
5
|
+
/**
|
|
6
|
+
* `ChatConversationListItem`s and `ChatConversationListGroup`s. Omit children
|
|
7
|
+
* to show the empty state; arrays and fragments are checked automatically.
|
|
8
|
+
*/
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
className?: string;
|
|
11
|
+
/** Shows the standard skeleton rows in place of the list. */
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
/** Shown above any cached items, in place of the empty state. */
|
|
14
|
+
errorContent?: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Host controls below the list, such as a Load more button. Shown only when
|
|
17
|
+
* the list has children and isn't loading.
|
|
18
|
+
*/
|
|
19
|
+
footer?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A compact list of conversations for a sidebar. It owns arrow-key focus
|
|
23
|
+
* movement and its loading, empty, and error presentation; hosts own data,
|
|
24
|
+
* selection, routing, pagination, and mutations.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ChatConversationList({ 'aria-label': ariaLabel, children, className, loading, errorContent, footer, }: ChatConversationListProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { hasContent } from "../../utils/hasContent.js";
|
|
3
|
+
import { Text } from "../Text/Text.js";
|
|
4
|
+
import { Skeleton } from "../Skeleton/Skeleton.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region packages/components/src/components/ChatConversationList/ChatConversationList.tsx
|
|
7
|
+
var NAVIGATION_KEYS = /* @__PURE__ */ new Set([
|
|
8
|
+
"ArrowDown",
|
|
9
|
+
"ArrowUp",
|
|
10
|
+
"Home",
|
|
11
|
+
"End"
|
|
12
|
+
]);
|
|
13
|
+
/** Moves focus between this list's enabled rows, including open groups'. */
|
|
14
|
+
function handleNavigation(event) {
|
|
15
|
+
const list = event.currentTarget;
|
|
16
|
+
const target = event.target;
|
|
17
|
+
if (!NAVIGATION_KEYS.has(event.key) || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || !(target instanceof HTMLButtonElement) || !target.matches("[data-conversation-trigger]")) return;
|
|
18
|
+
const rows = Array.from(list.querySelectorAll("[data-conversation-trigger]:not(:disabled)")).filter((row) => row.closest("[data-conversation-list]") === list);
|
|
19
|
+
const index = rows.indexOf(target);
|
|
20
|
+
if (index === -1) return;
|
|
21
|
+
let nextIndex;
|
|
22
|
+
switch (event.key) {
|
|
23
|
+
case "ArrowDown":
|
|
24
|
+
nextIndex = Math.min(index + 1, rows.length - 1);
|
|
25
|
+
break;
|
|
26
|
+
case "ArrowUp":
|
|
27
|
+
nextIndex = Math.max(index - 1, 0);
|
|
28
|
+
break;
|
|
29
|
+
case "Home":
|
|
30
|
+
nextIndex = 0;
|
|
31
|
+
break;
|
|
32
|
+
default: nextIndex = rows.length - 1;
|
|
33
|
+
}
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
rows[nextIndex]?.focus();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A compact list of conversations for a sidebar. It owns arrow-key focus
|
|
39
|
+
* movement and its loading, empty, and error presentation; hosts own data,
|
|
40
|
+
* selection, routing, pagination, and mutations.
|
|
41
|
+
*/
|
|
42
|
+
function ChatConversationList({ "aria-label": ariaLabel, children, className, loading = false, errorContent, footer }) {
|
|
43
|
+
const hasError = errorContent != null && errorContent !== false;
|
|
44
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
45
|
+
className: cn("min-w-0 p-space-2", className),
|
|
46
|
+
children: [hasError && /* @__PURE__ */ jsx("div", {
|
|
47
|
+
role: "alert",
|
|
48
|
+
className: "p-space-3 text-error-secondary",
|
|
49
|
+
children: errorContent
|
|
50
|
+
}), loading ? /* @__PURE__ */ jsxs("div", {
|
|
51
|
+
role: "status",
|
|
52
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
53
|
+
className: "sr-only",
|
|
54
|
+
children: ["Loading ", ariaLabel]
|
|
55
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
56
|
+
"aria-hidden": true,
|
|
57
|
+
className: "flex flex-col gap-space-1",
|
|
58
|
+
children: Array.from({ length: 6 }, (_, index) => /* @__PURE__ */ jsx("div", {
|
|
59
|
+
className: "flex items-center rounded-lg px-space-3 py-space-2",
|
|
60
|
+
children: /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/5 motion-reduce:animate-none" })
|
|
61
|
+
}, index))
|
|
62
|
+
})]
|
|
63
|
+
}) : !hasContent(children) ? !hasError && /* @__PURE__ */ jsx("div", {
|
|
64
|
+
role: "status",
|
|
65
|
+
className: "p-space-8 text-center text-tertiary",
|
|
66
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
67
|
+
variant: "sm",
|
|
68
|
+
children: "No conversations yet"
|
|
69
|
+
})
|
|
70
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
71
|
+
role: "list",
|
|
72
|
+
"aria-label": ariaLabel,
|
|
73
|
+
"data-conversation-list": "",
|
|
74
|
+
className: "flex min-w-0 flex-col gap-space-1",
|
|
75
|
+
onKeyDown: handleNavigation,
|
|
76
|
+
children
|
|
77
|
+
}), footer] })]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { ChatConversationList };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=ChatConversationList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatConversationList.js","names":[],"sources":["../../../src/components/ChatConversationList/ChatConversationList.tsx"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { hasContent } from '../../utils/hasContent';\nimport { Skeleton } from '../Skeleton';\nimport { Text } from '../Text';\n\nexport interface ChatConversationListProps {\n /** Names the list and its loading status. */\n 'aria-label': string;\n /**\n * `ChatConversationListItem`s and `ChatConversationListGroup`s. Omit children\n * to show the empty state; arrays and fragments are checked automatically.\n */\n children?: ReactNode;\n className?: string;\n /** Shows the standard skeleton rows in place of the list. */\n loading?: boolean;\n /** Shown above any cached items, in place of the empty state. */\n errorContent?: ReactNode;\n /**\n * Host controls below the list, such as a Load more button. Shown only when\n * the list has children and isn't loading.\n */\n footer?: ReactNode;\n}\n\nconst NAVIGATION_KEYS = new Set(['ArrowDown', 'ArrowUp', 'Home', 'End']);\n\n/** Moves focus between this list's enabled rows, including open groups'. */\nfunction handleNavigation(event: KeyboardEvent<HTMLDivElement>) {\n const list = event.currentTarget;\n const target = event.target;\n if (\n !NAVIGATION_KEYS.has(event.key) ||\n event.defaultPrevented ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.shiftKey ||\n !(target instanceof HTMLButtonElement) ||\n !target.matches('[data-conversation-trigger]')\n ) {\n return;\n }\n\n // Skips rows from another list rendered inside this one, such as in a\n // host's custom item.\n const rows = Array.from(\n list.querySelectorAll<HTMLButtonElement>(\n '[data-conversation-trigger]:not(:disabled)'\n )\n ).filter((row) => row.closest('[data-conversation-list]') === list);\n const index = rows.indexOf(target);\n if (index === -1) return;\n\n let nextIndex: number;\n switch (event.key) {\n case 'ArrowDown':\n nextIndex = Math.min(index + 1, rows.length - 1);\n break;\n case 'ArrowUp':\n nextIndex = Math.max(index - 1, 0);\n break;\n case 'Home':\n nextIndex = 0;\n break;\n default:\n nextIndex = rows.length - 1;\n }\n\n event.preventDefault();\n rows[nextIndex]?.focus();\n}\n\n/**\n * A compact list of conversations for a sidebar. It owns arrow-key focus\n * movement and its loading, empty, and error presentation; hosts own data,\n * selection, routing, pagination, and mutations.\n */\nexport function ChatConversationList({\n 'aria-label': ariaLabel,\n children,\n className,\n loading = false,\n errorContent,\n footer,\n}: ChatConversationListProps) {\n const hasError = errorContent != null && errorContent !== false;\n\n return (\n <div className={cn('min-w-0 p-space-2', className)}>\n {hasError && (\n <div role=\"alert\" className=\"p-space-3 text-error-secondary\">\n {errorContent}\n </div>\n )}\n {loading ? (\n <div role=\"status\">\n <span className=\"sr-only\">Loading {ariaLabel}</span>\n <div aria-hidden className=\"flex flex-col gap-space-1\">\n {Array.from({ length: 6 }, (_, index) => (\n <div\n key={index}\n className=\"flex items-center rounded-lg px-space-3 py-space-2\"\n >\n <Skeleton className=\"h-4 w-3/5 motion-reduce:animate-none\" />\n </div>\n ))}\n </div>\n </div>\n ) : !hasContent(children) ? (\n !hasError && (\n <div role=\"status\" className=\"p-space-8 text-center text-tertiary\">\n <Text variant=\"sm\">No conversations yet</Text>\n </div>\n )\n ) : (\n <>\n <div\n role=\"list\"\n aria-label={ariaLabel}\n data-conversation-list=\"\"\n className=\"flex min-w-0 flex-col gap-space-1\"\n onKeyDown={handleNavigation}\n >\n {children}\n </div>\n {footer}\n </>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;AA2BA,IAAM,kCAAkB,IAAI,IAAI;CAAC;CAAa;CAAW;CAAQ;AAAK,CAAC;;AAGvE,SAAS,iBAAiB,OAAsC;CAC9D,MAAM,OAAO,MAAM;CACnB,MAAM,SAAS,MAAM;CACrB,IACE,CAAC,gBAAgB,IAAI,MAAM,GAAG,KAC9B,MAAM,oBACN,MAAM,UACN,MAAM,WACN,MAAM,WACN,MAAM,YACN,EAAE,kBAAkB,sBACpB,CAAC,OAAO,QAAQ,6BAA6B,GAE7C;CAKF,MAAM,OAAO,MAAM,KACjB,KAAK,iBACH,4CACF,CACF,CAAC,CAAC,QAAQ,QAAQ,IAAI,QAAQ,0BAA0B,MAAM,IAAI;CAClE,MAAM,QAAQ,KAAK,QAAQ,MAAM;CACjC,IAAI,UAAU,IAAI;CAElB,IAAI;CACJ,QAAQ,MAAM,KAAd;EACE,KAAK;GACH,YAAY,KAAK,IAAI,QAAQ,GAAG,KAAK,SAAS,CAAC;GAC/C;EACF,KAAK;GACH,YAAY,KAAK,IAAI,QAAQ,GAAG,CAAC;GACjC;EACF,KAAK;GACH,YAAY;GACZ;EACF,SACE,YAAY,KAAK,SAAS;CAC9B;CAEA,MAAM,eAAe;CACrB,KAAK,UAAU,EAAE,MAAM;AACzB;;;;;;AAOA,SAAgB,qBAAqB,EACnC,cAAc,WACd,UACA,WACA,UAAU,OACV,cACA,UAC4B;CAC5B,MAAM,WAAW,gBAAgB,QAAQ,iBAAiB;CAE1D,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,qBAAqB,SAAS;EAAjD,UAAA,CACG,YACC,oBAAC,OAAD;GAAK,MAAK;GAAQ,WAAU;GACzB,UAAA;EACE,CAAA,GAEN,UACC,qBAAC,OAAD;GAAK,MAAK;GAAV,UAAA,CACE,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CAA0B,YAAS,SAAgB;GACnD,CAAA,GAAA,oBAAC,OAAD;IAAK,eAAA;IAAY,WAAU;IACxB,UAAA,MAAM,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,UAC7B,oBAAC,OAAD;KAEE,WAAU;KAEV,UAAA,oBAAC,UAAD,EAAU,WAAU,uCAAwC,CAAA;IACzD,GAJE,KAIF,CACN;GACE,CAAA,CACF;EACH,CAAA,IAAA,CAAC,WAAW,QAAQ,IACtB,CAAC,YACC,oBAAC,OAAD;GAAK,MAAK;GAAS,WAAU;GAC3B,UAAA,oBAAC,MAAD;IAAM,SAAQ;IAAK,UAAA;GAA0B,CAAA;EAC1C,CAAA,IAGP,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;GACE,MAAK;GACL,cAAY;GACZ,0BAAuB;GACvB,WAAU;GACV,WAAW;GAEV;EACE,CAAA,GACJ,MACD,EAAA,CAAA,CAED;;AAET"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { IconComponent } from '../../utils/icon-types.js';
|
|
3
|
+
interface ChatConversationListActionsProps {
|
|
4
|
+
title: string;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The three-dot menu for a row. It sits over the row's trailing slot and
|
|
10
|
+
* appears on hover or keyboard focus; on touch it stays visible in the flow.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ChatConversationListActions({ title, disabled, children, }: ChatConversationListActionsProps): import("react").JSX.Element;
|
|
13
|
+
interface ChatConversationListActionItemProps {
|
|
14
|
+
icon: IconComponent;
|
|
15
|
+
label: string;
|
|
16
|
+
/** Missing callbacks disable the item. */
|
|
17
|
+
onSelect?: () => void;
|
|
18
|
+
destructive?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** One of the default Rename, Pin, or Delete entries. */
|
|
21
|
+
export declare function ChatConversationListActionItem({ icon: Icon, label, onSelect, destructive, }: ChatConversationListActionItemProps): import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../DropdownMenu/DropdownMenu.js";
|
|
3
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { DotsThreeIcon } from "@phosphor-icons/react/dist/ssr/DotsThree";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region packages/components/src/components/ChatConversationList/ChatConversationListActions.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The three-dot menu for a row. It sits over the row's trailing slot and
|
|
10
|
+
* appears on hover or keyboard focus; on touch it stays visible in the flow.
|
|
11
|
+
*/
|
|
12
|
+
function ChatConversationListActions({ title, disabled, children }) {
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
if (disabled && open) setOpen(false);
|
|
15
|
+
return /* @__PURE__ */ jsx("div", {
|
|
16
|
+
className: cn("pointer-events-none absolute inset-y-0 right-0 mr-space-3 flex shrink-0 items-center border-2 border-transparent opacity-0 group-focus-within/conversation:opacity-100 group-hover/conversation:opacity-100 [@media(hover:none)]:static [@media(hover:none)]:opacity-100", open && "opacity-100"),
|
|
17
|
+
children: /* @__PURE__ */ jsxs(DropdownMenu, {
|
|
18
|
+
open,
|
|
19
|
+
onOpenChange: setOpen,
|
|
20
|
+
children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
|
|
21
|
+
asChild: true,
|
|
22
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
23
|
+
"data-conversation-actions": "",
|
|
24
|
+
icon: DotsThreeIcon,
|
|
25
|
+
iconWeight: "regular",
|
|
26
|
+
label: `Actions for ${title}`,
|
|
27
|
+
size: "xs",
|
|
28
|
+
variant: "plain",
|
|
29
|
+
color: "secondary",
|
|
30
|
+
disabled,
|
|
31
|
+
className: cn("pointer-events-none cursor-pointer transition-none disabled:cursor-not-allowed group-focus-within/conversation:pointer-events-auto group-hover/conversation:pointer-events-auto [@media(hover:none)]:pointer-events-auto", open && "pointer-events-auto"),
|
|
32
|
+
tooltipProps: { disabled: true },
|
|
33
|
+
onClick: (event) => event.stopPropagation()
|
|
34
|
+
})
|
|
35
|
+
}), /* @__PURE__ */ jsx(DropdownMenuContent, {
|
|
36
|
+
align: "end",
|
|
37
|
+
preventClickThrough: true,
|
|
38
|
+
onClick: (event) => event.stopPropagation(),
|
|
39
|
+
children
|
|
40
|
+
})]
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** One of the default Rename, Pin, or Delete entries. */
|
|
45
|
+
function ChatConversationListActionItem({ icon: Icon, label, onSelect, destructive = false }) {
|
|
46
|
+
return /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
47
|
+
size: "sm",
|
|
48
|
+
className: cn("gap-space-2", destructive && "text-error-secondary"),
|
|
49
|
+
disabled: !onSelect,
|
|
50
|
+
onSelect,
|
|
51
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
52
|
+
size: 16,
|
|
53
|
+
weight: "regular",
|
|
54
|
+
"aria-hidden": true
|
|
55
|
+
}), label]
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { ChatConversationListActionItem, ChatConversationListActions };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=ChatConversationListActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatConversationListActions.js","names":[],"sources":["../../../src/components/ChatConversationList/ChatConversationListActions.tsx"],"sourcesContent":["import { type ReactNode, useState } from 'react';\n\nimport { DotsThreeIcon } from '@phosphor-icons/react/dist/ssr/DotsThree';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent } from '../../utils/icon-types';\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from '../DropdownMenu';\nimport { IconButton } from '../IconButton';\n\ninterface ChatConversationListActionsProps {\n title: string;\n disabled: boolean;\n children: ReactNode;\n}\n\n/**\n * The three-dot menu for a row. It sits over the row's trailing slot and\n * appears on hover or keyboard focus; on touch it stays visible in the flow.\n */\nexport function ChatConversationListActions({\n title,\n disabled,\n children,\n}: ChatConversationListActionsProps) {\n const [open, setOpen] = useState(false);\n // Closes the menu when the row becomes disabled, so it can't reopen on its\n // own once the row is enabled again.\n if (disabled && open) setOpen(false);\n\n return (\n <div\n className={cn(\n 'pointer-events-none absolute inset-y-0 right-0 mr-space-3 flex shrink-0 items-center border-2 border-transparent opacity-0 group-focus-within/conversation:opacity-100 group-hover/conversation:opacity-100 [@media(hover:none)]:static [@media(hover:none)]:opacity-100',\n open && 'opacity-100'\n )}\n >\n <DropdownMenu open={open} onOpenChange={setOpen}>\n <DropdownMenuTrigger asChild>\n <IconButton\n // Lets the row's indicator hide while the menu is open, which\n // Radix marks with data-state=\"open\" on this trigger.\n data-conversation-actions=\"\"\n icon={DotsThreeIcon}\n iconWeight=\"regular\"\n label={`Actions for ${title}`}\n size=\"xs\"\n variant=\"plain\"\n color=\"secondary\"\n disabled={disabled}\n className={cn(\n 'pointer-events-none cursor-pointer transition-none disabled:cursor-not-allowed group-focus-within/conversation:pointer-events-auto group-hover/conversation:pointer-events-auto [@media(hover:none)]:pointer-events-auto',\n open && 'pointer-events-auto'\n )}\n tooltipProps={{ disabled: true }}\n // Keeps the click from reaching host handlers around the list.\n onClick={(event) => event.stopPropagation()}\n />\n </DropdownMenuTrigger>\n <DropdownMenuContent\n align=\"end\"\n preventClickThrough\n // The menu portals out, but React still bubbles its clicks through\n // the row to host handlers.\n onClick={(event) => event.stopPropagation()}\n >\n {children}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n );\n}\n\ninterface ChatConversationListActionItemProps {\n icon: IconComponent;\n label: string;\n /** Missing callbacks disable the item. */\n onSelect?: () => void;\n destructive?: boolean;\n}\n\n/** One of the default Rename, Pin, or Delete entries. */\nexport function ChatConversationListActionItem({\n icon: Icon,\n label,\n onSelect,\n destructive = false,\n}: ChatConversationListActionItemProps) {\n return (\n <DropdownMenuItem\n size=\"sm\"\n className={cn('gap-space-2', destructive && 'text-error-secondary')}\n disabled={!onSelect}\n onSelect={onSelect}\n >\n <Icon size={16} weight=\"regular\" aria-hidden />\n {label}\n </DropdownMenuItem>\n );\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,4BAA4B,EAC1C,OACA,UACA,YACmC;CACnC,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAGtC,IAAI,YAAY,MAAM,QAAQ,KAAK;CAEnC,OACE,oBAAC,OAAD;EACE,WAAW,GACT,4QACA,QAAQ,aACV;EAEA,UAAA,qBAAC,cAAD;GAAoB;GAAM,cAAc;GAAxC,UAAA,CACE,oBAAC,qBAAD;IAAqB,SAAA;IACnB,UAAA,oBAAC,YAAD;KAGE,6BAA0B;KAC1B,MAAM;KACN,YAAW;KACX,OAAO,eAAe;KACtB,MAAK;KACL,SAAQ;KACR,OAAM;KACI;KACV,WAAW,GACT,4NACA,QAAQ,qBACV;KACA,cAAc,EAAE,UAAU,KAAK;KAE/B,UAAU,UAAU,MAAM,gBAAgB;IAC3C,CAAA;GACkB,CAAA,GACrB,oBAAC,qBAAD;IACE,OAAM;IACN,qBAAA;IAGA,UAAU,UAAU,MAAM,gBAAgB;IAEzC;GACkB,CAAA,CACT;;CACX,CAAA;AAET;;AAWA,SAAgB,+BAA+B,EAC7C,MAAM,MACN,OACA,UACA,cAAc,SACwB;CACtC,OACE,qBAAC,kBAAD;EACE,MAAK;EACL,WAAW,GAAG,eAAe,eAAe,sBAAsB;EAClE,UAAU,CAAC;EACD;EAJZ,UAAA,CAME,oBAAC,MAAD;GAAM,MAAM;GAAI,QAAO;GAAU,eAAA;EAAa,CAAA,GAC7C,KACe;;AAEtB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface ChatConversationListGroupActions {
|
|
3
|
+
/**
|
|
4
|
+
* Hosts own rename and delete dialogs, confirmation, and persistence.
|
|
5
|
+
* Missing callbacks disable their menu items.
|
|
6
|
+
*/
|
|
7
|
+
onRename?: () => void;
|
|
8
|
+
onDelete?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export interface ChatConversationListGroupProps {
|
|
11
|
+
title: string;
|
|
12
|
+
/** `ChatConversationListItem`s. Groups can't be nested. */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
actions?: ChatConversationListGroupActions;
|
|
15
|
+
/** Controls expansion when provided; otherwise the group manages it. */
|
|
16
|
+
open?: boolean;
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
onOpenChange?: (open: boolean) => void;
|
|
19
|
+
/** Disables the toggle and menu. Children keep their own disabled state. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A collapsible folder of conversations, one level deep. Its items join the
|
|
25
|
+
* list's arrow-key navigation while it's open.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ChatConversationListGroup({ title, children, actions, open: openProp, defaultOpen, onOpenChange, disabled, className, }: ChatConversationListGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { Text } from "../Text/Text.js";
|
|
3
|
+
import { DropdownMenuSeparator } from "../DropdownMenu/DropdownMenu.js";
|
|
4
|
+
import { ChatConversationListActionItem, ChatConversationListActions } from "./ChatConversationListActions.js";
|
|
5
|
+
import { createContext, useContext, useEffect, useId } from "react";
|
|
6
|
+
import { CaretRightIcon } from "@phosphor-icons/react/dist/ssr/CaretRight";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
9
|
+
import { PencilSimpleIcon } from "@phosphor-icons/react/dist/ssr/PencilSimple";
|
|
10
|
+
import { TrashIcon } from "@phosphor-icons/react/dist/ssr/Trash";
|
|
11
|
+
//#region packages/components/src/components/ChatConversationList/ChatConversationListGroup.tsx
|
|
12
|
+
var InsideGroupContext = createContext(false);
|
|
13
|
+
/**
|
|
14
|
+
* A collapsible folder of conversations, one level deep. Its items join the
|
|
15
|
+
* list's arrow-key navigation while it's open.
|
|
16
|
+
*/
|
|
17
|
+
function ChatConversationListGroup({ title, children, actions, open: openProp, defaultOpen = false, onOpenChange, disabled = false, className }) {
|
|
18
|
+
const nested = useContext(InsideGroupContext);
|
|
19
|
+
const contentId = useId();
|
|
20
|
+
const [open = false, setOpen] = useControllableState({
|
|
21
|
+
prop: openProp,
|
|
22
|
+
defaultProp: defaultOpen,
|
|
23
|
+
onChange: onOpenChange
|
|
24
|
+
});
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (nested) console.error("ChatConversationListGroup cannot be nested. Render groups as siblings in ChatConversationList.");
|
|
27
|
+
}, [nested]);
|
|
28
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
29
|
+
role: "listitem",
|
|
30
|
+
className: cn("min-w-0", className),
|
|
31
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
32
|
+
className: "group/conversation relative flex min-w-0 items-center rounded-lg hover:bg-surface-level-1-hover",
|
|
33
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
34
|
+
type: "button",
|
|
35
|
+
"data-conversation-trigger": "",
|
|
36
|
+
"aria-expanded": open,
|
|
37
|
+
"aria-controls": open ? contentId : void 0,
|
|
38
|
+
disabled,
|
|
39
|
+
onClick: () => setOpen(!open),
|
|
40
|
+
className: "flex min-w-0 flex-1 cursor-pointer items-center gap-space-2 rounded-md border-2 border-transparent bg-transparent px-space-3 py-space-2 text-left outline-hidden focus-visible:border-focus disabled:cursor-not-allowed disabled:opacity-50",
|
|
41
|
+
children: [
|
|
42
|
+
/* @__PURE__ */ jsx("span", {
|
|
43
|
+
className: "flex size-4 shrink-0 items-center justify-center",
|
|
44
|
+
children: /* @__PURE__ */ jsx(CaretRightIcon, {
|
|
45
|
+
size: 12,
|
|
46
|
+
weight: "regular",
|
|
47
|
+
"aria-hidden": true,
|
|
48
|
+
className: cn("text-icon-secondary transition-transform duration-normal motion-reduce:transition-none", open && "rotate-90")
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ jsx(Text, {
|
|
52
|
+
as: "span",
|
|
53
|
+
variant: "sm",
|
|
54
|
+
weight: "medium",
|
|
55
|
+
className: "min-w-0 flex-1 truncate",
|
|
56
|
+
children: title
|
|
57
|
+
}),
|
|
58
|
+
actions && /* @__PURE__ */ jsx("span", {
|
|
59
|
+
"aria-hidden": true,
|
|
60
|
+
className: "w-5 shrink-0 [@media(hover:none)]:hidden"
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
}), actions && /* @__PURE__ */ jsxs(ChatConversationListActions, {
|
|
64
|
+
title,
|
|
65
|
+
disabled,
|
|
66
|
+
children: [
|
|
67
|
+
/* @__PURE__ */ jsx(ChatConversationListActionItem, {
|
|
68
|
+
icon: PencilSimpleIcon,
|
|
69
|
+
label: "Rename",
|
|
70
|
+
onSelect: actions.onRename
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
73
|
+
/* @__PURE__ */ jsx(ChatConversationListActionItem, {
|
|
74
|
+
icon: TrashIcon,
|
|
75
|
+
label: "Delete",
|
|
76
|
+
onSelect: actions.onDelete,
|
|
77
|
+
destructive: true
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
})]
|
|
81
|
+
}), open && /* @__PURE__ */ jsx("div", {
|
|
82
|
+
id: contentId,
|
|
83
|
+
role: "list",
|
|
84
|
+
"aria-label": title,
|
|
85
|
+
className: "flex min-w-0 flex-col gap-space-1 pl-space-5 pt-space-1",
|
|
86
|
+
children: /* @__PURE__ */ jsx(InsideGroupContext.Provider, {
|
|
87
|
+
value: true,
|
|
88
|
+
children
|
|
89
|
+
})
|
|
90
|
+
})]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { ChatConversationListGroup };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=ChatConversationListGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatConversationListGroup.js","names":[],"sources":["../../../src/components/ChatConversationList/ChatConversationListGroup.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n useContext,\n useEffect,\n useId,\n} from 'react';\n\nimport { CaretRightIcon } from '@phosphor-icons/react/dist/ssr/CaretRight';\nimport { PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';\nimport { TrashIcon } from '@phosphor-icons/react/dist/ssr/Trash';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\n\nimport { cn } from '../../utils/cn';\nimport { DropdownMenuSeparator } from '../DropdownMenu';\nimport { Text } from '../Text';\nimport {\n ChatConversationListActionItem,\n ChatConversationListActions,\n} from './ChatConversationListActions';\n\nconst InsideGroupContext = createContext(false);\n\nexport interface ChatConversationListGroupActions {\n /**\n * Hosts own rename and delete dialogs, confirmation, and persistence.\n * Missing callbacks disable their menu items.\n */\n onRename?: () => void;\n onDelete?: () => void;\n}\n\nexport interface ChatConversationListGroupProps {\n title: string;\n /** `ChatConversationListItem`s. Groups can't be nested. */\n children?: ReactNode;\n actions?: ChatConversationListGroupActions;\n /** Controls expansion when provided; otherwise the group manages it. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n /** Disables the toggle and menu. Children keep their own disabled state. */\n disabled?: boolean;\n className?: string;\n}\n\n/**\n * A collapsible folder of conversations, one level deep. Its items join the\n * list's arrow-key navigation while it's open.\n */\nexport function ChatConversationListGroup({\n title,\n children,\n actions,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n disabled = false,\n className,\n}: ChatConversationListGroupProps) {\n const nested = useContext(InsideGroupContext);\n const contentId = useId();\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n useEffect(() => {\n if (nested) {\n console.error(\n 'ChatConversationListGroup cannot be nested. Render groups as siblings in ChatConversationList.'\n );\n }\n }, [nested]);\n\n return (\n <div role=\"listitem\" className={cn('min-w-0', className)}>\n <div className=\"group/conversation relative flex min-w-0 items-center rounded-lg hover:bg-surface-level-1-hover\">\n <button\n type=\"button\"\n data-conversation-trigger=\"\"\n aria-expanded={open}\n aria-controls={open ? contentId : undefined}\n disabled={disabled}\n onClick={() => setOpen(!open)}\n className=\"flex min-w-0 flex-1 cursor-pointer items-center gap-space-2 rounded-md border-2 border-transparent bg-transparent px-space-3 py-space-2 text-left outline-hidden focus-visible:border-focus disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <span className=\"flex size-4 shrink-0 items-center justify-center\">\n <CaretRightIcon\n size={12}\n weight=\"regular\"\n aria-hidden\n className={cn(\n 'text-icon-secondary transition-transform duration-normal motion-reduce:transition-none',\n open && 'rotate-90'\n )}\n />\n </span>\n <Text\n as=\"span\"\n variant=\"sm\"\n weight=\"medium\"\n className=\"min-w-0 flex-1 truncate\"\n >\n {title}\n </Text>\n {/* Reserves room for the actions button, which sits over the row. */}\n {actions && (\n <span\n aria-hidden\n className=\"w-5 shrink-0 [@media(hover:none)]:hidden\"\n />\n )}\n </button>\n {actions && (\n <ChatConversationListActions title={title} disabled={disabled}>\n <ChatConversationListActionItem\n icon={PencilSimpleIcon}\n label=\"Rename\"\n onSelect={actions.onRename}\n />\n <DropdownMenuSeparator />\n <ChatConversationListActionItem\n icon={TrashIcon}\n label=\"Delete\"\n onSelect={actions.onDelete}\n destructive\n />\n </ChatConversationListActions>\n )}\n </div>\n {/* Unmounted while closed, so arrow keys skip its items. */}\n {open && (\n <div\n id={contentId}\n role=\"list\"\n aria-label={title}\n className=\"flex min-w-0 flex-col gap-space-1 pl-space-5 pt-space-1\"\n >\n <InsideGroupContext.Provider value={true}>\n {children}\n </InsideGroupContext.Provider>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAM,qBAAqB,cAAc,KAAK;;;;;AA6B9C,SAAgB,0BAA0B,EACxC,OACA,UACA,SACA,MAAM,UACN,cAAc,OACd,cACA,WAAW,OACX,aACiC;CACjC,MAAM,SAAS,WAAW,kBAAkB;CAC5C,MAAM,YAAY,MAAM;CACxB,MAAM,CAAC,OAAO,OAAO,WAAW,qBAAqB;EACnD,MAAM;EACN,aAAa;EACb,UAAU;CACZ,CAAC;CAED,gBAAgB;EACd,IAAI,QACF,QAAQ,MACN,gGACF;CAEJ,GAAG,CAAC,MAAM,CAAC;CAEX,OACE,qBAAC,OAAD;EAAK,MAAK;EAAW,WAAW,GAAG,WAAW,SAAS;EAAvD,UAAA,CACE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,qBAAC,UAAD;IACE,MAAK;IACL,6BAA0B;IAC1B,iBAAe;IACf,iBAAe,OAAO,YAAY,KAAA;IACxB;IACV,eAAe,QAAQ,CAAC,IAAI;IAC5B,WAAU;IAPZ,UAAA;KASE,oBAAC,QAAD;MAAM,WAAU;MACd,UAAA,oBAAC,gBAAD;OACE,MAAM;OACN,QAAO;OACP,eAAA;OACA,WAAW,GACT,0FACA,QAAQ,WACV;MACD,CAAA;KACG,CAAA;KACN,oBAAC,MAAD;MACE,IAAG;MACH,SAAQ;MACR,QAAO;MACP,WAAU;MAET,UAAA;KACG,CAAA;KAEL,WACC,oBAAC,QAAD;MACE,eAAA;MACA,WAAU;KACX,CAAA;IAEG;GACP,CAAA,GAAA,WACC,qBAAC,6BAAD;IAAoC;IAAiB;IAArD,UAAA;KACE,oBAAC,gCAAD;MACE,MAAM;MACN,OAAM;MACN,UAAU,QAAQ;KACnB,CAAA;KACD,oBAAC,uBAAD,CAAwB,CAAA;KACxB,oBAAC,gCAAD;MACE,MAAM;MACN,OAAM;MACN,UAAU,QAAQ;MAClB,aAAA;KACD,CAAA;IAC0B;GAE5B,CAAA,CAAA;EAEJ,CAAA,GAAA,QACC,oBAAC,OAAD;GACE,IAAI;GACJ,MAAK;GACL,cAAY;GACZ,WAAU;GAEV,UAAA,oBAAC,mBAAmB,UAApB;IAA6B,OAAO;IACjC;GAC0B,CAAA;EAC1B,CAAA,CAEJ;;AAET"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ReactNode } from 'react';
|
|
2
|
+
export interface ChatConversationListItemActions {
|
|
3
|
+
/**
|
|
4
|
+
* Hosts own dialogs, confirmation, persistence, and mutation errors. Missing
|
|
5
|
+
* callbacks disable their menu items.
|
|
6
|
+
*/
|
|
7
|
+
onRename?: () => void;
|
|
8
|
+
onTogglePin?: () => void;
|
|
9
|
+
onDelete?: () => void;
|
|
10
|
+
/** Labels the pin item Unpin. */
|
|
11
|
+
pinned?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Replaces the default Rename, Pin/Unpin, and Delete items. Compose
|
|
14
|
+
* `DropdownMenuItem` and related primitives.
|
|
15
|
+
*/
|
|
16
|
+
items?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Native button props and the ref target the conversation button, so hosts
|
|
20
|
+
* can compose it with triggers such as `Tooltip`.
|
|
21
|
+
*/
|
|
22
|
+
export interface ChatConversationListItemProps extends Omit<ComponentPropsWithRef<'button'>, 'children' | 'title' | 'type' | 'dangerouslySetInnerHTML' | 'aria-label' | 'aria-current'> {
|
|
23
|
+
/** Full title, used for the accessible name. */
|
|
24
|
+
title: string;
|
|
25
|
+
/** Replaces the visible title. Must be non-interactive; put controls in `actions`. */
|
|
26
|
+
titleContent?: ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* Non-interactive trailing indicator with its own accessible text, such as a
|
|
29
|
+
* spinner or attention icon. Takes the unread dot's place.
|
|
30
|
+
*/
|
|
31
|
+
indicator?: ReactNode;
|
|
32
|
+
/** Reveals a three-dot menu over the indicator on hover or keyboard focus. */
|
|
33
|
+
actions?: ChatConversationListItemActions;
|
|
34
|
+
selected?: boolean;
|
|
35
|
+
unread?: boolean;
|
|
36
|
+
/** Styles the outer row; other native props target the conversation button. */
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
/** One conversation row in a `ChatConversationList` or `ChatConversationListGroup`. */
|
|
40
|
+
export declare function ChatConversationListItem({ title, titleContent, indicator, actions, selected, unread, disabled, className, 'aria-describedby': ariaDescribedBy, ...buttonProps }: ChatConversationListItemProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { Text } from "../Text/Text.js";
|
|
3
|
+
import { DropdownMenuSeparator } from "../DropdownMenu/DropdownMenu.js";
|
|
4
|
+
import { ChatConversationListActionItem, ChatConversationListActions } from "./ChatConversationListActions.js";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { PencilSimpleIcon } from "@phosphor-icons/react/dist/ssr/PencilSimple";
|
|
8
|
+
import { TrashIcon } from "@phosphor-icons/react/dist/ssr/Trash";
|
|
9
|
+
import { PushPinIcon } from "@phosphor-icons/react/dist/ssr/PushPin";
|
|
10
|
+
//#region packages/components/src/components/ChatConversationList/ChatConversationListItem.tsx
|
|
11
|
+
/** One conversation row in a `ChatConversationList` or `ChatConversationListGroup`. */
|
|
12
|
+
function ChatConversationListItem({ title, titleContent, indicator, actions, selected = false, unread = false, disabled = false, className, "aria-describedby": ariaDescribedBy, ...buttonProps }) {
|
|
13
|
+
const unreadId = useId();
|
|
14
|
+
const indicatorId = useId();
|
|
15
|
+
const hasIndicator = indicator != null && indicator !== false;
|
|
16
|
+
const describedBy = [
|
|
17
|
+
ariaDescribedBy,
|
|
18
|
+
unread ? unreadId : void 0,
|
|
19
|
+
hasIndicator ? indicatorId : void 0
|
|
20
|
+
].filter(Boolean).join(" ") || void 0;
|
|
21
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
22
|
+
role: "listitem",
|
|
23
|
+
className: cn("group/conversation relative flex min-w-0 items-center rounded-lg", selected ? "bg-selected hover:bg-selected-hover" : "hover:bg-surface-level-1-hover", className),
|
|
24
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
25
|
+
...buttonProps,
|
|
26
|
+
type: "button",
|
|
27
|
+
"data-conversation-trigger": "",
|
|
28
|
+
"aria-label": title,
|
|
29
|
+
"aria-current": selected ? "true" : void 0,
|
|
30
|
+
"aria-describedby": describedBy,
|
|
31
|
+
disabled,
|
|
32
|
+
className: "flex min-w-0 flex-1 cursor-pointer items-center gap-space-2 rounded-md border-2 border-transparent bg-transparent px-space-3 py-space-2 text-left outline-hidden focus-visible:border-focus disabled:cursor-not-allowed disabled:opacity-50",
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ jsx(Text, {
|
|
35
|
+
as: "span",
|
|
36
|
+
variant: "sm",
|
|
37
|
+
weight: unread ? "medium" : "normal",
|
|
38
|
+
className: "min-w-0 flex-1 truncate",
|
|
39
|
+
children: titleContent ?? title
|
|
40
|
+
}),
|
|
41
|
+
(hasIndicator || unread || actions) && /* @__PURE__ */ jsx("span", {
|
|
42
|
+
id: hasIndicator ? indicatorId : void 0,
|
|
43
|
+
className: cn("flex min-w-5 max-w-[40%] shrink-0 items-center justify-center overflow-hidden", actions && "[@media(hover:hover)]:group-focus-within/conversation:opacity-0 [@media(hover:hover)]:group-hover/conversation:opacity-0 [@media(hover:hover)]:group-has-[[data-conversation-actions][data-state=open]]/conversation:opacity-0", !hasIndicator && !unread && "[@media(hover:none)]:hidden"),
|
|
44
|
+
children: hasIndicator ? indicator : unread ? /* @__PURE__ */ jsx("span", {
|
|
45
|
+
"aria-hidden": true,
|
|
46
|
+
className: "size-1 shrink-0 rounded-full bg-brand"
|
|
47
|
+
}) : null
|
|
48
|
+
}),
|
|
49
|
+
unread && /* @__PURE__ */ jsx("span", {
|
|
50
|
+
id: unreadId,
|
|
51
|
+
className: "sr-only",
|
|
52
|
+
children: "Unread"
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
}), actions && /* @__PURE__ */ jsx(ChatConversationListActions, {
|
|
56
|
+
title,
|
|
57
|
+
disabled,
|
|
58
|
+
children: actions.items ?? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
59
|
+
/* @__PURE__ */ jsx(ChatConversationListActionItem, {
|
|
60
|
+
icon: PencilSimpleIcon,
|
|
61
|
+
label: "Rename",
|
|
62
|
+
onSelect: actions.onRename
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ jsx(ChatConversationListActionItem, {
|
|
65
|
+
icon: PushPinIcon,
|
|
66
|
+
label: actions.pinned ? "Unpin" : "Pin",
|
|
67
|
+
onSelect: actions.onTogglePin
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
70
|
+
/* @__PURE__ */ jsx(ChatConversationListActionItem, {
|
|
71
|
+
icon: TrashIcon,
|
|
72
|
+
label: "Delete",
|
|
73
|
+
onSelect: actions.onDelete,
|
|
74
|
+
destructive: true
|
|
75
|
+
})
|
|
76
|
+
] })
|
|
77
|
+
})]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { ChatConversationListItem };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=ChatConversationListItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatConversationListItem.js","names":[],"sources":["../../../src/components/ChatConversationList/ChatConversationListItem.tsx"],"sourcesContent":["import { type ComponentPropsWithRef, type ReactNode, useId } from 'react';\n\nimport { PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';\nimport { PushPinIcon } from '@phosphor-icons/react/dist/ssr/PushPin';\nimport { TrashIcon } from '@phosphor-icons/react/dist/ssr/Trash';\n\nimport { cn } from '../../utils/cn';\nimport { DropdownMenuSeparator } from '../DropdownMenu';\nimport { Text } from '../Text';\nimport {\n ChatConversationListActionItem,\n ChatConversationListActions,\n} from './ChatConversationListActions';\n\nexport interface ChatConversationListItemActions {\n /**\n * Hosts own dialogs, confirmation, persistence, and mutation errors. Missing\n * callbacks disable their menu items.\n */\n onRename?: () => void;\n onTogglePin?: () => void;\n onDelete?: () => void;\n /** Labels the pin item Unpin. */\n pinned?: boolean;\n /**\n * Replaces the default Rename, Pin/Unpin, and Delete items. Compose\n * `DropdownMenuItem` and related primitives.\n */\n items?: ReactNode;\n}\n\n/**\n * Native button props and the ref target the conversation button, so hosts\n * can compose it with triggers such as `Tooltip`.\n */\nexport interface ChatConversationListItemProps extends Omit<\n ComponentPropsWithRef<'button'>,\n | 'children'\n | 'title'\n | 'type'\n | 'dangerouslySetInnerHTML'\n | 'aria-label'\n | 'aria-current'\n> {\n /** Full title, used for the accessible name. */\n title: string;\n /** Replaces the visible title. Must be non-interactive; put controls in `actions`. */\n titleContent?: ReactNode;\n /**\n * Non-interactive trailing indicator with its own accessible text, such as a\n * spinner or attention icon. Takes the unread dot's place.\n */\n indicator?: ReactNode;\n /** Reveals a three-dot menu over the indicator on hover or keyboard focus. */\n actions?: ChatConversationListItemActions;\n selected?: boolean;\n unread?: boolean;\n /** Styles the outer row; other native props target the conversation button. */\n className?: string;\n}\n\n/** One conversation row in a `ChatConversationList` or `ChatConversationListGroup`. */\nexport function ChatConversationListItem({\n title,\n titleContent,\n indicator,\n actions,\n selected = false,\n unread = false,\n disabled = false,\n className,\n 'aria-describedby': ariaDescribedBy,\n ...buttonProps\n}: ChatConversationListItemProps) {\n const unreadId = useId();\n const indicatorId = useId();\n const hasIndicator = indicator != null && indicator !== false;\n const describedBy =\n [\n ariaDescribedBy,\n unread ? unreadId : undefined,\n hasIndicator ? indicatorId : undefined,\n ]\n .filter(Boolean)\n .join(' ') || undefined;\n\n return (\n <div\n role=\"listitem\"\n className={cn(\n 'group/conversation relative flex min-w-0 items-center rounded-lg',\n selected\n ? 'bg-selected hover:bg-selected-hover'\n : 'hover:bg-surface-level-1-hover',\n className\n )}\n >\n {/* A native button, not Button: the row needs a flexible title and\n sibling actions rather than Button's control sizing. */}\n <button\n {...buttonProps}\n type=\"button\"\n data-conversation-trigger=\"\"\n aria-label={title}\n aria-current={selected ? 'true' : undefined}\n aria-describedby={describedBy}\n disabled={disabled}\n className=\"flex min-w-0 flex-1 cursor-pointer items-center gap-space-2 rounded-md border-2 border-transparent bg-transparent px-space-3 py-space-2 text-left outline-hidden focus-visible:border-focus disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <Text\n as=\"span\"\n variant=\"sm\"\n weight={unread ? 'medium' : 'normal'}\n className=\"min-w-0 flex-1 truncate\"\n >\n {titleContent ?? title}\n </Text>\n {/* The trailing slot also reserves room for the actions button, which\n covers it on hover, focus, or while its menu is open. On touch the\n actions sit in the flow instead, so an empty slot collapses. */}\n {(hasIndicator || unread || actions) && (\n <span\n id={hasIndicator ? indicatorId : undefined}\n className={cn(\n 'flex min-w-5 max-w-[40%] shrink-0 items-center justify-center overflow-hidden',\n actions &&\n '[@media(hover:hover)]:group-focus-within/conversation:opacity-0 [@media(hover:hover)]:group-hover/conversation:opacity-0 [@media(hover:hover)]:group-has-[[data-conversation-actions][data-state=open]]/conversation:opacity-0',\n !hasIndicator && !unread && '[@media(hover:none)]:hidden'\n )}\n >\n {hasIndicator ? (\n indicator\n ) : unread ? (\n <span\n aria-hidden\n className=\"size-1 shrink-0 rounded-full bg-brand\"\n />\n ) : null}\n </span>\n )}\n {unread && (\n <span id={unreadId} className=\"sr-only\">\n Unread\n </span>\n )}\n </button>\n {actions && (\n <ChatConversationListActions title={title} disabled={disabled}>\n {actions.items ?? (\n <>\n <ChatConversationListActionItem\n icon={PencilSimpleIcon}\n label=\"Rename\"\n onSelect={actions.onRename}\n />\n <ChatConversationListActionItem\n icon={PushPinIcon}\n label={actions.pinned ? 'Unpin' : 'Pin'}\n onSelect={actions.onTogglePin}\n />\n <DropdownMenuSeparator />\n <ChatConversationListActionItem\n icon={TrashIcon}\n label=\"Delete\"\n onSelect={actions.onDelete}\n destructive\n />\n </>\n )}\n </ChatConversationListActions>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AA8DA,SAAgB,yBAAyB,EACvC,OACA,cACA,WACA,SACA,WAAW,OACX,SAAS,OACT,WAAW,OACX,WACA,oBAAoB,iBACpB,GAAG,eAC6B;CAChC,MAAM,WAAW,MAAM;CACvB,MAAM,cAAc,MAAM;CAC1B,MAAM,eAAe,aAAa,QAAQ,cAAc;CACxD,MAAM,cACJ;EACE;EACA,SAAS,WAAW,KAAA;EACpB,eAAe,cAAc,KAAA;CAC/B,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;CAElB,OACE,qBAAC,OAAD;EACE,MAAK;EACL,WAAW,GACT,oEACA,WACI,wCACA,kCACJ,SACF;EARF,UAAA,CAYE,qBAAC,UAAD;GACE,GAAI;GACJ,MAAK;GACL,6BAA0B;GAC1B,cAAY;GACZ,gBAAc,WAAW,SAAS,KAAA;GAClC,oBAAkB;GACR;GACV,WAAU;GARZ,UAAA;IAUE,oBAAC,MAAD;KACE,IAAG;KACH,SAAQ;KACR,QAAQ,SAAS,WAAW;KAC5B,WAAU;KAET,UAAA,gBAAgB;IACb,CAAA;KAIJ,gBAAgB,UAAU,YAC1B,oBAAC,QAAD;KACE,IAAI,eAAe,cAAc,KAAA;KACjC,WAAW,GACT,iFACA,WACE,kOACF,CAAC,gBAAgB,CAAC,UAAU,6BAC9B;KAEC,UAAA,eACC,YACE,SACF,oBAAC,QAAD;MACE,eAAA;MACA,WAAU;KACX,CAAA,IACC;IACA,CAAA;IAEP,UACC,oBAAC,QAAD;KAAM,IAAI;KAAU,WAAU;KAAU,UAAA;IAElC,CAAA;GAEF;EACP,CAAA,GAAA,WACC,oBAAC,6BAAD;GAAoC;GAAiB;GAClD,UAAA,QAAQ,SACP,qBAAA,YAAA,EAAA,UAAA;IACE,oBAAC,gCAAD;KACE,MAAM;KACN,OAAM;KACN,UAAU,QAAQ;IACnB,CAAA;IACD,oBAAC,gCAAD;KACE,MAAM;KACN,OAAO,QAAQ,SAAS,UAAU;KAClC,UAAU,QAAQ;IACnB,CAAA;IACD,oBAAC,uBAAD,CAAwB,CAAA;IACxB,oBAAC,gCAAD;KACE,MAAM;KACN,OAAM;KACN,UAAU,QAAQ;KAClB,aAAA;IACD,CAAA;GACD,EAAA,CAAA;EAEuB,CAAA,CAE5B;;AAET"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ChatConversationList } from './ChatConversationList.js';
|
|
2
|
+
export type { ChatConversationListProps } from './ChatConversationList.js';
|
|
3
|
+
export { ChatConversationListGroup } from './ChatConversationListGroup.js';
|
|
4
|
+
export type { ChatConversationListGroupActions, ChatConversationListGroupProps, } from './ChatConversationListGroup.js';
|
|
5
|
+
export { ChatConversationListItem } from './ChatConversationListItem.js';
|
|
6
|
+
export type { ChatConversationListItemActions, ChatConversationListItemProps, } from './ChatConversationListItem.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ChatConversationList } from "./ChatConversationList.js";
|
|
2
|
+
import { ChatConversationListGroup } from "./ChatConversationListGroup.js";
|
|
3
|
+
import { ChatConversationListItem } from "./ChatConversationListItem.js";
|
|
4
|
+
export { ChatConversationList, ChatConversationListGroup, ChatConversationListItem };
|