Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions web/common/src/components/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useState } from 'react'
import React from 'react'

import { Button, type ButtonProps } from '@/components/Button/Button'

type TimerID = ReturnType<typeof setTimeout>
import { useCopyClipboard } from '@/hooks/useCopyClipboard'

export interface CopyButtonProps extends Omit<ButtonProps, 'children'> {
text: string
Expand All @@ -25,22 +24,7 @@ export const CopyButton = React.forwardRef<HTMLButtonElement, CopyButtonProps>(
},
ref,
) => {
const [copied, setCopied] = useState<TimerID | null>(null)

const copy = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault()
e.stopPropagation()

if (copied) {
clearTimeout(copied)
}

navigator.clipboard.writeText(text).then(() => {
setCopied(setTimeout(() => setCopied(null), delay))
})

onClick?.(e)
}
const [copyToClipboard, isCopied] = useCopyClipboard(delay)

return (
<Button
Expand All @@ -49,11 +33,14 @@ export const CopyButton = React.forwardRef<HTMLButtonElement, CopyButtonProps>(
title={title}
size={size}
variant={variant}
onClick={copy}
disabled={disabled || !!copied}
onClick={e => {
e.stopPropagation()
copyToClipboard(text)
}}
disabled={disabled || !!isCopied}
{...props}
>
{children(copied != null)}
{children(isCopied != null)}
</Button>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LoadingIcon } from './LoadingIcon'
export interface LoadingContainerProps
extends React.HTMLAttributes<HTMLDivElement> {
isLoading?: boolean
message?: string
message?: React.ReactNode
side?: Side
className?: string
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react-vite'
import MessageContainer from './MessageContainer'
import { MessageContainer } from './MessageContainer'

const meta = {
title: 'Components/Containers/MessageContainer',
Expand Down
16 changes: 9 additions & 7 deletions web/common/src/components/MessageContainer/MessageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { cn } from '@/utils'
import { LoadingContainer } from '../LoadingContainer/LoadingContainer'
import { HorizontalContainer } from '../HorizontalContainer/HorizontalContainer'

export default function MessageContainer({
children,
className,
wrap = false,
isLoading = false,
}: {
export interface MessageContainerProps {
children: React.ReactNode
className?: string
wrap?: boolean
isLoading?: boolean
}) {
}

export function MessageContainer({
children,
className,
wrap = false,
isLoading = false,
}: MessageContainerProps) {
return (
<HorizontalContainer
data-component="MessageContainer"
Expand Down
3 changes: 2 additions & 1 deletion web/common/src/components/ModelName/ModelName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const ModelName = React.forwardRef<HTMLDivElement, ModelNameProps>(
return (
<span
data-testid="model-name"
className="overflow-hidden"
className="flex overflow-hidden"
>
{catalog && (
<>
Expand Down Expand Up @@ -138,6 +138,7 @@ export const ModelName = React.forwardRef<HTMLDivElement, ModelNameProps>(
)}
<span
className={cn(
'truncate',
grayscale
? 'text-model-name-grayscale-model'
: 'text-model-name-model',
Expand Down
24 changes: 11 additions & 13 deletions web/common/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import {
import React from 'react'

import { cn } from '@/utils'
import type { Position } from '@/types'

import './Tooltip.css'

export type TooltipSide = Extract<Position, 'top' | 'bottom' | 'left' | 'right'>
export type TooltipAlign = Extract<Position, 'center' | 'start' | 'end'>
export interface TooltipProps {
trigger: React.ReactNode
children: React.ReactNode
side?: 'top' | 'bottom' | 'left' | 'right'
align?: 'center' | 'start' | 'end'
delayDuration?: number
sideOffset?: number
alignOffset?: number
className?: string
}

export function Tooltip({
delayDuration = 200,
Expand All @@ -24,16 +31,7 @@ export function Tooltip({
trigger,
children,
className,
}: {
trigger: React.ReactNode
children: React.ReactNode
side?: TooltipSide
align?: TooltipAlign
delayDuration?: number
sideOffset?: number
alignOffset?: number
className?: string
}) {
}: TooltipProps) {
return (
<TooltipProvider delayDuration={delayDuration}>
<TooltipRoot>
Expand Down
10 changes: 6 additions & 4 deletions web/common/src/components/Typography/Description.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { cn } from '@/utils'
import React from 'react'

export interface DescriptionProps {
children?: React.ReactNode
className?: string
}

export function Description({
children,
className,
...props
}: {
children?: React.ReactNode
className?: string
}) {
}: DescriptionProps) {
return (
<div
data-component="Description"
Expand Down
12 changes: 7 additions & 5 deletions web/common/src/components/Typography/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { getHeadlineTextSize } from './help'
import type { HeadlineLevel } from '@/types'
import { cn } from '@/utils'

export interface HeadlineProps {
level: HeadlineLevel
children: React.ReactNode
className?: string
}

export function Headline({
level = 1,
children,
className,
...props
}: {
level: HeadlineLevel
children: React.ReactNode
className?: string
}) {
}: HeadlineProps) {
const Tag = `h${level}` as keyof JSX.IntrinsicElements

return (
Expand Down
24 changes: 13 additions & 11 deletions web/common/src/components/Typography/Information.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import { getTextSize } from './help'
import type { Size } from '@/types'
import { Tooltip } from '../Tooltip/Tooltip'

export interface InformationProps {
children?: React.ReactNode
className?: string
classNameTooltip?: string
side?: 'right' | 'left'
size?: Size
sideOffset?: number
delayDuration?: number
info?: React.ReactNode
infoIcon?: React.ReactNode
}

export function Information({
children,
className,
Expand All @@ -22,17 +34,7 @@ export function Information({
/>
),
...props
}: {
children?: React.ReactNode
className?: string
classNameTooltip?: string
side?: 'right' | 'left'
size?: Size
sideOffset?: number
delayDuration?: number
info?: React.ReactNode
infoIcon?: React.ReactNode
}) {
}: InformationProps) {
return (
<div
data-component="Information"
Expand Down
10 changes: 4 additions & 6 deletions web/common/src/components/Typography/Tagline.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { cn } from '@/utils'

export function Tagline({
className,
children,
...props
}: {
export interface TaglineProps {
className?: string
children?: React.ReactNode
}) {
}

export function Tagline({ className, children, ...props }: TaglineProps) {
return (
<div
data-component="Tagline"
Expand Down
10 changes: 4 additions & 6 deletions web/common/src/components/Typography/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { cn } from '@/utils'

export function Text({
className,
children,
...props
}: {
export interface TextProps {
className?: string
children?: React.ReactNode
}) {
}

export function Text({ className, children, ...props }: TextProps) {
return (
<div
data-component="Text"
Expand Down
22 changes: 12 additions & 10 deletions web/common/src/components/VirtualList/FilterableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import { VerticalContainer } from '../VerticalContainer/VerticalContainer'
import { HorizontalContainer } from '../HorizontalContainer/HorizontalContainer'
import { Badge } from '../Badge/Badge'
import { cn } from '@/utils'
import MessageContainer from '../MessageContainer/MessageContainer'
import { MessageContainer } from '../MessageContainer/MessageContainer'
import { Input } from '../Input/Input'

export interface FilterableListProps<TItem> {
items: TItem[]
filterOptions?: IFuseOptions<TItem>
disabled?: boolean
placeholder?: string
autoFocus?: boolean
className?: string
children: (options: TItem[], resetSearch: () => void) => React.ReactNode
}

export function FilterableList<TItem>({
items,
disabled,
Expand All @@ -16,15 +26,7 @@ export function FilterableList<TItem>({
filterOptions,
className,
children,
}: {
items: TItem[]
filterOptions?: IFuseOptions<TItem>
disabled?: boolean
placeholder?: string
autoFocus?: boolean
className?: string
children: (options: TItem[], resetSearch: () => void) => React.ReactNode
}) {
}: FilterableListProps<TItem>) {
const [search, setSearch] = React.useState('')

const fuse = new Fuse(items, filterOptions)
Expand Down
16 changes: 9 additions & 7 deletions web/common/src/components/VirtualList/VirtualList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import { Button } from '../Button/Button'
import { ScrollContainer } from '../ScrollContainer/ScrollContainer'
import { VerticalContainer } from '../VerticalContainer/VerticalContainer'

export interface VirtualListProps<TItem> {
items: TItem[]
estimatedListItemHeight: number
renderListItem: (item: TItem) => React.ReactNode
isSelected?: (item: TItem) => boolean
className?: string
}

export function VirtualList<TItem>({
items,
estimatedListItemHeight,
renderListItem,
isSelected,
className,
}: {
items: TItem[]
estimatedListItemHeight: number
renderListItem: (item: TItem) => React.ReactNode
isSelected?: (item: TItem) => boolean
className?: string
}) {
}: VirtualListProps<TItem>) {
const scrollableAreaRef = React.useRef<HTMLDivElement>(null)

const [activeItemIndex] = React.useMemo(() => {
Expand Down
16 changes: 16 additions & 0 deletions web/common/src/hooks/useCopyClipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useState } from 'react'

type TimerID = ReturnType<typeof setTimeout>

export function useCopyClipboard(
delay: number = 2000,
): [(text: string) => void, TimerID | null] {
const [isCopied, setIsCopied] = useState<TimerID | null>(null)

const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text)
setIsCopied(setTimeout(() => setIsCopied(null), delay))
}

return [copyToClipboard, isCopied]
}
Loading