From eda941e64fb8c331b2f343c3b45e78837557705b Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Wed, 28 Dec 2016 22:33:41 +0800 Subject: [PATCH] Alert: replace render function with default slot --- examples/docs/en-US/alert.md | 3 +-- examples/docs/zh-CN/alert.md | 3 +-- packages/alert/src/main.vue | 22 ++++------------------ test/unit/specs/alert.spec.js | 29 ----------------------------- 4 files changed, 6 insertions(+), 51 deletions(-) diff --git a/examples/docs/en-US/alert.md b/examples/docs/en-US/alert.md index 53228a33f..230e29551 100644 --- a/examples/docs/en-US/alert.md +++ b/examples/docs/en-US/alert.md @@ -165,8 +165,7 @@ Description includes a message with more detailed information. |---------- |-------------- |---------- |-------------------------------- |-------- | | **title** | title **REQUIRED** | string | — | — | | type | component type | string | success/warning/info/error | info | -| description | supportive text | string | — | — | -| render-content | render function for content area, overrides `description` | function(h) | — | — | +| description | descriptive text. Can also be passed with the default slot | string | — | — | | closable | if closable or not | boolean | — | true | | close-text | customized close button text | string | — | — | | show-icon | if a type icon is displayed | boolean | — | false | diff --git a/examples/docs/zh-CN/alert.md b/examples/docs/zh-CN/alert.md index 18eaf173e..09451c5b4 100644 --- a/examples/docs/zh-CN/alert.md +++ b/examples/docs/zh-CN/alert.md @@ -169,8 +169,7 @@ |---------- |-------------- |---------- |-------------------------------- |-------- | | **title** | 标题,**必选参数** | string | — | — | | type | 主题 | string | success/warning/info/error | info | -| description | 辅助性文字 | string | — | — | -| render-content | 内容区域的渲染函数,会覆盖 `description` | function(h) | — | — | +| description | 辅助性文字。也可通过默认 slot 传入 | string | — | — | | closable | 是否可关闭 | boolean | — | true | | close-text | 关闭按钮自定义文本 | string | — | — | | show-icon | 是否显示图标 | boolean | — | false | diff --git a/packages/alert/src/main.vue b/packages/alert/src/main.vue index 5dfa6b192..fc3742fbe 100644 --- a/packages/alert/src/main.vue +++ b/packages/alert/src/main.vue @@ -4,7 +4,9 @@
{{ title }} - + +

{{ description }}

+
{{closeText}}
@@ -45,8 +47,7 @@ showIcon: { type: Boolean, default: false - }, - renderContent: Function + } }, data() { @@ -55,21 +56,6 @@ }; }, - components: { - descContent: { - render(h) { - const parent = this.$parent; - if (parent.renderContent) { - return parent.renderContent(h); - } else if (parent.description) { - return

{ parent.description }

; - } else { - return ''; - } - } - } - }, - methods: { close() { this.visible = false; diff --git a/test/unit/specs/alert.spec.js b/test/unit/specs/alert.spec.js index 6230883dc..e9d1149a9 100644 --- a/test/unit/specs/alert.spec.js +++ b/test/unit/specs/alert.spec.js @@ -36,35 +36,6 @@ describe('Alert', () => { .to.equal('Unbowed, Unbent, Unbroken'); }); - it('render-content', () => { - vm = createVue({ - data() { - return { - text: 'test' - }; - }, - template: ` -
- -
- `, - methods: { - customContent(h) { - return ( -

- { this.text } -

- ); - } - } - }, true); - let button = vm.$el.querySelector('.custom-button'); - expect(button).to.exist; - expect(button.textContent).to.equal('test'); - }); - it('close', () => { vm = createVue({ template: `