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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.901",
3
+ "version": "0.0.902",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -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 { icon, state = "normal", action, className } = props
32
- const [_state, setState] = useState("normal")
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
- function activate() {
39
- setState("running")
40
- if (action) action()
41
- }
42
+ useEffect(() => {
43
+ if (states[_state] && states[_state].autoexec) execute()
44
+ }, [_state])
42
45
 
43
- let actionIcon = icon
44
-
45
- switch(_state) {
46
- case "normal":
47
- actionIcon = icon
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={actionIcon} action={activate} className={`${className} action-btn ${_state}`} />
57
+ <Button {...props} icon={icon} label={label} action={execute} className={`${className} action-btn ${_state}`} />
62
58
  )
63
59
 
64
60
  }
65
61
 
66
- const ProgressButtonTest = (props) => {
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 label="Test1" icon="add" action={() => console.log("test")} state="success" raised/>
97
+ <ActionButton states={states} state="normal" raised/>
70
98
  )
71
99
  }