@@ -4,6 +4,7 @@ import classNames from 'classnames'
4
4
5
5
import { CLink , CLinkProps } from '../link/CLink'
6
6
7
+ import { PolymorphicRefForwardingComponent } from '../../helpers'
7
8
import { colorPropType } from '../../props'
8
9
import type { Colors , Shapes } from '../../types'
9
10
@@ -12,6 +13,10 @@ export interface CButtonProps extends Omit<CLinkProps, 'size'> {
12
13
* Toggle the active state for the component.
13
14
*/
14
15
active ?: boolean
16
+ /**
17
+ * Component used for the root node. Either a string to use a HTML element or a component.
18
+ */
19
+ as ?: ElementType
15
20
/**
16
21
* A string of all className you want applied to the base component.
17
22
*/
@@ -22,10 +27,6 @@ export interface CButtonProps extends Omit<CLinkProps, 'size'> {
22
27
* @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
23
28
*/
24
29
color ?: Colors
25
- /**
26
- * Component used for the root node. Either a string to use a HTML element or a component.
27
- */
28
- component ?: string | ElementType
29
30
/**
30
31
* Toggle the disabled state for the component.
31
32
*/
@@ -59,24 +60,17 @@ export interface CButtonProps extends Omit<CLinkProps, 'size'> {
59
60
variant ?: 'outline' | 'ghost'
60
61
}
61
62
62
- export const CButton = forwardRef < HTMLButtonElement | HTMLAnchorElement , CButtonProps > (
63
+ export const CButton : PolymorphicRefForwardingComponent < 'button' , CButtonProps > = forwardRef <
64
+ HTMLButtonElement | HTMLAnchorElement ,
65
+ CButtonProps
66
+ > (
63
67
(
64
- {
65
- children,
66
- className,
67
- color,
68
- component = 'button' ,
69
- shape,
70
- size,
71
- type = 'button' ,
72
- variant,
73
- ...rest
74
- } ,
68
+ { children, as = 'button' , className, color, shape, size, type = 'button' , variant, ...rest } ,
75
69
ref ,
76
70
) => {
77
71
return (
78
72
< CLink
79
- component = { rest . href ? 'a' : component }
73
+ as = { rest . href ? 'a' : as }
80
74
{ ...( ! rest . href && { type : type } ) }
81
75
className = { classNames (
82
76
'btn' ,
@@ -95,10 +89,10 @@ export const CButton = forwardRef<HTMLButtonElement | HTMLAnchorElement, CButton
95
89
)
96
90
97
91
CButton . propTypes = {
92
+ as : PropTypes . elementType ,
98
93
children : PropTypes . node ,
99
94
className : PropTypes . string ,
100
95
color : colorPropType ,
101
- component : PropTypes . elementType ,
102
96
shape : PropTypes . string ,
103
97
size : PropTypes . oneOf ( [ 'sm' , 'lg' ] ) ,
104
98
type : PropTypes . oneOf ( [ 'button' , 'submit' , 'reset' ] ) ,
0 commit comments