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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.662",
3
+ "version": "0.0.664",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState } from '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 = useMemo(() => {
50
- return React.cloneElement(steps[current], { ref: stepRef })
51
- }, [current])
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
- <Button label="Anterior" disabled={current === 0} action={prev} />
76
- {current < steps.length - 1 ? <Button label="Siguiente" disabled={stepRef.current && stepRef.current.isValid()} action={next} /> : <Button label="Finalizar" disabled={stepRef.current && stepRef.current.isValid()} action={finish} raised />}
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
- useImperativeHandle(ref, () => ({ onComplete }))
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 onComplete (onSuccess, onError) {
17
- console.log("onComplete", props.label)
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="name" label="Name" value={form.name} onChange={changeForm} />
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
- <Step1 label="Paso 2"/>
42
- <Step1 label="Paso 3"/>
118
+ <Step2 label="Paso 2"/>
119
+ <Step3 label="Paso 3"/>
43
120
  </Wizard>
44
121
  </>
45
122
  )