File tree Expand file tree Collapse file tree 3 files changed +50
-11
lines changed Expand file tree Collapse file tree 3 files changed +50
-11
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ export type BadgeProps = {
1414 severity ?: AlertProps . Severity | "new" ;
1515 small ?: boolean ;
1616 noIcon ?: boolean ;
17+ /** Default: "p" */
18+ as ?: "p" | "span" ;
1719 children : NonNullable < ReactNode > ;
1820} ;
1921
@@ -23,6 +25,7 @@ export const Badge = memo(
2325 const {
2426 id : props_id ,
2527 className,
28+ as = "p" ,
2629 style,
2730 severity,
2831 small : isSmall = false ,
@@ -38,24 +41,24 @@ export const Badge = memo(
3841 "explicitlyProvidedId" : props_id
3942 } ) ;
4043
41- return (
42- < p
43- id = { id }
44- className = { cx (
44+ return React . createElement (
45+ as ,
46+ {
47+ " className" : cx (
4548 fr . cx (
4649 "fr-badge" ,
4750 severity !== undefined && `fr-badge--${ severity } ` ,
4851 { "fr-badge--sm" : isSmall } ,
4952 { "fr-badge--no-icon" : noIcon || severity === undefined }
5053 ) ,
5154 className
52- ) }
53- style = { style }
54- ref = { ref }
55- { ... rest }
56- >
57- { children }
58- </ p >
55+ ) ,
56+ id ,
57+ style ,
58+ ref ,
59+ ... rest
60+ } ,
61+ < > { children } </ >
5962 ) ;
6063 } )
6164) ;
Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ const { meta, getStory } = getStoryFactory({
2929 "type" : { "name" : "boolean" } ,
3030 "description" : "Set small badge size (`sm`) when true"
3131 } ,
32+ "as" : {
33+ "options" : ( ( ) => {
34+ const options = [ "p" , "span" , undefined ] as const ;
35+
36+ assert < Equals < typeof options [ number ] , BadgeProps [ "as" ] > > ( ) ;
37+
38+ return options ;
39+ } ) ( ) ,
40+ "control" : { type : "select" , labels : { null : "default p element" } } ,
41+ "description" :
42+ "You can specify a 'span' element instead of default 'p' if the badge is inside a `<p>`."
43+ } ,
3244 "children" : {
3345 "type" : { "name" : "string" , "required" : true } ,
3446 "description" : "Label to display on the badge"
Original file line number Diff line number Diff line change 11import React , { useState } from "react" ;
22import { Header } from "../dist/Header" ;
3+ import { Badge } from "../dist/Badge" ;
34import { MainNavigation } from "../dist/MainNavigation" ;
45import { sectionName } from "./sectionName" ;
56import { getStoryFactory } from "./getStory" ;
@@ -115,6 +116,29 @@ export const SimpleHeaderWithServiceTitleAndTagline = getStory({
115116 "serviceTagline" : "baseline - précisions sur l'organisation"
116117} ) ;
117118
119+ export const SimpleHeaderWithServiceTitleAndBetaBadge = getStory ( {
120+ "id" : "fr-header-simple-header-with-service-title-and-tagline" ,
121+ "brandTop" : (
122+ < >
123+ INTITULE
124+ < br />
125+ OFFICIEL
126+ </ >
127+ ) ,
128+ "homeLinkProps" : {
129+ "href" : "/" ,
130+ "title" : "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)"
131+ } ,
132+ "serviceTitle" : (
133+ < >
134+ Nom du site / service{ " " }
135+ < Badge noIcon severity = "success" as = "span" >
136+ Beta
137+ </ Badge >
138+ </ >
139+ )
140+ } ) ;
141+
118142export const HeaderWithQuickAccessItems = getStory (
119143 {
120144 "id" : "fr-header-header-with-quick-access-items" ,
You can’t perform that action at this time.
0 commit comments