Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Added 'since' and 'until' selection modes
Browse files Browse the repository at this point in the history
  • Loading branch information
theonelucas committed May 22, 2019
1 parent a44856c commit fc0a316
Show file tree
Hide file tree
Showing 27 changed files with 13,433 additions and 538 deletions.
12,566 changes: 12,566 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"publish": "(cd dist; npm publish)",
"test": "ng test",
"lint": "ng lint",
"lintFix": "prettier --write 'src/**/*.ts' && tslint --fix 'src/**/*.ts'",
"e2e": "ng e2e"
},
"dependencies": {
Expand All @@ -25,6 +26,7 @@
"@angular/platform-browser": "7.1.0",
"@angular/platform-browser-dynamic": "7.1.0",
"core-js": "^2.6.5",
"prettier": "^1.17.1",
"rxjs": "^6.4.0",
"zone.js": "0.8.26"
},
Expand Down
30 changes: 19 additions & 11 deletions saturn-datepicker/src/datepicker/calendar-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

/* tslint:disable: component-selector component-class-suffix use-host-property-decorator */

import {
ChangeDetectionStrategy,
Component,
Expand All @@ -16,7 +18,7 @@ import {
ViewEncapsulation,
NgZone,
OnChanges,
SimpleChanges,
SimpleChanges
} from '@angular/core';
import {take} from 'rxjs/operators';

Expand All @@ -37,7 +39,6 @@ export class SatCalendarCell {
public cssClasses?: SatCalendarCellCssClasses) {}
}


/**
* An internal component used to display calendar data in a table.
* @docs-private
Expand Down Expand Up @@ -88,8 +89,11 @@ export class SatCalendarBody implements OnChanges {
/** Whether to mark all dates as semi-selected. */
@Input() rangeFull: boolean;

/** Whether to use date range selection behaviour.*/
@Input() rangeMode = false;
/** Selection mode */
@Input() selectionMode = '';

/** Possible selection modes, in the order that they should appear */
@Input() selectionModes = [];

/** The minimum number of free cells needed to fit the label in the first row. */
@Input() labelMinRequiredCells: number;
Expand Down Expand Up @@ -162,12 +166,16 @@ export class SatCalendarBody implements OnChanges {
cellNumber -= this._firstRowOffset;
}

return cellNumber == this.activeCell;
return cellNumber === this.activeCell;
}

/** Whenever to mark cell as semi-selected (inside dates interval). */
_isSemiSelected(date: number) {
if (!this.rangeMode) {
if (
!['range', 'since', 'until'].includes(this.selectionMode) &&
this.begin === null &&
this.end === null
) {
return false;
}
if (this.rangeFull) {
Expand All @@ -188,7 +196,7 @@ export class SatCalendarBody implements OnChanges {

/** Whenever to mark cell as semi-selected before the second date is selected (between the begin cell and the hovered cell). */
_isBetweenOverAndBegin(date: number): boolean {
if (!this._cellOver || !this.rangeMode || !this.beginSelected) {
if (!this._cellOver || !['range', 'since', 'until'].includes(this.selectionMode) || !this.beginSelected) {
return false;
}
if (this.isBeforeSelected && !this.begin) {
Expand All @@ -205,7 +213,7 @@ export class SatCalendarBody implements OnChanges {

/** Whenever to mark cell as begin of the range. */
_isBegin(date: number): boolean {
if (this.rangeMode && this.beginSelected && this._cellOver) {
if (['range', 'since', 'until'].includes(this.selectionMode) && this.beginSelected && this._cellOver) {
if (this.isBeforeSelected && !this.begin) {
return this._cellOver === date;
} else {
Expand All @@ -218,7 +226,7 @@ export class SatCalendarBody implements OnChanges {

/** Whenever to mark cell as end of the range. */
_isEnd(date: number): boolean {
if (this.rangeMode && this.beginSelected && this._cellOver) {
if (['range', 'since', 'until'].includes(this.selectionMode) && this.beginSelected && this._cellOver) {
if (this.isBeforeSelected && !this.begin) {
return false;
} else {
Expand All @@ -234,7 +242,7 @@ export class SatCalendarBody implements OnChanges {
this._ngZone.runOutsideAngular(() => {
this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => {
const activeCell: HTMLElement | null =
this._elementRef.nativeElement.querySelector('.mat-calendar-body-active');
this._elementRef.nativeElement.querySelector('.mat-calendar-body-active');

if (activeCell) {
activeCell.focus();
Expand All @@ -245,6 +253,6 @@ export class SatCalendarBody implements OnChanges {

/** Whenever to highlight the target cell when selecting the second date in range mode */
_previewCellOver(date: number): boolean {
return this._cellOver === date && this.rangeMode && this.beginSelected;
return this._cellOver === date && ['range', 'since', 'until'].includes(this.selectionMode) && this.beginSelected;
}
}
2 changes: 1 addition & 1 deletion saturn-datepicker/src/datepicker/calendar.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion saturn-datepicker/src/datepicker/calendar.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<div class="selection-wrapper" *ngIf="selectionModes && selectionModes.length > 1">
<mat-button-toggle-group
name="fontStyle"
aria-label="Selection type"
[(value)]="selectionMode"
>
<mat-button-toggle *ngFor="let sm of selectionModes;" [value]="sm">
<span class="selection-mode-title">{{ sm }}</span>
</mat-button-toggle>
</mat-button-toggle-group>
</div>

<ng-template [cdkPortalOutlet]="_calendarHeaderPortal"></ng-template>

Expand All @@ -8,7 +19,9 @@
[selected]="selected"
[beginDate]="beginDate"
[endDate]="endDate"
[rangeMode]="rangeMode"
[selectionMode]="selectionMode"
[selectionModes]="selectionModes"
[initialSelectionMode]="initialSelectionMode"
[closeAfterSelection]="closeAfterSelection"
[dateFilter]="dateFilter"
[maxDate]="maxDate"
Expand Down
Loading

0 comments on commit fc0a316

Please sign in to comment.