Skip to content

Commit

Permalink
feat(comp:stepper): add dot prop (#1401)
Browse files Browse the repository at this point in the history
fix #1082
  • Loading branch information
kovsu committed Jan 12, 2023
1 parent ba15f33 commit aa90a7e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/components/stepper/__tests__/steps.spec.ts
Expand Up @@ -55,6 +55,15 @@ describe('Stepper', () => {
expect(onUpdateActiveKey).toBeCalledTimes(1)
})

test('dot work', async () => {
const wrapper = StepperMount({ props: { dot: true } })
const items = await wrapper.findAll('.ix-stepper-item')

expect(items[0].classes()).toContain('ix-stepper-item-dot')
expect(items[1].classes()).toContain('ix-stepper-item-dot')
expect(items[2].classes()).toContain('ix-stepper-item-dot')
})

test('labelPlacement work', async () => {
const wrapper = StepperMount({ props: { labelPlacement: 'bottom' } })

Expand Down
14 changes: 14 additions & 0 deletions packages/components/stepper/demo/Dot.md
@@ -0,0 +1,14 @@
---
title:
zh: 点状步骤条
en: Dot Stepper
order: 10
---

## zh

点状的步骤条。

## en

The dot style stepper.
7 changes: 7 additions & 0 deletions packages/components/stepper/demo/Dot.vue
@@ -0,0 +1,7 @@
<template>
<IxStepper :activeKey="2" :dot="true" labelPlacement="bottom">
<IxStepperItem title="Finished" description="This is a description."></IxStepperItem>
<IxStepperItem title="In Progress" description="This is a description."></IxStepperItem>
<IxStepperItem title="Waiting" description="This is a description."></IxStepperItem>
</IxStepper>
</template>
2 changes: 1 addition & 1 deletion packages/components/stepper/docs/Api.zh.md
Expand Up @@ -7,7 +7,7 @@
| ---| --- | --- | --- | --- | --- |
`v-model:activeKey` | 当前的激活节点的 `key` | `VKey` | - | - | - |
`clickable` | 是否可点击 | `boolean` | `false` | - | - |
`dot` | 是否为点状步骤条 | `boolean \| #dot={key, status}` | `false` | - | - |
`dot` | 是否为点状步骤条 | `boolean` | `false` | - | - |
`labelPlacement` | 指定文本信息放置的位置 | `'end' \| 'bottom'` | `'end'` | -| - |
`percent` | 当前激活节点的进度 | `number` | - | - | 取值是 0-100 |
`size` | 指定节点的大小 | `'md' \| 'sm'` | `'md'` | ✅ | - |
Expand Down
7 changes: 6 additions & 1 deletion packages/components/stepper/src/StepperItem.tsx
Expand Up @@ -46,13 +46,17 @@ export default defineComponent({
const classes = computed(() => {
const prefixCls = mergedPrefixCls.value
const { disabled, icon } = props
const { dot, labelPlacement } = parentProps

return normalizeClass({
[prefixCls]: true,
[`${prefixCls}-${status.value}`]: true,
[`${prefixCls}-active`]: isActive.value,
[`${prefixCls}-clickable`]: parentProps.clickable && !disabled,
[`${prefixCls}-disabled`]: disabled,
[`${prefixCls}-with-icon`]: icon || !!slots.icon,
[`${prefixCls}-dot`]: dot,
[`${prefixCls}-label-${labelPlacement}`]: true,
})
})

Expand All @@ -66,6 +70,7 @@ export default defineComponent({
return () => {
const prefixCls = mergedPrefixCls.value
const clickable = parentProps.clickable && !props.disabled
const { dot } = parentProps
const iconNode = renderIcon(props, slots, parentProps, status, key)
const titleNode = convertStringVNode(slots, props, 'title')
const descriptionNode = convertStringVNode(slots, props, 'description')
Expand All @@ -77,7 +82,7 @@ export default defineComponent({
onClick={clickable ? onClick : undefined}
>
<div class={`${prefixCls}-tail`}></div>
<div class={`${prefixCls}-icon`}>{iconNode}</div>
<div class={`${prefixCls}-icon`}>{dot ? '' : iconNode}</div>
<div class={`${prefixCls}-content`}>
<div class={`${prefixCls}-title`}>{titleNode}</div>
{descriptionNode && <div class={`${prefixCls}-description`}>{descriptionNode}</div>}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/stepper/src/types.ts
Expand Up @@ -34,6 +34,10 @@ export const stepperProps = {
type: Boolean,
default: false,
},
dot: {
type: Boolean,
default: false,
},

'onUpdate:activeKey': [Function, Array] as PropType<MaybeArray<(key: any) => void>>,
} as const
Expand Down
12 changes: 12 additions & 0 deletions packages/components/stepper/style/index.less
Expand Up @@ -58,6 +58,18 @@
}
}

&-label-bottom {
.@{stepper-item-prefix}-content {
margin-top: -10px;
}
}

&-dot {
.@{stepper-item-prefix}-icon {
transform: scale(0.35) ;
}
}

&-icon {
display: inline-flex;
align-items: center;
Expand Down
4 changes: 4 additions & 0 deletions packages/components/stepper/style/mixin.less
Expand Up @@ -14,6 +14,10 @@
color: @@icon-color;
}

&-@{status}.@{stepper-item-prefix}-dot &-icon {
background: @@icon-color;
}

&-@{status} &-content &-title {
color: @@title-color;
}
Expand Down

0 comments on commit aa90a7e

Please sign in to comment.