Skip to content

Commit

Permalink
feat(datepicker): add onTouched support, add forms demos, split demos…
Browse files Browse the repository at this point in the history
… for old and new datepicker
  • Loading branch information
IlyaSurmay committed Sep 6, 2017
1 parent 16affdd commit 17405b7
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 94 deletions.
204 changes: 122 additions & 82 deletions demo/src/app/components/+datepicker/datepicker-section.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,151 @@
import { Component } from '@angular/core';
import { DEMOS } from './demos';
// webpack html imports
let oldTitleDoc = require('html-loader!markdown-loader!./docs/titleOld.md');
let titleDoc = require('html-loader!markdown-loader!./docs/title.md');

@Component({
selector: 'datepicker-section',
template: `
template: `
<demo-section [name]="name" [src]="src">
<p>Datepicker is a highly configurable component that adds datepicker functionality to your pages. You can
customize the date format and language, restrict the selectable date ranges.</p>
<h2>Contents</h2>
<ul>
<li><a routerLink="." fragment="usage">Usage</a></li>
<li><a routerLink="." fragment="examples">Examples</a>
<ul>
<li><a routerLink="." fragment="basic">Basic</a></li>
<li><a routerLink="." fragment="themes">Themes</a></li>
<li><a routerLink="." fragment="locales">Locales</a></li>
<li><a routerLink="." fragment="min-max">Min-max</a></li>
<li><a routerLink="." fragment="disabled">Disabled</a></li>
<li><a routerLink="." fragment="forms">Forms</a></li>
</ul>
</li>
<li><a routerLink="." fragment="api-reference">API Reference</a>
<tabset>
<tab heading="Current">
<p>Datepicker is a highly configurable component that adds datepicker functionality to your pages. You can
customize the date format and language, restrict the selectable date ranges.</p>
<h2>Contents</h2>
<ul>
<li><a routerLink="." fragment="datepicker-component">DatePickerComponent</a></li>
<li><a routerLink="." fragment="bs-datepicker-component">BsDatepickerComponent</a></li>
<li><a routerLink="." fragment="bs-daterangepicker-component">BsDaterangepickerComponent</a></li>
<li><a routerLink="." fragment="usage">Usage</a></li>
<li><a routerLink="." fragment="examples">Examples</a>
<ul>
<li><a routerLink="." fragment="basic">Basic</a></li>
<li><a routerLink="." fragment="themes">Themes</a></li>
<li><a routerLink="." fragment="locales">Locales</a></li>
<li><a routerLink="." fragment="min-max">Min-max</a></li>
<li><a routerLink="." fragment="disabled">Disabled</a></li>
<li><a routerLink="." fragment="forms">Forms</a></li>
<li><a routerLink="." fragment="reactive">Reactive forms</a></li>
</ul>
</li>
<li><a routerLink="." fragment="api-reference">API Reference</a>
<ul>
<li><a routerLink="." fragment="bs-datepicker-component">BsDatepickerComponent</a></li>
<li><a routerLink="." fragment="bs-daterangepicker-component">BsDaterangepickerComponent</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 routerLink="." fragment="usage" id="usage">Usage</h2>
<h2 routerLink="." fragment="usage" id="usage">Usage</h2>
<p [innerHtml]="titleDoc"></p>
<p [innerHtml]="titleDoc"></p>
<h2 routerLink="." fragment="examples" id="examples">Examples</h2>
<h3 routerLink="." fragment="basic" id="basic">Basic</h3>
<ng-sample-box [ts]="demos.pop.component" [html]="demos.pop.html">
<p><code>BsDatepickerModule</code> is activily developed but you can use it already</p>
<p>Notebale change is additional css for it <code> "/datepicker/bs-datepicker.css"</code> <br></p>
<p>There are two ways of adding css:</p>
<ul>
<li>Load it from CDN. Add <code>&lt;link rel="stylesheet" href="https://unpkg.com/ngx-bootstrap/datepicker/bs-datepicker.css"&gt;</code> to your <code>index.html</code></li>
<li>Load it from <code>node_modules/ngx-bootstrap/datepicker/bs-datepicker.css</code> via package bundler like Angular CLI, if you're using one.</li>
</ul>
<p>In nearest time will be added:</p>
<ul>
<li><s>1. Month and year selection</s></li>
<li><s>2. Min/max dates restrcitions</s></li>
<li><s>3. Color theming</s></li>
<li>4. Options to replace any part of template</li>
<li><s>5. Configuration</s></li>
<li><s>6. Integration with forms, only for input fields</s></li>
<li>etc.</li>
</ul>
<demo-date-picker-popup></demo-date-picker-popup>
</ng-sample-box>
<h2 routerLink="." fragment="examples" id="examples">Examples</h2>
<h3 routerLink="." fragment="basic" id="basic">Basic</h3>
<ng-sample-box [ts]="demos.pop.component" [html]="demos.pop.html">
<p><code>BsDatepickerModule</code> is activily developed but you can use it already</p>
<p>Notebale change is additional css for it <code> "/datepicker/bs-datepicker.css"</code> <br></p>
<p>There are two ways of adding css:</p>
<ul>
<li>Load it from CDN. Add <code>&lt;link rel="stylesheet" href="https://unpkg.com/ngx-bootstrap/datepicker/bs-datepicker.css"&gt;</code> to your <code>index.html</code></li>
<li>Load it from <code>node_modules/ngx-bootstrap/datepicker/bs-datepicker.css</code> via package bundler like Angular CLI, if you're using one.</li>
</ul>
<p>In nearest time will be added:</p>
<ul>
<li><s>1. Month and year selection</s></li>
<li><s>2. Min/max dates restrcitions</s></li>
<li><s>3. Color theming</s></li>
<li>4. Options to replace any part of template</li>
<li><s>5. Configuration</s></li>
<li>6. Integration with forms, only for input fields</li>
<li>etc.</li>
</ul>
<demo-date-picker-popup></demo-date-picker-popup>
</ng-sample-box>
<h3 routerLink="." fragment="themes" id="themes">Themes</h3>
<ng-sample-box [ts]="demos.colorTheming.component" [html]="demos.colorTheming.html">
<p>Datepicker comes with some default color schemes.
You can change it by manipulating <code>containerClass</code> property in <code>bsConfig</code> object</p>
<p>There are 6 color schemes: <code>theme-default</code>, <code>theme-green</code>, <code>theme-blue</code>,
<code>theme-dark-blue</code>, <code>theme-red</code>, <code>theme-orange</code></p>
<demo-datepicker-color-theming></demo-datepicker-color-theming>
</ng-sample-box>
<h3 routerLink="." fragment="themes" id="themes">Themes</h3>
<ng-sample-box [ts]="demos.colorTheming.component" [html]="demos.colorTheming.html">
<p>Datepicker comes with some default color schemes.
You can change it by manipulating <code>containerClass</code> property in <code>bsConfig</code> object</p>
<p>There are 6 color schemes: <code>theme-default</code>, <code>theme-green</code>, <code>theme-blue</code>,
<code>theme-dark-blue</code>, <code>theme-red</code>, <code>theme-orange</code></p>
<demo-datepicker-color-theming></demo-datepicker-color-theming>
</ng-sample-box>
<h3 routerLink="." fragment="locales" id="locales">Locales</h3>
<h3 routerLink="." fragment="locales" id="locales">Locales</h3>
<ng-sample-box [ts]="demos.changeLocale.component" [html]="demos.changeLocale.html">
<p>Datepicker can use different locales. <br>It's possible to change a locale by changing <code>locale</code>
property in <code>bsConfig</code> object, list of available locales is in dropdown below.</p>
<p>To use a different locale, you have to import it from <code>ngx-bootstrap/bs-moment</code> and define it
in your <code>@NgModule</code> using function <code>defineLocale</code></p>
<p>Example: </p>
<code>import {{ '{' }} defineLocale {{ '}' }} from 'ngx-bootstrap/bs-moment';</code><br>
<code>import {{ '{' }} de {{ '}' }} from 'ngx-bootstrap/locale';</code><br>
<code>defineLocale('de', de));</code>
<br><br>
<demo-datepicker-change-locale></demo-datepicker-change-locale>
</ng-sample-box>
<ng-sample-box [ts]="demos.changeLocale.component" [html]="demos.changeLocale.html">
<p>Datepicker is fully compatible with any locale. It's possible to change a locale by changing <code>locale</code> property in <code>bsConfig</code> object</p>
<demo-datepicker-change-locale></demo-datepicker-change-locale>
</ng-sample-box>
<h3 routerLink="." fragment="min-max" id="min-max">Min-max</h3>
<ng-sample-box [ts]="demos.minMax.component" [html]="demos.minMax.html">
<p>You can set min and max date of datepicker/daterangepicker using <code>minDate</code> and <code>maxDate</code> properties</p>
<p>In the following example <code>minDate</code> is set to yesterday and <code>maxDate</code> to the current day in the next week</p>
<demo-datepicker-min-max></demo-datepicker-min-max>
</ng-sample-box>
<h3 routerLink="." fragment="min-max" id="min-max">Min-max</h3>
<ng-sample-box [ts]="demos.minMax.component" [html]="demos.minMax.html">
<p>You can set min and max date of datepicker/daterangepicker using <code>minDate</code> and <code>maxDate</code> properties</p>
<p>In the following example <code>minDate</code> is set to yesterday and <code>maxDate</code> to the current day in the next week</p>
<demo-datepicker-min-max></demo-datepicker-min-max>
</ng-sample-box>
<h3 routerLink="." fragment="disabled" id="disabled">Disabled (scratch, WIP)</h3>
<ng-sample-box [ts]="demos.disabled.component" [html]="demos.disabled.html">
<p>If you want to disable datepicker set is <code>isDisabled</code> property to true</p>
<demo-datepicker-disabled></demo-datepicker-disabled>
</ng-sample-box>
<h3 routerLink="." fragment="disabled" id="disabled">Disabled (scratch, WIP)</h3>
<ng-sample-box [ts]="demos.disabled.component" [html]="demos.disabled.html">
<p>If you want to disable datepicker set is <code>isDisabled</code> property to true</p>
<demo-datepicker-disabled></demo-datepicker-disabled>
</ng-sample-box>
<h3 routerLink="." fragment="forms" id="forms">Forms</h3>
<ng-sample-box [ts]="demos.forms.component" [html]="demos.forms.html">
<p>Datepicker and daterangepicker can be used in forms. Keep in mind that value of <code>ngModel</code>
is <code>Date</code> object (array of 2 object for daterangepicker)</p>
<demo-datepicker-forms></demo-datepicker-forms>
</ng-sample-box>
<h3 routerLink="." fragment="forms" id="forms">Forms</h3>
<ng-sample-box [ts]="demos.forms.component" [html]="demos.forms.html">
<demo-datepicker-forms></demo-datepicker-forms>
</ng-sample-box>
<h3 routerLink="." fragment="reactive" id="reactive">Reactive forms</h3>
<ng-sample-box [ts]="demos.reactive.component" [html]="demos.reactive.html">
<demo-datepicker-reactive-forms></demo-datepicker-reactive-forms>
</ng-sample-box>
<h2 routerLink="." fragment="api-reference" id="api-reference">API Reference</h2>
<ng-api-doc id="bs-datepicker-component" directive="BsDatepickerComponent"></ng-api-doc>
<ng-api-doc id="bs-daterangepicker-component" directive="BsDaterangepickerComponent"></ng-api-doc>
</tab>
<tab heading="Old">
<p>This is a legacy version of datepicker without support of daterangepicker, locales, themes, etc.</p>
<h2>Contents</h2>
<ul>
<li><a routerLink="." fragment="usageOld">Usage</a></li>
<li><a routerLink="." fragment="examplesOld">Example</a> </li>
<li><a routerLink="." fragment="api-referenceOld">API Reference</a>
<ul>
<li><a routerLink="." fragment="datepicker-component">DatePickerComponent</a></li>
</ul>
</li>
</ul>
<h2 routerLink="." fragment="usageOld" id="usageOld">Usage</h2>
<ng-sample-box [ts]="demos.old.component" [html]="demos.old.html">
<datepicker-demo></datepicker-demo>
</ng-sample-box>
<p [innerHtml]="oldTitleDoc"></p>
<h2 routerLink="." fragment="examplesOld" id="examplesOld">Example</h2>
<ng-sample-box [ts]="demos.old.component" [html]="demos.old.html">
<datepicker-demo></datepicker-demo>
</ng-sample-box>
<h2 routerLink="." fragment="api-reference" id="api-reference">API Reference</h2>
<ng-api-doc id="datepicker-component" directive="DatePickerComponent"></ng-api-doc>
<ng-api-doc id="bs-datepicker-component" directive="BsDatepickerComponent"></ng-api-doc>
<ng-api-doc id="bs-daterangepicker-component" directive="BsDaterangepickerComponent"></ng-api-doc>
<h2 routerLink="." fragment="api-referenceOld" id="api-referenceOld">API Reference</h2>
<ng-api-doc id="datepicker-component" directive="DatePickerComponent"></ng-api-doc>
</tab>
</tabset>
</demo-section>`
})
export class DatepickerSectionComponent {
public name: string = 'Datepicker';
public src: string = 'https://github.com/valor-software/ngx-bootstrap/tree/development/src/datepicker';
public demos: any = DEMOS;
public oldTitleDoc: string = oldTitleDoc;
public titleDoc: string = titleDoc;
}
8 changes: 5 additions & 3 deletions demo/src/app/components/+datepicker/demo-datepicker.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { DatepickerModule, BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { TabsModule } from 'ngx-bootstrap/tabs';

import { SharedModule } from '../../shared';
import { DatepickerSectionComponent } from './datepicker-section.component';
import { DEMO_COMPONENTS } from './demos';
import { routes } from './demo-datepicker.routes';

import { defineLocale, getSetGlobalLocale } from 'ngx-bootstrap/bs-moment';
import { defineLocale } from 'ngx-bootstrap/bs-moment';
import {
ar, de, enGb, es, esDo, esUs, fr, hi, it, ja, ko, nl, nlBe, pl, ptBr, ru, zhCn
} from 'ngx-bootstrap/locale';
Expand All @@ -18,7 +19,6 @@ const locales = [ar, de, enGb, es, esDo, esUs, fr, hi, it, ja, ko, nl, nlBe, pl,

locales.forEach(locale => defineLocale(locale.abbr, locale));

getSetGlobalLocale('en');

@NgModule({
declarations: [
Expand All @@ -28,8 +28,10 @@ getSetGlobalLocale('en');
imports: [
DatepickerModule.forRoot(),
BsDatepickerModule.forRoot(),
TabsModule.forRoot(),
CommonModule,
FormsModule,
ReactiveFormsModule,
SharedModule,
RouterModule.forChild(routes)
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<input type="text" bsDatepicker [(ngModel)]="datepickerModel" />
<input type="text" bsDaterangepicker [(ngModel)]="daterangepickerModel" />
<div class="row">
<div class="col-xs-3 form-group">
<input type="text" class="form-control" placeholder="Datepicker" bsDatepicker [(ngModel)]="datepickerModel" />
</div>
<div class="col-xs-3 form-group">
<input type="text" class="form-control" placeholder="Daterangepicker" bsDaterangepicker [(ngModel)]="daterangepickerModel" />
</div>
</div>
<div class="row">
<div class="col-xs-12">
<pre>{{datepickerModel}}<br>{{daterangepickerModel}}</pre>
</div>
</div>


8 changes: 7 additions & 1 deletion demo/src/app/components/+datepicker/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DemoDatepickerChangeLocaleComponent } from './change-locale/change-loca
import { DemoDatepickerMinMaxComponent } from './min-max/min-max.component';
import { DemoDatepickerDisabledComponent } from './disabled/disabled.component';
import { DemoDatepickerFormsComponent } from './forms/forms.component';
import { DemoDatepickerReactiveFormsComponent } from './reactive-forms/reactive-forms.component';

export const DEMO_COMPONENTS = [
DatepickerDemoComponent,
Expand All @@ -13,7 +14,8 @@ export const DEMO_COMPONENTS = [
DemoDatepickerChangeLocaleComponent,
DemoDatepickerMinMaxComponent,
DemoDatepickerDisabledComponent,
DemoDatepickerFormsComponent
DemoDatepickerFormsComponent,
DemoDatepickerReactiveFormsComponent
];

export const DEMOS = {
Expand Down Expand Up @@ -44,5 +46,9 @@ export const DEMOS = {
forms: {
component: require('!!raw-loader?lang=typescript!./forms/forms.component.ts'),
html: require('!!raw-loader?lang=markup!./forms/forms.component.html')
},
reactive: {
component: require('!!raw-loader?lang=typescript!./reactive-forms/reactive-forms.component.ts'),
html: require('!!raw-loader?lang=markup!./reactive-forms/reactive-forms.component.html')
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="row">
<form [formGroup]="myForm">
<div class="col-xs-3 form-group">
<input type="text" class="form-control" placeholder="Datepicker" bsDatepicker formControlName="date" />
</div>
<div class="col-xs-3 form-group">
<input type="text" class="form-control" placeholder="Daterangepicker" bsDaterangepicker formControlName="range" />
</div>
</form>
</div>
<div class="row">
<div class="col-xs-12">
<pre>{{myForm.value | json}}</pre>
</div>
</div>


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

@Component({
selector: 'demo-datepicker-reactive-forms',
templateUrl: './reactive-forms.component.html'
})
export class DemoDatepickerReactiveFormsComponent implements OnInit {
myForm: FormGroup;
constructor(private formBuilder: FormBuilder) { }

ngOnInit() {
this.myForm = this.formBuilder.group({
date: null,
range: null
});
}
}
8 changes: 4 additions & 4 deletions demo/src/app/components/+datepicker/docs/title.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
```typescript
// RECOMMENDED (doesn't work with system.js)
import { DatepickerModule } from 'ngx-bootstrap/datepicker';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
// or
import { DatepickerModule } from 'ngx-bootstrap';
import { BsDatepickerModule } from 'ngx-bootstrap';

@NgModule({
imports: [DatepickerModule.forRoot(),...]
imports: [BsDatepickerModule.forRoot(),...]
})
export class AppModule(){}
export class AppModule(){}
```
11 changes: 11 additions & 0 deletions demo/src/app/components/+datepicker/docs/titleOld.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```typescript
// RECOMMENDED (doesn't work with system.js)
import { DatepickerModule } from 'ngx-bootstrap/datepicker';
// or
import { DatepickerModule } from 'ngx-bootstrap';

@NgModule({
imports: [DatepickerModule.forRoot(),...]
})
export class AppModule(){}
```
Loading

0 comments on commit 17405b7

Please sign in to comment.