gaufre: new variant props to impact sizing

this is done to integrate the button more easily in an app using the
DSFR heading
This commit is contained in:
Emmanuel Pelletier
2024-05-15 20:39:33 +02:00
parent d741b0595b
commit 4b64642837
4 changed files with 73 additions and 13 deletions

View File

@@ -1,11 +1,27 @@
import { useTranslate } from "../i18n/useTranslate" import { useTranslate } from "../i18n/useTranslate"
export const Gaufre = () => { export type Props = {
/**
* Variantes d'affichage :
*
* "responsive": Affiche un bouton plus petit sur écran mobile/tablette, plus grand sur écran plus large.
* "small": Affiche un bouton plus petit.
*/
variant?: "responsive" | "small"
}
const variantClasses = {
responsive: "lasuite-gaufre-btn--responsive",
small: "lasuite-gaufre-btn--small",
}
export const Gaufre = ({ variant }: Props) => {
const { t } = useTranslate() const { t } = useTranslate()
const variantClass = !!variant ? variantClasses[variant] : ""
return ( return (
<button <button
type="button" type="button"
className="lasuite-gaufre-btn lasuite-gaufre-btn--vanilla js-lasuite-gaufre-btn" className={`lasuite-gaufre-btn ${variantClass} lasuite-gaufre-btn--vanilla js-lasuite-gaufre-btn`}
title={t("gaufre.label")} title={t("gaufre.label")}
> >
{t("gaufre.label")} {t("gaufre.label")}

View File

@@ -1,9 +1,13 @@
import { ReactNode } from "react" import "@gouvfr/dsfr/dist/core/core.module"
import "@gouvfr/dsfr/dist/component/navigation/navigation.module"
import "@gouvfr/dsfr/dist/component/modal/modal.module"
import "@gouvfr/dsfr/dist/component/header/header.module"
import { Gaufre } from "../components/Gaufre"
/** /**
* This component is there to test showing the Gaufre button in a classic DSFR header * This component is there to test showing the Gaufre button in a classic DSFR header
*/ */
export const DsfrHeader = ({ actions }: { actions: Array<ReactNode> }) => { export const DsfrHeader = () => {
return ( return (
<header role="banner" className="fr-header"> <header role="banner" className="fr-header">
<div className="fr-header__body"> <div className="fr-header__body">
@@ -17,6 +21,19 @@ export const DsfrHeader = ({ actions }: { actions: Array<ReactNode> }) => {
officiel officiel
</p> </p>
</div> </div>
<div className="fr-header__navbar">
<Gaufre variant="small" />
<button
className="fr-btn--menu fr-btn"
data-fr-opened="false"
aria-controls="modal-499"
aria-haspopup="menu"
id="button-500"
title="Menu"
>
Menu
</button>
</div>
</div> </div>
<div className="fr-header__service"> <div className="fr-header__service">
<a <a
@@ -34,19 +51,27 @@ export const DsfrHeader = ({ actions }: { actions: Array<ReactNode> }) => {
<div className="fr-header__tools-links"> <div className="fr-header__tools-links">
<ul className="fr-btns-group"> <ul className="fr-btns-group">
<li> <li>
<a className="fr-btn fr-icon-add-circle-line" href="[url - à modifier]"> <a className="fr-btn fr-icon-add-circle-line" href="#">
Créer un espace Créer un espace
</a> </a>
</li> </li>
{actions.map((action, i) => ( <li>
<li key={i}>{action}</li> <Gaufre variant="small" />
))} </li>
</ul> </ul>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div className="fr-header__menu fr-modal" id="modal-499" aria-labelledby="button-500">
<div className="fr-container">
<button className="fr-btn--close fr-btn" aria-controls="modal-499" title="Fermer">
Fermer
</button>
<div className="fr-header__menu-links"> </div>
</div>
</div>
</header> </header>
) )
} }

View File

@@ -115,7 +115,7 @@ const routes = [
label: "Gaufre (header DSFR)", label: "Gaufre (header DSFR)",
component: ( component: (
<StylesStandalone type="gaufre"> <StylesStandalone type="gaufre">
<DsfrHeader actions={[<Gaufre />]} /> <DsfrHeader />
<div className="fr-container fr-p-4w"> <div className="fr-container fr-p-4w">
<p> <p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac diam a libero posuere Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac diam a libero posuere
@@ -157,7 +157,6 @@ const routes = [
<DarkTheme> <DarkTheme>
<StylesGaufre> <StylesGaufre>
<div <div
data-fr-scheme="dark"
style={{ style={{
margin: "2rem auto", margin: "2rem auto",
width: 800, width: 800,

View File

@@ -36,7 +36,7 @@
font-size: 1.125rem !important; font-size: 1.125rem !important;
line-height: 1.75rem !important; line-height: 1.75rem !important;
min-height: 3rem !important; min-height: 3rem !important;
padding: 0.5rem 1.5rem !important; padding: 0.5rem !important;
background-color: transparent !important; background-color: transparent !important;
color: #000091 !important; color: #000091 !important;
box-shadow: inset 0 0 0 1px #ddd !important; box-shadow: inset 0 0 0 1px #ddd !important;
@@ -44,8 +44,6 @@
white-space: nowrap !important; white-space: nowrap !important;
max-width: 3rem !important; max-width: 3rem !important;
max-height: 3rem !important; max-height: 3rem !important;
padding-left: 0.5rem !important;
padding-right: 0.5rem !important;
} }
[data-fr-scheme="dark"] .lasuite-gaufre-btn--vanilla { [data-fr-scheme="dark"] .lasuite-gaufre-btn--vanilla {
@@ -67,6 +65,28 @@
--icon-size: 2rem !important; --icon-size: 2rem !important;
} }
.lasuite-gaufre-btn--vanilla.lasuite-gaufre-btn--small {
min-height: 2.5rem !important;
max-width: 2.5rem !important;
max-height: 2.5rem !important;
}
.lasuite-gaufre-btn--vanilla.lasuite-gaufre-btn--small::before {
--icon-size: 1.5rem !important;
}
@media screen and (max-width: 991px) {
.lasuite-gaufre-btn--vanilla.lasuite-gaufre-btn--responsive {
min-height: 2.5rem !important;
max-width: 2.5rem !important;
max-height: 2.5rem !important;
}
.lasuite-gaufre-btn--vanilla.lasuite-gaufre-btn--responsive::before {
--icon-size: 1.5rem !important;
}
}
.lasuite-gaufre-btn--vanilla:hover, .lasuite-gaufre-btn--vanilla:hover,
.lasuite-gaufre-btn--vanilla:focus-visible { .lasuite-gaufre-btn--vanilla:focus-visible {
background-color: #f6f6f6 !important; background-color: #f6f6f6 !important;