-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
95 lines (84 loc) · 2.01 KB
/
index.tsx
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
import { Component, h, JwcComponent, Prop, Fragment } from 'jwcjs'
import css from './index.css'
@Component({
name: 'lantern-element',
css,
})
export class LanternElement extends JwcComponent {
/**
* The text on lantern,use `,` to divide the text
*/
@Prop({ default: '春,节' })
text = '春,节'
/**
* The number of lanterns returned, up to 2
*/
@Prop({ default: 2 })
number = 2
/**
* display on moblie (very not recommended)
*/
@Prop({ default: false })
displayMobile = false;
/**
* Whether to display left or right; otherwise, the output will be based on the 'position' field
*/
@Prop({ default: false })
disPlayBoth = false
/**
* The position of the lantern, left or right
*/
@Prop({ default: 'right'})
position = 'right'
private loopRender(i: number, position: string) {
return (
<div class={`lantern-box${i} push-${position} ${this.displayMobile ? '' : 'mobileNo'}`}>
<div class="lantern">
<div class="xian"></div>
<div class="lantern-a">
<div class="lantern-b">
<div class="lantern-t">${this.sliceName()[i]}</div>
</div>
</div>
<div class="shui shui-a">
<div class="shui-c"></div>
<div class="shui-b"></div>
</div>
</div>
</div>
)
}
private sliceName() {
return this.text.split(',')
}
override render() {
const arr = new Array(this.number)
return (
<>
{
this.disPlayBoth ? (
<>
{
arr.map((_, i) => this.loopRender(i, 'left'))
}
{
arr.map((_, i) => this.loopRender(i, 'right'))
}
</>
) : (
<>
{
arr.map((_, i) => this.loopRender(i, this.position))
}
</>
)
}
</>
)
}
}
declare global {
interface HTMLElementTagNameMap {
'lantern-element': LanternElement
}
}