mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
47 lines
1.1 KiB
Vue
47 lines
1.1 KiB
Vue
<template>
|
|
<div :class="[ns.b(), ns.m(simple ? 'simple' : direction)]">
|
|
<slot />
|
|
<steps-sorter />
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { getCurrentInstance, provide, watch } from 'vue'
|
|
import { CHANGE_EVENT } from '@element-plus/constants'
|
|
import { useNamespace, useOrderedChildren } from '@element-plus/hooks'
|
|
import { stepsEmits, stepsProps } from './steps'
|
|
import { STEPS_INJECTION_KEY } from './tokens'
|
|
|
|
import type { StepItemState } from './item.vue'
|
|
|
|
defineOptions({
|
|
name: 'ElSteps',
|
|
})
|
|
|
|
const props = defineProps(stepsProps)
|
|
const emit = defineEmits(stepsEmits)
|
|
|
|
const ns = useNamespace('steps')
|
|
const {
|
|
children: steps,
|
|
addChild: addStep,
|
|
removeChild: removeStep,
|
|
ChildrenSorter: StepsSorter,
|
|
} = useOrderedChildren<StepItemState>(getCurrentInstance()!, 'ElStep')
|
|
|
|
watch(steps, () => {
|
|
steps.value.forEach((instance: StepItemState, index: number) => {
|
|
instance.setIndex(index)
|
|
})
|
|
})
|
|
|
|
provide(STEPS_INJECTION_KEY, { props, steps, addStep, removeStep })
|
|
|
|
watch(
|
|
() => props.active,
|
|
(newVal: number, oldVal: number) => {
|
|
emit(CHANGE_EVENT, newVal, oldVal)
|
|
}
|
|
)
|
|
</script>
|