-
Notifications
You must be signed in to change notification settings - Fork 32
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: new Time
-mask (kit
) + new overwriteMode
-mode (core
)
#37
Conversation
Visit the preview URL for this PR (updated for commit 120ca80): https://maskito--pr37-time-mask-a5dx300z.web.app (expires Wed, 14 Dec 2022 10:09:01 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 61e4dea776cbea516b68c67840913d2edd88bb90 |
efef971
to
70a0516
Compare
29ff827
to
87087e6
Compare
Time
-maskTime
-mask (kit
) + new overwriteMode
-mode (core
)
a3d5b1f
to
4546d60
Compare
Time
-mask (kit
) + new overwriteMode
-mode (core
)Time
-mask (kit
) + new overwriteMode
-mode (core
)
/** | ||
* @param timeString can be with/without fixed characters | ||
*/ | ||
export function parseTimeString(timeString: string): MaskitoTimeSegments { |
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.
This function looks like it works with hours down to milliseconds with optional precision, but what if we want to go the other way around and store seconds + milliseconds and optionally add minutes and hours?
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.
@@ -0,0 +1,6 @@ | |||
export interface MaskitoTimeSegments<T = string> { |
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.
What's the point of generic here? Shouldn't it just be string | number
?
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.
This type is used many times in the code.
Sometimes it is convenient to have object with all strings. Sometimes with all numbers.
And don't do extra type checks.
@@ -0,0 +1 @@ | |||
export type MaskitoTimeMode = 'HH:MM' | 'HH:MM:SS' | 'HH:MM:SS.MSS'; |
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.
That's what I asked about in parsing function. I think we should also support SS.MSS
and MM.SS.MSS
. Maybe in the next iteration, but keep that in mind.
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.
Okey, let's keep it in mind for the next iteration.
For the first iteration, all kit
-masks should reproduce already existing Taiga UI features + fixing old bugs.
All new features – next iteration.
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.
import {MaskitoTimeSegments} from '../types'; | ||
|
||
export const DEFAULT_TIME_SEGMENT_MAX_VALUES: MaskitoTimeSegments<number> = { | ||
hours: 23, |
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.
Just something to keep in mind, we'd want to support AM/PM mode eventually too.
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.
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.
elementState.value.slice(0, from) + | ||
insertedText + | ||
elementState.value.slice(to); | ||
elementState.value.slice(0, from) + data + elementState.value.slice(to); |
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.
What is the difference between insertedText
and data
in this case?
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.
data
- inserted characters BEFORE preprocessing (raw data fromEvent.data
).insertedText
- inserted characters AFTER preprocessing
We calculate newPossibleValue
to decide if we have to prevent native event? Will natively typed character make mask valid (without programatic interference)?
It is especially useful for RegExp
-mask (without fixed characters masks).
The majority of all typed characters can be inserted natively (without programatic value patching) ?
'HH:MM:SS.MSS': maskitoTimeOptionsGenerator({mode: 'HH:MM:SS.MSS'}), | ||
'HH:MM 12-hours': maskitoTimeOptionsGenerator({ | ||
mode: 'HH:MM', | ||
timeSegmentMaxValues: {hours: 12}, |
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.
Maybe just maxValues
?
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.
In my opinion, It is not obvious for user what maxValues
-option means :(
For example, maxValues: {HH: 11, MM: 30}
. Okey, 11:31
is obviously invalid value. What's about 10:31
?
projects/kit/src/lib/time/processors/zero-placeholders-preprocessor.ts
Outdated
Show resolved
Hide resolved
}; | ||
} | ||
|
||
function padWithZeroes(timeSegment: string, maxSegmentValue: string): string { |
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.
Shouldn't it just be padStart somehow?
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 can be possible if all time segments are the same length (but they can be 2 or 3-character length).
That is why I need recursive function here.
d977517
to
aa28b8d
Compare
10bf574
to
120ca80
Compare
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Closes #30