feat(progress): add default slot (#1426)

* feat(progress): add default slot

* feat: add slot param

* feat: update

* feat: perf slot
This commit is contained in:
kooriookami 2021-02-05 16:27:44 +08:00 committed by GitHub
parent 6cba9795d6
commit fcf86b9730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 187 additions and 15 deletions

View File

@ -129,4 +129,13 @@ describe('Progress.vue', () => {
})
expect(wrapper.find('.el-progress__text').text()).toBe('占比100%')
})
test('slot', () => {
const wrapper = mount(Progress, {
slots: {
default: '自定义内容',
},
})
expect(wrapper.find('.el-progress__text').text()).toBe('自定义内容')
})
})

View File

@ -17,7 +17,11 @@
<div v-if="type === 'line'" class="el-progress-bar">
<div class="el-progress-bar__outer" :style="{height: `${strokeWidth}px`}">
<div class="el-progress-bar__inner" :style="barStyle">
<div v-if="showText && textInside" class="el-progress-bar__innerText">{{ content }}</div>
<div v-if="(showText || $slots.default) && textInside" class="el-progress-bar__innerText">
<slot v-bind="slotData">
<span>{{ content }}</span>
</slot>
</div>
</div>
</div>
</div>
@ -43,12 +47,14 @@
</svg>
</div>
<div
v-if="showText && !textInside"
v-if="(showText || $slots.default) && !textInside"
class="el-progress__text"
:style="{fontSize: `${progressTextSize}px`}"
>
<template v-if="!status">{{ content }}</template>
<i v-else :class="iconClass"></i>
<slot v-bind="slotData">
<span v-if="!status">{{ content }}</span>
<i v-else :class="iconClass"></i>
</slot>
</div>
</div>
</template>
@ -172,7 +178,7 @@ export default defineComponent({
const circlePathStyle = computed(() => {
return {
strokeDasharray: `${perimeter.value * rate.value * (props.percentage / 100) }px, ${perimeter.value}px`,
strokeDasharray: `${perimeter.value * rate.value * (props.percentage / 100)}px, ${perimeter.value}px`,
strokeDashoffset: strokeDashoffset.value,
transition: 'stroke-dasharray 0.6s ease 0s, stroke 0.6s ease',
}
@ -249,6 +255,12 @@ export default defineComponent({
}
}
const slotData = computed(() => {
return {
percentage: props.percentage,
}
})
return {
barStyle,
relativeStrokeWidth,
@ -264,6 +276,7 @@ export default defineComponent({
progressTextSize,
content,
getCurrentColor,
slotData,
}
},
})

View File

@ -5,13 +5,14 @@
@include b(progress) {
position: relative;
line-height: 1;
display: flex;
align-items: center;
@include e(text) {
font-size:14px;
font-size: 14px;
color: $--color-text-regular;
display: inline-block;
vertical-align: middle;
margin-left: 10px;
margin-left: 5px;
min-width: 50px;
line-height: 1;
i {
@ -20,7 +21,7 @@
}
}
@include m((circle,dashboard)) {
@include m((circle, dashboard)) {
display: inline-block;
.#{$namespace}-progress__text {
@ -91,11 +92,7 @@
}
@include b(progress-bar) {
padding-right: 50px;
display: inline-block;
vertical-align: middle;
width: 100%;
margin-right: -55px;
flex-grow: 1;
box-sizing: border-box;
@include e(outer) {

View File

@ -3,7 +3,20 @@
margin-bottom: 15px;
width: 350px;
}
.#{$namespace}-progress--circle {
margin-right: 15px;
}
.percentage-value {
display: block;
margin-top: 10px;
font-size: 28px;
}
.percentage-label {
display: block;
margin-top: 10px;
font-size: 12px;
}
}

View File

@ -159,6 +159,29 @@ You also can specify `type` attribute to `dashboard` to use dashboard progress b
```
:::
### Customized content
:::demo Use default slot to add customized content.
```html
<el-progress :percentage="50">
<el-button type="text">Content</el-button>
</el-progress>
<el-progress :text-inside="true" :stroke-width="20" :percentage="50" status="exception">
<span>Content</span>
</el-progress>
<el-progress type="circle" :percentage="100" status="success">
<el-button type="success" icon="el-icon-check" circle></el-button>
</el-progress>
<el-progress type="dashboard" :percentage="80">
<template #default="{ percentage }">
<span class="percentage-value">{{ percentage }}%</span>
<span class="percentage-label">Progressing</span>
</template>
</el-progress>
```
:::
### Attributes
| Attribute | Description | Type | Accepted Values | Default |
| --- | ---- | ---- | ---- | ---- |
@ -172,3 +195,8 @@ You also can specify `type` attribute to `dashboard` to use dashboard progress b
| show-text | whether to show percentage | boolean | — | true |
| stroke-linecap | circle/dashboard type shape at the end path | string | butt/round/square | round |
| format | custom text format | function(percentage) | — | — |
### Slot
| name | Description |
|------|--------|
| default | Customized content, parameter is { percentage } |

View File

@ -157,6 +157,29 @@ Puede utilizar el atributo `color` para establecer el color de la barra de progr
```
:::
### Customized content
:::demo Use default slot to add customized content.
```html
<el-progress :percentage="50">
<el-button type="text">Content</el-button>
</el-progress>
<el-progress :text-inside="true" :stroke-width="20" :percentage="50" status="exception">
<span>Content</span>
</el-progress>
<el-progress type="circle" :percentage="100" status="success">
<el-button type="success" icon="el-icon-check" circle></el-button>
</el-progress>
<el-progress type="dashboard" :percentage="80">
<template #default="{ percentage }">
<span class="percentage-value">{{ percentage }}%</span>
<span class="percentage-label">Progressing</span>
</template>
</el-progress>
```
:::
### Atributos
| Atributo | Descripción | Tipo | Valores aceptado | Por defecto |
| ------------ | ---------------------------------------- | ------- | ----------------- | ----------- |
@ -170,3 +193,8 @@ Puede utilizar el atributo `color` para establecer el color de la barra de progr
| show-text | mostrar porcentaje | boolean | — | true |
| stroke-linecap | circle/dashboard type shape at the end path | string | butt/round/square | round |
| format | personalizar el formato de texto estableciendo format | function(percentage) | — | — |
### Slot
| name | Description |
|------|--------|
| default | Customized content, parameter is { percentage } |

View File

@ -159,6 +159,29 @@ Vous pouvez également spécifier l'attribut `type` de `dashboard` pour utiliser
```
:::
### Customized content
:::demo Use default slot to add customized content.
```html
<el-progress :percentage="50">
<el-button type="text">Content</el-button>
</el-progress>
<el-progress :text-inside="true" :stroke-width="20" :percentage="50" status="exception">
<span>Content</span>
</el-progress>
<el-progress type="circle" :percentage="100" status="success">
<el-button type="success" icon="el-icon-check" circle></el-button>
</el-progress>
<el-progress type="dashboard" :percentage="80">
<template #default="{ percentage }">
<span class="percentage-value">{{ percentage }}%</span>
<span class="percentage-label">Progressing</span>
</template>
</el-progress>
```
:::
### Attributs
| Attribut | Description | Type | Valeurs acceptées | Défaut |
@ -173,3 +196,8 @@ Vous pouvez également spécifier l'attribut `type` de `dashboard` pour utiliser
| show-text | Si le pourcentage doit être affiché. | boolean | — | true |
| stroke-linecap | circle/dashboard type shape at the end path | string | butt/round/square | round |
| format | Vous pouvez personnaliser le format du texte en définissant le format | function(percentage) | — | — |
### Slot
| name | Description |
|------|--------|
| default | Customized content, parameter is { percentage } |

View File

@ -159,6 +159,29 @@
```
:::
### Customized content
:::demo Use default slot to add customized content.
```html
<el-progress :percentage="50">
<el-button type="text">Content</el-button>
</el-progress>
<el-progress :text-inside="true" :stroke-width="20" :percentage="50" status="exception">
<span>Content</span>
</el-progress>
<el-progress type="circle" :percentage="100" status="success">
<el-button type="success" icon="el-icon-check" circle></el-button>
</el-progress>
<el-progress type="dashboard" :percentage="80">
<template #default="{ percentage }">
<span class="percentage-value">{{ percentage }}%</span>
<span class="percentage-label">Progressing</span>
</template>
</el-progress>
```
:::
### 属性
| Attribute | Description | Type | Accepted Values | Default |
| --- | ---- | ---- | ---- | ---- |
@ -172,3 +195,8 @@
| show-text | パーセンテージ表示の有無 | boolean | — | true |
| stroke-linecap | 終点でのサークル/ダッシュボード型の形状 | string | butt/round/square | round |
| format | カスタムテキスト形式 | function(percentage) | — | — |
### Slot
| name | Description |
|------|--------|
| default | Customized content, parameter is { percentage } |

View File

@ -163,6 +163,29 @@ Progress 组件可通过 `type` 属性来指定使用环形进度条,在环形
```
:::
### 自定义内容
:::demo 通过默认插槽添加自定义内容。
```html
<el-progress :percentage="50">
<el-button type="text">自定义内容</el-button>
</el-progress>
<el-progress :text-inside="true" :stroke-width="20" :percentage="50" status="exception">
<span>自定义内容</span>
</el-progress>
<el-progress type="circle" :percentage="100" status="success">
<el-button type="success" icon="el-icon-check" circle></el-button>
</el-progress>
<el-progress type="dashboard" :percentage="80">
<template #default="{ percentage }">
<span class="percentage-value">{{ percentage }}%</span>
<span class="percentage-label">当前进度</span>
</template>
</el-progress>
```
:::
### Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|------------- |---------------- |---------------- |---------------------- |-------- |
@ -176,3 +199,8 @@ Progress 组件可通过 `type` 属性来指定使用环形进度条,在环形
| show-text | 是否显示进度条文字内容 | boolean | — | true |
| stroke-linecap | circle/dashboard 类型路径两端的形状 | string | butt/round/square | round |
| format | 指定进度条文字内容 | function(percentage) | — | — |
### Slot
| name | 说明 |
|------|--------|
| default | 自定义内容,参数为 { percentage } |