File tree 3 files changed +43
-4
lines changed
3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,29 @@ import type {
5
5
Size , SizeAlias , Spacing , SpacingAlias
6
6
} from './types' ;
7
7
8
+ const isNegativeAlias = ( alias : string ) => (
9
+ alias . charAt ( 0 ) === '-'
10
+ ) ;
11
+
12
+ const translateSpacing = (
13
+ alias : SpacingAlias ,
14
+ scale : { [ x : SpacingAlias ] : Spacing }
15
+ ) : Spacing | undefined => {
16
+ if ( ! alias ) { return undefined ; }
17
+
18
+ let scaleAlias = String ( alias ) ;
19
+ let isNegative = false ;
20
+
21
+ if ( isNegativeAlias ( scaleAlias ) ) {
22
+ isNegative = true ;
23
+ scaleAlias = scaleAlias . slice ( 1 ) ;
24
+ }
25
+
26
+ if ( ! scale [ scaleAlias ] ) { return undefined ; }
27
+
28
+ return Number ( scale [ scaleAlias ] ) * ( isNegative ? - 1 : 1 ) ;
29
+ } ;
30
+
8
31
export default class Layout {
9
32
private _config : LayoutConfig ;
10
33
@@ -19,7 +42,7 @@ export default class Layout {
19
42
}
20
43
21
44
spacing ( alias : SpacingAlias ) : Spacing | undefined {
22
- return this . _config . spacings [ alias ] ;
45
+ return translateSpacing ( alias , this . _config . spacings ) ;
23
46
}
24
47
25
48
size ( alias : SizeAlias ) : Size | undefined {
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ export default {
23
23
size : 'xs' ,
24
24
marginLeft : '2' ,
25
25
color : 'primary.900' ,
26
+ padding : 0.5 ,
27
+ marginY : - 0.5 ,
26
28
borderRadius : 'full' ,
27
29
__pressed : {
28
30
backgroundColor : 'secondary.300'
Original file line number Diff line number Diff line change @@ -19,15 +19,29 @@ export type ColorType = Leaves<IThemeConfig[ 'palette' ][ 'base' ]>
19
19
20
20
type RNStyles = ViewStyle & ImageStyle & TextStyle ;
21
21
22
+ type GetLayoutScaleValuesWithNegativeValues <
23
+ T extends keyof IThemeConfig [ 'layout' ]
24
+ > = {
25
+ [ K in keyof IThemeConfig [ 'layout' ] [ T ] ] -?: K extends string | number
26
+ ? K | `-${K } `
27
+ : never
28
+ } [ keyof IThemeConfig [ 'layout' ] [ T ] ]
29
+
30
+ type SpaceType = GetLayoutScaleValuesWithNegativeValues < 'spacings' >
31
+ | ( string & { } )
32
+ | ( number & { } ) ;
33
+
22
34
type GetThemeScaleValues < T extends keyof IThemeConfig > = 'palette' extends T
23
35
? ColorType
24
36
: keyof IThemeConfig [ T ] | ( string & { } ) | ( number & { } ) ;
25
37
26
38
type GetThemeCategorizedScaleValues <
27
39
T extends keyof IThemeConfig , Y extends keyof IThemeConfig [ T ]
28
- > = (
29
- keyof IThemeConfig [ T ] [ Y ] | ( string & { } ) | ( number & { } )
30
- ) ;
40
+ > = 'layout' extends T
41
+ ? 'spacings' extends Y
42
+ ? SpaceType
43
+ : keyof IThemeConfig [ T ] [ Y ] | ( string & { } ) | ( number & { } )
44
+ : keyof IThemeConfig [ T ] [ Y ] | ( string & { } ) | ( number & { } ) ;
31
45
32
46
type GetCategorizedRNStyles < key , category extends keyof IThemeConfig , scale = null > = (
33
47
scale extends keyof IThemeConfig [ category ]
You can’t perform that action at this time.
0 commit comments