@@ -2,7 +2,7 @@ import React from "react";
22import type { ColorDecisionAndCorrespondingOption } from "../../scripts/build/cssToTs/colorDecisionAndCorrespondingOptions" ;
33import { fr } from "../../dist/fr" ;
44import Tooltip from "@mui/material/Tooltip" ;
5- import { useStyles } from "./makeStyles " ;
5+ import { useStyles } from "tss-react " ;
66import { CopyToClipboardButton } from "./CopyToClipboardButton" ;
77import { Accordion } from "../../dist/Accordion" ;
88import { Evt } from "evt" ;
@@ -39,29 +39,20 @@ export function ColorDecisionCard(
3939 "color" : fr . colors . decisions . text . mention . grey . default
4040 } }
4141 >
42- Color Decision path
43- { /*
44- <Tooltip
45- title={
46- <a href="https://guides.react-dsfr.fr/css-in-js#colors" target="_blank">
47- How to access the <code>theme</code> object
48- </a>
49- }
50- placement="top"
51- arrow
52- >
53- <i className={fr.cx("ri-information-line")} />
54- </Tooltip>{" "}
55- */ }
56- :
42+ Color Decision path :
5743 </ span >
5844
5945 < code >
6046 < Tooltip
47+ classes = { {
48+ tooltip : css ( {
49+ "maxWidth" : "none"
50+ } )
51+ } }
6152 title = {
6253 < code
6354 style = { {
64- "fontSize" : "1.2em "
55+ "fontSize" : "1.7em "
6556 } }
6657 >
6758 var({ colorDecisionName } )
@@ -78,7 +69,7 @@ export function ColorDecisionCard(
7869 </ Tooltip >
7970 </ code >
8071 < CopyToClipboardButton
81- textToCopy = { [ "theme " , "decisions" , ...themePath ] . join ( "." ) }
72+ textToCopy = { [ "fr" , "colors ", "decisions" , ...themePath ] . join ( "." ) }
8273 evtAction = { evtCopyToClipboardButtonAction }
8374 />
8475 </ div >
@@ -101,32 +92,66 @@ export function ColorDecisionCard(
10192 < div style = { { "marginTop" : fr . spacing ( "2v" ) } } >
10293 { typeof colorOption . color === "string" ? (
10394 < >
104- < span > Colors: </ span > : < ColoredSquare hexColorCode = { colorOption . color } />
95+ < span
96+ style = { {
97+ "color" : fr . colors . decisions . text . mention . grey . default
98+ } }
99+ >
100+ Hex color code:
101+ < Tooltip
102+ title = {
103+ "This decision resolve the the same hex color code in both dark and light mode"
104+ }
105+ placement = "top"
106+ arrow
107+ >
108+ < i className = { fr . cx ( "ri-information-line" ) } />
109+ </ Tooltip >
110+ </ span >
111+
112+ < ColoredSquare
113+ hexColorCode = { colorOption . color }
114+ isDark = { false }
115+ themePath = { themePath }
116+ />
105117 </ >
106118 ) : (
107119 < >
108120 < span
109121 style = { {
110- "color" : fr . colors . decisions . text . mention . grey . default
122+ "color" : fr . colors . decisions . text . mention . grey . default ,
123+ "marginRight" : 2
111124 } }
112125 >
113- Dark mode:{ " " }
126+ Dark mode:
114127 </ span >
115- < ColoredSquare hexColorCode = { colorOption . color . dark } />
116128
129+ < ColoredSquare
130+ hexColorCode = { colorOption . color . dark }
131+ themePath = { themePath }
132+ isDark = { true }
133+ />
134+ < br />
117135 < span
118136 style = { {
119- "color" : fr . colors . decisions . text . mention . grey . default
137+ "display" : "inline-block" ,
138+ "color" : fr . colors . decisions . text . mention . grey . default ,
139+ "marginTop" : fr . spacing ( "5v" )
120140 } }
121141 >
122- Light mode:{ " " }
142+ Light mode:
123143 </ span >
124- < ColoredSquare hexColorCode = { colorOption . color . light } />
144+
145+ < ColoredSquare
146+ hexColorCode = { colorOption . color . light }
147+ themePath = { themePath }
148+ isDark = { false }
149+ />
125150 </ >
126151 ) }
127152 </ div >
128153 < Accordion
129- className = { css ( { "marginTop" : fr . spacing ( "4v " ) } ) }
154+ className = { css ( { "marginTop" : fr . spacing ( "5v " ) } ) }
130155 label = "Corresponding color option"
131156 >
132157 < p >
@@ -160,30 +185,69 @@ export function ColorDecisionCard(
160185 ) ;
161186}
162187
163- function ColoredSquare ( props : { hexColorCode : string } ) {
164- const { hexColorCode } = props ;
188+ function ColoredSquare ( props : {
189+ hexColorCode : string ;
190+ themePath : readonly string [ ] ;
191+ isDark : boolean ;
192+ } ) {
193+ const { hexColorCode, themePath, isDark } = props ;
194+
195+ const { css } = useStyles ( ) ;
196+
197+ const evtCopyToClipboardButtonAction = useConst ( ( ) => Evt . create < "trigger click" > ( ) ) ;
198+
199+ const codeToGetHex = `fr.colors.getHex({ isDark: ${
200+ isDark ? "true" : "false"
201+ } }).decisions${ themePath . join ( "." ) } `;
165202
166203 return (
167- < div
168- style = { {
169- display : "inline"
204+ < Tooltip
205+ classes = { {
206+ tooltip : css ( {
207+ "maxWidth" : "none"
208+ } )
170209 } }
210+ title = {
211+ < code
212+ style = { {
213+ "fontSize" : "1.5em"
214+ } }
215+ >
216+ { codeToGetHex }
217+ </ code >
218+ }
219+ placement = "top"
220+ arrow
171221 >
172- < code > { hexColorCode } </ code >
173-
174- < div
175- style = { {
176- "display" : "inline-block" ,
177- "borderWidth" : 2 ,
178- "borderStyle" : "solid" ,
179- "borderColor" : fr . colors . decisions . border . default . grey . default ,
180- "width" : 30 ,
181- "height" : 30 ,
182- "backgroundColor" : hexColorCode ,
183- "position" : "relative" ,
184- "top" : 8
185- } }
186- />
187- </ div >
222+ < div style = { { "display" : "inline-block" } } >
223+ < div
224+ style = { {
225+ display : "inline-block"
226+ } }
227+ onClick = { ( ) => evtCopyToClipboardButtonAction . post ( "trigger click" ) }
228+ >
229+ < div
230+ style = { {
231+ "display" : "inline-block" ,
232+ "borderWidth" : 2 ,
233+ "borderStyle" : "solid" ,
234+ "borderColor" : fr . colors . decisions . border . default . grey . default ,
235+ "width" : 30 ,
236+ "height" : 30 ,
237+ "backgroundColor" : hexColorCode ,
238+ "position" : "relative" ,
239+ "top" : 8
240+ } }
241+ />
242+
243+ < code > { hexColorCode } </ code >
244+ </ div >
245+
246+ < CopyToClipboardButton
247+ textToCopy = { codeToGetHex }
248+ evtAction = { evtCopyToClipboardButtonAction }
249+ />
250+ </ div >
251+ </ Tooltip >
188252 ) ;
189253}
0 commit comments