Skip to content

Commit 331a1e1

Browse files
committed
feat:add step props
1 parent 9c04970 commit 331a1e1

File tree

12 files changed

+311
-40
lines changed

12 files changed

+311
-40
lines changed

build/webpack.config.base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
resolve: {
1212
extensions: ['.js', '.vue', '.json'],
1313
alias: {
14+
'@': utils.resolve('src'),
1415
'assets': utils.resolve('assets'),
1516
'static': utils.resolve('static'),
1617
'packages': utils.resolve('packages'),

doc/markdown/nSteps/en-US/index.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
# Step
1+
# Steps
2+
A navigation bar that guides users to complete tasks in accordance with the process.
3+
4+
- Steps Step bar component.
5+
- Step Every step in the step bar.
6+
7+
## Examples
8+
9+
### Basic use
10+
11+
:::demo
12+
```html
13+
<template>
14+
<n-steps :active="1">
15+
<n-step title="Step1" description="Step1 description"/>
16+
<n-step title="Step2" description="Step2 description"/>
17+
<n-step title="Step3" description="Step3 description"/>
18+
<n-step title="Step4" description="Step4 description"/>
19+
</n-steps>
20+
</template>
21+
22+
```
23+
:::
24+
25+
## API
26+
27+
### Steps
28+
29+
Step bar component
30+
31+
| Property | Description | Type | Default |
32+
| :--- | :--- | :--- | :--- |
33+
| active | Current active item | Number,String | |
34+
| direction | Specify the direction of the step bar. Currently supports horizontal (horizontal) and vertical (vertical) two directions | String | horizontal |
35+
36+
### Step
37+
38+
Every step in the step bar
39+
40+
| Property | Description | Type | Default |
41+
| :--- | :--- | :--- | :--- |
42+
| title | Title | String | |
43+
| description | Detailed description of the step, optional | String | |

doc/markdown/nSteps/zh-CN/index.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
引导用户按照流程完成任务的导航条。
33

44
- Steps 步骤条组件
5-
- StepsItem 步骤条内的每一个步骤。
5+
- Step 步骤条内的每一个步骤。
66

77
## 代码演示
88

@@ -20,4 +20,24 @@
2020
</template>
2121

2222
```
23-
:::
23+
:::
24+
25+
## API
26+
27+
### Steps
28+
29+
整体步骤条。
30+
31+
| 参数 | 说明 | 类型 | 默认值 |
32+
| :--- | :--- | :--- | :--- |
33+
| active | 当前活动值 | Number,String | |
34+
| direction | 指定步骤条方向。目前支持水平(horizontal)和竖直(vertical)两种方向 | String | horizontal |
35+
36+
### Step
37+
38+
步骤条内的每一个步骤。
39+
40+
| 参数 | 说明 | 类型 | 默认值 |
41+
| :--- | :--- | :--- | :--- |
42+
| title | 标题 | String | |
43+
| description | 步骤的详情描述,可选 | String | |

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"babel-plugin-syntax-jsx": "^6.18.0",
5858
"babel-plugin-transform-vue-jsx": "^3.7.0",
5959
"babel-preset-env": "^1.7.0",
60+
"classnames": "^2.2.6",
6061
"copy-webpack-plugin": "5.0.4",
6162
"css-loader": "2.1.1",
6263
"deepmerge": "^4.2.2",

packages/n-step/src/index.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
display: flex;
33
align-items: center;
44
margin: 0 0 0 5px;
5+
color: #8E8E93;
56
.icon{
67
text-align: center;
78
line-height: 30px;
89
height: 30px;
910
width: 30px;
10-
color: #8E8E93;
1111
border: 1px solid #8E8E93;
1212
border-radius: 50%;
1313
}
14+
.active {
15+
border: 1px solid #3498FF;
16+
}
1417
.content{
1518
margin-left: 10px;
1619
.title{
1720
font-family: PingFangSC-Medium;
1821
font-size: 16px;
19-
color: #8E8E93;
2022
line-height: 30px;
2123
}
2224
.description{
2325
font-family: PingFangSC-Regular;
2426
font-size: 14px;
25-
color: #8E8E93;
2627
line-height: 20px;
2728
}
2829
}
@@ -31,4 +32,7 @@
3132
height: 1px;
3233
background: #3498FF;
3334
}
35+
}
36+
.active {
37+
color: #3498FF;
3438
}

packages/n-step/src/index.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@ import { defineComponent,onMounted } from '@vue/composition-api';
22
import './index.scss';
33

44
interface stepProps {
5-
title: String
6-
description: String
5+
title: string
6+
description: string,
7+
isLatest: boolean,
8+
index: number,
9+
active: boolean,
710
}
811

912
export default defineComponent({
1013
name: 'NStep',
11-
props: ['title','description'],
12-
setup(props:stepProps, {parent,slots}) {
13-
onMounted(async () => {
14-
if (parent !== null) {
15-
console.log(parent.$attrs.active)
16-
}
17-
})
14+
props: ['title','description','isLatest','index', 'active'],
15+
setup(props:stepProps, {slots}) {
1816
return () => (
19-
<div class={['n-step']}>
20-
<div class="icon">1</div>
17+
<div class={['n-step',props.active ? 'active' : '']}>
18+
<div class={['icon',props.active ? 'active' : '' ]}>{props.index + 1}</div>
2119
<div class="content">
2220
<div class="title">{props.title}</div>
2321
<div class="description">{props.description}</div>
2422
</div>
25-
<div class="line" />
23+
{ !props.isLatest && <div class="line" /> }
2624
{slots.default && slots.default()}
2725
</div>
2826
)

packages/n-steps/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import nSteps from './src/index.tsx';
1+
import nSteps from './src/index';
22
nSteps.install = function (Vue) {
33
Vue.component('NSteps', nSteps);
44
};

packages/n-steps/src/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { filterEmpty, getPropsData } from '@/utils/props';
2+
import { cloneElement } from '@/utils/vnode';
3+
import './index.scss';
4+
5+
export default {
6+
name: 'NSteps',
7+
props: {
8+
vertical: {
9+
type: [Boolean, String]
10+
},
11+
active: {
12+
type: [Number]
13+
}
14+
},
15+
methods: {
16+
renderChild (child, index, filteredChildren) {
17+
const childProps = getPropsData(child);
18+
let setpProps = {
19+
props: {
20+
...childProps,
21+
active: index === this.active - 1,
22+
index,
23+
isLatest: index === filteredChildren.length - 1
24+
}
25+
};
26+
return cloneElement(child, setpProps);
27+
}
28+
},
29+
render () {
30+
const { vertical, $slots } = this;
31+
const filteredChildren = filterEmpty($slots.default);
32+
return (
33+
<div class={['n-steps', vertical ? 'vertical' : 'horizontal']}>
34+
{filteredChildren.map((child, index) => {
35+
return this.renderChild(child, index, filteredChildren);
36+
})}
37+
</div>
38+
);
39+
}
40+
};

packages/n-steps/src/index.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/utils/props.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const camelizeRE = /-(\w)/g;
2+
const camelize = str => {
3+
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
4+
};
5+
export function getPropsData (ele) {
6+
let componentOptions = ele.componentOptions;
7+
if (ele.$vnode) {
8+
componentOptions = ele.$vnode.componentOptions;
9+
}
10+
return componentOptions ? componentOptions.propsData || {} : {};
11+
};
12+
13+
export function isEmptyElement (c) {
14+
return !(c.tag || (c.text && c.text.trim() !== ''));
15+
}
16+
17+
export function isStringElement (c) {
18+
return !c.tag;
19+
}
20+
21+
export function filterEmpty (children = []) {
22+
return children.filter(c => !isEmptyElement(c));
23+
}
24+
25+
export function parseStyleText (cssText = '', camel) {
26+
const res = {};
27+
const listDelimiter = /;(?![^(]*\))/g;
28+
const propertyDelimiter = /:(.+)/;
29+
cssText.split(listDelimiter).forEach(function (item) {
30+
if (item) {
31+
const tmp = item.split(propertyDelimiter);
32+
if (tmp.length > 1) {
33+
const k = camel ? camelize(tmp[0].trim()) : tmp[0].trim();
34+
res[k] = tmp[1].trim();
35+
}
36+
}
37+
});
38+
return res;
39+
};

0 commit comments

Comments
 (0)