Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 54e13dc

Browse files
committed
refactor: avatarStyles to tuple syntax
1 parent d3f5aa1 commit 54e13dc

File tree

2 files changed

+104
-57
lines changed

2 files changed

+104
-57
lines changed
Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,88 @@
1-
import { pxToRem } from '../../../../lib'
2-
import { ComponentSlotStylesInput, ICSSInJSStyle } from '../../../types'
1+
import { ComponentSelectorsAndStyles } from '../../../types'
32
import { AvatarProps } from '../../../../components/Avatar/Avatar'
3+
import { AvatarVariables } from 'src/themes/teams/components/Avatar/avatarVariables'
4+
import { backportComponentStyle } from 'src/lib/resolveComponentRules'
45

5-
const sizeToPxValue = {
6-
smallest: 24,
7-
smaller: 24,
8-
small: 24,
9-
medium: 32,
10-
large: 36,
11-
larger: 42,
12-
largest: 48,
13-
}
6+
const avatarStyles: ComponentSelectorsAndStyles<AvatarProps, AvatarVariables> = v => ({
7+
root: [
8+
[
9+
null,
10+
{
11+
position: 'relative',
12+
backgroundColor: 'inherit',
13+
display: 'inline-block',
14+
verticalAlign: 'middle',
15+
height: v.medium,
16+
width: v.medium,
17+
},
18+
],
19+
[{ size: 'smallest' }, { width: v.smallest, height: v.smallest }],
20+
[{ size: 'smaller' }, { width: v.smaller, height: v.smaller }],
21+
[{ size: 'small' }, { width: v.small, height: v.small }],
22+
[{ size: 'medium' }, { width: v.medium, height: v.medium }],
23+
[{ size: 'large' }, { width: v.large, height: v.large }],
24+
[{ size: 'larger' }, { width: v.larger, height: v.larger }],
25+
[{ size: 'largest' }, { width: v.largest, height: v.largest }],
26+
],
1427

15-
const avatarStyles: ComponentSlotStylesInput<AvatarProps, any> = {
16-
root: ({ props: { size } }): ICSSInJSStyle => {
17-
const sizeInRem = pxToRem(sizeToPxValue[size])
28+
//
29+
// Image
30+
//
31+
image: [
32+
[
33+
null,
34+
{
35+
borderColor: v.avatarBorderColor,
36+
borderStyle: 'solid',
37+
borderWidth: v.avatarBorderWidth,
1838

19-
return {
20-
position: 'relative',
21-
backgroundColor: 'inherit',
22-
display: 'inline-block',
23-
verticalAlign: 'middle',
24-
height: sizeInRem,
25-
width: sizeInRem,
26-
}
27-
},
28-
image: ({ variables: v }): ICSSInJSStyle => ({
29-
borderColor: v.avatarBorderColor,
30-
borderStyle: 'solid',
31-
borderWidth: `${v.avatarBorderWidth}px`,
39+
height: '100%',
40+
objectFit: 'cover',
41+
verticalAlign: 'top',
42+
width: '100%',
43+
},
44+
],
45+
],
3246

33-
height: '100%',
34-
objectFit: 'cover',
35-
verticalAlign: 'top',
36-
width: '100%',
37-
}),
38-
label: ({ props: { size } }): ICSSInJSStyle => {
39-
const sizeInRem = pxToRem(sizeToPxValue[size])
40-
return {
41-
display: 'inline-block',
42-
width: sizeInRem,
43-
height: sizeInRem,
44-
lineHeight: sizeInRem,
45-
fontSize: pxToRem(sizeToPxValue[size] / 2.333),
46-
verticalAlign: 'top',
47-
textAlign: 'center',
48-
padding: '0px',
49-
}
50-
},
51-
status: ({ variables: v }): ICSSInJSStyle => ({
52-
position: 'absolute',
53-
bottom: 0,
54-
right: 0,
55-
boxShadow: `0 0 0 ${pxToRem(v.statusBorderWidth)} ${v.statusBorderColor}`,
56-
}),
57-
}
47+
//
48+
// Label
49+
//
50+
label: [
51+
[
52+
null,
53+
{
54+
display: 'inline-block',
55+
width: v.medium,
56+
height: v.medium,
57+
lineHeight: v.medium,
58+
fontSize: `calc(${v.medium} / 2.333)`,
59+
verticalAlign: 'top',
60+
textAlign: 'center',
61+
padding: '0px',
62+
},
63+
],
64+
[{ size: 'smallest' }, { width: v.smallest, height: v.smallest, lineHeight: v.smallest }],
65+
[{ size: 'smaller' }, { width: v.smaller, height: v.smaller, lineHeight: v.smaller }],
66+
[{ size: 'small' }, { width: v.small, height: v.small, lineHeight: v.small }],
67+
[{ size: 'medium' }, { width: v.medium, height: v.medium, lineHeight: v.medium }],
68+
[{ size: 'large' }, { width: v.large, height: v.large, lineHeight: v.large }],
69+
[{ size: 'larger' }, { width: v.larger, height: v.larger, lineHeight: v.larger }],
70+
[{ size: 'largest' }, { width: v.largest, height: v.largest, lineHeight: v.largest }],
71+
],
5872

59-
export default avatarStyles
73+
//
74+
// Status
75+
//
76+
status: [
77+
[
78+
null,
79+
{
80+
position: 'absolute',
81+
bottom: 0,
82+
right: 0,
83+
boxShadow: `0 0 0 ${v.statusBorderWidth} ${v.statusBorderColor}`,
84+
},
85+
],
86+
],
87+
})
88+
export default backportComponentStyle(avatarStyles)
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
import { pxToRem } from 'src/lib'
2+
13
export interface AvatarVariables {
24
avatarBorderColor: string
3-
avatarBorderWidth: number
5+
avatarBorderWidth: string
46
statusBorderColor: string
5-
statusBorderWidth: number
7+
statusBorderWidth: string
8+
9+
smallest: string
10+
smaller: string
11+
small: string
12+
medium: string
13+
large: string
14+
larger: string
15+
largest: string
616
}
717

818
export default (siteVariables): AvatarVariables => ({
919
avatarBorderColor: '',
10-
avatarBorderWidth: 0,
20+
avatarBorderWidth: '0',
1121
statusBorderColor: siteVariables.bodyBackground,
12-
statusBorderWidth: 2,
22+
statusBorderWidth: '2px',
23+
24+
smallest: pxToRem(24),
25+
smaller: pxToRem(24),
26+
small: pxToRem(24),
27+
medium: pxToRem(32),
28+
large: pxToRem(36),
29+
larger: pxToRem(42),
30+
largest: pxToRem(48),
1331
})

0 commit comments

Comments
 (0)