Skip to content

Commit

Permalink
Add date format support
Browse files Browse the repository at this point in the history
  • Loading branch information
junjizhi committed Jun 11, 2021
1 parent cd8da97 commit 97541be
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default Vue.extend({
:items="timelineItems"
:reverse="true"
:loading="true"
:date-format="'dd/MM/yy HH:mm:ss'"
/>
</b-card>
</div>
Expand All @@ -81,11 +82,11 @@ export default Vue.extend({

## Features
- [x] Loading spinner
- [ ] Support item head color variants
- [x] Support `reverse` props
- [x] Custom timestamp format
- [ ] Support item head color variants
- [ ] Support custom icons
- [ ] Refactor timeline and item into separate components
- [ ] Custom timestamp format

## Component Reference
### Properties
Expand Down
10 changes: 4 additions & 6 deletions dev/serve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ export default Vue.extend({
{
timestamp: Date.parse('2021-05-29T20:20:46.444Z'),
title: 'Dolore ullamco exercitation commodo',
content: 'Esse dolore consectetur aliqua laboris sunt aliqua do non.',
link: 'https://example1.com'
content: 'Esse dolore consectetur aliqua laboris sunt aliqua do non.'
},
{
timestamp: Date.parse('2021-05-28T20:20:46.444Z'),
title: 'Voluptate pariatur dolore laborum eu',
link: '#'
title: 'Voluptate pariatur dolore laborum eu'
},
{
timestamp: Date.parse('2021-01-28T20:20:46.444Z'),
title: 'Mollit aliqua velit nostrud ipsum',
content: 'Magna officia est fugiat sit esse consectetur labore elit nulla duis consectetur. Et sit velit ad ipsum officia.',
link: '#'
content: 'Magna officia est fugiat sit esse consectetur labore elit nulla duis consectetur. Et sit velit ad ipsum officia.'
}
]
}
Expand All @@ -47,6 +44,7 @@ export default Vue.extend({
:items="timelineItems"
:reverse="false"
:loading="true"
:date-format="'dd/MM/yy HH:mm:ss'"
/>
</b-card>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/bootstrap-vue-timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('bootstrap vue timeline component', () => {
propsData: {
items: sampleItems,
reverse: false,
loading: true
loading: true,
dateFormat: 'dd/MM/yy HH:mm:ss'
}
})
const text = wrapper.text()
Expand Down
6 changes: 4 additions & 2 deletions src/bootstrap-vue-timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default /*#__PURE__*/{
props: {
items: Array,
reverse: Boolean,
loading: Boolean
loading: Boolean,
dateFormat: String,
},
methods: {
orderedItems() {
Expand All @@ -39,7 +40,8 @@ export default /*#__PURE__*/{
return formatDistanceToNow(timestamp, { addSuffix: true })
},
formatFull(timestamp) {
return format(timestamp, 'yyyy-MM-dd HH:mm:ss')
const dateFormat = this.dateFormat || 'yyyy-MM-dd HH:mm:ss'
return format(timestamp, dateFormat)
},
timestampElementId(item) {
return item.timestamp + item.title + '-timestamp'
Expand Down

0 comments on commit 97541be

Please sign in to comment.