-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
EButton.ts
79 lines (72 loc) 路 2.08 KB
/
EButton.ts
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
import type { CSSProperties, PropType } from 'vue'
import { computed, defineComponent, h } from 'vue'
import { convertStyleStringToObj, pxToPt } from '../utils'
export default defineComponent({
name: 'EButton',
props: {
px: {
type: [String, Number] as PropType<string | number>,
},
py: {
type: [String, Number] as PropType<string | number>,
default: 0,
},
target: {
type: String,
default: '_blank',
},
href: String,
style: Object,
},
setup(props, { slots }) {
const px = props.px || 0
const py = props.py || 0
const textRaise = pxToPt(Number.parseInt(py.toString()) * 2)
const styles = typeof props.style === 'string' ? convertStyleStringToObj(props.style) : props.style
const buttonStyle = {
lineHeight: '100%',
textDecoration: 'none',
display: 'inline-block',
maxWidth: '100%',
...styles,
} as CSSProperties
if ((py || px) && buttonStyle)
buttonStyle.padding = `${py}px ${px}px`
const buttonTextStyle = computed(
() =>
({
maxWidth: '100%',
display: 'inline-block',
lineHeight: '120%',
textDecoration: 'none',
textTransform: 'none',
msoPaddingAlt: '0px',
msoTextRaise: pxToPt(py.toString()),
}) as CSSProperties,
)
const firstSpan = `<!--[if mso]><i style="letter-spacing: ${px}px;mso-font-width:-100%;mso-text-raise:${textRaise}" hidden> </i><![endif]-->`
const secondSpan = `<!--[if mso]><i style="letter-spacing: ${px}px;mso-font-width:-100%" hidden> </i><![endif]-->`
return () => {
return h(
'a',
{
'data-id': '__vue-email-button',
'style': buttonStyle,
'href': props.href,
'target': props.target,
},
[
h('span', { innerHTML: firstSpan }),
h(
'span',
{
style: buttonTextStyle.value,
},
slots.default?.(),
),
h('span', { innerHTML: secondSpan }),
],
)
}
},
})