Skip to content

Commit

Permalink
fix(components): added invalid-day to datepicker
Browse files Browse the repository at this point in the history
feature/150167-datepicker
  • Loading branch information
liviaalmeida committed Nov 6, 2019
1 parent db283fa commit 0417990
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sandbox/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ setTimeout(() => {
const carousel = new BlipCarousel('carousel', 300)
carousel.render()

const picker = new BlipDatepicker({hasTime: true})
const today = new Date()
const tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1)
const lastYear = new Date(today.getFullYear() - 1, today.getMonth(), today.getDate())
const picker = new BlipDatepicker({hasTime: true, validPeriod: {startDate: lastYear, endDate: tomorrow}})
const pickerParent = document.getElementById('datepicker')

pickerParent.appendChild(picker.render(new Date()))
8 changes: 7 additions & 1 deletion src/components/blipDatepicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class BlipDatepicker extends Component {
monthDay: 'month-day',
lastMonth: 'last-month',
nextMonth: 'next-month',
invalidDay: 'invalid-day',
currentMonth: 'current-month',
rangeLimit: 'range-limit',
inRange: 'in-range',
Expand All @@ -98,6 +99,8 @@ export class BlipDatepicker extends Component {

this._selectedDay = options.selectedDay || undefined
this._selectedPeriod = options.selectedPeriod || undefined
this._validPeriod = options.validPeriod || undefined

this._onMonthButtonClick = options.onMonthButtonClick || this._onMonthButtonClick
this.onDateSelectorShow = options.onDateSelectorShow || undefined
this.onDateSelectorHide = options.onDateSelectorHide || undefined
Expand Down Expand Up @@ -325,7 +328,7 @@ export class BlipDatepicker extends Component {
}

_isValidDay(day) {
return day.classList.contains(BlipDatepicker.style.currentMonth)
return day.classList.contains(BlipDatepicker.style.currentMonth) && !day.classList.contains(BlipDatepicker.style.invalidDay)
}

_renderMonth() {
Expand Down Expand Up @@ -364,6 +367,9 @@ export class BlipDatepicker extends Component {
day.classList.add(BlipDatepicker.style.nextMonth)
break
}
if (this._validPeriod && !DateHelper.isBetween(this._validPeriod.startDate, this._validPeriod.endDate, dayDate)) {
day.classList.add(BlipDatepicker.style.invalidDay)
}
}
)
firstDayOfWeek = DateHelper.moveDay(firstDayOfWeek, BlipDatepicker.weekSize)
Expand Down
4 changes: 2 additions & 2 deletions src/scss/components/_datepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@
.month-day {
color: $bp-color-desk;

&.last-month, &.next-month {
&.last-month, &.next-month, &.invalid-day {
color: $bp-color-time;
}

&.in-range {
background-color: $bp-color-sky;
}

&.range-limit div, &.current-month:hover div {
&.range-limit div, &.current-month:not(.invalid-day):hover div {
color: $bp-color-white;
background-color: $bp-color-bot;
}
Expand Down

0 comments on commit 0417990

Please sign in to comment.