Skip to content

Commit 903697a

Browse files
committed
refactor: add styled component props
1 parent a9fa934 commit 903697a

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

src/components/common/Button/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from 'react'
22
import { DefaultTheme } from 'styled-components'
3+
import { WithStyledProps } from '../../../types'
34

45
export type ButtonSize = 'sm' | 'md' | 'lg'
56
export type ButtonTag = 'button' | 'a'
67

78
export type ButtonProps = AnchorHTMLAttributes<HTMLAnchorElement> &
8-
ButtonHTMLAttributes<HTMLButtonElement> & {
9+
ButtonHTMLAttributes<HTMLButtonElement> &
10+
WithStyledProps<ButtonTag> & {
911
children: ReactNode
1012
kind?: string
1113
variant?: string
@@ -18,7 +20,6 @@ export type ButtonProps = AnchorHTMLAttributes<HTMLAnchorElement> &
1820
focus?: boolean
1921
disabled?: boolean
2022

21-
as?: ButtonTag
2223
className?: string
2324

2425
animation?:

src/components/common/TextGradient/types.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HTMLAttributes, ReactNode } from 'react'
22
import { Typo, TypoKind } from '../../../themes/types'
3+
import { WithStyledProps } from '../../../types'
34

45
export type TypeElements =
56
| 'h1'
@@ -17,14 +18,14 @@ export type TypeElements =
1718
| 'span'
1819
| 'strong'
1920

20-
export type TextGradientProps = HTMLAttributes<HTMLElement> & {
21-
children: ReactNode
22-
size?: number | string
23-
color?: string
24-
type?: TypoKind
25-
className?: string
26-
as?: TypeElements
27-
}
21+
export type TextGradientProps = HTMLAttributes<HTMLElement> &
22+
WithStyledProps<TypeElements> & {
23+
children: ReactNode
24+
size?: number | string
25+
color?: string
26+
type?: TypoKind
27+
className?: string
28+
}
2829

2930
export type StyledTextGradientProps = {
3031
size?: number | string

src/components/common/Tooltip/cmp.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export const Tooltip = ({
3232
onClose,
3333
onCloseClick,
3434
closeDelay = 200,
35+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
36+
forwardedAs: _forwardedAs,
37+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
38+
as: _as,
3539
...rest
3640
}: TooltipProps) => {
3741
const tooltipRef = useRef<any>()
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ReactNode, RefObject } from 'react'
22
import { FloatPosition, FloatPositionType } from '../../../hooks'
3+
import { WithStyledProps } from '../../../types'
34

45
export type TooltipPositionType = FloatPositionType
56
export type TooltipPosition = FloatPosition
67
export type TooltipVariant = 1 | 2
78

8-
export type TooltipProps = {
9+
export type TooltipProps = WithStyledProps & {
910
my: TooltipPositionType
1011
at: TooltipPositionType
1112
margin?: TooltipPosition
@@ -22,12 +23,12 @@ export type TooltipProps = {
2223
onClose?: () => void
2324
onCloseClick?: () => void
2425
} & (
25-
| {
26-
children: ReactNode & { ref?: RefObject<any> }
27-
targetRef?: RefObject<any>
28-
}
29-
| {
30-
children?: ReactNode & { ref?: RefObject<any> }
31-
targetRef: RefObject<any>
32-
}
33-
)
26+
| {
27+
children: ReactNode & { ref?: RefObject<any> }
28+
targetRef?: RefObject<any>
29+
}
30+
| {
31+
children?: ReactNode & { ref?: RefObject<any> }
32+
targetRef: RefObject<any>
33+
}
34+
)

src/components/forms/CompositeTitle/cmp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const CompositeTitle = ({
1111
numberColor = 'text',
1212
labelColor = 'text',
1313
label,
14+
forwardedAs: _forwardedAs, // eslint-disable-line @typescript-eslint/no-unused-vars
1415
...rest
1516
}: CompositeTitleProps) => {
1617
return (

src/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
import { AnchorHTMLAttributes, ComponentType, ImgHTMLAttributes } from 'react'
2+
import type { CSSProp } from 'styled-components'
23
import type { IconName } from './components/common/Icon'
34

5+
/**
6+
* Utility type for adding styled-components props to component types.
7+
* Provides `as`, `forwardedAs`, and `css` props with optional type constraints.
8+
*
9+
* @template TAs - Type constraint for `as` and `forwardedAs` props (defaults to string | Element)
10+
*
11+
* @example
12+
* // With type constraint
13+
* type ButtonProps = WithStyledProps<'button' | 'a'> & { ... }
14+
*
15+
* @example
16+
* // Without constraint (accepts any element)
17+
* type GenericProps = WithStyledProps & { ... }
18+
*/
19+
export type WithStyledProps<TAs = string | Element> = {
20+
as?: TAs
21+
forwardedAs?: TAs
22+
css?: CSSProp
23+
}
24+
425
export type Route = {
526
href: string
627
external?: boolean

0 commit comments

Comments
 (0)