datepicker: add clear button (#12480)

* datepicker: add clear button

* use close icon instead of "x" as text
This commit is contained in:
negue
2020-08-29 17:22:31 +02:00
committed by GitHub
parent 1b301e9c68
commit aa1ea74daa
2 changed files with 23 additions and 1 deletions

View File

@@ -276,6 +276,7 @@
:date.sync="task.date" :date.sync="task.date"
:disabled="challengeAccessRequired" :disabled="challengeAccessRequired"
:highlighted="calendarHighlights" :highlighted="calendarHighlights"
:clear-button="true"
/> />
</div> </div>
</div> </div>

View File

@@ -12,6 +12,12 @@
calendar-class="calendar-padding" calendar-class="calendar-padding"
@input="upDate($event)" @input="upDate($event)"
> >
<div slot="afterDateInput"
class="vdp-datepicker__clear-button"
v-if="clearButton && value"
v-html="icons.close"
@click="upDate(null)">
</div>
<div slot="beforeCalendarHeader"> <div slot="beforeCalendarHeader">
<div class="datetime-buttons"> <div class="datetime-buttons">
<button <button
@@ -37,17 +43,19 @@
import moment from 'moment'; import moment from 'moment';
import datepicker from 'vuejs-datepicker'; import datepicker from 'vuejs-datepicker';
import calendarIcon from '@/assets/svg/calendar.svg'; import calendarIcon from '@/assets/svg/calendar.svg';
import closeIcon from '@/assets/svg/close.svg';
export default { export default {
components: { components: {
datepicker, datepicker,
}, },
props: ['date', 'disabled', 'highlighted'], props: ['date', 'disabled', 'highlighted', 'clearButton'],
data () { data () {
return { return {
value: this.date, value: this.date,
icons: Object.freeze({ icons: Object.freeze({
calendar: calendarIcon, calendar: calendarIcon,
close: closeIcon,
}), }),
}; };
}, },
@@ -195,4 +203,17 @@ export default {
color: $gray-50; color: $gray-50;
} }
} }
.vdp-datepicker__clear-button {
background: transparent !important;
display: block;
height: 30px;
cursor: pointer;
svg {
margin: auto 0.75rem;
width: 0.75rem;
height: 30px;
}
}
</style> </style>