diff --git a/src/button/README.md b/src/button/README.md index 922c2de2b..b79d44c9b 100644 --- a/src/button/README.md +++ b/src/button/README.md @@ -132,3 +132,10 @@ Vue.use(Button); | --- | --- | --- | | click | Triggered when click button and not disabled or loading | _event: Event_ | | touchstart | Triggered when touch start | _event: TouchEvent_ | + +### Slots + +| Name | Description | +| ----------------- | ------------------- | +| default | Default slot | +| loading `v2.10.1` | Custom loading icon | diff --git a/src/button/README.zh-CN.md b/src/button/README.zh-CN.md index 8c01ac951..6d741ac99 100644 --- a/src/button/README.zh-CN.md +++ b/src/button/README.zh-CN.md @@ -155,3 +155,10 @@ Vue.use(Button); | ---------- | ---------------------------------------- | ------------------- | | click | 点击按钮,且按钮状态不为加载或禁用时触发 | _event: Event_ | | touchstart | 开始触摸按钮时触发 | _event: TouchEvent_ | + +### Slots + +| 名称 | 说明 | +| ----------------- | -------------- | +| default | 按钮内容 | +| loading `v2.10.1` | 自定义加载图标 | diff --git a/src/button/index.tsx b/src/button/index.tsx index 6b3c6e5c2..5cfd67ce8 100644 --- a/src/button/index.tsx +++ b/src/button/index.tsx @@ -10,7 +10,7 @@ import Loading, { LoadingType } from '../loading'; // Types import { CreateElement, RenderContext } from 'vue/types'; -import { DefaultSlots } from '../utils/types'; +import { ScopedSlot, DefaultSlots } from '../utils/types'; export type ButtonType = 'default' | 'primary' | 'info' | 'warning' | 'danger'; @@ -41,12 +41,16 @@ export type ButtonEvents = { onClick?(event: Event): void; }; +export type ButttonSlots = DefaultSlots & { + loading?: ScopedSlot; +}; + const [createComponent, bem] = createNamespace('button'); function Button( h: CreateElement, props: ButtonProps, - slots: DefaultSlots, + slots: ButttonSlots, ctx: RenderContext ) { const { @@ -112,12 +116,16 @@ function Button( if (loading) { content.push( - + slots.loading ? ( + slots.loading() + ) : ( + + ) ); } else if (icon) { content.push( @@ -188,4 +196,4 @@ Button.props = { }, }; -export default createComponent(Button); +export default createComponent(Button); diff --git a/src/button/test/__snapshots__/index.spec.js.snap b/src/button/test/__snapshots__/index.spec.js.snap index 239b474c2..6c8c5a8eb 100644 --- a/src/button/test/__snapshots__/index.spec.js.snap +++ b/src/button/test/__snapshots__/index.spec.js.snap @@ -7,6 +7,12 @@ exports[`icon-prefix prop 1`] = ` `; +exports[`loading slot 1`] = ` + +`; + exports[`loading-size prop 1`] = `