-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* v-picker * v-time-picker-clock * v-time-picker-title * v-date-picker-title * v-date-picker-header * v-date-picker-years * v-date-picker-date-table, v-date-picker-month-table * v-time-picker * v-date-picker * misc, cleanup * test: touch usage in pickers * added transition prop to v-picker * fixes, codebeat improvements * fixes, codebeat improvements * fixes, codebeat improvements * codebeat improvements * fixed picker title background in dark mode * code style update * ampm computed prop * even more refactoring (picker-button mixin) * fixed test * fix(date-picker): incorrect button styles active and current dates (and months) in date-picker had incorrect styles fixes #2812 (cherry picked from commit 2e9d6af) * fix(date-picker): allow external switching between date and month view switching between date and month view using type prop was not working closes #2809 (cherry picked from commit d6935aa) * fix: do not pad hours with 0 in am/pm mode * fix: time picker clock size * fix: time picker title colon size in landscape mode * fix: time picker active & disabled button text color * fix: do not emit input if hour/minute is not allowed * fix: restored firstAllowed
- Loading branch information
1 parent
8b96ef9
commit e2dbf20
Showing
64 changed files
with
7,280 additions
and
5,834 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Mixins | ||
import Colorable from '../../mixins/colorable' | ||
import DatePickerTable from './mixins/date-picker-table' | ||
|
||
// Utils | ||
import { pad, createNativeLocaleFormatter, monthChange } from './util' | ||
import { createRange } from '../../util/helpers' | ||
import isValueAllowed from '../../util/isValueAllowed' | ||
|
||
export default { | ||
name: 'v-date-picker-date-table', | ||
|
||
mixins: [ | ||
Colorable, | ||
DatePickerTable | ||
], | ||
|
||
props: { | ||
firstDayOfWeek: { | ||
type: [String, Number], | ||
default: 0 | ||
}, | ||
weekdayFormat: { | ||
type: Function, | ||
default: null | ||
} | ||
}, | ||
|
||
computed: { | ||
formatter () { | ||
return this.format || createNativeLocaleFormatter(this.locale, { day: 'numeric', timeZone: 'UTC' }, { start: 8, length: 2 }) | ||
}, | ||
weekdayFormatter () { | ||
return this.weekdayFormat || createNativeLocaleFormatter(this.locale, { weekday: 'narrow', timeZone: 'UTC' }) | ||
}, | ||
weekDays () { | ||
const first = parseInt(this.firstDayOfWeek, 10) | ||
|
||
return this.weekdayFormatter | ||
? createRange(7).map(i => this.weekdayFormatter(`2017-01-${first + i + 15}`)) // 2017-01-15 is Sunday | ||
: createRange(7).map(i => ['S', 'M', 'T', 'W', 'T', 'F', 'S'][(i + first) % 7]) | ||
} | ||
}, | ||
|
||
methods: { | ||
calculateTableDate (delta) { | ||
return monthChange(this.tableDate, Math.sign(delta || 1)) | ||
}, | ||
genTHead () { | ||
const days = this.weekDays.map(day => this.$createElement('th', day)) | ||
return this.$createElement('thead', this.genTR(days)) | ||
}, | ||
genButtonClasses (day, disabled) { | ||
const isActive = this.isActive(day) | ||
const isCurrent = this.isCurrent(day) | ||
const classes = Object.assign({ | ||
'btn--active': isActive, | ||
'btn--outline': isCurrent && !isActive, | ||
'btn--disabled': disabled | ||
}, this.themeClasses) | ||
|
||
return (isActive || isCurrent) | ||
? this.addBackgroundColorClassChecks(classes) | ||
: classes | ||
}, | ||
genButton (day) { | ||
const date = `${this.displayedYear}-${pad(this.displayedMonth + 1)}-${pad(day)}` | ||
const disabled = !isValueAllowed(date, this.allowedDates) | ||
|
||
return this.$createElement('button', { | ||
staticClass: 'btn btn--raised btn--icon', | ||
'class': this.genButtonClasses(day, disabled), | ||
attrs: { | ||
type: 'button' | ||
}, | ||
domProps: { | ||
disabled, | ||
innerHTML: `<span class="btn__content">${this.formatter(date)}</span>` | ||
}, | ||
on: disabled ? {} : { | ||
click: () => this.$emit('input', date) | ||
} | ||
}) | ||
}, | ||
// Returns number of the days from the firstDayOfWeek to the first day of the current month | ||
weekDaysBeforeFirstDayOfTheMonth () { | ||
const firstDayOfTheMonth = new Date(`${this.displayedYear}-${pad(this.displayedMonth + 1)}-01T00:00:00+00:00`) | ||
const weekDay = firstDayOfTheMonth.getUTCDay() | ||
return (weekDay - parseInt(this.firstDayOfWeek) + 7) % 7 | ||
}, | ||
genTBody () { | ||
const children = [] | ||
const daysInMonth = new Date(this.displayedYear, this.displayedMonth + 1, 0).getDate() | ||
let rows = [] | ||
const day = this.weekDaysBeforeFirstDayOfTheMonth() | ||
|
||
for (let i = 0; i < day; i++) { | ||
rows.push(this.$createElement('td')) | ||
} | ||
|
||
for (let i = 1; i <= daysInMonth; i++) { | ||
rows.push(this.$createElement('td', [this.genButton(i)])) | ||
|
||
if (rows.length % 7 === 0) { | ||
children.push(this.genTR(rows)) | ||
rows = [] | ||
} | ||
} | ||
|
||
if (rows.length) { | ||
children.push(this.genTR(rows)) | ||
} | ||
|
||
return this.$createElement('tbody', children) | ||
}, | ||
genTR (children) { | ||
return [this.$createElement('tr', children)] | ||
}, | ||
isActive (date) { | ||
return this.selectedYear === this.displayedYear && | ||
this.selectedMonth === this.displayedMonth && | ||
this.selectedDate === date | ||
}, | ||
isCurrent (date) { | ||
return this.currentYear === this.displayedYear && | ||
this.currentMonth === this.displayedMonth && | ||
this.currentDate === date | ||
} | ||
}, | ||
|
||
render (h) { | ||
return this.genTable('date-picker-table date-picker-table--date', [ | ||
this.genTHead(), | ||
this.genTBody() | ||
]) | ||
} | ||
} |
Oops, something went wrong.