Skip to content

Commit ced98ff

Browse files
committed
Support item slots
1 parent 58fa225 commit ced98ff

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,22 @@ export default Vue.extend({
8888
- [x] Support `reverse` props
8989
- [x] Custom timestamp format
9090
- [x] Support item head color variants
91+
- [x] Support custom slots
9192
- [ ] Support custom icons
9293
- [ ] Refactor timeline and item into separate components
9394
- [ ] Emit events
9495

9596
## Component Reference
9697
### Props
9798

98-
| Name | Type | Description |
99-
| ------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100-
| `items` | `Array` | A list of timeline items to display. Supported keys include: `timestamp`, `title`, `content`. |
101-
| `reverse` | `Boolean` | The component displays a vertical timeline in the order of the `items` prop. If `reserve` is set to false, it displays items in reverse order.<br/> Default: false. |
102-
| `loading` | `Boolean` | If true, display a loading spinner in the last item. |
103-
| `date-format` | `String` | Controls the date format in the tooltip when you hover the human friendly time. Default: 'yyyy-MM-dd HH:mm:ss' |
104-
| `variant` | `String` | Color variant. It supports [Bootstrap color variants](https://bootstrap-vue.org/docs/reference/color-variants#color-variants-and-css-class-mapping), including 'primary', 'success'. Default: 'primary' |
99+
| Name | Type | Description | Default |
100+
| --------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
101+
| `items` | `Array` | A list of timeline items to display. Supported keys include: `timestamp`, `title`, `content`. | |
102+
| `reverse` | `Boolean` | The component displays a vertical timeline in the order of the `items` prop. If `reserve` is set to false, it displays items in reverse order.<br/> Default: false. | |
103+
| `loading` | `Boolean` | If true, display a loading spinner in the last item. | |
104+
| `date-format` | `String` | Controls the date format in the tooltip when you hover the human friendly time. Default: 'yyyy-MM-dd HH:mm:ss' | |
105+
| `variant` | `String` | Color variant. It supports [Bootstrap color variants](https://bootstrap-vue.org/docs/reference/color-variants#color-variants-and-css-class-mapping), including 'primary', 'success'. Default: 'primary' | |
106+
| `human-friendly-time` | `Boolean` | Displays human friendly time, e.g., '2 months ago'. If false, display the time as formatted according to the `dateFormat` param. Default: true | `true` |
105107
### Slots
106108
N/A
107109
### Events

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-vue-timeline",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"author": "Junji Zhi <[email protected]>",
55
"license": "MIT",
66
"repository": {

src/bootstrap-vue-timeline.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export default /*#__PURE__*/{
3636
* Default: 'primary'
3737
*/
3838
variant: String,
39+
/**
40+
* Displays human friendly time, e.g., '2 months ago'. If false, display the time as formatted according to the `dateFormat` param.
41+
* Default: true
42+
*/
43+
humanFriendlyTime: {
44+
type: Boolean,
45+
default: true
46+
}
3947
},
4048
methods: {
4149
bootstrapVariant() {
@@ -104,18 +112,23 @@ export default /*#__PURE__*/{
104112
<small
105113
:id="timestampElementId(item)"
106114
class="mt-2"
107-
> {{ formatAgo(item.timestamp) }}</small>
115+
> {{ humanFriendlyTime ? formatAgo(item.timestamp) : formatFull(item.timestamp) }}</small>
108116

109117
<b-tooltip
110118
:target="timestampElementId(item)"
111119
triggers="hover"
112120
>
113-
{{ formatFull(item.timestamp) }}
121+
{{ humanFriendlyTime ? formatFull(item.timestamp) : formatAgo(item.timestamp) }}
114122
</b-tooltip>
115123
</div>
116124

117125
<small class="mb-1 item-description">
118-
{{ item.content || '' }}
126+
<slot
127+
:item="item"
128+
name="item"
129+
>
130+
{{ item.content || '' }}
131+
</slot>
119132
</small>
120133
</div>
121134
</b-list-group-item>

0 commit comments

Comments
 (0)