diff --git a/packages/element-plus/index.ts b/packages/element-plus/index.ts index 344bbf7749..2976341d0f 100644 --- a/packages/element-plus/index.ts +++ b/packages/element-plus/index.ts @@ -4,9 +4,10 @@ import ElBadge from '@element-plus/badge' import ElCard from '@element-plus/card' import ElTag from '@element-plus/tag' import ElDivider from '@element-plus/divider' +import ElTimeLine from '@element-plus/time-line' export { - ElButton, ElBadge, ElCard, ElDivider, ElTag, + ElButton, ElBadge, ElCard, ElDivider, ElTag, ElTimeLine, } export default function install(app: App): void { @@ -15,4 +16,5 @@ export default function install(app: App): void { ElCard(app) ElTag(app) ElDivider(app) + ElTimeLine(app) } diff --git a/packages/element-plus/package.json b/packages/element-plus/package.json index 1d5f269b8b..b7d5be193e 100644 --- a/packages/element-plus/package.json +++ b/packages/element-plus/package.json @@ -17,6 +17,8 @@ "@element-plus/badge": "^0.0.0", "@element-plus/button": "^0.0.0", "@element-plus/card": "^0.0.0", - "@element-plus/tag": "^0.0.0" + "@element-plus/tag": "^0.0.0", + "@element-plus/time-line": "^0.0.0", + "@element-plus/divider": "^0.0.0" } } diff --git a/packages/time-line/__tests__/time-line.spec.ts b/packages/time-line/__tests__/time-line.spec.ts new file mode 100644 index 0000000000..954edd7563 --- /dev/null +++ b/packages/time-line/__tests__/time-line.spec.ts @@ -0,0 +1,211 @@ +import { mount } from '@vue/test-utils' +import TimeLine from '../src/index.vue' +import TimeLineItem from '../src/item.vue' +import { defineComponent } from 'vue' + +const Component = defineComponent({ + components: { + 'el-timeline': TimeLine, + 'el-timeline-item': TimeLineItem, + }, + props: [], + data() { + return { + activities: [{ + content: 'Step 1: xxxxxx', + timestamp: '2018-04-11', + }, { + content: 'Step 2: xxxxxx', + timestamp: '2018-04-13', + }, { + content: 'Step 3: xxxxxx', + timestamp: '2018-04-15', + }], + } + }, + template: ` + + + {{activity.content}} + + + `, +}) + +describe('TimeLine.vue', () => { + test('create', () => { + const wrapper = mount(Component) + const vm = wrapper.vm + + const contentWrappers = wrapper.findAll('.el-timeline-item__content') + contentWrappers.forEach((content, index) => { + expect(content.text()).toEqual(vm.activities[index].content) + }) + + const timestampWrappers = wrapper.findAll('.el-timeline-item__timestamp') + timestampWrappers.forEach((timestamp, index) => { + expect(timestamp.text()).toEqual(vm.activities[index].timestamp) + }) + }) + + test('placement', () => { + const wrapper = mount({ + ...Component, + template: ` + + + {{activity.content}} + + + `, + data() { + return { + activities: [{ + content: 'Step 1: xxxxxx', + timestamp: '2018-04-11', + placement: 'top', + }, { + content: 'Step 2: xxxxxx', + timestamp: '2018-04-13', + }, { + content: 'Step 3: xxxxxx', + timestamp: '2018-04-15', + }], + } + }, + }) + const timestampWrapper = wrapper.findAll('.el-timeline-item__timestamp')[0] + expect(timestampWrapper.classes('is-top')).toBe(true) + }) + + test('hide-timestamp', () => { + const wrapper = mount({ + ...Component, + template: ` + + + {{activity.content}} + + + `, + data() { + return { + activities: [{ + content: 'Step 1: xxxxxx', + timestamp: '2018-04-11', + hideTimestamp: true, + }, { + content: 'Step 2: xxxxxx', + timestamp: '2018-04-13', + }, { + content: 'Step 3: xxxxxx', + timestamp: '2018-04-15', + }], + } + }, + }) + const timestampWrappers = wrapper.findAll('.el-timeline-item__timestamp') + expect(timestampWrappers.length).toEqual(2) + }) + + test('color', () => { + const wrapper = mount({ + ...Component, + template: ` + + + Step 1: xxxxxx + + + `, + }) + const vm = wrapper.vm + const nodeElm = vm.$el.querySelector('.el-timeline-item__node') + expect(nodeElm.style.backgroundColor).toEqual('rgb(255, 0, 0)') + }) + + test('type', () => { + const wrapper = mount({ + ...Component, + template: ` + + + Step 1: xxxxxx + + + `, + }) + const nodeWrapper = wrapper.find('.el-timeline-item__node') + expect(nodeWrapper.classes('el-timeline-item__node--primary')).toBe(true) + }) + + test('size', () => { + const wrapper = mount({ + ...Component, + template: ` + + + Step 1: xxxxxx + + + `, + }) + const nodeWrapper = wrapper.find('.el-timeline-item__node') + expect(nodeWrapper.classes('el-timeline-item__node--large')).toBe(true) + }) + + test('icon', () => { + const wrapper = mount({ + ...Component, + template: ` + + + Step 1: xxxxxx + + + `, + }) + const nodeWrapper = wrapper.find('.el-timeline-item__icon') + expect(nodeWrapper.classes('el-icon-more')).toBe(true) + }) + + test('dot', () => { + const wrapper = mount({ + ...Component, + template: ` + + + + + + `, + }) + + const dotWrapper = wrapper.find('.el-timeline-item__dot') + expect(dotWrapper.text()).toEqual('dot') + expect(wrapper.find('.el-timeline-item__node').exists()).toBe(false) + }) +}) diff --git a/packages/time-line/doc/basic.vue b/packages/time-line/doc/basic.vue new file mode 100644 index 0000000000..353f948541 --- /dev/null +++ b/packages/time-line/doc/basic.vue @@ -0,0 +1,46 @@ + + + diff --git a/packages/time-line/doc/index.stories.ts b/packages/time-line/doc/index.stories.ts new file mode 100644 index 0000000000..c62b4a98eb --- /dev/null +++ b/packages/time-line/doc/index.stories.ts @@ -0,0 +1,6 @@ +export { default as BasicUsage } from './basic.vue' + +export default { + title: 'TimeLine', +} + diff --git a/packages/time-line/index.ts b/packages/time-line/index.ts new file mode 100644 index 0000000000..5eeea18046 --- /dev/null +++ b/packages/time-line/index.ts @@ -0,0 +1,7 @@ +import { App } from 'vue' +import TimeLine from './src/index.vue' +import TimeLineItem from './src/item.vue' +export default (app: App): void => { + app.component(TimeLine.name, TimeLine) + app.component(TimeLineItem.name, TimeLineItem) +} diff --git a/packages/time-line/package.json b/packages/time-line/package.json new file mode 100644 index 0000000000..a6ba1a90ba --- /dev/null +++ b/packages/time-line/package.json @@ -0,0 +1,12 @@ +{ + "name": "@element-plus/time-line", + "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/time-line/src/index.vue b/packages/time-line/src/index.vue new file mode 100644 index 0000000000..2581f2e976 --- /dev/null +++ b/packages/time-line/src/index.vue @@ -0,0 +1,40 @@ + diff --git a/packages/time-line/src/item.vue b/packages/time-line/src/item.vue new file mode 100644 index 0000000000..4df9ba2dbc --- /dev/null +++ b/packages/time-line/src/item.vue @@ -0,0 +1,97 @@ + + +