ywana-core8 0.0.654 → 0.0.656
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 +34 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +0 -1
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +34 -25
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +34 -25
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/incubator/wizard.css +0 -1
- package/src/incubator/wizard.js +19 -15
- package/src/incubator/wizard.test.js +25 -9
package/package.json
CHANGED
package/src/incubator/wizard.css
CHANGED
package/src/incubator/wizard.js
CHANGED
@@ -1,33 +1,36 @@
|
|
1
|
-
import React, { useState } from 'react'
|
1
|
+
import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState } from 'react'
|
2
2
|
import { Icon } from '../html'
|
3
3
|
import { Button } from '../html/button'
|
4
4
|
import './wizard.css'
|
5
5
|
|
6
6
|
export const Wizard = (props) => {
|
7
7
|
|
8
|
-
const {
|
8
|
+
const { init = 0, onClose, children } = props
|
9
9
|
const [current=0, setCurrent] = useState(init)
|
10
|
+
|
11
|
+
const steps = React.Children.toArray(children)
|
12
|
+
const stepRef = useRef()
|
10
13
|
|
11
14
|
function prev() {
|
12
15
|
if (current > 0) setCurrent(current - 1)
|
13
16
|
}
|
14
17
|
|
15
|
-
function next() {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
} else {
|
20
|
-
setCurrent(current + 1)
|
21
|
-
}
|
18
|
+
async function next() {
|
19
|
+
await stepRef.current.onNext(() => {
|
20
|
+
setCurrent(current + 1)
|
21
|
+
})
|
22
22
|
}
|
23
23
|
|
24
|
-
function finish() {
|
25
|
-
|
26
|
-
if (step.onComplete) step.onComplete(() => {
|
24
|
+
async function finish() {
|
25
|
+
await stepRef.current.onNext(() => {
|
27
26
|
if (onClose) onClose()
|
28
27
|
})
|
29
28
|
}
|
30
29
|
|
30
|
+
const currentStep = useMemo(() => {
|
31
|
+
return React.cloneElement(steps[current], { ref: stepRef })
|
32
|
+
}, [current])
|
33
|
+
|
31
34
|
return (
|
32
35
|
<div className="wizard">
|
33
36
|
<div className="wizard-steps">
|
@@ -40,18 +43,19 @@ export const Wizard = (props) => {
|
|
40
43
|
{done && <Icon icon="check" />}
|
41
44
|
{active && <Icon icon="play_arrow" />}
|
42
45
|
</div>
|
43
|
-
<div className="wizard-step-label">{step.label}</div>
|
46
|
+
<div className="wizard-step-label">{step.props.label}</div>
|
44
47
|
</div>
|
45
48
|
)
|
46
49
|
})}
|
47
50
|
</div>
|
48
51
|
<div className="wizard-content">
|
49
|
-
{
|
52
|
+
{currentStep}
|
50
53
|
</div>
|
51
54
|
<div className="wizard-actions">
|
52
55
|
<Button label="Anterior" disabled={current === 0} action={prev} />
|
53
|
-
{ current < steps.length -1 ? <Button label="Siguiente" disabled={current
|
56
|
+
{ current < steps.length -1 ? <Button label="Siguiente" disabled={stepRef.current.isValid()} action={next} /> : <Button label="Finalizar" disabled={stepRef.current.isValid()} action={finish} raised /> }
|
54
57
|
</div>
|
55
58
|
</div>
|
56
59
|
)
|
57
60
|
}
|
61
|
+
|
@@ -1,16 +1,32 @@
|
|
1
|
-
import React, { useState } from 'react'
|
2
|
-
import { Wizard
|
1
|
+
import React, { forwardRef, useImperativeHandle, useState } from 'react'
|
2
|
+
import { Wizard} from './wizard'
|
3
|
+
|
4
|
+
export const Step1 = forwardRef((props, ref) => {
|
5
|
+
|
6
|
+
useImperativeHandle(ref, () => ({ onComplete }))
|
7
|
+
|
8
|
+
function onComplete (onSuccess, onError) {
|
9
|
+
console.log("onComplete", props.label)
|
10
|
+
onSuccess()
|
11
|
+
}
|
12
|
+
|
13
|
+
return (
|
14
|
+
<div>
|
15
|
+
<h1>Step</h1>
|
16
|
+
</div>
|
17
|
+
)
|
18
|
+
})
|
19
|
+
|
3
20
|
|
4
21
|
const WizardTest = (prop) => {
|
5
22
|
|
6
23
|
return (
|
7
|
-
<>
|
8
|
-
<Wizard
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
]} init={0} />
|
24
|
+
<>
|
25
|
+
<Wizard init={0} >
|
26
|
+
<Step1 label="Paso 1"/>
|
27
|
+
<Step1 label="Paso 2"/>
|
28
|
+
<Step1 label="Paso 3"/>
|
29
|
+
</Wizard>
|
14
30
|
</>
|
15
31
|
)
|
16
32
|
}
|