Skip to content

Commit f9b412d

Browse files
authored
chore(web_common): export components with types (#5347)
1 parent 5f223bd commit f9b412d

File tree

15 files changed

+138
-95
lines changed

15 files changed

+138
-95
lines changed

web/common/src/components/CopyButton/CopyButton.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, { useState } from 'react'
1+
import React from 'react'
22

33
import { Button, type ButtonProps } from '@/components/Button/Button'
4-
5-
type TimerID = ReturnType<typeof setTimeout>
4+
import { useCopyClipboard } from '@/hooks/useCopyClipboard'
65

76
export interface CopyButtonProps extends Omit<ButtonProps, 'children'> {
87
text: string
@@ -25,22 +24,7 @@ export const CopyButton = React.forwardRef<HTMLButtonElement, CopyButtonProps>(
2524
},
2625
ref,
2726
) => {
28-
const [copied, setCopied] = useState<TimerID | null>(null)
29-
30-
const copy = (e: React.MouseEvent<HTMLButtonElement>) => {
31-
e.preventDefault()
32-
e.stopPropagation()
33-
34-
if (copied) {
35-
clearTimeout(copied)
36-
}
37-
38-
navigator.clipboard.writeText(text).then(() => {
39-
setCopied(setTimeout(() => setCopied(null), delay))
40-
})
41-
42-
onClick?.(e)
43-
}
27+
const [copyToClipboard, isCopied] = useCopyClipboard(delay)
4428

4529
return (
4630
<Button
@@ -49,11 +33,14 @@ export const CopyButton = React.forwardRef<HTMLButtonElement, CopyButtonProps>(
4933
title={title}
5034
size={size}
5135
variant={variant}
52-
onClick={copy}
53-
disabled={disabled || !!copied}
36+
onClick={e => {
37+
e.stopPropagation()
38+
copyToClipboard(text)
39+
}}
40+
disabled={disabled || !!isCopied}
5441
{...props}
5542
>
56-
{children(copied != null)}
43+
{children(isCopied != null)}
5744
</Button>
5845
)
5946
},

web/common/src/components/LoadingContainer/LoadingContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LoadingIcon } from './LoadingIcon'
66
export interface LoadingContainerProps
77
extends React.HTMLAttributes<HTMLDivElement> {
88
isLoading?: boolean
9-
message?: string
9+
message?: React.ReactNode
1010
side?: Side
1111
className?: string
1212
}

web/common/src/components/MessageContainer/MessageContainer.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Meta, StoryObj } from '@storybook/react-vite'
2-
import MessageContainer from './MessageContainer'
2+
import { MessageContainer } from './MessageContainer'
33

44
const meta = {
55
title: 'Components/Containers/MessageContainer',

web/common/src/components/MessageContainer/MessageContainer.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import { cn } from '@/utils'
22
import { LoadingContainer } from '../LoadingContainer/LoadingContainer'
33
import { HorizontalContainer } from '../HorizontalContainer/HorizontalContainer'
44

5-
export default function MessageContainer({
6-
children,
7-
className,
8-
wrap = false,
9-
isLoading = false,
10-
}: {
5+
export interface MessageContainerProps {
116
children: React.ReactNode
127
className?: string
138
wrap?: boolean
149
isLoading?: boolean
15-
}) {
10+
}
11+
12+
export function MessageContainer({
13+
children,
14+
className,
15+
wrap = false,
16+
isLoading = false,
17+
}: MessageContainerProps) {
1618
return (
1719
<HorizontalContainer
1820
data-component="MessageContainer"

web/common/src/components/ModelName/ModelName.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const ModelName = React.forwardRef<HTMLDivElement, ModelNameProps>(
106106
return (
107107
<span
108108
data-testid="model-name"
109-
className="overflow-hidden"
109+
className="flex overflow-hidden"
110110
>
111111
{catalog && (
112112
<>
@@ -138,6 +138,7 @@ export const ModelName = React.forwardRef<HTMLDivElement, ModelNameProps>(
138138
)}
139139
<span
140140
className={cn(
141+
'truncate',
141142
grayscale
142143
? 'text-model-name-grayscale-model'
143144
: 'text-model-name-model',

web/common/src/components/Tooltip/Tooltip.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ import {
88
import React from 'react'
99

1010
import { cn } from '@/utils'
11-
import type { Position } from '@/types'
1211

1312
import './Tooltip.css'
1413

15-
export type TooltipSide = Extract<Position, 'top' | 'bottom' | 'left' | 'right'>
16-
export type TooltipAlign = Extract<Position, 'center' | 'start' | 'end'>
14+
export interface TooltipProps {
15+
trigger: React.ReactNode
16+
children: React.ReactNode
17+
side?: 'top' | 'bottom' | 'left' | 'right'
18+
align?: 'center' | 'start' | 'end'
19+
delayDuration?: number
20+
sideOffset?: number
21+
alignOffset?: number
22+
className?: string
23+
}
1724

1825
export function Tooltip({
1926
delayDuration = 200,
@@ -24,16 +31,7 @@ export function Tooltip({
2431
trigger,
2532
children,
2633
className,
27-
}: {
28-
trigger: React.ReactNode
29-
children: React.ReactNode
30-
side?: TooltipSide
31-
align?: TooltipAlign
32-
delayDuration?: number
33-
sideOffset?: number
34-
alignOffset?: number
35-
className?: string
36-
}) {
34+
}: TooltipProps) {
3735
return (
3836
<TooltipProvider delayDuration={delayDuration}>
3937
<TooltipRoot>

web/common/src/components/Typography/Description.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { cn } from '@/utils'
22
import React from 'react'
33

4+
export interface DescriptionProps {
5+
children?: React.ReactNode
6+
className?: string
7+
}
8+
49
export function Description({
510
children,
611
className,
712
...props
8-
}: {
9-
children?: React.ReactNode
10-
className?: string
11-
}) {
13+
}: DescriptionProps) {
1214
return (
1315
<div
1416
data-component="Description"

web/common/src/components/Typography/Headline.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import { getHeadlineTextSize } from './help'
33
import type { HeadlineLevel } from '@/types'
44
import { cn } from '@/utils'
55

6+
export interface HeadlineProps {
7+
level: HeadlineLevel
8+
children: React.ReactNode
9+
className?: string
10+
}
11+
612
export function Headline({
713
level = 1,
814
children,
915
className,
1016
...props
11-
}: {
12-
level: HeadlineLevel
13-
children: React.ReactNode
14-
className?: string
15-
}) {
17+
}: HeadlineProps) {
1618
const Tag = `h${level}` as keyof JSX.IntrinsicElements
1719

1820
return (

web/common/src/components/Typography/Information.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import { getTextSize } from './help'
66
import type { Size } from '@/types'
77
import { Tooltip } from '../Tooltip/Tooltip'
88

9+
export interface InformationProps {
10+
children?: React.ReactNode
11+
className?: string
12+
classNameTooltip?: string
13+
side?: 'right' | 'left'
14+
size?: Size
15+
sideOffset?: number
16+
delayDuration?: number
17+
info?: React.ReactNode
18+
infoIcon?: React.ReactNode
19+
}
20+
921
export function Information({
1022
children,
1123
className,
@@ -22,17 +34,7 @@ export function Information({
2234
/>
2335
),
2436
...props
25-
}: {
26-
children?: React.ReactNode
27-
className?: string
28-
classNameTooltip?: string
29-
side?: 'right' | 'left'
30-
size?: Size
31-
sideOffset?: number
32-
delayDuration?: number
33-
info?: React.ReactNode
34-
infoIcon?: React.ReactNode
35-
}) {
37+
}: InformationProps) {
3638
return (
3739
<div
3840
data-component="Information"

web/common/src/components/Typography/Tagline.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { cn } from '@/utils'
22

3-
export function Tagline({
4-
className,
5-
children,
6-
...props
7-
}: {
3+
export interface TaglineProps {
84
className?: string
95
children?: React.ReactNode
10-
}) {
6+
}
7+
8+
export function Tagline({ className, children, ...props }: TaglineProps) {
119
return (
1210
<div
1311
data-component="Tagline"

0 commit comments

Comments
 (0)