forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
63 lines (58 loc) · 2.36 KB
/
common.ts
File metadata and controls
63 lines (58 loc) · 2.36 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
import type { CSSProperties, HTMLAttributes } from "vue"
export type BaseProps = Pick<
CSSProperties,
| 'position'
| 'width' | 'height' | 'minHeight' | 'maxWidth' | 'lineHeight'
| 'boxSizing' | 'cursor'
| 'padding' | 'paddingBlock' | 'paddingInline'
| 'margin' | 'marginTop' | 'marginBottom' | 'marginBlock' | 'marginInline'
| 'fontSize' | 'fontWeight'
>
& Pick<HTMLAttributes, 'class' | 'id'>
& {
inline?: boolean
color?: 'text-primary' | 'text-secondary' | 'text-regular' | CSSProperties['color']
bgColor?: CSSProperties['backgroundColor']
style?: CSSProperties
onClick?: (ev: MouseEvent) => void
}
export const ALL_BASE_PROPS: (keyof BaseProps)[] = [
'margin', 'marginTop', 'marginBottom', 'marginBlock', 'marginInline',
'maxWidth', 'minHeight', 'width', 'height', 'lineHeight',
'padding', 'paddingBlock', 'paddingInline',
'position', 'boxSizing', 'cursor',
'color', 'fontSize', 'fontWeight', 'bgColor',
'id', 'class', 'style',
'inline',
'onClick',
]
export const cvtPxScale = (val: number | string | undefined): string | undefined => typeof val === 'number' ? `${val}px` : val
const cvtColor = (color: BaseProps['color']): CSSProperties['color'] => {
if (color === 'text-primary') return 'var(--el-text-color-primary)'
if (color === 'text-secondary') return 'var(--el-text-color-secondary)'
if (color === 'text-regular') return 'var(--el-text-color-regular)'
return color
}
export const cvt2BaseStyle = (props: BaseProps): CSSProperties => ({
position: props.position,
width: cvtPxScale(props.width),
height: cvtPxScale(props.height),
lineHeight: cvtPxScale(props.lineHeight),
minHeight: cvtPxScale(props.minHeight),
boxSizing: props.boxSizing,
cursor: props.cursor,
margin: cvtPxScale(props.margin),
marginInline: cvtPxScale(props.marginInline),
marginBlock: cvtPxScale(props.marginBlock),
marginTop: cvtPxScale(props.marginTop),
marginBottom: cvtPxScale(props.marginBottom),
maxWidth: cvtPxScale(props.maxWidth),
padding: cvtPxScale(props.padding),
paddingBlock: cvtPxScale(props.paddingBlock),
paddingInline: cvtPxScale(props.paddingInline),
color: cvtColor(props.color),
backgroundColor: props.bgColor,
fontSize: cvtPxScale(props.fontSize),
fontWeight: props.fontWeight,
...props.style,
})