@@ -22,7 +22,7 @@ type DataAttribute = Record<`data-${string}`, string | boolean | null | undefine
22
22
23
23
export type TagProps = TagProps . Common &
24
24
( TagProps . WithIcon | TagProps . WithoutIcon ) &
25
- ( TagProps . AsAnchor | TagProps . AsButton | TagProps . AsSpan ) ;
25
+ ( TagProps . AsAnchor | TagProps . AsButton | TagProps . AsParagraph ) ;
26
26
export namespace TagProps {
27
27
export type Common = {
28
28
id ?: string ;
@@ -47,134 +47,148 @@ export namespace TagProps {
47
47
linkProps : RegisteredLinkProps ;
48
48
onClick ?: never ;
49
49
nativeButtonProps ?: never ;
50
+ /** @deprecated Tag is now <p> by default. Use `nativeParagraphProps` instead. */
50
51
nativeSpanProps ?: never ;
52
+ nativeParagraphProps ?: never ;
51
53
dismissible ?: never ;
52
54
pressed ?: never ;
53
55
} ;
54
56
export type AsButton = {
55
57
linkProps ?: never ;
58
+ /** @deprecated Tag is now <p> by default. Use `nativeParagraphProps` instead. */
56
59
nativeSpanProps ?: never ;
60
+ nativeParagraphProps ?: never ;
57
61
/** Default: false */
58
62
dismissible ?: boolean ;
59
63
pressed ?: boolean ;
60
64
onClick ?: React . MouseEventHandler < HTMLButtonElement > ;
61
65
nativeButtonProps ?: ComponentProps < "button" > & DataAttribute ;
62
66
} ;
63
- export type AsSpan = {
67
+ export type AsParagraph = {
64
68
linkProps ?: never ;
65
69
onClick ?: never ;
66
70
dismissible ?: never ;
67
71
pressed ?: never ;
68
72
nativeButtonProps ?: never ;
73
+ /** @deprecated Tag is now <p> by default. Use `nativeParagraphProps` instead. */
69
74
nativeSpanProps ?: ComponentProps < "span" > & DataAttribute ;
75
+ nativeParagraphProps ?: ComponentProps < "p" > & DataAttribute ;
70
76
} ;
77
+
78
+ /** @deprecated Tag is now <p> by default. Use `AsParagraph` instead. */
79
+ export type AsSpan = AsParagraph ;
71
80
}
72
81
73
82
/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-tag> */
74
83
export const Tag = memo (
75
- forwardRef < HTMLButtonElement | HTMLAnchorElement | HTMLSpanElement , TagProps > ( ( props , ref ) => {
76
- const {
77
- id : id_props ,
78
- className : prop_className ,
79
- children,
80
- title,
81
- iconId,
82
- small = false ,
83
- pressed,
84
- dismissible = false ,
85
- linkProps,
86
- nativeButtonProps,
87
- nativeSpanProps,
88
- style,
89
- onClick,
90
- ...rest
91
- } = props ;
84
+ forwardRef < HTMLButtonElement | HTMLAnchorElement | HTMLParagraphElement , TagProps > (
85
+ ( props , ref ) => {
86
+ const {
87
+ id : id_props ,
88
+ className : prop_className ,
89
+ children,
90
+ title,
91
+ iconId,
92
+ small = false ,
93
+ pressed,
94
+ dismissible = false ,
95
+ linkProps,
96
+ nativeButtonProps,
97
+ nativeParagraphProps,
98
+ nativeSpanProps,
99
+ style,
100
+ onClick,
101
+ ...rest
102
+ } = props ;
92
103
93
- assert < Equals < keyof typeof rest , never > > ( ) ;
104
+ assert < Equals < keyof typeof rest , never > > ( ) ;
94
105
95
- const id = useAnalyticsId ( {
96
- "defaultIdPrefix" : "fr-tag" ,
97
- "explicitlyProvidedId" : id_props
98
- } ) ;
106
+ const id = useAnalyticsId ( {
107
+ "defaultIdPrefix" : "fr-tag" ,
108
+ "explicitlyProvidedId" : id_props
109
+ } ) ;
99
110
100
- const { Link } = getLink ( ) ;
111
+ const { Link } = getLink ( ) ;
101
112
102
- const className = cx (
103
- fr . cx (
104
- "fr-tag" ,
105
- small && `fr-tag--sm` ,
106
- iconId ,
107
- iconId && "fr-tag--icon-left" , // actually, it's always left but we need it in order to have the icon rendering
108
- dismissible && "fr-tag--dismiss"
109
- ) ,
110
- linkProps !== undefined && linkProps . className ,
111
- prop_className
112
- ) ;
113
+ const className = cx (
114
+ fr . cx (
115
+ "fr-tag" ,
116
+ small && `fr-tag--sm` ,
117
+ iconId ,
118
+ iconId && "fr-tag--icon-left" , // actually, it's always left but we need it in order to have the icon rendering
119
+ dismissible && "fr-tag--dismiss"
120
+ ) ,
121
+ linkProps !== undefined && linkProps . className ,
122
+ prop_className
123
+ ) ;
124
+
125
+ const nativeParagraphOrSpanProps = nativeParagraphProps ?? nativeSpanProps ;
113
126
114
- return (
115
- < >
116
- { linkProps !== undefined && (
117
- < Link
118
- { ...linkProps }
119
- id = { id_props ?? linkProps . id ?? id }
120
- title = { title ?? linkProps . title }
121
- className = { cx ( linkProps ?. className , className ) }
122
- style = { {
123
- ...linkProps ?. style ,
124
- ...style
125
- } }
126
- ref = { ref as React . ForwardedRef < HTMLAnchorElement > }
127
- { ...rest }
128
- >
129
- { children }
130
- </ Link >
131
- ) }
132
- { nativeButtonProps !== undefined && (
133
- < button
134
- { ...nativeButtonProps }
135
- id = { id_props ?? nativeButtonProps . id ?? id }
136
- className = { cx ( nativeButtonProps ?. className , className ) }
137
- style = { {
138
- ...nativeButtonProps ?. style ,
139
- ...style
140
- } }
141
- title = { title ?? nativeButtonProps ?. title }
142
- onClick = { onClick ?? nativeButtonProps ?. onClick }
143
- disabled = { nativeButtonProps ?. disabled }
144
- ref = { ref as React . ForwardedRef < HTMLButtonElement > }
145
- aria-pressed = { pressed }
146
- { ...rest }
147
- >
148
- { children }
149
- </ button >
150
- ) }
151
- { linkProps === undefined && nativeButtonProps === undefined && (
152
- < p
153
- { ...nativeSpanProps }
154
- id = { id_props ?? nativeSpanProps ?. id ?? id }
155
- className = { cx ( nativeSpanProps ?. className , className ) }
156
- style = { {
157
- ...nativeSpanProps ?. style ,
158
- ...style
159
- } }
160
- title = { title ?? nativeSpanProps ?. title }
161
- ref = { ref as React . ForwardedRef < HTMLParagraphElement > }
162
- { ...rest }
163
- >
164
- { children }
165
- </ p >
166
- ) }
167
- </ >
168
- ) ;
169
- } )
127
+ return (
128
+ < >
129
+ { linkProps !== undefined && (
130
+ < Link
131
+ { ...linkProps }
132
+ id = { id_props ?? linkProps . id ?? id }
133
+ title = { title ?? linkProps . title }
134
+ className = { cx ( linkProps ?. className , className ) }
135
+ style = { {
136
+ ...linkProps ?. style ,
137
+ ...style
138
+ } }
139
+ ref = { ref as React . ForwardedRef < HTMLAnchorElement > }
140
+ { ...rest }
141
+ >
142
+ { children }
143
+ </ Link >
144
+ ) }
145
+ { nativeButtonProps !== undefined && (
146
+ < button
147
+ { ...nativeButtonProps }
148
+ id = { id_props ?? nativeButtonProps . id ?? id }
149
+ className = { cx ( nativeButtonProps ?. className , className ) }
150
+ style = { {
151
+ ...nativeButtonProps ?. style ,
152
+ ...style
153
+ } }
154
+ title = { title ?? nativeButtonProps ?. title }
155
+ onClick = { onClick ?? nativeButtonProps ?. onClick }
156
+ disabled = { nativeButtonProps ?. disabled }
157
+ ref = { ref as React . ForwardedRef < HTMLButtonElement > }
158
+ aria-pressed = { pressed }
159
+ { ...rest }
160
+ >
161
+ { children }
162
+ </ button >
163
+ ) }
164
+ { linkProps === undefined && nativeButtonProps === undefined && (
165
+ < p
166
+ { ...nativeParagraphOrSpanProps }
167
+ id = { id_props ?? nativeParagraphOrSpanProps ?. id ?? id }
168
+ className = { cx ( nativeParagraphOrSpanProps ?. className , className ) }
169
+ style = { {
170
+ ...nativeParagraphOrSpanProps ?. style ,
171
+ ...style
172
+ } }
173
+ title = { title ?? nativeParagraphOrSpanProps ?. title }
174
+ ref = { ref as React . ForwardedRef < HTMLParagraphElement > }
175
+ { ...rest }
176
+ >
177
+ { children }
178
+ </ p >
179
+ ) }
180
+ </ >
181
+ ) ;
182
+ }
183
+ )
170
184
) as MemoExoticComponent <
171
185
ForwardRefExoticComponent <
172
186
TagProps . Common &
173
187
( TagProps . WithIcon | TagProps . WithoutIcon ) &
174
188
(
175
189
| ( TagProps . AsAnchor & RefAttributes < HTMLAnchorElement > )
176
190
| ( TagProps . AsButton & RefAttributes < HTMLButtonElement > )
177
- | ( TagProps . AsSpan & RefAttributes < HTMLSpanElement > )
191
+ | ( TagProps . AsParagraph & RefAttributes < HTMLParagraphElement > )
178
192
)
179
193
>
180
194
> ;
0 commit comments