From 3bfa92ce4ba438fd3c6776f45b5a226ce0898d79 Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Thu, 17 Nov 2016 16:51:32 +0800 Subject: [PATCH] Alert: add render-content --- examples/docs/en-US/alert.md | 1 + examples/docs/zh-CN/alert.md | 1 + packages/alert/src/main.vue | 20 ++++++++++++++++++-- test/unit/specs/alert.spec.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/examples/docs/en-US/alert.md b/examples/docs/en-US/alert.md index 11990af59..53228a33f 100644 --- a/examples/docs/en-US/alert.md +++ b/examples/docs/en-US/alert.md @@ -166,6 +166,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) | — | — | | 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 b4d975560..18eaf173e 100644 --- a/examples/docs/zh-CN/alert.md +++ b/examples/docs/zh-CN/alert.md @@ -170,6 +170,7 @@ | **title** | 标题,**必选参数** | string | — | — | | type | 主题 | string | success/warning/info/error | info | | description | 辅助性文字 | string | — | — | +| render-content | 内容区域的渲染函数,会覆盖 `description` | function(h) | — | — | | 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 19558612d..5dfa6b192 100644 --- a/packages/alert/src/main.vue +++ b/packages/alert/src/main.vue @@ -4,7 +4,7 @@
{{ title }} -

{{ description }}

+ {{closeText}}
@@ -45,7 +45,8 @@ showIcon: { type: Boolean, default: false - } + }, + renderContent: Function }, data() { @@ -54,6 +55,21 @@ }; }, + 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 e9d1149a9..6230883dc 100644 --- a/test/unit/specs/alert.spec.js +++ b/test/unit/specs/alert.spec.js @@ -36,6 +36,35 @@ 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: `