From 548568abb081616cad8589b46a2823579d8549e1 Mon Sep 17 00:00:00 2001 From: Caaalabash <1121062986@qq.com> Date: Tue, 4 Aug 2020 10:54:43 +0800 Subject: [PATCH] feat(backtop): add backtop component --- packages/backtop/__tests__/backtop.spec.ts | 29 ++++++ packages/backtop/doc/basic.vue | 40 ++++++++ packages/backtop/doc/index.stories.ts | 5 + packages/backtop/index.ts | 5 + packages/backtop/package.json | 12 +++ packages/backtop/src/index.vue | 113 +++++++++++++++++++++ packages/element-plus/index.ts | 3 + packages/element-plus/package.json | 1 + 8 files changed, 208 insertions(+) create mode 100644 packages/backtop/__tests__/backtop.spec.ts create mode 100644 packages/backtop/doc/basic.vue create mode 100644 packages/backtop/doc/index.stories.ts create mode 100644 packages/backtop/index.ts create mode 100644 packages/backtop/package.json create mode 100644 packages/backtop/src/index.vue diff --git a/packages/backtop/__tests__/backtop.spec.ts b/packages/backtop/__tests__/backtop.spec.ts new file mode 100644 index 0000000000..c45b0a064f --- /dev/null +++ b/packages/backtop/__tests__/backtop.spec.ts @@ -0,0 +1,29 @@ +import { mount } from '@vue/test-utils' +import Backtop from '../src/index.vue' + +const _mount = (template: string) => mount({ + components: { + 'el-backtop': Backtop, + }, + template, +}, { attachTo: document.body }) + +describe('Backtop.vue', () => { + test('render',async () => { + const wrapper = _mount(` +
+
+ +
+
+ `) + expect(wrapper.find('.el-backtop').exists()).toBe(false) + wrapper.element.scrollTop = 2000 + await wrapper.trigger('scroll') + expect(wrapper.find('.el-backtop').exists()).toBe(true) + expect(wrapper.find('.el-backtop').attributes('style')).toBe('right: 100px; bottom: 200px;') + expect(wrapper.find('.el-icon-caret-top').exists()).toBe(true) + await wrapper.trigger('click') + expect(wrapper.emitted()).toBeDefined() + }) +}) diff --git a/packages/backtop/doc/basic.vue b/packages/backtop/doc/basic.vue new file mode 100644 index 0000000000..1e1b8fb91b --- /dev/null +++ b/packages/backtop/doc/basic.vue @@ -0,0 +1,40 @@ + + + diff --git a/packages/backtop/doc/index.stories.ts b/packages/backtop/doc/index.stories.ts new file mode 100644 index 0000000000..95efd14ad2 --- /dev/null +++ b/packages/backtop/doc/index.stories.ts @@ -0,0 +1,5 @@ +export { default as BasicUsage } from './basic.vue' + +export default { + title: 'Backtop', +} diff --git a/packages/backtop/index.ts b/packages/backtop/index.ts new file mode 100644 index 0000000000..be24e8662a --- /dev/null +++ b/packages/backtop/index.ts @@ -0,0 +1,5 @@ +import { App } from 'vue' +import Backtop from './src/index.vue' +export default (app: App): void => { + app.component(Backtop.name, Backtop) +} diff --git a/packages/backtop/package.json b/packages/backtop/package.json new file mode 100644 index 0000000000..027256dd7e --- /dev/null +++ b/packages/backtop/package.json @@ -0,0 +1,12 @@ +{ + "name": "@element-plus/backtop", + "version": "0.0.0", + "main": "dist/index.js", + "license": "MIT", + "peerDependencies": { + "vue": "^3.0.0-rc.1" + }, + "devDependencies": { + "@vue/test-utils": "^2.0.0-beta.0" + } +} diff --git a/packages/backtop/src/index.vue b/packages/backtop/src/index.vue new file mode 100644 index 0000000000..65d0578981 --- /dev/null +++ b/packages/backtop/src/index.vue @@ -0,0 +1,113 @@ + + + diff --git a/packages/element-plus/index.ts b/packages/element-plus/index.ts index b4adeae233..ae3ca78d6d 100644 --- a/packages/element-plus/index.ts +++ b/packages/element-plus/index.ts @@ -1,5 +1,6 @@ import type { App } from 'vue' import ElAvatar from '@element-plus/avatar' +import ElBacktop from '@element-plus/backtop' import ElButton from '@element-plus/button' import ElBadge from '@element-plus/badge' import ElCard from '@element-plus/card' @@ -18,6 +19,7 @@ import ElNotification from '@element-plus/notification' export { ElAvatar, + ElBacktop, ElLayout, ElButton, ElBadge, @@ -37,6 +39,7 @@ export { export default function install(app: App): void { ElAvatar(app) + ElBacktop(app) ElButton(app) ElBadge(app) ElCard(app) diff --git a/packages/element-plus/package.json b/packages/element-plus/package.json index 7c77e61268..d0da9f9d50 100644 --- a/packages/element-plus/package.json +++ b/packages/element-plus/package.json @@ -16,6 +16,7 @@ "dependencies": { "@element-plus/avatar": "^0.0.0", "@element-plus/badge": "^0.0.0", + "@element-plus/backtop": "^0.0.0", "@element-plus/button": "^0.0.0", "@element-plus/breadcrumb": "^0.0.0", "@element-plus/card": "^0.0.0",