@@ -9,16 +9,23 @@ import * as R from 'ramda'
9
9
10
10
const fallback = { }
11
11
12
+ const rootFontSize = 16
13
+
14
+ const px = ( unit ) => `${ unit } px`
15
+ const em = ( unit ) => `${ unit } em`
16
+ const rem = ( unit ) => `${ unit } rem`
17
+
12
18
const buildProps = ( states ) => {
13
19
let buttonProps = { }
14
20
15
21
const pressed = R . find ( withName ( 'pressed' ) , states )
16
22
const hovered = R . find ( withName ( 'hover' ) , states )
17
23
const focused = R . find ( withName ( 'focused' ) , states )
18
24
const enabled = R . find ( withName ( 'enabled' ) , states )
25
+ const disabled = R . find ( withName ( 'disabled' ) , states )
19
26
20
- if ( enabled ) {
21
- const components = enabled . children
27
+ if ( enabled || disabled ) {
28
+ const components = ( enabled || disabled ) . children
22
29
const button = R . find ( withName ( 'button' ) , components )
23
30
const label = R . find ( withName ( 'label' ) , components )
24
31
const spacing = R . filter ( withName ( 'spacing' ) , components )
@@ -27,44 +34,53 @@ const buildProps = (states) => {
27
34
if ( button ) {
28
35
const button_ = R . head ( button . children )
29
36
const { cornerRadius, strokeWeight, absoluteBoundingBox } = button_
30
- const { height} = absoluteBoundingBox
37
+ const { height } = absoluteBoundingBox
31
38
const fill = button_ . fills . find ( withType ( 'solid' ) ) || fallback
32
39
const stroke = button_ . strokes . find ( withType ( 'solid' ) ) || fallback
33
40
34
41
buttonProps = {
35
42
...buttonProps ,
36
- cornerRadius,
37
- height,
43
+ height : px ( height ) ,
38
44
background : colortoRgba ( fill . color ) ,
39
- borderColor : colortoRgba ( stroke . color ) ,
40
- borderWidth : strokeWeight ,
45
+ border : {
46
+ color : colortoRgba ( stroke . color ) ,
47
+ width : px ( strokeWeight ) ,
48
+ radius : px ( cornerRadius ) ,
49
+ } ,
41
50
}
42
51
}
43
52
44
53
if ( label ) {
45
54
const {
46
- fontPostScriptName ,
55
+ fontFamily ,
47
56
fontSize,
48
57
fontWeight,
49
58
letterSpacing,
50
- lineHeightPx,
59
+ textAlignHorizontal = 'center' ,
60
+ lineHeightPercentFontSize,
51
61
} = label . style
62
+ const fill = label . fills . find ( withType ( 'solid' ) ) || fallback
52
63
64
+ const fontSizeRem = ( fontSize / rootFontSize ) . toFixed ( 3 )
65
+ const lineHeightEm = ( lineHeightPercentFontSize / 100 ) . toFixed ( 3 )
66
+ const letterSpacingEm = ( letterSpacing / fontSizeRem ) . toFixed ( 3 )
53
67
buttonProps = {
54
68
...buttonProps ,
69
+ color : colortoRgba ( fill . color ) ,
55
70
typography : {
56
- font : fontPostScriptName ,
57
- fontSize,
71
+ fontFamily ,
72
+ fontSize : rem ( fontSizeRem ) ,
58
73
fontWeight,
59
- letterSpacing,
60
- lineHeight : lineHeightPx ,
74
+ letterSpacing : letterSpacing ? em ( letterSpacingEm ) : 0 ,
75
+ lineHeight : em ( lineHeightEm ) ,
76
+ textAlign : R . toLower ( textAlignHorizontal ) ,
61
77
} ,
62
78
}
63
79
}
64
80
65
81
if ( spacing . length > 0 ) {
66
82
// Spacing can be used in any form, so we create an object
67
- // with names prefixed with "Spacing" in figma
83
+ // with names prefixed with "Spacing" in figma´
68
84
const spacingProps = R . reduce (
69
85
( acc , val ) => {
70
86
const spacer = R . head ( val . children )
@@ -76,7 +92,7 @@ const buildProps = (states) => {
76
92
)
77
93
return {
78
94
...acc ,
79
- [ name ] : spacingValue ,
95
+ [ name ] : px ( spacingValue ) ,
80
96
}
81
97
}
82
98
return acc
@@ -94,10 +110,12 @@ const buildProps = (states) => {
94
110
if ( clickbounds ) {
95
111
const clickbound = R . head ( clickbounds . children )
96
112
const { height } = clickbound . absoluteBoundingBox
113
+ const clickboundOffset = ( height - parseInt ( buttonProps . height , 10 ) ) / 2
97
114
98
115
buttonProps = {
99
116
...buttonProps ,
100
- clickbound : height ,
117
+ clickbound : px ( height ) ,
118
+ clickboundOffset : px ( clickboundOffset ) ,
101
119
}
102
120
}
103
121
}
@@ -117,8 +135,8 @@ const buildProps = (states) => {
117
135
focus : {
118
136
type : focusStyle ,
119
137
color : colortoRgba ( stroke . color ) ,
120
- width : dashWidth ,
121
- gap : dashGap ,
138
+ width : px ( dashWidth ) ,
139
+ gap : px ( dashGap ) ,
122
140
} ,
123
141
}
124
142
}
0 commit comments