diff --git a/docs/markdown/v2-progress-tracking.md b/docs/markdown/v2-progress-tracking.md index b5cb740b7..7959b9002 100644 --- a/docs/markdown/v2-progress-tracking.md +++ b/docs/markdown/v2-progress-tracking.md @@ -54,6 +54,7 @@ ## NoticeBar - 新增`left-icon`插槽 +- 新增`right-icon`插槽 ### Sku diff --git a/packages/notice-bar/index.js b/packages/notice-bar/index.js index 9e98dc09a..97e6d1b95 100644 --- a/packages/notice-bar/index.js +++ b/packages/notice-bar/index.js @@ -77,9 +77,7 @@ export default sfc({ }, render(h) { - const { mode } = this; - - const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : ''; + const { slots, mode, leftIcon, onClickIcon } = this; const barStyle = { color: this.color, @@ -92,20 +90,41 @@ export default sfc({ animationDuration: this.duration + 's' }; - const LeftIcon = - this.slots('left-icon') || - (this.leftIcon && ); + function LeftIcon() { + const slot = slots('left-icon'); + + if (slot) { + return slot; + } + + if (leftIcon) { + return ; + } + } + + function RightIcon() { + const slot = slots('right-icon'); + + if (slot) { + return slot; + } + + const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : ''; + if (iconName) { + return ; + } + } return (
{ this.$emit('click'); }} > - {LeftIcon} + {LeftIcon()}
- {iconName && ( - - )} + {RightIcon()}
); } diff --git a/packages/notice-bar/index.less b/packages/notice-bar/index.less index 26e8dde79..54187050c 100644 --- a/packages/notice-bar/index.less +++ b/packages/notice-bar/index.less @@ -11,17 +11,14 @@ color: @orange-dark; background-color: @orange-light; - &__left-icon { + &__left-icon, + &__right-icon { font-size: 16px; min-width: 22px; } &__right-icon { - top: 50%; - right: 15px; - font-size: 16px; - position: absolute; - margin-top: -0.5em; + text-align: right; } &__wrap { @@ -63,11 +60,6 @@ } } } - - &--withicon { - position: relative; - padding-right: 40px; - } } /** diff --git a/packages/notice-bar/test/__snapshots__/index.spec.js.snap b/packages/notice-bar/test/__snapshots__/index.spec.js.snap index 2b0a8b6a2..ad9b50e93 100644 --- a/packages/notice-bar/test/__snapshots__/index.spec.js.snap +++ b/packages/notice-bar/test/__snapshots__/index.spec.js.snap @@ -1,10 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`left-icon slot 1`] = ` +exports[`icon slot 1`] = `
Custom Left Icon
Content
-
-
+
Custom Right Icon `; diff --git a/packages/notice-bar/test/index.spec.js b/packages/notice-bar/test/index.spec.js index c38fc7397..df1b7a133 100644 --- a/packages/notice-bar/test/index.spec.js +++ b/packages/notice-bar/test/index.spec.js @@ -13,12 +13,13 @@ test('close event', () => { expect(wrapper.emitted('close')).toBeTruthy(); }); -test('left-icon slot', () => { +test('icon slot', () => { const wrapper = mount({ template: ` Content + `, components: {