Skip to content

Commit c6be652

Browse files
committed
Some more work on white labelling
1 parent e7f851c commit c6be652

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

src/mui/mui.tsx

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import React, { useMemo, useEffect, type ReactNode } from "react";
55
import * as mui from "@mui/material/styles";
66
import { fr } from "../fr";
7+
import type { FrCoreClassName } from "../fr/generatedFromCss/classNames";
78
import { useIsDark } from "../useIsDark";
89
import { typography } from "../fr/generatedFromCss/typography";
910
import { spacingTokenByValue } from "../fr/generatedFromCss/spacing";
10-
import { assert } from "tsafe/assert";
11+
import { assert, type Equals } from "tsafe/assert";
1112
import { objectKeys } from "tsafe/objectKeys";
1213
import { id } from "tsafe/id";
1314
import { useBreakpointsValuesPx, type BreakpointsValues } from "../useBreakpointsValuesPx";
@@ -571,11 +572,18 @@ export function createDsfrCustomBrandingProvider(params: {
571572
[`.${fr.cx("fr-footer__bottom-copy")}`]: {
572573
display: "none"
573574
},
574-
[`.${fr.cx("fr-btn")}`]: {
575+
[getPrimaryButtonClassSelector()]: {
575576
"--hover-tint": theme.palette.primary.dark,
576577
"--active-tint": mui.darken(theme.palette.primary.main, 0.24),
577-
"&:hover, &:active": {
578-
color: theme.palette.primary.contrastText
578+
color: theme.palette.primary.contrastText
579+
},
580+
[`.${fr.cx("fr-header__tools-links")}`]: {
581+
[`&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& .${fr.cx("fr-btn")}`]: {
582+
color: theme.palette.primary.main,
583+
"--hover-tint":
584+
fr.colors.decisions.background.raised.grey.hover,
585+
"--active-tint":
586+
fr.colors.decisions.background.raised.grey.active
579587
}
580588
},
581589
[`.${fr.cx("fr-input")}, .${fr.cx("fr-select")}`]: {
@@ -596,3 +604,57 @@ export function createDsfrCustomBrandingProvider(params: {
596604

597605
return { DsfrCustomBrandingProvider };
598606
}
607+
608+
function getPrimaryButtonClassSelector() {
609+
type BtnClassNames = Extract<FrCoreClassName, `fr-btn--${string}`>;
610+
611+
type BtnVariant = BtnClassNames extends `fr-btn--${infer Variant}` ? Variant : never;
612+
613+
type BtnVariantWithoutPosition = Exclude<
614+
BtnVariant,
615+
"align-on-content" | "icon-left" | "icon-right" | "sm" | "lg"
616+
>;
617+
618+
const btnVariants = [
619+
"close",
620+
"tooltip",
621+
"fullscreen",
622+
"display",
623+
"account",
624+
"team",
625+
"briefcase",
626+
"sort",
627+
"secondary",
628+
"tertiary",
629+
"tertiary-no-outline",
630+
"facebook",
631+
"linkedin",
632+
"mastodon",
633+
"threads",
634+
"twitter",
635+
"twitter-x",
636+
"mail",
637+
"copy",
638+
"dailymotion",
639+
"github",
640+
"instagram",
641+
"snapchat",
642+
"telegram",
643+
"tiktok",
644+
"twitch",
645+
"vimeo",
646+
"youtube",
647+
"menu",
648+
"search"
649+
] as const;
650+
651+
assert<Equals<BtnVariantWithoutPosition, typeof btnVariants[number]>>();
652+
653+
let selector = `.${fr.cx("fr-btn")}`;
654+
655+
for (const btnVariant of btnVariants) {
656+
selector += `:not(.${fr.cx(`fr-btn--${btnVariant}`)})`;
657+
}
658+
659+
return selector;
660+
}

0 commit comments

Comments
 (0)