mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-30 10:13:04 +00:00
Improve Inputs
This commit is contained in:
parent
fd4266dde6
commit
d3577ceb6a
3 changed files with 25 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ export const EmailInput = (props: ComponentProps<'input'>) => (
|
||||||
id="email"
|
id="email"
|
||||||
placeholder="Digite seu e-mail"
|
placeholder="Digite seu e-mail"
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
|
format={sanitize}
|
||||||
inputMode="email"
|
inputMode="email"
|
||||||
type="text"
|
type="text"
|
||||||
minLength={5}
|
minLength={5}
|
||||||
|
|
@ -15,3 +16,5 @@ export const EmailInput = (props: ComponentProps<'input'>) => (
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const sanitize = (value: string) => value.toLowerCase().replace(/\s+/g, '').slice(0, 254)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,18 @@ export const NameInput = (props: ComponentProps<'input'>) => (
|
||||||
autoComplete="name"
|
autoComplete="name"
|
||||||
maxLength={120}
|
maxLength={120}
|
||||||
minLength={2}
|
minLength={2}
|
||||||
|
format={sanitize}
|
||||||
required
|
required
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const sanitize = (value: string) =>
|
||||||
|
value
|
||||||
|
.normalize('NFC')
|
||||||
|
.replace(/[^\p{L}\p{M}\s-]+/gu, '')
|
||||||
|
.replace(/-+/g, '-')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.replace(/\s*-\s*/g, '-')
|
||||||
|
.trim()
|
||||||
|
.slice(0, 120)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,18 @@ export const PostalCodeInput = (props: ComponentProps<'input'>) => (
|
||||||
id="postalCode"
|
id="postalCode"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="00000-000"
|
placeholder="00000-000"
|
||||||
|
format={format}
|
||||||
|
options={{
|
||||||
|
setValueAs: sanitize,
|
||||||
|
}}
|
||||||
pattern="^(?:\d{8})?$"
|
pattern="^(?:\d{8})?$"
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const sanitize = (value: string) => value.replace(/\D/g, '').slice(0, 8)
|
||||||
|
|
||||||
|
const format = (value: string) => {
|
||||||
|
const digits = sanitize(value)
|
||||||
|
return digits.length <= 5 ? digits : `${digits.slice(0, 5)}-${digits.slice(5)}`
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue