@subiz/widget-v4 4.1.141 → 4.1.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ import {Com} from '../common.js'
2
+ import {h, createRef, Fragment} from 'preact'
3
+ import sb from '../util/index.js'
4
+
5
+ export default class Form2 extends Com {
6
+ state = {
7
+ hovering: 0,
8
+ selected: 0,
9
+ }
10
+
11
+ constructor(props) {
12
+ super(props)
13
+ }
14
+
15
+ onMouseEnter = (v) => {
16
+ let {selected, hovering} = this.state
17
+ if (v <= selected) {
18
+ this.setState({hovering: selected})
19
+ return
20
+ }
21
+ this.setState({hovering: v})
22
+ }
23
+
24
+ onMouseLeave = () => {
25
+ let {selected, hovering} = this.state
26
+ this.setState({hovering: 0})
27
+ }
28
+
29
+ onToggleValue(v) {
30
+ let {selected} = this.state
31
+ let newVal = v
32
+ if (v === selected) newVal = 0
33
+ this.setState({selected: newVal, hovering: newVal})
34
+ this.props.onChange(newVal)
35
+ }
36
+
37
+ render() {
38
+ let {selected, hovering} = this.state
39
+ let star1Cls = 'star-wrapper'
40
+ if (selected >= 1) {
41
+ star1Cls += ' selected'
42
+ } else if (hovering >= 1) {
43
+ star1Cls += ' hovering'
44
+ }
45
+ let star2Cls = 'star-wrapper'
46
+ if (selected >= 2) {
47
+ star2Cls += ' selected'
48
+ } else if (hovering >= 2) {
49
+ star2Cls += ' hovering'
50
+ }
51
+ let star3Cls = 'star-wrapper'
52
+ if (selected >= 3) {
53
+ star3Cls += ' selected'
54
+ } else if (hovering >= 3) {
55
+ star3Cls += ' hovering'
56
+ }
57
+ let star4Cls = 'star-wrapper'
58
+ if (selected >= 4) {
59
+ star4Cls += ' selected'
60
+ } else if (hovering >= 4) {
61
+ star4Cls += ' hovering'
62
+ }
63
+ let star5Cls = 'star-wrapper'
64
+ if (selected >= 5) {
65
+ star5Cls += ' selected'
66
+ } else if (hovering >= 5) {
67
+ star5Cls += ' hovering'
68
+ }
69
+ return (
70
+ <div class='form-ratings-wrapper' onMouseLeave={() => this.onMouseLeave()}>
71
+ <div class={star1Cls} onClick={() => this.onToggleValue(1)} onMouseEnter={() => this.onMouseEnter(1)}>
72
+ <div class='star' />
73
+ </div>
74
+ <div class={star2Cls} onClick={() => this.onToggleValue(2)} onMouseEnter={() => this.onMouseEnter(2)}>
75
+ <div class='star' />
76
+ </div>
77
+ <div class={star3Cls} onClick={() => this.onToggleValue(3)} onMouseEnter={() => this.onMouseEnter(3)}>
78
+ <div class='star' />
79
+ </div>
80
+ <div class={star4Cls} onClick={() => this.onToggleValue(4)} onMouseEnter={() => this.onMouseEnter(4)}>
81
+ <div class='star' />
82
+ </div>
83
+ <div class={star5Cls} onClick={() => this.onToggleValue(5)} onMouseEnter={() => this.onMouseEnter(5)}>
84
+ <div class='star' />
85
+ </div>
86
+ </div>
87
+ )
88
+ }
89
+ }