Skip to content

Commit

Permalink
feature(uiComponents) ergonode#70 Updated logic and layout for DatePi…
Browse files Browse the repository at this point in the history
…cker
  • Loading branch information
maciejkaczorowski committed Jul 18, 2019
1 parent 9584661 commit 2a51329
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 149 deletions.
45 changes: 40 additions & 5 deletions components/Inputs/Date/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*/
<template>
<div class="date-picker">
<slot name="header">
<DatePickerHeader :header="header" />
</slot>
<DatePickerNavigationHeader
:header="calendarHeader"
@changeCalendarType="onChangeCalendarType"
Expand All @@ -26,6 +29,7 @@
</template>

<script>
import DatePickerHeader from '~/components/Inputs/Date/DatePickerHeader';
import DatePickerNavigationHeader from '~/components/Inputs/Date/DatePickerNavigationHeader';
import DatePickerCalendarContent from '~/components/Inputs/Date/DatePickerCalendarContent';
import {
Expand All @@ -38,12 +42,15 @@ import {
getYearsWithinRange,
getHeaderForCalendarDaysType,
getHeaderForCalendarYearsType,
zeroPad,
CALENDAR_MONTHS,
} from '~/model/calendar/calendar';
import { CalendarType } from '~/model/calendar/CalendarType';
export default {
name: 'DatePicker',
components: {
DatePickerHeader,
DatePickerNavigationHeader,
DatePickerCalendarContent,
},
Expand All @@ -52,22 +59,50 @@ export default {
type: Date,
default: null,
},
calendarDate: {
type: Date,
default() {
return new Date();
},
},
},
data() {
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1;
const today = new Date();
const year = this.calendarDate.getFullYear();
const month = this.calendarDate.getMonth() + 1;
return {
years: getYearsWithinRange([], year),
currentYear: year,
currentMonth: month,
currentYear: today.getFullYear(),
currentMonth: today.getMonth() + 1,
month,
year,
selectedCalendarType: CalendarType.DAY,
calendarHeader: getHeaderForCalendarDaysType(month, year),
};
},
computed: {
header() {
if (!this.value) return 'Pick a date';
const day = this.value.getDate();
const month = this.value.getMonth();
const year = this.value.getFullYear();
switch (this.selectedCalendarType) {
case CalendarType.DAY:
return `${day}.${zeroPad(month, 2)}.${year}`;
case CalendarType.MONTH: {
const monthDesc = Object.values(CALENDAR_MONTHS)[month];
return `${monthDesc} ${year}`;
}
case CalendarType.YEAR:
return year;
default:
return '';
}
},
},
methods: {
onDateChange(value) {
this.$emit('input', value);
Expand Down
36 changes: 36 additions & 0 deletions components/Inputs/Date/DatePickerHeader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © Bold Brand Commerce Sp. z o.o. All rights reserved.
* See LICENSE for license details.
*/
/*
* Copyright © Bold Brand Commerce Sp. z o.o. All rights reserved.
* See LICENSE for license details.
*/
<template>
<div class="header">
<span v-text="header" />
</div>
</template>

<script>
export default {
name: 'DatePickerHeader',
props: {
header: {
type: [String, Number],
required: true,
},
},
};
</script>

<style lang="scss" scoped>
.header {
@include setFont(medium, small, regular, $graphite);
display: flex;
justify-content: center;
align-items: center;
height: 32px;
}
</style>
30 changes: 16 additions & 14 deletions components/Inputs/Date/DatePickerNavigationHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
*/
<template>
<div class="date-picker-header">
<Button
slot="previous"
icon="arrow-single trans-quarter"
fab
color="transparent"
ripple-color="rgba(235, 235, 236, 1)"
@click.native="onPrevious" />
<slot name="previous">
<Button
icon="arrow-single trans-quarter"
fab
color="transparent"
ripple-color="rgba(235, 235, 236, 1)"
@click.native="onPrevious" />
</slot>
<span
class="header"
@click="onClick"
v-text="header" />
<Button
slot="next"
icon="arrow-single trans-three-fourth"
fab
color="transparent"
ripple-color="rgba(235, 235, 236, 1)"
@click.native="onNext" />
<slot name="next">
<Button
icon="arrow-single trans-three-fourth"
fab
color="transparent"
ripple-color="rgba(235, 235, 236, 1)"
@click.native="onNext" />
</slot>
</div>
</template>

Expand Down
Loading

0 comments on commit 2a51329

Please sign in to comment.