From ec37d8f05e6995d9ea7c751cf2d2721f3471f776 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Sun, 24 Nov 2024 00:07:00 -0800 Subject: [PATCH] refactor: namespace TooltipIconButton.Props (#1210) --- .../primitives/threadList/ThreadListItems.tsx | 6 +++--- packages/react/src/ui/assistant-action-bar.tsx | 17 +++++++---------- packages/react/src/ui/assistant-modal.tsx | 9 +++------ packages/react/src/ui/attachment-ui.tsx | 7 ++----- packages/react/src/ui/base/index.ts | 5 +---- .../react/src/ui/base/tooltip-icon-button.tsx | 12 +++++++----- packages/react/src/ui/branch-picker.tsx | 9 +++------ packages/react/src/ui/composer.tsx | 11 ++++------- packages/react/src/ui/thread.tsx | 7 ++----- packages/react/src/ui/user-action-bar.tsx | 7 ++----- 10 files changed, 34 insertions(+), 56 deletions(-) diff --git a/packages/react/src/primitives/threadList/ThreadListItems.tsx b/packages/react/src/primitives/threadList/ThreadListItems.tsx index e8f265f0c2..f7f2fcd49b 100644 --- a/packages/react/src/primitives/threadList/ThreadListItems.tsx +++ b/packages/react/src/primitives/threadList/ThreadListItems.tsx @@ -4,7 +4,7 @@ import { ComponentType, FC, memo, useMemo } from "react"; import { ThreadListItemRuntimeProvider } from "../../context/providers/ThreadListItemRuntimeProvider"; import { useAssistantRuntime, useThreadList } from "../../context"; -export namespace MessagePrimitiveContent { +export namespace ThreadListPrimitiveItems { export type Props = { archived?: boolean | undefined; components: { @@ -16,7 +16,7 @@ export namespace MessagePrimitiveContent { type ThreadListItemProps = { partIndex: number; archived: boolean; - components: MessagePrimitiveContent.Props["components"]; + components: ThreadListPrimitiveItems.Props["components"]; }; const ThreadListItemImpl: FC = ({ @@ -52,7 +52,7 @@ const ThreadListItem = memo( prev.components.ThreadListItem === next.components.ThreadListItem, ); -export const ThreadListPrimitiveItems: FC = ({ +export const ThreadListPrimitiveItems: FC = ({ archived = false, components, }) => { diff --git a/packages/react/src/ui/assistant-action-bar.tsx b/packages/react/src/ui/assistant-action-bar.tsx index 78287809f3..3fd395e535 100644 --- a/packages/react/src/ui/assistant-action-bar.tsx +++ b/packages/react/src/ui/assistant-action-bar.tsx @@ -11,10 +11,7 @@ import { ThumbsUpIcon, } from "lucide-react"; import { ActionBarPrimitive, MessagePrimitive } from "../primitives"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import { withDefaults } from "./utils/withDefaults"; import { useThreadConfig } from "./thread-config"; import { useThread } from "../context"; @@ -91,7 +88,7 @@ AssistantActionBarRoot.displayName = "AssistantActionBarRoot"; namespace AssistantActionBarCopy { export type Element = ActionBarPrimitive.Copy.Element; - export type Props = Partial & { + export type Props = Partial & { copiedDuration?: number | undefined; }; } @@ -141,7 +138,7 @@ const AssistantActionBarSpeechControl: FC = () => { namespace AssistantActionBarSpeak { export type Element = ActionBarPrimitive.Speak.Element; - export type Props = Partial; + export type Props = Partial; } const AssistantActionBarSpeak = forwardRef< @@ -168,7 +165,7 @@ AssistantActionBarSpeak.displayName = "AssistantActionBarSpeak"; namespace AssistantActionBarStopSpeaking { export type Element = ActionBarPrimitive.StopSpeaking.Element; - export type Props = Partial; + export type Props = Partial; } const AssistantActionBarStopSpeaking = forwardRef< @@ -197,7 +194,7 @@ AssistantActionBarStopSpeaking.displayName = "AssistantActionBarStopSpeaking"; namespace AssistantActionBarReload { export type Element = ActionBarPrimitive.Reload.Element; - export type Props = Partial; + export type Props = Partial; } const AssistantActionBarReload = forwardRef< @@ -223,7 +220,7 @@ AssistantActionBarReload.displayName = "AssistantActionBarReload"; namespace AssistantActionBarFeedbackPositive { export type Element = ActionBarPrimitive.FeedbackPositive.Element; - export type Props = Partial; + export type Props = Partial; } const AssistantActionBarFeedbackPositive = forwardRef< @@ -256,7 +253,7 @@ AssistantActionBarFeedbackPositive.displayName = namespace AssistantActionBarFeedbackNegative { export type Element = ActionBarPrimitive.FeedbackNegative.Element; - export type Props = Partial; + export type Props = Partial; } const AssistantActionBarFeedbackNegative = forwardRef< diff --git a/packages/react/src/ui/assistant-modal.tsx b/packages/react/src/ui/assistant-modal.tsx index c8e12f4f48..983637e9df 100644 --- a/packages/react/src/ui/assistant-modal.tsx +++ b/packages/react/src/ui/assistant-modal.tsx @@ -6,10 +6,7 @@ import { BotIcon, ChevronDownIcon } from "lucide-react"; import { AssistantModalPrimitive } from "../primitives"; import Thread from "./thread"; import { withDefaults } from "./utils/withDefaults"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import { ThreadConfig, ThreadConfigProvider, @@ -50,7 +47,7 @@ AssistantModalRoot.displayName = "AssistantModalRoot"; namespace AssistantModalTrigger { export type Element = HTMLButtonElement; - export type Props = Partial; + export type Props = Partial; } const AssistantModalTrigger = forwardRef< @@ -81,7 +78,7 @@ const ModalButtonStyled = withDefaults(TooltipIconButton, { namespace AssistantModalButton { export type Element = HTMLButtonElement; - export type Props = Partial & { + export type Props = Partial & { "data-state"?: "open" | "closed"; }; } diff --git a/packages/react/src/ui/attachment-ui.tsx b/packages/react/src/ui/attachment-ui.tsx index b71d3a00d6..2cbe883727 100644 --- a/packages/react/src/ui/attachment-ui.tsx +++ b/packages/react/src/ui/attachment-ui.tsx @@ -10,10 +10,7 @@ import { import { CircleXIcon, FileIcon } from "lucide-react"; import { withDefaults } from "./utils/withDefaults"; import { useThreadConfig } from "./thread-config"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import { AttachmentPrimitive } from "../primitives"; import { useAttachment } from "../context/react/AttachmentContext"; import { @@ -169,7 +166,7 @@ AttachmentUI.displayName = "Attachment"; namespace AttachmentRemove { export type Element = HTMLButtonElement; - export type Props = Partial; + export type Props = Partial; } const AttachmentRemove = forwardRef< diff --git a/packages/react/src/ui/base/index.ts b/packages/react/src/ui/base/index.ts index b5b2c15952..278a5d0094 100644 --- a/packages/react/src/ui/base/index.ts +++ b/packages/react/src/ui/base/index.ts @@ -10,9 +10,6 @@ export { Button, buttonVariants, type ButtonProps } from "./button"; export { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip"; -export { - TooltipIconButton, - type TooltipIconButtonProps, -} from "./tooltip-icon-button"; +export { TooltipIconButton } from "./tooltip-icon-button"; export { CircleStopIcon } from "./CircleStopIcon"; diff --git a/packages/react/src/ui/base/tooltip-icon-button.tsx b/packages/react/src/ui/base/tooltip-icon-button.tsx index 793063db5b..4442af3361 100644 --- a/packages/react/src/ui/base/tooltip-icon-button.tsx +++ b/packages/react/src/ui/base/tooltip-icon-button.tsx @@ -4,14 +4,16 @@ import { forwardRef } from "react"; import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip"; import { Button, ButtonProps } from "./button"; -export type TooltipIconButtonProps = ButtonProps & { - tooltip: string; - side?: "top" | "bottom" | "left" | "right"; -}; +export namespace TooltipIconButton { + export type Props = ButtonProps & { + tooltip: string; + side?: "top" | "bottom" | "left" | "right"; + }; +} export const TooltipIconButton = forwardRef< HTMLButtonElement, - TooltipIconButtonProps + TooltipIconButton.Props >(({ children, tooltip, side = "bottom", ...rest }, ref) => { return ( diff --git a/packages/react/src/ui/branch-picker.tsx b/packages/react/src/ui/branch-picker.tsx index dc2e2ed27b..bfe8fdc03f 100644 --- a/packages/react/src/ui/branch-picker.tsx +++ b/packages/react/src/ui/branch-picker.tsx @@ -3,10 +3,7 @@ import { ComponentPropsWithoutRef, forwardRef, type FC } from "react"; import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import { withDefaults } from "./utils/withDefaults"; import { useThreadConfig } from "./thread-config"; import { BranchPickerPrimitive } from "../primitives"; @@ -40,7 +37,7 @@ BranchPickerRoot.displayName = "BranchPickerRoot"; namespace BranchPickerPrevious { export type Element = BranchPickerPrimitive.Previous.Element; - export type Props = Partial; + export type Props = Partial; } const BranchPickerPrevious = forwardRef< @@ -88,7 +85,7 @@ BranchPickerState.displayName = "BranchPickerState"; namespace BranchPickerNext { export type Element = BranchPickerPrimitive.Next.Element; - export type Props = Partial; + export type Props = Partial; } const BranchPickerNext = forwardRef< diff --git a/packages/react/src/ui/composer.tsx b/packages/react/src/ui/composer.tsx index 391d51e61c..ac0221cf41 100644 --- a/packages/react/src/ui/composer.tsx +++ b/packages/react/src/ui/composer.tsx @@ -5,10 +5,7 @@ import { ComponentPropsWithoutRef, forwardRef, type FC } from "react"; import { PaperclipIcon, SendHorizontalIcon } from "lucide-react"; import { withDefaults } from "./utils/withDefaults"; import { useThreadConfig } from "./thread-config"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import { CircleStopIcon } from "./base/CircleStopIcon"; import { ComposerPrimitive, ThreadPrimitive } from "../primitives"; import { useThread } from "../context/react/ThreadContext"; @@ -94,7 +91,7 @@ const ComposerAttachButton = withDefaults(TooltipIconButton, { namespace ComposerAddAttachment { export type Element = HTMLButtonElement; - export type Props = Partial; + export type Props = Partial; } const ComposerAddAttachment = forwardRef< @@ -152,7 +149,7 @@ const ComposerSendButton = withDefaults(TooltipIconButton, { namespace ComposerSend { export type Element = HTMLButtonElement; - export type Props = Partial; + export type Props = Partial; } const ComposerSend = forwardRef( @@ -179,7 +176,7 @@ const ComposerCancelButton = withDefaults(TooltipIconButton, { namespace ComposerCancel { export type Element = HTMLButtonElement; - export type Props = Partial; + export type Props = Partial; } const ComposerCancel = forwardRef( diff --git a/packages/react/src/ui/thread.tsx b/packages/react/src/ui/thread.tsx index d182823c9f..063a032490 100644 --- a/packages/react/src/ui/thread.tsx +++ b/packages/react/src/ui/thread.tsx @@ -6,10 +6,7 @@ import { ArrowDownIcon } from "lucide-react"; import { withDefaults } from "./utils/withDefaults"; import Composer from "./composer"; import ThreadWelcome from "./thread-welcome"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import AssistantMessage from "./assistant-message"; import UserMessage from "./user-message"; import EditComposer from "./edit-composer"; @@ -133,7 +130,7 @@ const ThreadScrollToBottomIconButton = withDefaults(TooltipIconButton, { namespace ThreadScrollToBottom { export type Element = HTMLButtonElement; - export type Props = Partial; + export type Props = Partial; } const ThreadScrollToBottom = forwardRef< diff --git a/packages/react/src/ui/user-action-bar.tsx b/packages/react/src/ui/user-action-bar.tsx index 4112923606..41fa6dc89b 100644 --- a/packages/react/src/ui/user-action-bar.tsx +++ b/packages/react/src/ui/user-action-bar.tsx @@ -3,10 +3,7 @@ import { forwardRef, type FC } from "react"; import { PencilIcon } from "lucide-react"; -import { - TooltipIconButton, - TooltipIconButtonProps, -} from "./base/tooltip-icon-button"; +import { TooltipIconButton } from "./base/tooltip-icon-button"; import { withDefaults } from "./utils/withDefaults"; import { useThreadConfig } from "./thread-config"; import { useThread } from "../context"; @@ -38,7 +35,7 @@ UserActionBarRoot.displayName = "UserActionBarRoot"; namespace UserActionBarEdit { export type Element = ActionBarPrimitive.Edit.Element; - export type Props = Partial; + export type Props = Partial; } const UserActionBarEdit = forwardRef<