@@ -13,6 +13,7 @@ export const MARGIN_KEY_PATTERN = new RegExp(`margin[LTRBHV]?-([0-9]*|${Spacings
13
13
export const ALIGNMENT_KEY_PATTERN = / ( l e f t | t o p | r i g h t | b o t t o m | c e n t e r | c e n t e r V | c e n t e r H | s p r e a d ) / ;
14
14
export const POSITION_KEY_PATTERN = / ^ a b s ( [ F | L | R | T | B | V | H ] ) ? $ / ;
15
15
const BACKGROUND_COLOR_KEYS_PATTERN = Colors . getBackgroundKeysPattern ( ) ;
16
+ export const GAP_KEY_PATTERN = new RegExp ( `gap-([0-9]*|${ Spacings . getKeysPattern ( ) } )` ) ;
16
17
17
18
export interface AlteredOptions {
18
19
flex ?: boolean ;
@@ -33,6 +34,7 @@ export interface ExtractedStyle {
33
34
alignments ?: ReturnType < typeof extractAlignmentsValues > ;
34
35
flexStyle ?: ReturnType < typeof extractFlexStyle > ;
35
36
positionStyle ?: ReturnType < typeof extractPositionStyle > ;
37
+ gap ?: ReturnType < typeof extractGapValues > ;
36
38
}
37
39
38
40
export type ModifiersOptions = {
@@ -45,6 +47,7 @@ export type ModifiersOptions = {
45
47
alignments ?: boolean ;
46
48
flex ?: boolean ;
47
49
position ?: boolean ;
50
+ gap ?: boolean ;
48
51
} ;
49
52
50
53
const PADDING_VARIATIONS = {
@@ -74,11 +77,11 @@ const STYLE_KEY_CONVERTERS = {
74
77
} as const ;
75
78
76
79
export type PaddingLiterals = keyof typeof PADDING_VARIATIONS ;
77
- export type NativePaddingKeyType = typeof PADDING_VARIATIONS [ PaddingLiterals ] ;
80
+ export type NativePaddingKeyType = ( typeof PADDING_VARIATIONS ) [ PaddingLiterals ] ;
78
81
export type MarginLiterals = keyof typeof MARGIN_VARIATIONS ;
79
- export type NativeMarginModifierKeyType = typeof MARGIN_VARIATIONS [ MarginLiterals ] ;
82
+ export type NativeMarginModifierKeyType = ( typeof MARGIN_VARIATIONS ) [ MarginLiterals ] ;
80
83
export type FlexLiterals = keyof typeof STYLE_KEY_CONVERTERS ;
81
- export type NativeFlexModifierKeyType = typeof STYLE_KEY_CONVERTERS [ FlexLiterals ] ;
84
+ export type NativeFlexModifierKeyType = ( typeof STYLE_KEY_CONVERTERS ) [ FlexLiterals ] ;
82
85
export type ColorLiterals = keyof ( typeof colorsPalette & typeof DesignTokens ) ;
83
86
export type TypographyLiterals = keyof typeof TypographyPresets ;
84
87
export type BorderRadiusLiterals = keyof typeof BorderRadiusesLiterals ;
@@ -93,6 +96,7 @@ export type AlignmentLiterals =
93
96
| 'top'
94
97
| 'bottom' ;
95
98
export type PositionLiterals = 'absF' | 'absL' | 'absR' | 'absT' | 'absB' | 'absV' | 'absH' ;
99
+ export type GapLiterals = 'gap' ;
96
100
97
101
export type Modifier < T extends string > = Partial < Record < T , boolean > > ;
98
102
export type CustomModifier = { [ key : string ] : boolean } ;
@@ -109,14 +113,16 @@ export type MarginModifiers = Modifier<MarginLiterals>;
109
113
// export type MarginModifiers = Partial<{[key: `${MarginLiterals}-${number}`]: boolean}>;
110
114
export type FlexModifiers = Modifier < FlexLiterals > ;
111
115
export type BorderRadiusModifiers = Modifier < BorderRadiusLiterals > ;
116
+ export type GapModifiers = Modifier < GapLiterals > ;
112
117
113
118
export type ContainerModifiers = AlignmentModifiers &
114
119
PositionModifiers &
115
120
PaddingModifiers &
116
121
MarginModifiers &
117
122
FlexModifiers &
118
123
BorderRadiusModifiers &
119
- BackgroundColorModifier ;
124
+ BackgroundColorModifier &
125
+ GapModifiers ;
120
126
121
127
export function extractColorValue ( props : Dictionary < any > ) {
122
128
const colorPropsKeys = Object . keys ( props ) . filter ( key => Colors [ key ] !== undefined ) ;
@@ -187,6 +193,23 @@ export function extractMarginValues(props: Dictionary<any>) {
187
193
return margins ;
188
194
}
189
195
196
+ export function extractGapValues ( props : Dictionary < any > ) {
197
+ const gap : { gap ?: number } = { } ;
198
+ const gapPropsKeys = Object . keys ( props ) . filter ( key => GAP_KEY_PATTERN . test ( key ) ) ;
199
+ // Taking only the last one
200
+ const gapModifier = _ . findLast ( gapPropsKeys , key => props [ key ] === true ) ;
201
+ if ( gapModifier ) {
202
+ const [ , gapValue ] = gapModifier . split ( '-' ) as [ 'gap' , 'string' ] ;
203
+ const parsedNumber = Number ( gapValue ) ;
204
+ if ( ! isNaN ( parsedNumber ) ) {
205
+ gap . gap = parsedNumber ;
206
+ } else if ( Spacings . getKeysPattern ( ) . test ( gapValue ) ) {
207
+ gap . gap = Spacings [ gapValue as keyof typeof SpacingLiterals ] ;
208
+ }
209
+ }
210
+ return gap ;
211
+ }
212
+
190
213
export function extractAlignmentsValues ( props : Dictionary < any > ) {
191
214
const { row, center} = props ;
192
215
const alignments : any = { } ;
@@ -306,6 +329,7 @@ export function extractModifierProps(props: Dictionary<any>) {
306
329
PADDING_KEY_PATTERN ,
307
330
MARGIN_KEY_PATTERN ,
308
331
ALIGNMENT_KEY_PATTERN ,
332
+ GAP_KEY_PATTERN ,
309
333
Colors . getBackgroundKeysPattern ( )
310
334
] ;
311
335
const modifierProps = _ . pickBy ( props , ( _value , key ) => {
@@ -338,7 +362,9 @@ export function extractComponentProps(component: any, props: Dictionary<any>, ig
338
362
}
339
363
340
364
//@ts -ignore
341
- export function getThemeProps < T extends object > ( props : T = this . props , context = this . context , componentDisplayName = '' ) :T {
365
+ export function getThemeProps < T extends object > ( props : T = this . props ,
366
+ context = this . context ,
367
+ componentDisplayName = '' ) : T {
342
368
const componentName =
343
369
//@ts -ignore
344
370
componentDisplayName || this . displayName || this . constructor . displayName || this . constructor . name ;
@@ -368,7 +394,8 @@ export function generateModifiersStyle(options: ModifiersOptions = {
368
394
margins : true ,
369
395
alignments : true ,
370
396
flex : true ,
371
- position : true
397
+ position : true ,
398
+ gap : true
372
399
} ,
373
400
props : Dictionary < any > ) {
374
401
//@ts -ignore
@@ -406,6 +433,9 @@ props: Dictionary<any>) {
406
433
if ( options . position ) {
407
434
style . positionStyle = extractPositionStyle ( boundProps ) ;
408
435
}
436
+ if ( options . gap ) {
437
+ style . gap = extractGapValues ( boundProps ) ;
438
+ }
409
439
410
440
return style ;
411
441
// clean empty objects and undefined
0 commit comments