Skip to content

Commit 4a8b04d

Browse files
committed
Update color picker to use the CSS variable by default
1 parent e1821b1 commit 4a8b04d

File tree

2 files changed

+73
-31
lines changed

2 files changed

+73
-31
lines changed

stories/ColorHelper/ColorDecisionCard.tsx

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import React from "react";
22
import type { ColorDecisionAndCorrespondingOption } from "../../scripts/build/cssToTs/colorDecisionAndCorrespondingOptions";
3-
import { useColors } from "../../dist/useColors";
43
import { fr } from "../../dist/fr";
54
import Tooltip from "@mui/material/Tooltip";
65
import { useStyles } from "./makeStyles";
76
import { CopyToClipboardButton } from "./CopyToClipboardButton";
87
import { Accordion } from "../../dist/Accordion";
8+
import { Evt } from "evt";
9+
import { useConst } from "powerhooks/useConst";
910

1011
export function ColorDecisionCard(
1112
props: { className?: string } & ColorDecisionAndCorrespondingOption
1213
) {
1314
const { className, colorDecisionName, themePath, colorOption } = props;
1415

15-
const theme = useColors();
16-
1716
const { cx, css } = useStyles();
1817

18+
const evtCopyToClipboardButtonAction = useConst(() => Evt.create<"trigger click">());
19+
1920
return (
2021
<div
2122
className={cx(
2223
css({
2324
"borderWidth": 2,
2425
"borderStyle": "solid",
25-
"borderColor": theme.decisions.border.default.grey.default,
26+
"borderColor": fr.colors.decisions.border.default.grey.default,
2627
"&:hover": {
27-
"borderColor": theme.decisions.border.plain.grey.default
28+
"borderColor": fr.colors.decisions.border.plain.grey.default
2829
},
2930
"boxShadow": "0px 6px 10px 0px rgba(0,0,0,0.07)",
3031
"padding": fr.spacing("4v")
@@ -35,20 +36,11 @@ export function ColorDecisionCard(
3536
<div>
3637
<span
3738
style={{
38-
"color": theme.decisions.text.mention.grey.default
39-
}}
40-
>
41-
CSS variable:{" "}
42-
</span>
43-
&nbsp;<code>{colorDecisionName}</code>
44-
</div>
45-
<div style={{ "marginTop": fr.spacing("3v") }}>
46-
<span
47-
style={{
48-
"color": theme.decisions.text.mention.grey.default
39+
"color": fr.colors.decisions.text.mention.grey.default
4940
}}
5041
>
51-
Decision path{" "}
42+
Color Decision path
43+
{/*
5244
<Tooltip
5345
title={
5446
<a href="https://guides.react-dsfr.fr/css-in-js#colors" target="_blank">
@@ -60,15 +52,51 @@ export function ColorDecisionCard(
6052
>
6153
<i className={fr.cx("ri-information-line")} />
6254
</Tooltip>{" "}
55+
*/}
6356
:
64-
</span>{" "}
57+
</span>
58+
&nbsp;&nbsp;&nbsp;&nbsp;
6559
<code>
66-
theme.decisions.<strong>{themePath.join(".")}</strong>
60+
<Tooltip
61+
title={
62+
<code
63+
style={{
64+
"fontSize": "1.2em"
65+
}}
66+
>
67+
var({colorDecisionName})
68+
</code>
69+
}
70+
placement="top-end"
71+
>
72+
<span
73+
style={{ "display": "inline-block", "cursor": "pointer" }}
74+
onClick={() => evtCopyToClipboardButtonAction.post("trigger click")}
75+
>
76+
fr.colors.decisions.<strong>{themePath.join(".")}</strong>
77+
</span>
78+
</Tooltip>
6779
</code>
6880
<CopyToClipboardButton
6981
textToCopy={["theme", "decisions", ...themePath].join(".")}
82+
evtAction={evtCopyToClipboardButtonAction}
7083
/>
7184
</div>
85+
<div
86+
style={{
87+
"marginTop": fr.spacing("3v")
88+
}}
89+
>
90+
<span
91+
style={{
92+
"color": fr.colors.decisions.text.mention.grey.default
93+
}}
94+
>
95+
CSS variable name:
96+
</span>
97+
&nbsp; &nbsp; &nbsp; &nbsp;
98+
<code>{colorDecisionName}</code>
99+
</div>
72100

73101
<div style={{ "marginTop": fr.spacing("2v") }}>
74102
{typeof colorOption.color === "string" ? (
@@ -79,7 +107,7 @@ export function ColorDecisionCard(
79107
<>
80108
<span
81109
style={{
82-
"color": theme.decisions.text.mention.grey.default
110+
"color": fr.colors.decisions.text.mention.grey.default
83111
}}
84112
>
85113
Dark mode:{" "}
@@ -88,7 +116,7 @@ export function ColorDecisionCard(
88116
&nbsp; &nbsp;
89117
<span
90118
style={{
91-
"color": theme.decisions.text.mention.grey.default
119+
"color": fr.colors.decisions.text.mention.grey.default
92120
}}
93121
>
94122
Light mode:{" "}
@@ -104,7 +132,7 @@ export function ColorDecisionCard(
104132
<p>
105133
<span
106134
style={{
107-
"color": theme.decisions.text.mention.grey.default
135+
"color": fr.colors.decisions.text.mention.grey.default
108136
}}
109137
>
110138
CSS variable:{" "}
@@ -118,7 +146,7 @@ export function ColorDecisionCard(
118146
>
119147
<span
120148
style={{
121-
"color": theme.decisions.text.mention.grey.default
149+
"color": fr.colors.decisions.text.mention.grey.default
122150
}}
123151
>
124152
Option path:{" "}
@@ -135,8 +163,6 @@ export function ColorDecisionCard(
135163
function ColoredSquare(props: { hexColorCode: string }) {
136164
const { hexColorCode } = props;
137165

138-
const theme = useColors();
139-
140166
return (
141167
<div
142168
style={{
@@ -150,7 +176,7 @@ function ColoredSquare(props: { hexColorCode: string }) {
150176
"display": "inline-block",
151177
"borderWidth": 2,
152178
"borderStyle": "solid",
153-
"borderColor": theme.decisions.border.default.grey.default,
179+
"borderColor": fr.colors.decisions.border.default.grey.default,
154180
"width": 30,
155181
"height": 30,
156182
"backgroundColor": hexColorCode,

stories/ColorHelper/CopyToClipboardButton.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,38 @@ import { Button } from "../../dist/Button";
33
import { useStyles } from "./makeStyles";
44
import { fr } from "../../dist";
55
import { assert } from "tsafe/assert";
6+
import { type NonPostableEvt } from "evt";
7+
import { useEvt } from "evt/hooks";
68

79
type Props = {
810
className?: string;
911
textToCopy: string;
12+
evtAction: NonPostableEvt<"trigger click">;
1013
};
1114

1215
export function CopyToClipboardButton(props: Props) {
13-
const { className, textToCopy } = props;
16+
const { className, textToCopy, evtAction } = props;
1417

1518
const { css, cx, theme } = useStyles();
1619

1720
const [isCopiedFeedbackShown, setIsCopiedFeedbackShown] = useState(false);
1821

22+
const onButtonClick = () => {
23+
copyToClipboard(textToCopy);
24+
setIsCopiedFeedbackShown(true);
25+
};
26+
27+
useEvt(
28+
ctx => {
29+
evtAction.attach(
30+
action => action === "trigger click",
31+
ctx,
32+
() => onButtonClick()
33+
);
34+
},
35+
[evtAction]
36+
);
37+
1938
useEffect(() => {
2039
if (!isCopiedFeedbackShown) {
2140
return;
@@ -68,10 +87,7 @@ export function CopyToClipboardButton(props: Props) {
6887
iconId={"ri-clipboard-line"}
6988
priority="tertiary no outline"
7089
title="Copy to clipboard"
71-
onClick={() => {
72-
copyToClipboard(textToCopy);
73-
setIsCopiedFeedbackShown(true);
74-
}}
90+
onClick={onButtonClick}
7591
/>
7692
)}
7793
</div>

0 commit comments

Comments
 (0)