Skip to content

Commit 635bd69

Browse files
author
Nathan Reyes
committed
Adds support for custom 'day-content' slots (Closes #117).
1 parent a3f3392 commit 635bd69

File tree

6 files changed

+78
-49
lines changed

6 files changed

+78
-49
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
# v0.9.4
2+
## Improvements
3+
### `v-calendar`
4+
* Adds support for 'day-content' slots. :tada: :tada: :tada: This adds a lot of flexibility by allowing you to provide your own day cells. The layout has also been improved to grow with your cells, so you can now build larger calendars to fill with your own content.
5+
6+
```html
7+
<v-calendar>
8+
<div
9+
slot='day-content'
10+
slot-scope='{ day, attributes, contentStyle }'
11+
class='my-day'>
12+
<!-- Be sure to display the day of the month somewhere in your content -->
13+
{{ day.day }}
14+
</div>
15+
</v-calendar>
16+
```
17+
```css
18+
/* Set width and height and `v-calendar` will resize appropriately */
19+
.my-day {
20+
width: 40px;
21+
height: 40px;
22+
}
23+
/* You can also apply your own hover styles */
24+
.my-day:hover {
25+
background-color: #dadada;
26+
}
27+
```
28+
29+
You can get access to the following slot props:
30+
31+
| Prop | Type | Description |
32+
| ---- | ---- | ----------- |
33+
| [`day`](https://docs.vcalendar.io/api#day-object) | Object | Object with various day info. Use the `day.day` number prop to display the day of month in your slot content. |
34+
| `attibutes` | Array | List of attributes for this day. |
35+
| `contentStyle` | Object | Content style to apply if you wish, derived from `themeStyles.dayContent` and other attributes. |
36+
137
# v0.9.3
238
## Bug Fixes
339
### `v-calendar`

src/components/Calendar.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ export default {
266266
&:focus
267267
outline: none
268268
269-
270269
.c-pane-divider
271270
width: 1px
272271
border: 1px inset

src/components/CalendarDay.vue

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
class='c-day'
1515
:style='dayCellStyle'>
1616
<!-- Background layers -->
17-
<!-- <transition-group
17+
<transition-group
1818
name='background'
1919
tag='div'
20-
class='c-day-backgrounds'>
20+
class='c-day-backgrounds c-day-layer'>
2121
<div
2222
v-for='background in backgrounds'
2323
:key='background.key'
@@ -27,39 +27,25 @@
2727
:style='background.style'>
2828
</div>
2929
</div>
30-
</transition-group> -->
30+
</transition-group>
3131
<!-- Content layer -->
32-
<!-- <div
33-
class='c-day-layer c-day-box-center-center'>
34-
<div
35-
ref='dayContent'
36-
class='c-day-content'
37-
:style='contentStyle'
38-
@click='click'
39-
@mouseenter='mouseenter'
40-
@mouseover='mouseover'
41-
@mouseleave='mouseleave'>
42-
<slot name='day-content'
43-
:day='day'
44-
:attributes='attributesList'>
45-
{{ day.label }}
46-
</slot>
47-
</div>
48-
</div> -->
4932
<div
50-
class='day-content c-day-box-center-center'
51-
:style='contentStyle'
33+
class='c-day-content-wrapper'
5234
@click='click'
5335
@mouseenter='mouseenter'
5436
@mouseover='mouseover'
5537
@mouseleave='mouseleave'>
56-
<slot name='day-content'
57-
:day='day'
38+
<slot
39+
name='day-content'
40+
:day='day'
41+
:content-style='contentStyle'
5842
:attributes='attributesList'>
5943
<div
60-
class='c-day-box-center-center'
61-
>
62-
{{ day.label }}
44+
class='c-day-content'
45+
:style='contentStyle'>
46+
<div>
47+
{{ day.label }}
48+
</div>
6349
</div>
6450
</slot>
6551
</div>
@@ -607,8 +593,9 @@ export default {
607593
flex: 1
608594
609595
.c-day
610-
min-height: $day-height
611596
position: relative
597+
min-height: $day-min-height
598+
z-index: 1
612599
613600
.c-day-layer
614601
position: absolute
@@ -636,11 +623,31 @@ export default {
636623
.c-day-box-center-bottom
637624
+box(center, flex-end)
638625
626+
.c-day-content-wrapper
627+
display: flex
628+
justify-content: center
629+
align-items: center
630+
pointer-events: all
631+
user-select: none
632+
cursor: default
633+
634+
.c-day-content
635+
display: flex
636+
justify-content: center
637+
align-items: center
638+
width: $day-content-width
639+
height: $day-content-height
640+
font-size: $day-content-font-size
641+
font-weight: $day-content-font-weight
642+
line-height: 1
643+
border-radius: $day-content-border-radius
644+
transition: all $day-content-transition-time
645+
margin: .1rem .08rem
646+
639647
.c-day-backgrounds
640-
position: relative
641-
width: 100%
642-
height: 100%
643648
overflow: hidden
649+
pointer-events: none
650+
z-index: -1
644651
backface-visibility: hidden // Prevents glitches in Chrome by forcing hardware acceleration
645652
646653
.c-day-background
@@ -677,19 +684,6 @@ export default {
677684
background-color: $bar-background-color
678685
transition: all $day-content-transition-time
679686
680-
.c-day-content
681-
// +box()
682-
// width: $day-content-width
683-
// height: $day-content-height
684-
font-size: $day-content-font-size
685-
font-weight: $day-content-font-weight
686-
line-height: 1
687-
border-radius: $day-content-border-radius
688-
transition: all $day-content-transition-time
689-
user-select: none
690-
cursor: default
691-
pointer-events: all
692-
693687
.c-day-popover-content
694688
font-size: $day-popover-font-size
695689
font-weight: $day-popover-font-weight

src/components/DatePicker.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export default {
330330
highlight: params => ({
331331
backgroundColor: this.tintColor,
332332
...(isDrag && {
333-
height: '1.7rem',
333+
height: '1.64rem',
334334
opacity: 0.5,
335335
}),
336336
...((isFunction(highlight) && highlight(params)) || highlight),

src/styles/vars.sass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ $weeks-padding: 5px $pane-horizontal-padding 7px $pane-horizontal-padding
6060
$weeks-translate-x: 20px
6161
$weeks-transition: all .25s ease-in-out
6262

63-
$day-height: 32px
63+
$day-min-height: 28px
6464
$day-content-width: 1.8rem
6565
$day-content-height: 1.8rem
6666
$day-content-font-size: $size-6

src/utils/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ const defaults = {
7070
maxTapDuration: 200, // ms
7171
highlight: {
7272
animated: true,
73-
height: '1.9rem',
73+
height: '1.8rem',
7474
borderWidth: '0',
7575
borderStyle: 'solid',
7676
opacity: 1,
7777
},
7878
highlightCaps: {
7979
animated: true,
80-
height: '1.9rem',
80+
height: '1.8rem',
8181
borderWidth: '0',
8282
borderStyle: 'solid',
8383
opacity: 1,

0 commit comments

Comments
 (0)