-
Notifications
You must be signed in to change notification settings - Fork 72
[LG-5504] refactor(date-picker): migrate to use InputBox component
#3286
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
base: LG-5504/input-box-component
Are you sure you want to change the base?
[LG-5504] refactor(date-picker): migrate to use InputBox component
#3286
Conversation
… improved type handling and event management
…tSegment with additional props
…with improved type handling and segment management
…ved segment management and type handling
…es for better segment management
…pe handling and segment management
… new props for step handling and rollover management
…icker components for improved segment management and type handling
…nce segment validation logic for improved date handling
…ean up InputBox component
…alidation and formatting functions
…tSegment and InputBox tests for better coverage
…ent components by introducing utility functions
…gment components for improved clarity and documentation
…ent types with clearer examples
…Rules in InputBox types for better clarity
…ting getValueFormatter to accept segment-specific character counts
… for year segment and enhance validation logic
…ype safety and clarity
…ng and props validation
…r consistency and clarity across components
… tests for InputBox and InputSegment components
| ctx?.args.segment === 'day' | ||
| ? 'DD' | ||
| : ctx?.args.segment === 'month' | ||
| ? 'MM' | ||
| : 'YYYY' |
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.
can we use if/else instead?
https://github.com/mongodb/leafygreen-ui/blob/main/STYLEGUIDE.md
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.
turns out i don't even need this, removing
…ygreen-ui into LG-5504/input-box-in-date-picker-3
…tories for better segment handling
InputBox component
…ygreen-ui into LG-5504/input-box-in-date-picker-3
…ygreen-ui into LG-5504/input-box-in-date-picker-3
… props and enhancing context usage
…ygreen-ui into LG-5504/input-box-in-date-picker-3
…reen-ui into LG-5504/input-box-in-date-picker-3
…reen-ui into LG-5504/input-box-in-date-picker-3
| const segment = part.type as DateSegment; | ||
| const formatter = getValueFormatter(segment); | ||
| const formatter = getValueFormatter({ | ||
| charsPerSegment: charsPerSegment[segment], |
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.
It feels like there could be some confusion that the charsPerSegment param is a number while the charsPerSegment const is an object mapping a segment to a number. Could be helpful to rename charsPerSegment constant more explicitly. i.e. charsPerSegmentObj or charsPerSegmentMap
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.
Good call out. I like charsPerSegmentObj
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.
Or maybe changing the param to charsCount might be better, so that getValueFormatter is not exclusive to segments if we want to use this somewhere else in the future.
| customValidation: | ||
| segment === DateSegment.Year | ||
| ? (value: DateSegmentValue) => inRange(Number(value), 1000, 9999 + 1) | ||
| : 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.
could we add a comment about what this is for? does this override min / max validation?
| export interface DateInputBoxProviderProps { | ||
| /** | ||
| * Date value in UTC time | ||
| */ | ||
| value?: DateType; | ||
| } |
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.
I think something like this could work as well and be a little DRYer
| export interface DateInputBoxProviderProps { | |
| /** | |
| * Date value in UTC time | |
| */ | |
| value?: DateType; | |
| } | |
| export interface DateInputBoxProviderProps extends PropsWithChildren<DateInputBoxContextType> {}; |
| onKeyDown={onKeyDown} | ||
| segmentRefs={segmentRefs} | ||
| segmentEnum={DateSegment} | ||
| charsPerSegment={charsPerSegment} | ||
| formatParts={formatParts} | ||
| segments={segments} | ||
| setSegment={setSegment} | ||
| disabled={disabled} | ||
| segmentRules={dateSegmentRules} | ||
| onSegmentChange={onSegmentChange} | ||
| labelledBy={labelledBy} | ||
| segmentComponent={DateInputSegment} |
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.
if there are props that are not used for component logic, can we instead pass them through to InputBox through the spread ...rest?
…ygreen-ui into LG-5504/input-box-in-date-picker-3
…elated references to charsCount for consistency
…ate DateInputBoxProviderProps to extend PropsWithChildren for better type handling
…-digit year value in custom validation for date segments
…tead of charsPerSegment across components and tests for consistency
|
Coverage after merging LG-5504/input-box-in-date-picker-3 into LG-5504/input-box-component will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
✍️ Proposed changes
This PR is the third PR in a series of three PRs that add the new
InputBoxpackage and integrate it into the existingDatePickerpackage:InputSegment#3293InputBox#3285This PR refactors the date-picker package to leverage the new
@leafygreen-ui/input-boxcomponent instead of maintaining custom input segment implementations. This migration significantly simplifies the codebase by removing redundant logic and utilities, while maintaining the same functionality through the shared input-box component.Key changes include:
DateInputSegmentimplementation withInputSegmentfrom@leafygreen-ui/input-box🎟️ Jira ticket: LG-5504
✅ Checklist
pnpm changesetand documented my changes🧪 How to test changes