@@ -21,6 +21,10 @@ interface Props {
21
21
* Is the initial state is selected
22
22
*/
23
23
selected ?: boolean ;
24
+ /**
25
+ * Is the initial state is unavailable
26
+ */
27
+ unavailable ?: boolean ;
24
28
/**
25
29
* Is first render should be animated
26
30
*/
@@ -32,6 +36,10 @@ interface Props {
32
36
index ?: number ;
33
37
style ?: StyleProp < ViewStyle > ;
34
38
testID ?: string ;
39
+ /**
40
+ * Color swatch size
41
+ */
42
+ size ?: number ;
35
43
}
36
44
export type ColorSwatchProps = Props ;
37
45
@@ -133,7 +141,7 @@ class ColorSwatch extends PureComponent<Props> {
133
141
} ;
134
142
135
143
renderContent ( ) {
136
- const { style, color, onPress, ...others } = this . props ;
144
+ const { style, color, onPress, unavailable , size = DEFAULT_SIZE , ...others } = this . props ;
137
145
const { isSelected} = this . state ;
138
146
const Container = onPress ? TouchableOpacity : View ;
139
147
const tintColor = this . getTintColor ( color ) ;
@@ -147,21 +155,25 @@ class ColorSwatch extends PureComponent<Props> {
147
155
throttleTime = { 0 }
148
156
hitSlop = { { top : 10 , bottom : 10 , left : 10 , right : 10 } }
149
157
onPress = { this . onPress }
150
- style = { [ this . styles . container , style ] }
158
+ style = { [ this . styles . container , { width : size , height : size , borderRadius : size / 2 } , style ] }
151
159
onLayout = { this . onLayout }
152
160
{ ...accessibilityInfo }
153
161
>
154
162
{ Colors . isTransparent ( color ) && (
155
163
< Image source = { transparentImage } style = { this . styles . transparentImage } resizeMode = { 'cover' } />
156
164
) }
157
- < Animated . Image
158
- source = { Assets . icons . check }
159
- style = { {
160
- tintColor,
161
- opacity : isSelected ,
162
- transform : [ { scaleX : isSelected } , { scaleY : isSelected } ]
163
- } }
164
- />
165
+ { unavailable ? (
166
+ < View style = { [ this . styles . unavailable , { backgroundColor : tintColor } ] } />
167
+ ) : (
168
+ < Animated . Image
169
+ source = { Assets . icons . check }
170
+ style = { {
171
+ tintColor,
172
+ opacity : isSelected ,
173
+ transform : [ { scaleX : isSelected } , { scaleY : isSelected } ]
174
+ } }
175
+ />
176
+ ) }
165
177
</ Container >
166
178
) ;
167
179
}
@@ -196,12 +208,9 @@ function createStyles({color = Colors.grey30}) {
196
208
return StyleSheet . create ( {
197
209
container : {
198
210
backgroundColor : color ,
199
- width : DEFAULT_SIZE ,
200
- height : DEFAULT_SIZE ,
201
- borderRadius : DEFAULT_SIZE / 2 ,
202
- margin : SWATCH_MARGIN ,
203
211
borderWidth : color === 'transparent' ? undefined : 1 ,
204
- borderColor : Colors . rgba ( Colors . $outlineDisabledHeavy , 0.2 )
212
+ borderColor : Colors . rgba ( Colors . $outlineDisabledHeavy , 0.2 ) ,
213
+ margin : SWATCH_MARGIN
205
214
} ,
206
215
transparentImage : {
207
216
...StyleSheet . absoluteFillObject ,
@@ -210,6 +219,12 @@ function createStyles({color = Colors.grey30}) {
210
219
borderWidth : 1 ,
211
220
borderRadius : BorderRadiuses . br100 ,
212
221
borderColor : Colors . rgba ( Colors . $outlineDisabledHeavy , 0.2 )
222
+ } ,
223
+ unavailable : {
224
+ height : '100%' ,
225
+ width : 3 ,
226
+ transform : [ { rotate : '45deg' } ] ,
227
+ opacity : 0.7
213
228
}
214
229
} ) ;
215
230
}
0 commit comments