ywana-core8 0.0.901 → 0.0.902
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.
- package/dist/index.cjs +31 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +31 -26
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +31 -26
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/html/button.js +52 -24
package/package.json
CHANGED
package/src/html/button.js
CHANGED
@@ -26,46 +26,74 @@ export const Button = ({ label, icon, action, disabled = false, outlined, raised
|
|
26
26
|
)
|
27
27
|
}
|
28
28
|
|
29
|
+
/**
|
30
|
+
* Action Button
|
31
|
+
*/
|
29
32
|
export const ActionButton = (props) => {
|
30
33
|
|
31
|
-
const {
|
32
|
-
|
34
|
+
const { states, state, className } = props
|
35
|
+
|
36
|
+
const [_state, setState] = useState()
|
33
37
|
|
34
38
|
useEffect(() => {
|
35
39
|
setState(state)
|
36
40
|
}, [state])
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
+
useEffect(() => {
|
43
|
+
if (states[_state] && states[_state].autoexec) execute()
|
44
|
+
}, [_state])
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
break
|
49
|
-
case "running":
|
50
|
-
actionIcon = "rotate_right"
|
51
|
-
break
|
52
|
-
case "success":
|
53
|
-
actionIcon = "task_alt"
|
54
|
-
break
|
55
|
-
case "error":
|
56
|
-
actionIcon = "error"
|
57
|
-
break
|
46
|
+
async function execute() {
|
47
|
+
if (states[_state]) {
|
48
|
+
const newState = await states[_state].action()
|
49
|
+
if (newState) setState(newState)
|
50
|
+
}
|
58
51
|
}
|
59
52
|
|
53
|
+
if (!_state) return null
|
54
|
+
const { icon, label } = states[_state]
|
55
|
+
|
60
56
|
return (
|
61
|
-
<Button {...props} icon={
|
57
|
+
<Button {...props} icon={icon} label={label} action={execute} className={`${className} action-btn ${_state}`} />
|
62
58
|
)
|
63
59
|
|
64
60
|
}
|
65
61
|
|
66
|
-
const
|
62
|
+
const ActionButtonTest = (props) => {
|
63
|
+
|
64
|
+
const states = {
|
65
|
+
normal: {
|
66
|
+
icon: "add",
|
67
|
+
label: "Create Job",
|
68
|
+
action: () => {
|
69
|
+
return "running"
|
70
|
+
},
|
71
|
+
},
|
72
|
+
running: {
|
73
|
+
icon: "rotate_right",
|
74
|
+
label: "Creating Job",
|
75
|
+
autoexec: true,
|
76
|
+
action: () => {
|
77
|
+
console.log("Creating Job")
|
78
|
+
return new Promise((resolve, reject) => {
|
79
|
+
setTimeout(() => {
|
80
|
+
resolve("success")
|
81
|
+
}, 5000)
|
82
|
+
})
|
83
|
+
},
|
84
|
+
},
|
85
|
+
success: {
|
86
|
+
icon: "task_alt",
|
87
|
+
label: "Job Created"
|
88
|
+
|
89
|
+
},
|
90
|
+
error: {
|
91
|
+
icon: "error",
|
92
|
+
label: "Error"
|
93
|
+
}
|
94
|
+
}
|
67
95
|
|
68
96
|
return (
|
69
|
-
<ActionButton
|
97
|
+
<ActionButton states={states} state="normal" raised/>
|
70
98
|
)
|
71
99
|
}
|