diff --git a/packages/notice-bar/index.js b/packages/notice-bar/index.js new file mode 100644 index 000000000..d33e20e76 --- /dev/null +++ b/packages/notice-bar/index.js @@ -0,0 +1,116 @@ +import { use } from '../utils'; +import Icon from '../icon'; + +const [sfc, bem] = use('notice-bar'); + +export default sfc({ + props: { + text: String, + mode: String, + color: String, + leftIcon: String, + background: String, + delay: { + type: [String, Number], + default: 1 + }, + scrollable: { + type: Boolean, + default: true + }, + speed: { + type: Number, + default: 50 + } + }, + + data() { + return { + wrapWidth: 0, + firstRound: true, + duration: 0, + offsetWidth: 0, + showNoticeBar: true, + animationClass: '' + }; + }, + + watch: { + text: { + handler() { + this.$nextTick(() => { + const { wrap, content } = this.$refs; + if (!wrap || !content) { + return; + } + + const wrapWidth = wrap.getBoundingClientRect().width; + const offsetWidth = content.getBoundingClientRect().width; + if (this.scrollable && offsetWidth > wrapWidth) { + this.wrapWidth = wrapWidth; + this.offsetWidth = offsetWidth; + this.duration = offsetWidth / this.speed; + this.animationClass = bem('play'); + } + }); + }, + immediate: true + } + }, + + methods: { + onClickIcon() { + this.showNoticeBar = this.mode !== 'closeable'; + }, + + onAnimationEnd() { + this.firstRound = false; + this.$nextTick(() => { + this.duration = (this.offsetWidth + this.wrapWidth) / this.speed; + this.animationClass = bem('play--infinite'); + }); + } + }, + + render(h) { + const { mode } = this; + + const iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : ''; + + const barStyle = { + color: this.color, + background: this.background + }; + + const contentStyle = { + paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px', + animationDelay: (this.firstRound ? this.delay : 0) + 's', + animationDuration: this.duration + 's' + }; + + return ( +
{ + this.$emit('click'); + }} + > + {this.leftIcon && } +
+
+ {this.$slots.default || this.text} +
+
+ {iconName && } +
+ ); + } +}); diff --git a/packages/notice-bar/index.vue b/packages/notice-bar/index.vue deleted file mode 100644 index 1f172f790..000000000 --- a/packages/notice-bar/index.vue +++ /dev/null @@ -1,131 +0,0 @@ - - - diff --git a/packages/notice-bar/test/__snapshots__/demo.spec.js.snap b/packages/notice-bar/test/__snapshots__/demo.spec.js.snap index e49d78e40..5dae16ca3 100644 --- a/packages/notice-bar/test/__snapshots__/demo.spec.js.snap +++ b/packages/notice-bar/test/__snapshots__/demo.spec.js.snap @@ -8,31 +8,26 @@ exports[`renders demo correctly 1`] = `
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
-
-
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
-
-
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
-
+
-
足协杯战线连续第2年上演广州德比战,上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
-
+
diff --git a/packages/swipe-cell/test/__snapshots__/demo.spec.js.snap b/packages/swipe-cell/test/__snapshots__/demo.spec.js.snap index 22ec9de06..476963127 100644 --- a/packages/swipe-cell/test/__snapshots__/demo.spec.js.snap +++ b/packages/swipe-cell/test/__snapshots__/demo.spec.js.snap @@ -4,11 +4,9 @@ exports[`renders demo correctly 1`] = `
-
建议在手机模式下浏览本示例
-