-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(datepicker): Add initial view setting #221
feat(datepicker): Add initial view setting #221
Conversation
381f7cc
to
27674ee
Compare
Did you check what happens if initialView is not in the keys of config.mappings.changed? Does it behave well under those conditions? Otherwise a check must be added. |
27674ee
to
33531f3
Compare
Added a check to ensure the view exists in mappings.changed |
Nice, I mentioned it because I had already been thinking about implementing this. Keep it up! |
I appreciate your feedback, hope you hadn't started on it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR 🎉 Just a couple of things I've highlighted in the review comments 😄
@@ -112,6 +119,13 @@ export class DatepickerPage { | |||
defaultValue: "0" | |||
}, | |||
{ | |||
name: "pickerInitialView", | |||
type: "CalendarViewType", | |||
description: "Specifies the initial view for the datepicker. Options are: <code>CalendarViewType.Year</code>, " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the options list, use their string values rather than the enum references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding, because CalendarViewType is an enum
export enum CalendarViewType {
Year = 0, ...
}
there are no string equivalent values to use. For eg. this is not allowed
<suiDatepicker pickerInitialView="year">
To use string values instead of enums, a new type would need to be created similar to DatepickerMode
export type DatepickerMode = "year" | "month" | "date" | "datetime" | "time";
export const DatepickerMode = {
Year: "year" as DatepickerMode, ...
}
What is your preferred option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see, sorry completely forgot the fact that it was just an enum! Turning it into a string enum is definitely the way foward, as then it can be easily used in HTML
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alas TS 2.4.1 support still isn't in Angular when using strict null checks so the "enum" solution is still the best way
public set initialView(view:CalendarViewType) { | ||
if (this.changed && this.changed.has(view)) { | ||
this._initialView = view; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps throw an error here?
@@ -32,6 +33,19 @@ export class SuiDatepickerDirective | |||
this.onSelectedDateChange.emit(date); | |||
} | |||
|
|||
private _initialView:CalendarViewType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be nullable
@@ -60,6 +74,9 @@ export class SuiDatepickerDirective | |||
this.config = new TimeConfig(); | |||
break; | |||
} | |||
if (this._initialView != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on making initialView?:CalendarViewType
a constructor parameter of CalendarMapping
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean a parameter on CalendarMappings
? so it can be used like
export class DateMappings extends CalendarMappings {
constructor(initialView?:CalendarViewType) {
super(initialView || CalendarViewType.Date);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, though do this instead:
export class DateMappings extends CalendarMappings {
constructor(initialView:CalendarViewType = CalendarViewType.Date) {
super(initialView);
@@ -1,4 +1,5 @@ | |||
export { | |||
SuiDatepickerModule, | |||
DatepickerMode | |||
DatepickerMode, | |||
CalendarViewType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export as DatepickerViewType
for consistency
@@ -1,6 +1,6 @@ | |||
import { Component } from "@angular/core"; | |||
import { ApiDefinition } from "../../../components/api/api.component"; | |||
import { DatepickerMode } from "../../../../../../src/public"; | |||
import { DatepickerMode, CalendarViewType } from "../../../../../../src/public"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DatepickerViewType
(see bottom)
@@ -112,6 +119,13 @@ export class DatepickerPage { | |||
defaultValue: "0" | |||
}, | |||
{ | |||
name: "pickerInitialView", | |||
type: "CalendarViewType", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DatepickerViewType
(see bottom)
Partially addresses #165
Not sure if you want to expose CalendarViewType, or create a new export type similar to DatepickerMode