Skip to content
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): initial version of datepicker component #618

Merged
merged 1 commit into from
Sep 2, 2016

Conversation

maxokorokov
Copy link
Member

@maxokorokov maxokorokov commented Aug 22, 2016

First datepicker version (WIP)

Is inline datepicker, not in a popup and only the month view (this will easily extended later)

Current checklist:

  • finish tests
  • decide on and cleanup CSS/HTML for day and navigation templates
  • extract i18n from the calendar into separate class (+ maybe use native APIs?)
  • finish ngModel integration (now works only one way)
  • add documentation
  • at least one demo to start with
  • hide exposed NgbDate from the user
  • replace default navigation with month/year select boxes

Please leave feedback.

WIP for #20

@maxokorokov maxokorokov force-pushed the datepicker branch 2 times, most recently from e6d1e3e to 9c2ef50 Compare August 22, 2016 17:02
export interface NgbCalendar {
getDaysPerWeek(): number;
getWeeksPerMonth(): number;
getFirstDayOfWeek(): number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to make these three functions getters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't think you can have getters in interfaces in Typescript

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can have fields :-)

@maxokorokov
Copy link
Member Author

@pkozlowski-opensource thanks for the initial review. I know the HTML markup and CSS are a mess now - it migrated here from my proof-of-concept prototype. I'll leave only the bare minimum for the layout and use bootstrap styles wherever possible.

@maxokorokov
Copy link
Member Author

  • rebased to have datepicker.module.ts
  • cleaned up CSS significantly (removed custom colors and pixel sizes)
  • extracted default day template into datepicker-day-view.ts and made it use bootstrap classes
  • cleaned up model and argument names

@maxokorokov maxokorokov force-pushed the datepicker branch 9 times, most recently from 43eb02e to b5b1053 Compare August 31, 2016 15:46
@@ -0,0 +1,25 @@
export class NgbDate {
static from(date: {year: number, month: number, date?: number}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make month also optional ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but NgbDate is not user-exposed, so it wasn't necessary for now. See the public API in the NgbDatepicker

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should stick to minimal features as possible, that would be a feature request for the future.

@maxokorokov
Copy link
Member Author

If anybody was following current pull request / issue #20, looks like the initial version is ready. Last changes are:

  • split i18n and calendar
  • hidden internal NgbDate from the user
  • introduced datepicker-navigation-selection - a simpler navigation for the first version using two select boxes for month and year. 'Zoom' style navigation (as in angular-ui) could be added later on, as it's too much already.
  • introduced min/maxDates and navigateTo(date) in the API
  • updated the plunker
  • more tests and docs

So it looks like this for now (see demo for minimal API example):
screen shot 2016-08-31 at 18 58 42.

Reviews are welcome. It's big, but the minimal working component is kinda big.
Ping @pkozlowski-opensource, @wesleycho, @Foxandxss and whoever is interested

@maxokorokov maxokorokov changed the title WIP: feat(datepicker): adds datepicker component feat(datepicker): initial version of datepicker component Aug 31, 2016

model;

minDate = {year: 2000, month: 0, date: 7};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be day instead of date? For me date indicated the whole object. Could we please rename it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right, will rename, it will be better. Got confused by the standard js Date where there is a day field but getDate() method that returns it and getDay() that returns the day of the week...

}
`],
template: `
<tr>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restricts this component to being inside a tbody element - is this what we want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's restrictive as of now. Not only the ngbDatepickerNavigation, but also ngbDatepickerMonthView as well. It's because the simplest layout for the calendar I've came up with for now is a table - so all column alignment would be synchronised easily between navigation and dates, weekdays, etc. I would probably migrate to a better one if I knew how to do it easily with purer CSS.

Having said that, the only thing that's exposed now to the user is the template inside of a <td> element so the internals should be replaceable in the longer run. Now each section is just a table's <tbody>

@wesleycho
Copy link
Member

I have a question about NgbCalendar - do all calendar systems have concepts of months, weeks, and days?


@Component({
selector: 'ngbd-datepicker-basic',
template: require('./datepicker-basic.html')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be templateUrl: './datepicker-basic.html'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's the script that generates the demo skeleton apparently. Good catch, thanks. Will update the script in a separate PR.

@icfantv
Copy link
Member

icfantv commented Sep 1, 2016

TBH, it's been 6 weeks since I've done ng2 development and am not familiar w/ the changes past RC3. All this looks fine to me, but that should be taken w/ a grain of salt.

@wesleycho
Copy link
Member

After talking with @pkozlowski-opensource, this LGTM as is minus the demo template if we want to get in. My comments were more minor/affirming the decisions being made.

@maxokorokov
Copy link
Member Author

Thanks for taking a look, @wesleycho and @icfantv.

About calendars: I'm no calendar expert here, but I think it would be quite challenging to support calendars without day/month/year notion as well in one component. Or it will just be a parallel implementation inside.

Plus current implementation will need tuning for sure (ex. getWeeksPerMonth() in the calendar should probably be getWeeksPerMonth(month, year) as some calendars have different number of days in different months, etc)

@maxokorokov maxokorokov force-pushed the datepicker branch 2 times, most recently from 2dd9931 to 4d2c8f8 Compare September 2, 2016 09:11
@pkozlowski-opensource pkozlowski-opensource added this to the alpha.4 milestone Sep 2, 2016
import {NgbDatepickerModule} from './datepicker.module';
import {NgbDatepickerDayView} from './datepicker-day-view';

function getElement(element: HTMLElement): HTMLElement {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename it to sth more descriptive? What kind of an element we are trying to get?

@pkozlowski-opensource
Copy link
Member

LGTM apart from a small nit (don't really need to be fixed) and a missing browser sniffing. Great stuff @maxokorokov - datepickers are not easy but I think that we've got really nice API and architecture in here! Let's land this baby so people can play with it.

@sendilkumarn
Copy link
Contributor

@maxokorokov great one really 👏 👏 👏 👍

@jnizet
Copy link
Member

jnizet commented Sep 2, 2016

That looks great. 👍

I come a bit late to the game, but after just looking at the demo and playing a little bit with it, here are a few remarks:

  • some classes aren't exported, but should be, like DayTemplateContext, NgbDatepickerI18n.
  • NgbDatepickerI18n should be documented in the demo page
  • Just as for timepicker, I wonder if we shouldn't export an interface NgbDateStruct that would give a name to the year-month-day structure used as the model of the component.
  • If you specify a minDate but no maxDate, you get an exception. Not a big deal, but unexpected. The exception message is very clear though 👍
  • Saying that months are 0-based in the documentation wouldn't hurt. That's a never-ending source of bugs
  • It feels strange to have mandatory limits on the navigation. I understand that the use of a select box makes it mandatory, and I don't have any idea of how to change that, but still. The very first use-case that comes to mind is the selection of a birth date, and having only 10 years before now as the limit forces the user to set a min date... and a max date (see above). Not a big deal.

Again, very good job!

@maxokorokov
Copy link
Member Author

Thanks for the review @jnizet

  • DayTemplateContext is an interface purely for documentation, user doesn't need it
  • concerning min/max dates: default values are -10 and +10 yrs just to provide some default values and yes, you have to provide some limits for select boxes...
  • There is a different kind of 'zoom' navigation that might be implemented as in here for instance that will make navigation infinite. Can be done later
  • will allow setting only one of minDate or maxDate and leaving the second one as default value, you're right about this one

@icfantv
Copy link
Member

icfantv commented Sep 2, 2016

IMO, this is good. @maxokorokov have you made [do you want to make] any changes per @jnizet's recommendations, specifically, the last bullet above? If not, I'm inclined to merge this. We can tweak the padding after it lands.

@maxokorokov maxokorokov force-pushed the datepicker branch 3 times, most recently from 3997fd6 to e3e256f Compare September 2, 2016 21:30
@maxokorokov
Copy link
Member Author

Amended ie9 cursor test ignore and min/maxDate are completely optional now as in the comment above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants