-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add date and time types to input (#449)
- Loading branch information
1 parent
342a563
commit c19b0f6
Showing
27 changed files
with
187 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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,23 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
|
||
import { useStateEvents } from "./InputWrapper"; | ||
|
||
describe("useStateEvents", () => { | ||
it.each([ | ||
{ type: "text", value: "Hello", expected: true }, | ||
{ type: "number", value: "123", expected: true }, | ||
{ type: "text", value: undefined, expected: false }, | ||
{ type: "number", value: undefined, expected: false }, | ||
{ type: "date", value: "2021-01-01", expected: true }, | ||
{ type: "time", value: "12:00", expected: true }, | ||
{ type: "date", value: undefined, expected: true }, | ||
{ type: "time", value: undefined, expected: true }, | ||
] as const)( | ||
`should return typed=$expected if type is $type with value $value`, | ||
({ type, value, expected }) => { | ||
const { result } = renderHook(() => useStateEvents(value, type)); | ||
|
||
expect(result.current.typed).toBe(expected); | ||
} | ||
); | ||
}); |
This file contains 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 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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { KeyboardEvent } from "react"; | ||
|
||
import { InputProps } from "./Input"; | ||
|
||
// Check if input type number is valid as input type number doesn't currently work in browsers like Safari and Firefox | ||
export const checkIfValidNumberInput = (event: KeyboardEvent<HTMLElement>) => { | ||
const allowedCharacter = | ||
/^[\d.,]*$|(Backspace|Tab|Delete|ArrowLeft|ArrowRight|ArrowDown|ArrowUp)/; | ||
|
||
return !event.key.match(allowedCharacter) && event.preventDefault(); | ||
}; | ||
|
||
export const checkIfDateTimeInput = (type: InputProps["type"]) => | ||
["date", "time"].includes(type ?? ""); |
Oops, something went wrong.
c19b0f6
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.
Successfully deployed to the following URLs:
macaw-ui-next – ./
macaw-ui-next-git-canary-saleorcommerce.vercel.app
macaw-ui-next-saleorcommerce.vercel.app
macaw-ui-next.vercel.app
c19b0f6
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.
Successfully deployed to the following URLs:
macaw-ui – ./legacy
macaw-ui-saleorcommerce.vercel.app
macaw-ui.vercel.app
macaw-ui-git-canary-saleorcommerce.vercel.app