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: new Time-mask (kit) + new overwriteMode-mode (core) #37

Merged
merged 5 commits into from
Dec 14, 2022

Conversation

nsbarsukov
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows Conventional Commits
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring
  • Code style update
  • Build or CI related changes
  • Documentation content changes

Closes #30

@nsbarsukov nsbarsukov self-assigned this Dec 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

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

@nsbarsukov nsbarsukov force-pushed the time-mask branch 3 times, most recently from efef971 to 70a0516 Compare December 9, 2022 15:36
@nsbarsukov nsbarsukov changed the title [WIP] feat(kit): new Time-mask [WIP] feat: new Time-mask (kit) + new overwriteMode-mode (core) Dec 12, 2022
@nsbarsukov nsbarsukov changed the title [WIP] feat: new Time-mask (kit) + new overwriteMode-mode (core) feat: new Time-mask (kit) + new overwriteMode-mode (core) Dec 12, 2022
@nsbarsukov nsbarsukov marked this pull request as ready for review December 12, 2022 14:08
@waterplea
Copy link
Contributor

image
Pressing '2' does not do anything, should move caret behind '2'.

@waterplea
Copy link
Contributor

image
Pressing 1 moves all other digits to the left, making them invalid and thus drops all remaining characters. Not sure this is the best way to handle this. Maybe replace second char with 0 so numbers don't shift?

@waterplea
Copy link
Contributor

image

Pressing 1 doesn't do anything.

@waterplea
Copy link
Contributor

image

I have a feeling that in case of time we want to fill blank spaces with 0, otherwise it looks rather weird. What do you guys think?

/**
* @param timeString can be with/without fixed characters
*/
export function parseTimeString(timeString: string): MaskitoTimeSegments {
Copy link
Contributor

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?

Copy link
Member Author

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> {
Copy link
Contributor

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?

Copy link
Member Author

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';
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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,
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

@nsbarsukov nsbarsukov Dec 13, 2022

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);
Copy link
Contributor

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?

Copy link
Member Author

@nsbarsukov nsbarsukov Dec 13, 2022

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 from Event.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},
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just maxValues?

Copy link
Member Author

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/time-mask.ts Show resolved Hide resolved
};
}

function padWithZeroes(timeSegment: string, maxSegmentValue: string): string {
Copy link
Contributor

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?

Copy link
Member Author

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.

@nsbarsukov nsbarsukov merged commit 43dea21 into main Dec 14, 2022
@nsbarsukov nsbarsukov deleted the time-mask branch December 14, 2022 09:41
This was referenced Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 - Time-mask (@maskito/kit)
3 participants