-
Notifications
You must be signed in to change notification settings - Fork 8
feat(date-picker): replace moment with vanilla JS #1013
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ee6c99a
to
498311f
Compare
26693c0
to
fa801f3
Compare
fa801f3
to
a137ba5
Compare
5c393c6
to
7259230
Compare
7259230
to
b8cc29a
Compare
Mcourt
approved these changes
Sep 29, 2023
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.
Huge work!
Well done 👏🏻
StoryBook Test OK ✔️ |
Fixing a bug when providing an invalid to the date picker |
All good, merging this. I'm not planning on releasing it right away |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
General summary
Replacing moment with vanilla JS.
All the logic used to generate the month calendar is re-written in vanilla JS. The date utils from
@lumx/core
that used moment have been deprecated (will have to remove them in the next major version as it is a breaking change). The DatePicker/DatePickerField components API do not change at all since we already do not reference moment.The only challenging part for the implementation of the date picker was to get the first day of the week for a given locale (Monday in most of europe, Sunday in the US, etc.). The browser API
Intl.Local.getWeekInfo()
is still experimental (although partially implemented in Chrome & Safari via aweekInfo
accessor property). I've choose to try this browser API (most trustworthy source) and fallback to a lookup in a constant (built from locale date ofmoment
) for older browsers.Pros:
moment/locale/fr
)Cons:
Impact on bundle size
Before with @lumx/react v3.5.3
=> 44.5kb (gzipped) see on bundlephobia
=> 129kb (gzipped, including moment, lodash & react) see on bundlejs
After with @lumx/react v3.5.4-alpha-remove-moment.0 (with moment fully removed)
=> 45.1kB (gzipped) see on bundlephobia
=> 106kb (gzipped, including lodash & react) see on bundlejs
Non regression test
See in StoryBook
Alpha version:
v3.5.4-alpha-remove-moment.0
https://github.com/lumapps/design-system/actions/runs/6120085722StoryBook: https://b8cc29a9--5fbfb1d508c0520021560f10.chromatic.com/ (Chromatic build)⚠️ Outdated commit