ywana-core8 0.0.658 → 0.0.660

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.658",
3
+ "version": "0.0.660",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -3,11 +3,30 @@ import { Icon } from '../html'
3
3
  import { Button } from '../html/button'
4
4
  import './wizard.css'
5
5
 
6
+ /**
7
+ * Wizard Context
8
+ */
9
+ export const WizardContext = React.createContext({})
10
+
11
+ /**
12
+ * Wizard Provider
13
+ */
14
+ export const WizardProvider = (props) => {
15
+
16
+ const [form, setForm] = useState(props.form)
17
+
18
+ return (
19
+ <WizardContext.Provider value={{ form, setForm }}>
20
+ {props.children}
21
+ </WizardContext.Provider>
22
+ )
23
+ }
24
+
6
25
  export const Wizard = (props) => {
7
26
 
8
- const { init = 0, onClose, children } = props
9
- const [current=0, setCurrent] = useState(init)
10
-
27
+ const { form = {}, init = 0, onClose, children } = props
28
+ const [current = 0, setCurrent] = useState(init)
29
+
11
30
  const steps = React.Children.toArray(children)
12
31
  const stepRef = useRef()
13
32
 
@@ -17,7 +36,7 @@ export const Wizard = (props) => {
17
36
 
18
37
  async function next() {
19
38
  await stepRef.current.onNext(() => {
20
- setCurrent(current + 1)
39
+ setCurrent(current + 1)
21
40
  })
22
41
  }
23
42
 
@@ -32,30 +51,32 @@ export const Wizard = (props) => {
32
51
  }, [current])
33
52
 
34
53
  return (
35
- <div className="wizard">
36
- <div className="wizard-steps">
37
- {steps.map((step, index) => {
38
- const active = index === current
39
- const done = index < current
40
- return (
41
- <div key={index} className="wizard-step">
42
- <div className="wizard-step-icon">
43
- {done && <Icon icon="check" />}
44
- {active && <Icon icon="play_arrow" />}
54
+ <WizardProvider form={form}>
55
+ <div className="wizard">
56
+ <div className="wizard-steps">
57
+ {steps.map((step, index) => {
58
+ const active = index === current
59
+ const done = index < current
60
+ return (
61
+ <div key={index} className="wizard-step">
62
+ <div className="wizard-step-icon">
63
+ {done && <Icon icon="check" />}
64
+ {active && <Icon icon="play_arrow" />}
65
+ </div>
66
+ <div className="wizard-step-label">{step.props.label}</div>
45
67
  </div>
46
- <div className="wizard-step-label">{step.props.label}</div>
47
- </div>
48
- )
49
- })}
50
- </div>
51
- <div className="wizard-content">
52
- {currentStep}
53
- </div>
54
- <div className="wizard-actions">
55
- <Button label="Anterior" disabled={current === 0} action={prev} />
56
- { 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 /> }
68
+ )
69
+ })}
70
+ </div>
71
+ <div className="wizard-content">
72
+ {currentStep}
73
+ </div>
74
+ <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 />}
77
+ </div>
57
78
  </div>
58
- </div>
79
+ </WizardProvider>
59
80
  )
60
81
  }
61
82
 
@@ -1,10 +1,18 @@
1
1
  import React, { forwardRef, useImperativeHandle, useState } from 'react'
2
- import { Wizard} from './wizard'
2
+ import { Property, TextField } from '../html'
3
+ import { Wizard, WizardContext} from './wizard'
3
4
 
4
5
  export const Step1 = forwardRef((props, ref) => {
5
6
 
6
7
  useImperativeHandle(ref, () => ({ onComplete }))
7
8
 
9
+ const wizardContext = React.useContext(WizardContext)
10
+ const { form } = wizardContext
11
+
12
+ function changeForm(id, value) {
13
+ wizardContext.setForm({ ...form, [id]: value })
14
+ }
15
+
8
16
  function onComplete (onSuccess, onError) {
9
17
  console.log("onComplete", props.label)
10
18
  onSuccess()
@@ -13,6 +21,7 @@ export const Step1 = forwardRef((props, ref) => {
13
21
  return (
14
22
  <div>
15
23
  <h1>Step</h1>
24
+ <TextField id="name" label="Name" value={form.name} onChange={changeForm} />
16
25
  </div>
17
26
  )
18
27
  })
@@ -20,9 +29,14 @@ export const Step1 = forwardRef((props, ref) => {
20
29
 
21
30
  const WizardTest = (prop) => {
22
31
 
32
+ const initForm = {
33
+ name: "John",
34
+ description: "Test Description"
35
+ }
36
+
23
37
  return (
24
38
  <>
25
- <Wizard init={0} >
39
+ <Wizard init={0} form={initForm} >
26
40
  <Step1 label="Paso 1"/>
27
41
  <Step1 label="Paso 2"/>
28
42
  <Step1 label="Paso 3"/>