-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstyles.ts
More file actions
113 lines (102 loc) · 2.76 KB
/
styles.ts
File metadata and controls
113 lines (102 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { css } from '@emotion/react';
import { hexToRgba, getColorByToken } from '@jdesignlab/theme';
import { DEFAULT_BORDER_COLOR } from './constants';
import type { ColorToken } from '@jdesignlab/theme';
import type { Size, Variant, Direction, FlexMap, FlexToken } from './types';
export const createCardVariant = (
size: Size,
variant: Variant,
backgroundColor: ColorToken,
borderColor: ColorToken
) => {
const hexBorderColor = getColorByToken(borderColor);
const baseStyle = css({
boxSizing: 'border-box',
padding: '12px 24px'
});
const variantStyle = () => {
switch (variant) {
case 'filled':
return css({
boxSizing: 'border-box',
boxShadow: 'none',
backgroundColor: `${getColorByToken(backgroundColor)}`
});
case 'outlined':
return css({ boxSizing: 'border-box', border: `1px solid ${hexBorderColor}` });
default:
return css({
boxSizing: 'border-box',
boxShadow: `0 3px 6px ${hexToRgba(hexBorderColor, 0.16)}, 0 3px 6px ${hexToRgba(hexBorderColor, 0.2)}`
});
}
};
const sizeStyle = () => {
switch (size) {
case 'lg':
return css({
maxWidth: '720px'
});
case 'sm':
return css({
maxWidth: '200px'
});
// medium
default:
return css({
maxWidth: '440px'
});
}
};
return [baseStyle, variantStyle(), sizeStyle()];
};
export const createBorderDirection = (direction: Direction, borderColor: ColorToken) => {
if (direction === 'horizontal') {
return css({
boxSizing: 'border-box',
borderRight: `1px solid ${borderColor}`,
maxWidth: '33%',
wordWrap: 'break-word'
});
}
return css({
borderTop: `1px solid ${borderColor}`,
wordWrap: 'break-word',
maxWidth: '100%',
boxSizing: 'border-box'
});
};
export const createDivider = (direction: Direction) => {
const dividerColor = getColorByToken(DEFAULT_BORDER_COLOR);
if (direction === 'vertical') {
return css({
width: '100%',
height: 0,
margin: '12px 0',
borderTop: `${dividerColor} solid 1px`
});
}
return css({
height: '64px',
width: '1px',
margin: '0 4px',
borderLeft: `${dividerColor} solid 1px`
});
};
export const createFlexStyle = (justify: FlexToken, align: FlexToken, direction: Direction) => {
const flexMap: FlexMap = {
stretch: 'stretch',
start: 'flex-start',
end: 'flex-end',
center: 'center',
between: 'space-between',
around: 'space-around'
};
return css({
display: 'flex',
flexDirection: direction === 'horizontal' ? 'row' : 'column',
alignItems: `${flexMap[align]}`,
justifyContent: `${flexMap[justify]}`,
borderRadius: '8px'
});
};