forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQStep.js
More file actions
138 lines (116 loc) · 3.48 KB
/
QStep.js
File metadata and controls
138 lines (116 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { h, ref, computed, inject, getCurrentInstance, KeepAlive } from 'vue'
import QSlideTransition from '../slide-transition/QSlideTransition.js'
import StepHeader from './StepHeader.js'
import { usePanelChildProps } from '../../composables/private/use-panel.js'
import useCache from '../../composables/private/use-cache.js'
import { createComponent } from '../../utils/private/create.js'
import { stepperKey } from '../../utils/private/symbols.js'
import { hSlot } from '../../utils/private/render.js'
function getStepWrapper (slots) {
return h('div', {
class: 'q-stepper__step-content'
}, [
h('div', {
class: 'q-stepper__step-inner'
}, hSlot(slots.default))
])
}
const PanelWrapper = {
setup (_, { slots }) {
return () => getStepWrapper(slots)
}
}
export default createComponent({
name: 'QStep',
props: {
...usePanelChildProps,
icon: String,
color: String,
title: {
type: String,
required: true
},
caption: String,
prefix: [ String, Number ],
doneIcon: String,
doneColor: String,
activeIcon: String,
activeColor: String,
errorIcon: String,
errorColor: String,
headerNav: {
type: Boolean,
default: true
},
done: Boolean,
error: Boolean
},
setup (props, { attrs, slots }) {
const { proxy: { $q } } = getCurrentInstance()
const $stepper = inject(stepperKey, () => {
console.error('QStep needs to be child of QStepper')
})
const { getCacheWithFn } = useCache()
const rootRef = ref(null)
const isActive = computed(() => $stepper.value.modelValue === props.name)
const scrollEvent = computed(() => (
($q.platform.is.ios !== true && $q.platform.is.chrome === true)
|| isActive.value !== true
|| $stepper.value.vertical !== true
? {}
: {
onScroll (e) {
const { target } = e
if (target.scrollTop > 0) {
target.scrollTop = 0
}
attrs.onScroll !== void 0 && attrs.onScroll(e)
}
}
))
const contentKey = computed(() => (
typeof props.name === 'string' || typeof props.name === 'number'
? props.name
: String(props.name)
))
function getStepContent () {
const vertical = $stepper.value.vertical
if (vertical === true && $stepper.value.keepAlive === true) {
return h(
KeepAlive,
$stepper.value.keepAliveProps.value,
isActive.value === true
? [
h(
$stepper.value.needsUniqueKeepAliveWrapper.value === true
? getCacheWithFn(contentKey.value, () => ({ ...PanelWrapper, name: contentKey.value }))
: PanelWrapper,
{ key: contentKey.value },
slots.default
)
]
: void 0
)
}
return vertical !== true || isActive.value === true
? getStepWrapper(slots)
: void 0
}
return () => h(
'div',
{ ref: rootRef, class: 'q-stepper__step', ...scrollEvent.value },
$stepper.value.vertical === true
? [
h(StepHeader, {
stepper: $stepper.value,
step: props,
goToPanel: $stepper.value.goToPanel
}),
$stepper.value.animated === true
? h(QSlideTransition, getStepContent)
: getStepContent()
]
: [ getStepContent() ]
)
}
})