diff --git a/src/Badge.tsx b/src/Badge.tsx index 1ddda8e00..9fc723c80 100644 --- a/src/Badge.tsx +++ b/src/Badge.tsx @@ -14,6 +14,8 @@ export type BadgeProps = { severity?: AlertProps.Severity | "new"; small?: boolean; noIcon?: boolean; + /** Default: "p" */ + as?: "p" | "span"; children: NonNullable; }; @@ -23,6 +25,7 @@ export const Badge = memo( const { id: props_id, className, + as = "p", style, severity, small: isSmall = false, @@ -38,10 +41,10 @@ export const Badge = memo( "explicitlyProvidedId": props_id }); - return ( -

- {children} -

+ ), + id, + style, + ref, + ...rest + }, + <>{children} ); }) ); diff --git a/stories/Badge.stories.tsx b/stories/Badge.stories.tsx index d28077ed9..724774c7d 100644 --- a/stories/Badge.stories.tsx +++ b/stories/Badge.stories.tsx @@ -29,6 +29,18 @@ const { meta, getStory } = getStoryFactory({ "type": { "name": "boolean" }, "description": "Set small badge size (`sm`) when true" }, + "as": { + "options": (() => { + const options = ["p", "span", undefined] as const; + + assert>(); + + return options; + })(), + "control": { type: "select", labels: { null: "default p element" } }, + "description": + "You can specify a 'span' element instead of default 'p' if the badge is inside a `

`." + }, "children": { "type": { "name": "string", "required": true }, "description": "Label to display on the badge" diff --git a/stories/Header.stories.tsx b/stories/Header.stories.tsx index f9db7d49e..8c0f6f5cf 100644 --- a/stories/Header.stories.tsx +++ b/stories/Header.stories.tsx @@ -1,5 +1,6 @@ import React, { useState } from "react"; import { Header } from "../dist/Header"; +import { Badge } from "../dist/Badge"; import { MainNavigation } from "../dist/MainNavigation"; import { sectionName } from "./sectionName"; import { getStoryFactory } from "./getStory"; @@ -115,6 +116,29 @@ export const SimpleHeaderWithServiceTitleAndTagline = getStory({ "serviceTagline": "baseline - précisions sur l'organisation" }); +export const SimpleHeaderWithServiceTitleAndBetaBadge = getStory({ + "id": "fr-header-simple-header-with-service-title-and-tagline", + "brandTop": ( + <> + INTITULE +
+ OFFICIEL + + ), + "homeLinkProps": { + "href": "/", + "title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)" + }, + "serviceTitle": ( + <> + Nom du site / service{" "} + + Beta + + + ) +}); + export const HeaderWithQuickAccessItems = getStory( { "id": "fr-header-header-with-quick-access-items",