-
Notifications
You must be signed in to change notification settings - Fork 4
feat: remove react-text-mask and add rifm use textfield with mask's #57
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
Open
dpnunez
wants to merge
2
commits into
master
Choose a base branch
from
feat/change-mask-lib-to-rifm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1 +1,60 @@ | ||
| export const dateMask = [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/] | ||
| export const dateMask = { | ||
| format: string => { | ||
| const numbers = string.replace(/\D/g, '').substr(0, 8).split('') | ||
|
|
||
| return numbers.reduce((acc, digit, index) => `${acc}${[2, 4].includes(index) ? '/' : ''}${digit}`, '') | ||
| }, | ||
| accept: /\d+/g | ||
| } | ||
|
|
||
| export const phoneMask = { | ||
| format: string => { | ||
| const numbers = string.replace(/\D/g, '').substr(0, 11) | ||
| const match = numbers.match(/^(\d{1,2})(\d{0,5})(\d{0,4})$/) | ||
|
|
||
| if (!match) return numbers | ||
|
|
||
| return `(${match[1]})${match[2] ? ' ' : ''}${match[2]}${match[3] ? ' ' : ''}${match[3]}` | ||
| }, | ||
| accept: /\d+/g | ||
| } | ||
|
|
||
| export const cpfMask = { | ||
| format: string => { | ||
| const numbers = string.replace(/\D/g, '').substr(0, 11) | ||
| const match = numbers.match(/^(\d{1,3})(\d{0,3})(\d{0,3})(\d{0,2})$/) | ||
|
|
||
| if (!match) return numbers | ||
|
|
||
| return `${match[1]}${match[2] ? '.' : ''}${match[2]}${match[3] ? '.' : ''}${match[3]}${match[4] ? '-' : ''}${ | ||
| match[4] | ||
| }` | ||
| }, | ||
| accept: /\d+/g | ||
| } | ||
|
|
||
| export const cepMask = { | ||
| format: string => { | ||
| const numbers = string.replace(/\D/g, '').substr(0, 8) | ||
| const match = numbers.match(/^(\d{1,5})(\d{0,3})$/) | ||
|
|
||
| if (!match) return numbers | ||
|
|
||
| return `${match[1]}${match[2] ? '-' : ''}${match[2]}` | ||
| }, | ||
| accept: /\d+/g | ||
| } | ||
|
|
||
| export const moneyMask = { | ||
| format: string => { | ||
| const numbers = Number(string.replace(/\D/g, '')) / 100 | ||
|
|
||
| if (!numbers) return '' | ||
|
|
||
| return numbers.toLocaleString('pt-BR', { | ||
| style: 'currency', | ||
| currency: 'BRL' | ||
| }) | ||
| }, | ||
| accept: /\d+/g | ||
| } | ||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import React from 'react' | ||
| import { useForm } from 'react-hook-form' | ||
| import { useForm, FormProvider } from 'react-hook-form' | ||
|
|
||
| import Column from 'components/Column' | ||
| import Input from 'components/Input' | ||
|
|
@@ -12,29 +12,19 @@ import { loginResolver } from 'helpers/yup-schemas' | |
| const Login = () => { | ||
| const { login } = useUser() | ||
|
|
||
| const { register, handleSubmit, errors, formState } = useForm({ resolver: loginResolver }) | ||
| const methods = useForm({ resolver: loginResolver }) | ||
| const { handleSubmit, formState } = methods | ||
|
|
||
| return ( | ||
| <Column as='form' onSubmit={handleSubmit(login)} p={40} alignItems='center'> | ||
| <Input | ||
| name='email' | ||
| ref={register} | ||
| label='E-mail' | ||
| placeholder='[email protected]' | ||
| error={errors.email?.message} | ||
| /> | ||
| <Input | ||
| name='password' | ||
| ref={register} | ||
| label='Senha' | ||
| placeholder='******' | ||
| error={errors.password?.message} | ||
| type='password' | ||
| /> | ||
| <Button bg='purple' isLoading={formState.isSubmitting}> | ||
| Entrar | ||
| </Button> | ||
| </Column> | ||
| <FormProvider {...methods}> | ||
| <Column as='form' onSubmit={handleSubmit(login)} p={40} alignItems='center'> | ||
| <Input name='email' label='E-mail' placeholder='[email protected]' /> | ||
| <Input name='password' label='Senha' placeholder='******' type='password' /> | ||
| <Button bg='purple' isLoading={formState.isSubmitting}> | ||
| Entrar | ||
| </Button> | ||
| </Column> | ||
| </FormProvider> | ||
| ) | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
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.
achei muito pica já ter algumas das máscaras mais comuns, só algumas sugestões.
a de currency eu tentaria deixar mais genérico, de uma forma q a gente pudesse escolher moedas diferentes de BRL.
adicionar uma máscara de cnpj
criar um helper de criação de mascaras númericas, tipo oq o createNumberMask do text-mask-addons faz (https://www.npmjs.com/package/text-mask-addons), será que isso caberia mais à nossa lib de hooks (prometheus)?