Skip to content

Commit 36192b2

Browse files
committed
feat(pickers): Extract UpButton.vue & convert span to button
1 parent 16fbac7 commit 36192b2

File tree

11 files changed

+94
-54
lines changed

11 files changed

+94
-54
lines changed

src/components/Datepicker.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<slot name="beforeCalendarHeader" />
6464
<Component
6565
:is="picker"
66+
:bootstrap-styling="bootstrapStyling"
6667
class="picker-view"
6768
:day-cell-content="dayCellContent"
6869
:disabled-dates="disabledDates"

src/components/PickerDay.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
<PickerHeader
66
v-if="showHeader"
7+
:bootstrap-styling="bootstrapStyling"
78
:is-next-disabled="isNextDisabled"
89
:is-previous-disabled="isPreviousDisabled"
910
:is-rtl="isRtl"
1011
@page-change="changePage($event)"
1112
>
1213
<slot slot="prevIntervalBtn" name="prevIntervalBtn" />
13-
<span
14-
:class="{ up: !isUpDisabled }"
15-
class="day__month_btn"
16-
@click="$emit('set-view', 'month')"
14+
<UpButton
15+
ref="up"
16+
:class="{ btn: bootstrapStyling }"
17+
:is-disabled="isUpDisabled"
18+
@select="$emit('set-view', 'month')"
1719
>
1820
{{ pageTitleDay }}
19-
</span>
21+
</UpButton>
2022
<slot slot="nextIntervalBtn" name="nextIntervalBtn" />
2123
</PickerHeader>
2224

@@ -55,10 +57,11 @@ import pickerMixin from '~/mixins/pickerMixin.vue'
5557
import DisabledDate from '~/utils/DisabledDate'
5658
import HighlightedDate from '~/utils/HighlightedDate'
5759
import PickerCells from './PickerCells.vue'
60+
import UpButton from './UpButton.vue'
5861
5962
export default {
6063
name: 'PickerDay',
61-
components: { PickerCells },
64+
components: { PickerCells, UpButton },
6265
mixins: [pickerMixin],
6366
props: {
6467
dayCellContent: {

src/components/PickerHeader.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
<template>
22
<header>
3-
<span
3+
<button
44
class="prev"
5-
:class="{ disabled: isPreviousDisabled, rtl: isRtl }"
5+
:class="{ btn: bootstrapStyling, rtl: isRtl }"
6+
:disabled="isPreviousDisabled"
7+
type="button"
68
@click="isPreviousDisabled ? null : $emit('page-change', -1)"
79
>
810
<slot name="prevIntervalBtn">
911
<span class="default">&lt;</span>
1012
</slot>
11-
</span>
13+
</button>
1214
<slot />
13-
<span
15+
<button
1416
class="next"
15-
:class="{ disabled: isNextDisabled, rtl: isRtl }"
17+
:class="{ btn: bootstrapStyling, rtl: isRtl }"
18+
:disabled="isNextDisabled"
19+
type="button"
1620
@click="isNextDisabled ? null : $emit('page-change', 1)"
1721
>
1822
<slot name="nextIntervalBtn">
1923
<span class="default">&gt;</span>
2024
</slot>
21-
</span>
25+
</button>
2226
</header>
2327
</template>
2428

2529
<script>
2630
export default {
2731
name: 'PickerHeader',
2832
props: {
33+
bootstrapStyling: {
34+
type: Boolean,
35+
default: false,
36+
},
2937
isNextDisabled: {
3038
type: Boolean,
3139
required: true,

src/components/PickerMonth.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
<PickerHeader
66
v-if="showHeader"
7+
:bootstrap-styling="bootstrapStyling"
78
:is-next-disabled="isNextDisabled"
89
:is-previous-disabled="isPreviousDisabled"
910
:is-rtl="isRtl"
1011
@page-change="changePage($event)"
1112
>
1213
<slot slot="prevIntervalBtn" name="prevIntervalBtn" />
13-
<span
14-
class="month__year_btn"
15-
:class="{ up: !isUpDisabled }"
16-
@click="$emit('set-view', 'year')"
14+
<UpButton
15+
ref="up"
16+
:class="{ btn: bootstrapStyling }"
17+
:is-disabled="isUpDisabled"
18+
@select="$emit('set-view', 'year')"
1719
>
1820
{{ pageTitleMonth }}
19-
</span>
21+
</UpButton>
2022
<slot slot="nextIntervalBtn" name="nextIntervalBtn" />
2123
</PickerHeader>
2224

@@ -43,10 +45,11 @@
4345
import pickerMixin from '~/mixins/pickerMixin.vue'
4446
import DisabledDate from '~/utils/DisabledDate'
4547
import PickerCells from './PickerCells.vue'
48+
import UpButton from './UpButton.vue'
4649
4750
export default {
4851
name: 'PickerMonth',
49-
components: { PickerCells },
52+
components: { PickerCells, UpButton },
5053
mixins: [pickerMixin],
5154
computed: {
5255
/**

src/components/PickerYear.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
<PickerHeader
66
v-if="showHeader"
7+
:bootstrap-styling="bootstrapStyling"
78
:is-next-disabled="isNextDisabled"
89
:is-previous-disabled="isPreviousDisabled"
910
:is-rtl="isRtl"
1011
@page-change="changePage($event)"
1112
>
1213
<slot slot="prevIntervalBtn" name="prevIntervalBtn" />
13-
<span>
14+
<UpButton ref="up" :class="{ btn: bootstrapStyling }" :is-disabled="true">
1415
{{ pageTitleYear }}
15-
</span>
16+
</UpButton>
1617
<slot slot="nextIntervalBtn" name="nextIntervalBtn" />
1718
</PickerHeader>
1819

@@ -39,10 +40,11 @@
3940
import pickerMixin from '~/mixins/pickerMixin.vue'
4041
import DisabledDate from '~/utils/DisabledDate'
4142
import PickerCells from './PickerCells.vue'
43+
import UpButton from './UpButton.vue'
4244
4345
export default {
4446
name: 'PickerYear',
45-
components: { PickerCells },
47+
components: { PickerCells, UpButton },
4648
mixins: [pickerMixin],
4749
props: {
4850
yearRange: {

src/components/UpButton.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<button
3+
class="vdp-datepicker__up"
4+
:disabled="isDisabled"
5+
type="button"
6+
@click="$emit('select')"
7+
>
8+
<slot />
9+
</button>
10+
</template>
11+
12+
<script>
13+
export default {
14+
name: 'UpButton',
15+
props: {
16+
isDisabled: {
17+
type: Boolean,
18+
default: false,
19+
},
20+
},
21+
}
22+
</script>

src/mixins/pickerMixin.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export default {
77
components: { PickerHeader },
88
inheritAttrs: false,
99
props: {
10+
bootstrapStyling: {
11+
type: Boolean,
12+
default: false,
13+
},
1014
disabledDates: {
1115
type: Object,
1216
default() {

src/styles/style.scss

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@
4343

4444
header {
4545
display: flex;
46+
height: 40px;
4647
justify-content: space-between;
47-
line-height: 40px;
4848

49-
span {
50-
display: inline-block;
51-
text-align: center;
52-
width: 71.42857142857143%;
49+
button {
50+
border: none;
51+
52+
&:hover:not(:disabled) {
53+
background: #eee;
54+
}
55+
56+
&.vdp-datepicker__up {
57+
color: #000;
58+
flex-grow: 5;
59+
}
5360
}
5461

5562
.prev,
@@ -59,6 +66,7 @@
5966
width: 14.285714285714286%;
6067

6168
.default {
69+
display: flex;
6270
text-indent: -10000px;
6371

6472
&:after {
@@ -82,9 +90,13 @@
8290
border-right: 10px solid #000;
8391
margin-left: -5px;
8492
}
93+
}
8594

86-
&.disabled:after {
87-
border-right: 10px solid #ddd;
95+
&:disabled {
96+
.default {
97+
&:after {
98+
border-right: 10px solid #ddd;
99+
}
88100
}
89101
}
90102
}
@@ -95,33 +107,18 @@
95107
border-left: 10px solid #000;
96108
margin-left: 5px;
97109
}
98-
99-
&.disabled:after {
100-
border-left: 10px solid #ddd;
101-
}
102110
}
103-
}
104-
105-
.prev:not(.disabled),
106-
.next:not(.disabled),
107-
.up:not(.disabled) {
108-
cursor: pointer;
109111

110-
&:hover {
111-
background: #eee;
112+
&:disabled {
113+
.default {
114+
&:after {
115+
border-left: 10px solid #ddd;
116+
}
117+
}
112118
}
113119
}
114120
}
115121

116-
.disabled {
117-
color: #ddd;
118-
cursor: default;
119-
120-
//&.selected {
121-
// color: #104756;
122-
//}
123-
}
124-
125122
.cell {
126123
border: 1px solid transparent;
127124
display: inline-block;

test/unit/specs/Datepicker/restrictedViews.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ describe('Datepicker with restricted views', () => {
6262
expect(wrapper.vm.allowedToShowView('month')).toEqual(true)
6363
expect(wrapper.vm.picker).toBe('PickerDay')
6464

65-
let upButton = wrapper.find('.day__month_btn')
65+
let upButton = wrapper.find('.vdp-datepicker__up')
6666
await upButton.trigger('click')
6767
expect(wrapper.vm.picker).toBe('PickerMonth')
6868

69-
upButton = wrapper.find('.month__year_btn')
70-
expect(upButton.element.tabIndex).toBe(-1)
69+
upButton = wrapper.find('.vdp-datepicker__up')
70+
expect(upButton.element.disabled).toBe(true)
7171

7272
await wrapper.setProps({
7373
minimumView: 'month',

test/unit/specs/PickerDay/pickerDay.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('PickerDay', () => {
6464
})
6565

6666
it('emits set-view event with `month` when the up button is clicked', async () => {
67-
const upButton = wrapper.find('.day__month_btn')
67+
const upButton = wrapper.find('.vdp-datepicker__up')
6868
await upButton.trigger('click')
6969
expect(wrapper.emitted('set-view')[0][0]).toBe('month')
7070
})

0 commit comments

Comments
 (0)