2
2
3
3
const { get, times } = lodash ;
4
4
const { registerBlockType } = wp . blocks ;
5
- const { RichText, InspectorControls } = wp . editor ;
6
- const { PanelBody, RangeControl } = wp . components ;
5
+ const { RichText, InspectorControls, ColorPalette } = wp . editor ;
6
+ const { PanelBody, RangeControl, BaseControl } = wp . components ;
7
7
const { Fragment } = wp . element ;
8
8
const { __ , sprintf } = wp . i18n ;
9
9
@@ -13,20 +13,36 @@ registerBlockType('snow-monkey-awesome-custom-blocks/faq', {
13
13
category : 'smacb' ,
14
14
attributes : {
15
15
content : {
16
+ type : 'array' ,
16
17
source : 'query' ,
17
18
selector : '.smacb-faq__item' ,
19
+ default : [ ] ,
18
20
query : {
19
21
question : {
20
22
type : 'array' ,
21
23
source : 'children' ,
22
- selector : '.smacb-faq__item__question ' ,
24
+ selector : '.smacb-faq__item__question__body ' ,
23
25
default : [ ] ,
24
26
} ,
25
27
answer : {
26
28
type : 'array' ,
27
29
source : 'children' ,
28
- selector : '.smacb-faq__item__answer ' ,
30
+ selector : '.smacb-faq__item__answer__body ' ,
29
31
default : [ ] ,
32
+ } ,
33
+ questionColor : {
34
+ type : 'string' ,
35
+ default : '' ,
36
+ source : 'attribute' ,
37
+ selector : '.smacb-faq__item__question__label' ,
38
+ attribute : 'data-color' ,
39
+ } ,
40
+ answerColor : {
41
+ type : 'string' ,
42
+ default : '' ,
43
+ source : 'attribute' ,
44
+ selector : '.smacb-faq__item__answer__label' ,
45
+ attribute : 'data-color' ,
30
46
}
31
47
}
32
48
} ,
@@ -58,33 +74,71 @@ registerBlockType('snow-monkey-awesome-custom-blocks/faq', {
58
74
max = "50"
59
75
/>
60
76
</ PanelBody >
77
+
78
+ { times ( rows , ( index ) => {
79
+ const questionColor = get ( content , [ index , 'questionColor' ] , '' ) ;
80
+ const answerColor = get ( content , [ index , 'answerColor' ] , '' ) ;
81
+
82
+ return (
83
+ < PanelBody
84
+ title = { sprintf ( __ ( '(%d) Item Settings' , 'snow-monkey-awesome-custom-blocks' ) , index + 1 ) }
85
+ initialOpen = { false }
86
+ >
87
+ < BaseControl label = { __ ( 'Question Color' , 'snow-monkey-awesome-custom-blocks' ) } >
88
+ < ColorPalette
89
+ value = { questionColor }
90
+ onChange = { value => setAttributes ( { content : generateUpdatedAttribute ( content , index , 'questionColor' , value ) } ) }
91
+ />
92
+ </ BaseControl >
93
+
94
+ < BaseControl label = { __ ( 'Answer Color' , 'snow-monkey-awesome-custom-blocks' ) } >
95
+ < ColorPalette
96
+ value = { answerColor }
97
+ onChange = { value => setAttributes ( { content : generateUpdatedAttribute ( content , index , 'answerColor' , value ) } ) }
98
+ />
99
+ </ BaseControl >
100
+ </ PanelBody >
101
+ ) ;
102
+ } ) }
61
103
</ InspectorControls >
62
104
63
105
< div className = "smacb-faq" >
64
106
< div className = "smacb-faq__body" >
65
107
{ times ( rows , ( index ) => {
66
- const question = get ( content , [ index , 'question' ] , [ ] ) ;
67
- const answer = get ( content , [ index , 'answer' ] , [ ] ) ;
108
+ const question = get ( content , [ index , 'question' ] , [ ] ) ;
109
+ const answer = get ( content , [ index , 'answer' ] , [ ] ) ;
110
+ const questionColor = get ( content , [ index , 'questionColor' ] , '' ) ;
111
+ const answerColor = get ( content , [ index , 'answerColor' ] , '' ) ;
68
112
69
113
return (
70
114
< div className = "smacb-faq__item" >
71
- < RichText
72
- className = "smacb-faq__item__question"
73
- placeholder = { __ ( 'Write question…' , 'snow-monkey-awesome-custom-blocks' ) }
74
- value = { question }
75
- formattingControls = { [ ] }
76
- multiline = { false }
77
- onChange = { value => setAttributes ( { content : generateUpdatedAttribute ( content , index , 'question' , value ) } ) }
78
- />
115
+ < div className = "smacb-faq__item__question" >
116
+ < div className = "smacb-faq__item__question__label" style = { { color : questionColor } } data-color = { questionColor } >
117
+ Q
118
+ </ div >
119
+ < RichText
120
+ className = "smacb-faq__item__question__body"
121
+ placeholder = { __ ( 'Write question…' , 'snow-monkey-awesome-custom-blocks' ) }
122
+ value = { question }
123
+ formattingControls = { [ ] }
124
+ multiline = { false }
125
+ onChange = { value => setAttributes ( { content : generateUpdatedAttribute ( content , index , 'question' , value ) } ) }
126
+ />
127
+ </ div >
79
128
80
- < RichText
81
- className = "smacb-faq__item__answer"
82
- placeholder = { __ ( 'Write answer…' , 'snow-monkey-awesome-custom-blocks' ) }
83
- value = { answer }
84
- formattingControls = { [ ] }
85
- multiline = "p"
86
- onChange = { value => setAttributes ( { content : generateUpdatedAttribute ( content , index , 'answer' , value ) } ) }
87
- />
129
+ < div className = "smacb-faq__item__answer" >
130
+ < div className = "smacb-faq__item__answer__label" style = { { color : answerColor } } data-color = { answerColor } >
131
+ A
132
+ </ div >
133
+ < RichText
134
+ className = "smacb-faq__item__answer__body"
135
+ placeholder = { __ ( 'Write answer…' , 'snow-monkey-awesome-custom-blocks' ) }
136
+ value = { answer }
137
+ formattingControls = { [ ] }
138
+ multiline = "p"
139
+ onChange = { value => setAttributes ( { content : generateUpdatedAttribute ( content , index , 'answer' , value ) } ) }
140
+ />
141
+ </ div >
88
142
</ div >
89
143
) ;
90
144
} ) }
@@ -101,16 +155,29 @@ registerBlockType('snow-monkey-awesome-custom-blocks/faq', {
101
155
< div className = "smacb-faq" >
102
156
< div className = "smacb-faq__body" >
103
157
{ times ( rows , ( index ) => {
104
- const question = get ( content , [ index , 'question' ] , [ ] ) ;
105
- const answer = get ( content , [ index , 'answer' ] , [ ] ) ;
158
+ const question = get ( content , [ index , 'question' ] , [ ] ) ;
159
+ const answer = get ( content , [ index , 'answer' ] , [ ] ) ;
160
+ const questionColor = get ( content , [ index , 'questionColor' ] , '' ) ;
161
+ const answerColor = get ( content , [ index , 'answerColor' ] , '' ) ;
106
162
107
163
return (
108
164
< div className = "smacb-faq__item" >
109
165
< div className = "smacb-faq__item__question" >
110
- { question }
166
+ < div className = "smacb-faq__item__question__label" style = { { color : questionColor } } data-color = { questionColor } >
167
+ Q
168
+ </ div >
169
+ < div className = "smacb-faq__item__question__body" >
170
+ { question }
171
+ </ div >
111
172
</ div >
173
+
112
174
< div className = "smacb-faq__item__answer" >
113
- { answer }
175
+ < div className = "smacb-faq__item__answer__label" style = { { color : answerColor } } data-color = { answerColor } >
176
+ A
177
+ </ div >
178
+ < div className = "smacb-faq__item__answer__body" >
179
+ { answer }
180
+ </ div >
114
181
</ div >
115
182
</ div >
116
183
) ;
0 commit comments