ywana-core8 0.0.654 → 0.0.655

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.654",
3
+ "version": "0.0.655",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -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 { steps = [], init = 0, onClose } = props
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
18
  function next() {
16
- const step = steps[current]
17
- if (step.onComplete) {
18
- step.onComplete(() => { setCurrent(current + 1) })
19
- } else {
20
- setCurrent(current + 1)
21
- }
19
+ stepRef.current.onComplete(() => {
20
+ setCurrent(current + 1)
21
+ })
22
22
  }
23
23
 
24
24
  function finish() {
25
- const step = steps[current]
26
- if (step.onComplete) step.onComplete(() => {
25
+ stepRef.current.onComplete(() => {
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,13 +43,13 @@ 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
- {steps[current].content}
52
+ {currentStep}
50
53
  </div>
51
54
  <div className="wizard-actions">
52
55
  <Button label="Anterior" disabled={current === 0} action={prev} />
@@ -55,3 +58,4 @@ export const Wizard = (props) => {
55
58
  </div>
56
59
  )
57
60
  }
61
+
@@ -1,16 +1,32 @@
1
- import React, { useState } from 'react'
2
- import { Wizard } from './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
- <>sa
8
- <Wizard steps={[
9
- { label: "Paso 1", content: <div>Contenido 1</div>, onComplete: (onSuccess, onError) => { console.log("complete 1"); onSuccess() } },
10
- { label: "Paso 2", content: <div>Contenido 2</div>, onComplete: (onSuccess, onError) => { console.log("complete 2"); onSuccess() } },
11
- { label: "Paso 3", content: <div>Contenido 3</div>, onComplete: (onSuccess, onError) => { console.log("complete 3"); onSuccess() } },
12
- { label: "Paso 4", content: <div>Contenido 4</div>, onComplete: (onSuccess, onError) => { console.log("complete 4"); onSuccess() } },
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
  }