1
1
import { Box , Card , Divider , Inline , Label , Stack } from "@buildo/bento-design-system" ;
2
- import { ThemeConfig } from "../ConfiguratorStatusContext" ;
2
+ import { ThemeConfig , useConfiguratorStatusContext } from "../ConfiguratorStatusContext" ;
3
3
import { colorBoxRecipe } from "./PalettesDropdown.css" ;
4
4
import { SelectState } from "@react-stately/select" ;
5
5
import { AriaListBoxOptions , useListBox , useOption } from "@react-aria/listbox" ;
6
- import { Key , useRef } from "react" ;
6
+ import { useRef } from "react" ;
7
7
import { useTranslation } from "react-i18next" ;
8
+ import { Node } from "@react-types/shared" ;
9
+ import { PaletteName , getPalette , getPaletteKeyColor } from "../utils/paletteUtils" ;
8
10
9
11
type Props = {
10
12
colors : ThemeConfig [ "colors" ] ;
11
- value : string | null ;
12
- onChange : ( value : string ) => void ;
13
13
state : SelectState < object > ;
14
14
menuProps : AriaListBoxOptions < object > ;
15
15
} ;
16
16
17
17
function ColorBox ( {
18
- color,
19
- colorKey,
18
+ item,
20
19
state,
20
+ color,
21
21
} : {
22
- color : string ;
23
- colorKey : Key ;
22
+ item : Node < object > ;
24
23
state : SelectState < object > ;
24
+ color : string ;
25
25
} ) {
26
26
const ref = useRef ( null ) ;
27
- const { optionProps, isSelected } = useOption ( { key : colorKey } , state , ref ) ;
27
+ const { optionProps, isSelected } = useOption ( { key : item . key } , state , ref ) ;
28
+
28
29
return (
29
30
< Box
30
31
ref = { ref }
@@ -36,27 +37,27 @@ function ColorBox({
36
37
) ;
37
38
}
38
39
39
- function Palette ( props : {
40
- name : string ;
41
- onChange : ( value : string ) => void ;
42
- value : string | null ;
43
- state : SelectState < object > ;
44
- } ) {
45
- const colors = [ ...props . state . collection . getChildren ! ( props . name ) ] ;
40
+ function Palette ( props : { name : PaletteName ; state : SelectState < object > } ) {
41
+ const colors = useConfiguratorStatusContext ( ) . theme . colors ;
42
+ const colorItems = [ ...props . state . collection . getChildren ! ( props . name ) ] ;
43
+ const keyColor = getPaletteKeyColor ( props . name , colors ) ;
44
+ if ( keyColor ) {
45
+ const palette = getPalette ( keyColor ) ;
46
46
47
- return (
48
- < Inline space = { 4 } alignY = "stretch" >
49
- { colors . map ( ( color ) => {
50
- const colorBox = (
51
- < ColorBox colorKey = { color . key } state = { props . state } color = { color . textValue } />
52
- ) ;
53
- if ( color . key . toString ( ) . endsWith ( "reference" ) ) {
54
- return [ < Divider orientation = "vertical" /> , colorBox ] ;
55
- }
56
- return colorBox ;
57
- } ) }
58
- </ Inline >
59
- ) ;
47
+ return (
48
+ < Inline space = { 4 } alignY = "stretch" >
49
+ { colorItems . map ( ( colorItem , index ) => {
50
+ if ( colorItem . key . toString ( ) . endsWith ( "ref" ) ) {
51
+ return [
52
+ < Divider orientation = "vertical" /> ,
53
+ < ColorBox item = { colorItem } state = { props . state } color = { keyColor . referenceColor } /> ,
54
+ ] ;
55
+ }
56
+ return < ColorBox item = { colorItem } state = { props . state } color = { palette [ index ] . value } /> ;
57
+ } ) }
58
+ </ Inline >
59
+ ) ;
60
+ }
60
61
}
61
62
62
63
export function PalettesDropdown ( props : Props ) {
@@ -72,69 +73,48 @@ export function PalettesDropdown(props: Props) {
72
73
< Stack space = { 16 } >
73
74
< Inline space = { 4 } >
74
75
{ [ ...props . state . collection . getChildren ! ( "General" ) ] . map ( ( color ) => (
75
- < ColorBox color = { color . key as string } colorKey = { color . key } state = { props . state } />
76
+ < ColorBox item = { color } color = { color . textValue } state = { props . state } />
76
77
) ) }
77
78
</ Inline >
78
79
< Stack space = { 4 } >
79
80
< Label size = "small" > { t ( "ColorsSection.Step.brand" ) } </ Label >
80
- < Palette
81
- name = "BrandPrimary"
82
- onChange = { props . onChange }
83
- value = { props . value }
84
- state = { props . state }
85
- />
81
+ < Palette name = "BrandPrimary" state = { props . state } />
86
82
</ Stack >
87
83
< Stack space = { 4 } >
88
84
< Label size = "small" > { t ( "ColorsSection.Step.interactive" ) } </ Label >
89
85
< Inline space = { 4 } >
90
- < Palette
91
- name = "Interactive"
92
- onChange = { props . onChange }
93
- value = { props . value }
94
- state = { props . state }
95
- />
86
+ < Palette name = "Interactive" state = { props . state } />
96
87
</ Inline >
97
88
</ Stack >
98
89
< Stack space = { 4 } >
99
90
< Label size = "small" > { t ( "ColorsSection.Step.neutral" ) } </ Label >
100
- < Palette
101
- name = "Neutral"
102
- onChange = { props . onChange }
103
- value = { props . value }
104
- state = { props . state }
105
- />
91
+ < Palette name = "Neutral" state = { props . state } />
106
92
</ Stack >
107
93
< Stack space = { 4 } >
108
94
< Label size = "small" > { t ( "ColorsSection.Step.semantic" ) } </ Label >
109
- { [ "Informative" , "Positive" , "Warning" , "Negative" ] . map ( ( semanticColor ) => (
110
- < Palette
111
- name = { semanticColor }
112
- onChange = { props . onChange }
113
- value = { props . value }
114
- state = { props . state }
115
- />
116
- ) ) }
95
+ { ( [ "Informative" , "Positive" , "Warning" , "Negative" ] as PaletteName [ ] ) . map (
96
+ ( semanticColor ) => (
97
+ < Palette name = { semanticColor } state = { props . state } />
98
+ )
99
+ ) }
117
100
</ Stack >
118
101
< Stack space = { 4 } >
119
102
< Label size = "small" > { t ( "ColorsSection.Step.dataVisualization" ) } </ Label >
120
- { [
121
- "Grey" ,
122
- "Red" ,
123
- "Orange" ,
124
- "Yellow" ,
125
- "Green" ,
126
- "Jade" ,
127
- "Blue" ,
128
- "Indigo" ,
129
- "Violet" ,
130
- "Pink" ,
131
- ] . map ( ( dataVizColor ) => (
132
- < Palette
133
- name = { dataVizColor }
134
- onChange = { props . onChange }
135
- value = { props . value }
136
- state = { props . state }
137
- />
103
+ { (
104
+ [
105
+ "Grey" ,
106
+ "Red" ,
107
+ "Orange" ,
108
+ "Yellow" ,
109
+ "Green" ,
110
+ "Jade" ,
111
+ "Blue" ,
112
+ "Indigo" ,
113
+ "Violet" ,
114
+ "Pink" ,
115
+ ] as PaletteName [ ]
116
+ ) . map ( ( dataVizColor ) => (
117
+ < Palette name = { dataVizColor } state = { props . state } />
138
118
) ) }
139
119
</ Stack >
140
120
</ Stack >
0 commit comments