ywana-core8 0.0.662 → 0.0.664
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 +27 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +27 -20
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +27 -20
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/incubator/wizard.js +13 -7
- package/src/incubator/wizard.test.js +85 -8
package/package.json
CHANGED
package/src/incubator/wizard.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, {
|
1
|
+
import React, { useEffect, useRef, useState } from 'react'
|
2
2
|
import { Icon } from '../html'
|
3
3
|
import { Button } from '../html/button'
|
4
4
|
import './wizard.css'
|
@@ -26,10 +26,14 @@ export const Wizard = (props) => {
|
|
26
26
|
|
27
27
|
const { form = {}, init = 0, onClose, children } = props
|
28
28
|
const [current = 0, setCurrent] = useState(init)
|
29
|
-
|
29
|
+
const [valid, setValid] = useState(true)
|
30
30
|
const steps = React.Children.toArray(children)
|
31
31
|
const stepRef = useRef()
|
32
32
|
|
33
|
+
function validate(form, isValid) {
|
34
|
+
setValid(isValid)
|
35
|
+
}
|
36
|
+
|
33
37
|
function prev() {
|
34
38
|
if (current > 0) setCurrent(current - 1)
|
35
39
|
}
|
@@ -46,13 +50,14 @@ export const Wizard = (props) => {
|
|
46
50
|
})
|
47
51
|
}
|
48
52
|
|
49
|
-
const currentStep =
|
50
|
-
|
51
|
-
}
|
53
|
+
const currentStep = React.cloneElement(steps[current], { ref: stepRef, onChange: validate })
|
54
|
+
const nextButton = current < steps.length - 1 ? <Button label="Siguiented" action={next} raised disabled={!valid}/> : <Button label="Finish" action={finish} />
|
55
|
+
const prevButton = current > 0 ? <Button label="Atrás" action={prev} /> : null
|
52
56
|
|
53
57
|
return (
|
54
58
|
<WizardProvider form={form}>
|
55
59
|
<div className="wizard">
|
60
|
+
{current}
|
56
61
|
<div className="wizard-steps">
|
57
62
|
{steps.map((step, index) => {
|
58
63
|
const active = index === current
|
@@ -72,8 +77,9 @@ export const Wizard = (props) => {
|
|
72
77
|
{currentStep}
|
73
78
|
</div>
|
74
79
|
<div className="wizard-actions">
|
75
|
-
|
76
|
-
|
80
|
+
{prevButton}
|
81
|
+
<div></div>
|
82
|
+
{nextButton}
|
77
83
|
</div>
|
78
84
|
</div>
|
79
85
|
</WizardProvider>
|
@@ -1,45 +1,122 @@
|
|
1
|
-
import React, { forwardRef, useImperativeHandle, useState } from 'react'
|
1
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react'
|
2
2
|
import { Property, TextField } from '../html'
|
3
3
|
import { Wizard, WizardContext} from './wizard'
|
4
4
|
|
5
5
|
export const Step1 = forwardRef((props, ref) => {
|
6
|
+
useImperativeHandle(ref, () => ({ id: 1, onNext }))
|
6
7
|
|
7
|
-
|
8
|
+
const wizardContext = React.useContext(WizardContext)
|
9
|
+
const { form } = wizardContext
|
10
|
+
const { onChange } = props
|
11
|
+
|
12
|
+
useEffect(() => {
|
13
|
+
onChange(form, isValid(form))
|
14
|
+
}, [form])
|
15
|
+
|
16
|
+
function changeForm(id, value) {
|
17
|
+
wizardContext.setForm({ ...form, [id]: value })
|
18
|
+
}
|
19
|
+
|
20
|
+
function isValid(form) {
|
21
|
+
console.log("isValid1")
|
22
|
+
return form.name && form.name.length > 0
|
23
|
+
}
|
24
|
+
|
25
|
+
function onNext (onSuccess, onError) {
|
26
|
+
console.log("onNext1", props.label)
|
27
|
+
onSuccess()
|
28
|
+
}
|
8
29
|
|
30
|
+
return (
|
31
|
+
<div>
|
32
|
+
<h1>Step</h1>
|
33
|
+
<TextField id="name" label="Name" value={form.name} onChange={changeForm} />
|
34
|
+
</div>
|
35
|
+
)
|
36
|
+
})
|
37
|
+
|
38
|
+
export const Step2 = forwardRef((props, ref) => {
|
39
|
+
useImperativeHandle(ref, () => ({ id:2, isValid, onNext }))
|
40
|
+
|
9
41
|
const wizardContext = React.useContext(WizardContext)
|
10
42
|
const { form } = wizardContext
|
43
|
+
const { onChange } = props
|
44
|
+
|
45
|
+
useEffect(() => {
|
46
|
+
onChange(form, isValid(form))
|
47
|
+
}, [form])
|
11
48
|
|
12
49
|
function changeForm(id, value) {
|
13
50
|
wizardContext.setForm({ ...form, [id]: value })
|
51
|
+
props.onChange(form, isValid())
|
52
|
+
}
|
53
|
+
|
54
|
+
function isValid() {
|
55
|
+
console.log("isValid2")
|
56
|
+
return form.description && form.description.length > 0
|
14
57
|
}
|
15
58
|
|
16
|
-
function
|
17
|
-
console.log("
|
59
|
+
function onNext (onSuccess, onError) {
|
60
|
+
console.log("onNext2", props.label)
|
18
61
|
onSuccess()
|
19
62
|
}
|
20
63
|
|
21
64
|
return (
|
22
65
|
<div>
|
23
66
|
<h1>Step</h1>
|
24
|
-
<TextField id="
|
67
|
+
<TextField id="description" label="Name" value={form.description} onChange={changeForm} />
|
25
68
|
</div>
|
26
69
|
)
|
27
70
|
})
|
28
71
|
|
72
|
+
export const Step3 = forwardRef((props, ref) => {
|
73
|
+
useImperativeHandle(ref, () => ({ id:3, isValid, onNext }))
|
74
|
+
|
75
|
+
const wizardContext = React.useContext(WizardContext)
|
76
|
+
const { form } = wizardContext
|
77
|
+
const { onChange } = props
|
78
|
+
|
79
|
+
useEffect(() => {
|
80
|
+
onChange(form, isValid(form))
|
81
|
+
}, [form])
|
82
|
+
|
83
|
+
function changeForm(id, value) {
|
84
|
+
wizardContext.setForm({ ...form, [id]: value })
|
85
|
+
props.onChange(form, isValid())
|
86
|
+
}
|
87
|
+
|
88
|
+
function isValid() {
|
89
|
+
console.log("isValid3")
|
90
|
+
return form.address && form.address.length > 0
|
91
|
+
}
|
92
|
+
|
93
|
+
function onNext (onSuccess, onError) {
|
94
|
+
console.log("onNExt3", props.label)
|
95
|
+
onSuccess()
|
96
|
+
}
|
97
|
+
|
98
|
+
return (
|
99
|
+
<div>
|
100
|
+
<h1>Step</h1>
|
101
|
+
<TextField id="address" label="Name" value={form.address} onChange={changeForm} />
|
102
|
+
</div>
|
103
|
+
)
|
104
|
+
})
|
29
105
|
|
30
106
|
const WizardTest = (prop) => {
|
31
107
|
|
32
108
|
const initForm = {
|
33
109
|
name: "John",
|
34
|
-
description: "Test Description"
|
110
|
+
description: "Test Description",
|
111
|
+
address: "Test Address"
|
35
112
|
}
|
36
113
|
|
37
114
|
return (
|
38
115
|
<>
|
39
116
|
<Wizard init={0} form={initForm} >
|
40
117
|
<Step1 label="Paso 1"/>
|
41
|
-
<
|
42
|
-
<
|
118
|
+
<Step2 label="Paso 2"/>
|
119
|
+
<Step3 label="Paso 3"/>
|
43
120
|
</Wizard>
|
44
121
|
</>
|
45
122
|
)
|