ywana-core8 0.0.653 → 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.653",
3
+ "version": "0.0.655",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -0,0 +1 @@
1
+ export {Wizard } from './wizard'
@@ -0,0 +1,30 @@
1
+ .wizard {
2
+ border: solid 1px red;
3
+ }
4
+
5
+ .wizard-steps {
6
+ display: flex;
7
+ border-bottom: solid 1px var(--divider-color);
8
+ }
9
+
10
+ .wizard-step {
11
+ flex: 1;
12
+ padding: 0 .5rem;
13
+ display: flex;
14
+ align-items: center;
15
+ }
16
+
17
+ .wizard-step:not(:last-child) {
18
+ border-right: solid 1px var(--divider-color);
19
+ }
20
+
21
+ .wizard-content {
22
+ min-height: 10rem;
23
+ }
24
+
25
+ .wizard-actions {
26
+ border-top: solid 1px var(--divider-color);
27
+ display: flex;
28
+ justify-content: space-between;
29
+ padding: .5rem;
30
+ }
@@ -0,0 +1,61 @@
1
+ import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState } from 'react'
2
+ import { Icon } from '../html'
3
+ import { Button } from '../html/button'
4
+ import './wizard.css'
5
+
6
+ export const Wizard = (props) => {
7
+
8
+ const { init = 0, onClose, children } = props
9
+ const [current=0, setCurrent] = useState(init)
10
+
11
+ const steps = React.Children.toArray(children)
12
+ const stepRef = useRef()
13
+
14
+ function prev() {
15
+ if (current > 0) setCurrent(current - 1)
16
+ }
17
+
18
+ function next() {
19
+ stepRef.current.onComplete(() => {
20
+ setCurrent(current + 1)
21
+ })
22
+ }
23
+
24
+ function finish() {
25
+ stepRef.current.onComplete(() => {
26
+ if (onClose) onClose()
27
+ })
28
+ }
29
+
30
+ const currentStep = useMemo(() => {
31
+ return React.cloneElement(steps[current], { ref: stepRef })
32
+ }, [current])
33
+
34
+ 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" />}
45
+ </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={current === steps.length - 1} action={next} /> : <Button label="Finalizar" action={finish} raised /> }
57
+ </div>
58
+ </div>
59
+ )
60
+ }
61
+
@@ -0,0 +1,32 @@
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
+
20
+
21
+ const WizardTest = (prop) => {
22
+
23
+ return (
24
+ <>
25
+ <Wizard init={0} >
26
+ <Step1 label="Paso 1"/>
27
+ <Step1 label="Paso 2"/>
28
+ <Step1 label="Paso 3"/>
29
+ </Wizard>
30
+ </>
31
+ )
32
+ }
package/src/index.js CHANGED
@@ -7,4 +7,7 @@ export * from './widgets'
7
7
  export * from './site'
8
8
  export * from './domain'
9
9
 
10
+
11
+ export * from './incubator'
12
+
10
13
  export const isFunction = value => value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);