Skip to content

Commit

Permalink
Merge branch 'su37josephxia-timeline'
Browse files Browse the repository at this point in the history
  • Loading branch information
shengxinjing committed Sep 4, 2020
2 parents 32b4a70 + 3854c3f commit 8d2a0aa
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build/bin/build-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ ComponentNames.forEach((name) => {
'notification',
'page-header',
'message',
'timeline',
'timeline-item',
'input-number',
'step',
'steps',
Expand Down
2 changes: 1 addition & 1 deletion packages/color-picker/src/components/picker-dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ref="hue"
:color="color"
vertical
style="float: right;"
style="float: right"
></hue-slider>
<sv-panel ref="sl" :color="color"></sv-panel>
</div>
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions packages/timeline-item/__tests__/TimelineItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import TimelineItem from '../TimelineItem.vue'
import { mount } from '@vue/test-utils'
describe('TimelineItem.vue', () => {
it('should timeline works', () => {
const wrapper = mount(TimelineItem, {
props: {
timestamp: '2018-04-15'
},
slots: {
default: '吃饭饭'
}
})

expect(wrapper.find('.el-timeline-item__timestamp').text()).toBe(
'2018-04-15'
)
expect(wrapper.find('.el-timeline-item__content').text()).toBe('吃饭饭')
})
})
2 changes: 1 addition & 1 deletion packages/timeline-item/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ElTimelineItem from '../timeline/src/item'
import ElTimelineItem from './TimelineItem'

/* istanbul ignore next */
ElTimelineItem.install = function (app) {
Expand Down
17 changes: 14 additions & 3 deletions packages/timeline/src/main.vue → packages/timeline/Timeline.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { Fragment } from 'vue'
export default {
name: 'ElTimeline',
Expand All @@ -21,10 +22,20 @@ export default {
'el-timeline': true,
'is-reverse': reverse
}
let slots = this.$slots.default || []
if (reverse) {
slots = slots.reverse()
let slots
if (this.$slots.default) {
slots = this.$slots.default()
let children
if (slots.length > 0 && slots[0].type === Fragment) {
children = slots[0].children
} else {
children = slots
}
if (reverse) {
children.reverse()
}
}
return <ul class={classes}>{slots}</ul>
}
}
Expand Down
38 changes: 38 additions & 0 deletions packages/timeline/__tests__/Timeline.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Timeline from '../Timeline.vue'
import { mount } from '@vue/test-utils'
describe('Timeline.vue', () => {
it('should slot works', () => {
const wrapper = mount(Timeline, {
slots: {
default: [`A`, `B`]
}
})
expect(wrapper.find('.el-timeline').text()).toBe('AB')
})

it('should props reverse works', () => {
const wrapper = mount(Timeline, {
props: {
reverse: true
},
slots: {
default: [`A`, `B`]
}
})
expect(wrapper.find('.el-timeline').text()).toBe('BA')
})

it('should slot null', () => {
const wrapper = mount(Timeline, {})
expect(wrapper.find('.el-timeline').text()).toBe('')
})

it('should slot empty array', () => {
const wrapper = mount(Timeline, {
slots: {
default: []
}
})
expect(wrapper.find('.el-timeline').text()).toBe('')
})
})
2 changes: 1 addition & 1 deletion packages/timeline/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Timeline from './src/main'
import Timeline from './Timeline'

/* istanbul ignore next */
Timeline.install = function (app) {
Expand Down

1 comment on commit 8d2a0aa

@vercel
Copy link

@vercel vercel bot commented on 8d2a0aa Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.