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

Commit

Permalink
feat(timepicker): Added experimental timepicker and timeinput compone…
Browse files Browse the repository at this point in the history
…nts.
  • Loading branch information
thomaspink authored and lukasholzer committed Nov 16, 2020
1 parent e7fecc2 commit 8784ec3
Show file tree
Hide file tree
Showing 57 changed files with 2,214 additions and 2 deletions.
22 changes: 22 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,28 @@
},
"schematics": {}
},
"datepicker": {
"projectType": "library",
"root": "libs/barista-components/experimental/datepicker",
"sourceRoot": "libs/barista-components/experimental/datepicker/src",
"prefix": "dt",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"libs/barista-components/experimental/datepicker/tsconfig.lib.json",
"libs/barista-components/experimental/datepicker/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!libs/barista-components/experimantal/datepicker/**"
]
}
}
},
"schematics": {}
},
"drawer": {
"projectType": "library",
"root": "libs/barista-components/drawer",
Expand Down
4 changes: 4 additions & 0 deletions apps/demos/src/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ import {
DtExampleComboboxCustomOptionHeight,
DtExampleFilterFieldInfiniteDataDepth,
DtExampleSelectCustomValueTemplate,
DtExampleDatepickerDark,
DtExampleDatepickerDefault
} from '@dynatrace/examples';

// The Routing Module replaces the routing configuration in the root or feature module.
Expand Down Expand Up @@ -581,6 +583,8 @@ const ROUTES: Routes = [
{ path: 'drawer-dynamic-example', component: DtExampleDrawerDynamic },
{ path: 'drawer-nested-example', component: DtExampleDrawerNested },
{ path: 'drawer-over-example', component: DtExampleDrawerOver },
{ path: 'datepicker-dark-example', component: DtExampleDatepickerDark},
{ path: 'datepicker-default-example', component: DtExampleDatepickerDefault},
{
path: 'drawer-table-default-example',
component: DtExampleDrawerTableDefault,
Expand Down
13 changes: 13 additions & 0 deletions apps/demos/src/nav-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ export const DT_DEMOS_EXAMPLE_NAV_ITEMS = [
},
],
},
{
name: 'datepicker',
examples: [
{
name: 'datepicker-dark-example',
route: '/datepicker-dark-example',
},
{
name: 'datepicker-default-example',
route: '/datepicker-default-example',
},
],
},
{
name: 'drawer',
examples: [
Expand Down
11 changes: 10 additions & 1 deletion apps/dev/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { ConsumptionDemo } from './consumption/consumption-demo.component';
import { ContainerBreakpointObserverDemo } from './container-breakpoint-observer/container-breakpoint-observer-demo.component';
import { ContextDialogDemo } from './context-dialog/context-dialog-demo.component';
import { CopyToClipboardDemo } from './copy-to-clipboard/copy-to-clipboard-demo.component';
import { DatepickerDemo } from './datepicker/datepicker-demo.component';
import { DrawerDemo } from './drawer/drawer-demo.component';
import { DrawerTableDemo } from './drawer-table/drawer-table-demo.component';
import { EmptyStateDemo } from './empty-state/empty-state-demo';
Expand Down Expand Up @@ -94,6 +95,9 @@ import { DtIconModule } from '@dynatrace/barista-components/icon';
import {
DT_DEFAULT_UI_TEST_CONFIG,
DT_UI_TEST_CONFIG,
DtNativeDateModule,
DT_OVERLAY_THEMING_CONFIG,
DT_DEFAULT_DARK_THEMING_CONFIG,
} from '@dynatrace/barista-components/core';
import { ComboboxDemo } from './combobox/combobox-demo.component';

Expand All @@ -111,6 +115,7 @@ export class NoopRouteComponent {}
DtIconModule.forRoot({ svgIconLocation: '/assets/icons/{{name}}.svg' }),
DevAppDynatraceModule,
DragDropModule,
DtNativeDateModule,
],
declarations: [
DevApp,
Expand All @@ -127,7 +132,7 @@ export class NoopRouteComponent {}
ConfirmationDialogDemo,
ContextDialogDemo,
CopyToClipboardDemo,

DatepickerDemo,
DrawerDemo,
DrawerTableDemo,
ExpandablePanelDemo,
Expand Down Expand Up @@ -184,6 +189,10 @@ export class NoopRouteComponent {}
Location,
{ provide: LocationStrategy, useClass: PathLocationStrategy },
{ provide: DT_UI_TEST_CONFIG, useValue: DT_DEFAULT_UI_TEST_CONFIG },
{
provide: DT_OVERLAY_THEMING_CONFIG,
useValue: DT_DEFAULT_DARK_THEMING_CONFIG,
},
{ provide: STEPPER_GLOBAL_OPTIONS, useValue: { showError: true } },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand Down
17 changes: 17 additions & 0 deletions apps/dev/src/datepicker/datepicker-demo.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>Datepicker</h1>

<h2>Timepicker</h2>

<dt-timepicker [disabled]="isTimepickerDisabled"></dt-timepicker>

<dt-checkbox [(ngModel)]="isTimepickerDisabled">Disabled</dt-checkbox>

<div dtTheme=":dark" class="dt-example-dark">
<h2>Dark Mode Timepicker</h2>

<dt-timepicker
dtTheme=":dark"
[disabled]="isDarkTimepickerDisabled"
></dt-timepicker>
<dt-checkbox [(ngModel)]="isDarkTimepickerDisabled">Disabled</dt-checkbox>
</div>
7 changes: 7 additions & 0 deletions apps/dev/src/datepicker/datepicker-demo.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.dt-checkbox {
margin-top: 10px;
}

.dt-example-dark h2 {
color: white;
}
27 changes: 27 additions & 0 deletions apps/dev/src/datepicker/datepicker-demo.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Component } from '@angular/core';

@Component({
selector: 'demo-component',
templateUrl: 'datepicker-demo.component.html',
styleUrls: ['datepicker-demo.component.scss'],
})
export class DatepickerDemo {
isTimepickerDisabled = false;
isDarkTimepickerDisabled = false;
}
2 changes: 2 additions & 0 deletions apps/dev/src/devapp-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ConsumptionDemo } from './consumption/consumption-demo.component';
import { ContainerBreakpointObserverDemo } from './container-breakpoint-observer/container-breakpoint-observer-demo.component';
import { ContextDialogDemo } from './context-dialog/context-dialog-demo.component';
import { CopyToClipboardDemo } from './copy-to-clipboard/copy-to-clipboard-demo.component';
import { DatepickerDemo } from './datepicker/datepicker-demo.component';
import { DrawerDemo } from './drawer/drawer-demo.component';
import { DrawerTableDemo } from './drawer-table/drawer-table-demo.component';
import { EmptyStateDemo } from './empty-state/empty-state-demo';
Expand Down Expand Up @@ -95,6 +96,7 @@ const routes: Routes = [
{ path: 'context-dialog', component: ContextDialogDemo },
{ path: 'confirmation-dialog', component: ConfirmationDialogDemo },
{ path: 'copy-to-clipboard', component: CopyToClipboardDemo },
{ path: 'datepicker', component: DatepickerDemo },
{ path: 'drawer', component: DrawerDemo },
{ path: 'drawer-table', component: DrawerTableDemo },
{ path: 'empty-state', component: EmptyStateDemo },
Expand Down
1 change: 1 addition & 0 deletions apps/dev/src/devapp.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class DevApp implements AfterContentInit, OnDestroy {
},
{ name: 'Context-dialog', route: '/context-dialog' },
{ name: 'Copy-to-clipboard', route: '/copy-to-clipboard' },
{ name: 'Datepicker', route: '/datepicker' },
{ name: 'Drawer', route: '/drawer' },
{ name: 'Drawer-table', route: '/drawer-table' },
{ name: 'Empty-state', route: '/empty-state' },
Expand Down
2 changes: 2 additions & 0 deletions apps/dev/src/dt-components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { DtConsumptionModule } from '@dynatrace/barista-components/consumption';
import { DtContainerBreakpointObserverModule } from '@dynatrace/barista-components/container-breakpoint-observer';
import { DtContextDialogModule } from '@dynatrace/barista-components/context-dialog';
import { DtCopyToClipboardModule } from '@dynatrace/barista-components/copy-to-clipboard';
import { DtDatepickerModule } from '@dynatrace/barista-components/experimental/datepicker';
import { DtDrawerModule } from '@dynatrace/barista-components/drawer';
import { DtDrawerTableModule } from '@dynatrace/barista-components/experimental/drawer-table';
import { DtEmptyStateModule } from '@dynatrace/barista-components/empty-state';
Expand Down Expand Up @@ -95,6 +96,7 @@ import { DtComboboxModule } from '@dynatrace/barista-components/experimental/com
DtConfirmationDialogModule,
DtContextDialogModule,
DtCopyToClipboardModule,
DtDatepickerModule,
DtDrawerModule,
DtDrawerTableModule,
DtExpandablePanelModule,
Expand Down
1 change: 1 addition & 0 deletions libs/barista-components/config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ COMPONENTS = [
"expandable-section",
"expandable-text",
"experimental/combobox",
"experimental/datepicker",
"experimental/drawer-table",
"quick-filter",
"filter-field",
Expand Down
1 change: 1 addition & 0 deletions libs/barista-components/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './src/tree/index';
export * from './src/animations/index';
export * from './src/overlay/index';
export * from './src/testing/index';
export * from './src/date/index';
130 changes: 130 additions & 0 deletions libs/barista-components/core/src/date/date-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { inject, InjectionToken, LOCALE_ID } from '@angular/core';
import { Observable, Subject } from 'rxjs';

/** InjectionToken for datepicker that can be used to override default locale code. */
export const DT_DATE_LOCALE = new InjectionToken<string>('DT_DATE_LOCALE', {
providedIn: 'root',
factory: DT_DATE_LOCALE_FACTORY,
});

/** @docs-private */
export function DT_DATE_LOCALE_FACTORY(): string {
return inject(LOCALE_ID);
}

export abstract class DtDateAdapter<D> {
/** The locale to use for all dates. */
protected locale: any;

/** A stream that emits when the locale changes. */
get localeChanges(): Observable<void> {
return this._localeChanges.asObservable();
}
protected _localeChanges = new Subject<void>();

/** Sets the locale used for all dates. */
setLocale(locale: any): void {
this.locale = locale;
this._localeChanges.next();
}

/**
* Creates a date with the given year, month, and date.
* Does not allow over/under-flow of the month and date.
*/
abstract createDate(year: number, month: number, date: number): D;

/** Gets today's date. */
abstract today(): D;

/** Gets the year component of the given date. */
abstract getYear(date: D): number;

/** Gets the month component of the given date. */
abstract getMonth(date: D): number;

/** Gets the date of the month component of the given date. */
abstract getDate(date: D): number;

/** Gets the day of the week component of the given date. */
abstract getDayOfWeek(date: D): number;

/** Gets the first day of the week. */
abstract getFirstDayOfWeek(): number;

/** Gets a list of names for the days of the week. */
abstract getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[];

/** Gets the number of days in the month of the given date. */
abstract getNumDaysInMonth(date: D): number;

/** Gets a list of names for the dates of the month. */
abstract getDateNames(): string[];

/** Checks whether the given object is considered a date instance by this DateAdapter. */
abstract isDateInstance(obj: any): obj is D;

/** Checks whether the given date is valid. */
abstract isValid(date: D): boolean;

/** Formats a date as a string according to the given format. */
abstract format(date: D, displayFormat: Object): string;

/**
* Adds the given number of years to the date. Years are counted as if flipping 12 pages on the
* calendar for each year and then finding the closest date in the new month. For example when
* adding 1 year to Feb 29, 2016, the resulting date will be Feb 28, 2017.
*/
abstract addCalendarYears(date: D, years: number): D;

/**
* Adds the given number of months to the date. Months are counted as if flipping a page on the
* calendar for each month and then finding the closest date in the new month. For example when
* adding 1 month to Jan 31, 2017, the resulting date will be Feb 28, 2017.
*/
abstract addCalendarMonths(date: D, months: number): D;

/** Adds the given number of days to the date. */
abstract addCalendarDays(date: D, days: number): D;

/**
* Compares two dates.
* Returns 0 if the dates are equal,
* a number less than 0 if the first date is earlier,
* a number greater than 0 if the first date is later
*/
compareDate(first: D, second: D): number {
return (
this.getYear(first) - this.getYear(second) ||
this.getMonth(first) - this.getMonth(second) ||
this.getDate(first) - this.getDate(second)
);
}

/** Clamp the given date between min and max dates. */
clampDate(date: D, min?: D | null, max?: D | null): D {
if (min && this.compareDate(date, min) < 0) {
return min;
}
if (max && this.compareDate(date, max) > 0) {
return max;
}
return date;
}
}
24 changes: 24 additions & 0 deletions libs/barista-components/core/src/date/date-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { NgModule } from '@angular/core';
import { DtDateAdapter } from './date-adapter';
import { DtNativeDateAdapter } from './native-date-adapter';

@NgModule({
providers: [{ provide: DtDateAdapter, useClass: DtNativeDateAdapter }],
})
export class DtNativeDateModule {}
19 changes: 19 additions & 0 deletions libs/barista-components/core/src/date/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './date-adapter';
export * from './native-date-adapter';
export * from './date-module';
Loading

0 comments on commit 8784ec3

Please sign in to comment.