-
Notifications
You must be signed in to change notification settings - Fork 33
Date/DateTime inputs #756
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
Date/DateTime inputs #756
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5308e68
WIP
vbabich faa7750
Masked input updates and tests, Time, Date, DateTime inputs
vbabich 7d17841
Truncate empty mask on the right
vbabich 67e863e
Cleanup diff
vbabich 7c84049
Fix addSeparators, add unit tests
vbabich 7ce0369
Delete old DateInput dependent on jsapi-shim, update Styleguide
vbabich ac45cdd
Cleanup
vbabich bbc23fa
Uppercase placeholders
vbabich 063880b
Update packages/components/src/DateInput.tsx
vbabich 1f3794f
Update packages/components/src/DateInput.tsx
vbabich 86b5c0b
Update packages/components/src/DateInput.tsx
vbabich 511fa69
Update packages/components/src/DateInput.tsx
vbabich f39de69
Update packages/components/src/DateTimeInput.tsx
vbabich d46e14b
Update packages/components/src/DateTimeInput.tsx
vbabich 5843782
Update packages/components/src/DateTimeInput.tsx
vbabich 1eb8fd8
Fix review comments
vbabich 0cbf245
Fix review comments, add DateInputUtils
vbabich beaa7ad
Fix validation issue, cleanup tests
vbabich a6e9317
Comment cleanup
vbabich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SelectionSegment } from './MaskedInput'; | ||
|
||
export function getNextNumberSegmentValue( | ||
delta: number, | ||
segmentValue: string, | ||
lowerBound: number, | ||
upperBound: number, | ||
length: number | ||
): string { | ||
const modValue = upperBound - lowerBound + 1; | ||
const newSegmentValue = | ||
((((parseInt(segmentValue, 10) - delta - lowerBound) % modValue) + | ||
modValue) % | ||
modValue) + | ||
lowerBound; | ||
return `${newSegmentValue}`.padStart(length, '0'); | ||
} | ||
|
||
export function getNextSegmentValue( | ||
range: SelectionSegment, | ||
delta: number, | ||
segmentValue: string | ||
): string { | ||
const { selectionStart } = range; | ||
if (selectionStart === 0) { | ||
return getNextNumberSegmentValue(delta, segmentValue, 1900, 2099, 4); | ||
} | ||
if (selectionStart === 5) { | ||
return getNextNumberSegmentValue(delta, segmentValue, 1, 12, 2); | ||
} | ||
if (selectionStart === 8) { | ||
return getNextNumberSegmentValue(delta, segmentValue, 1, 31, 2); | ||
} | ||
if (selectionStart === 11) { | ||
// Hours input | ||
return getNextNumberSegmentValue(delta, segmentValue, 0, 23, 2); | ||
} | ||
if (selectionStart === 17 || selectionStart === 14) { | ||
// Minutes/seconds input | ||
return getNextNumberSegmentValue(delta, segmentValue, 0, 59, 2); | ||
} | ||
if (selectionStart === 20 || selectionStart === 24 || selectionStart === 28) { | ||
// Milli, micro, and nanosecond input | ||
return getNextNumberSegmentValue(delta, segmentValue, 0, 999, 3); | ||
} | ||
|
||
return segmentValue; | ||
} |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.