Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-fmt-input

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-fmt-input

React formatted input component

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

This is a test task from a job interview, which was allocated 30 minutes of live coding. Maybe this example will be useful for someone to start a more advanced component or you can use it as is.

demo

Component API

interface FormattedInputProps {
  label: string;
  value: string;
  mask: string;
  placeholder: string;
  errorMessage: string;
  parser?: (str: string | null | undefined) => string;
  formatter?: (str: string, mask: string) => string;
  onChange: (str: string) => void;
}

Mask format

^ - upercase character
_ - lowercase character
# - number

Example:

import {useState} from 'react';
import {defaultParser, defaultFormatter, FormattedInput} from 'react-fmt-input';


const Demo = () => {
  const [phone, setPhone] = useState<string>("");

  return (
    <FormattedInput
      label="Phone"
      value={phone}
      mask="+# (###) ###-##-##"
      placeholder="+7 (999) 123-45-67"
      errorMessage="Invalid number"
      onChange={setPhone}
      parser={defaultParser} // optional
      formatter={defaultFormatter} // optional
    />
  )
};

Demo project

https://github.com/kobzarvs/formatted-input-demo

Vercel demo

https://react-formatted-input.vercel.app/

Keywords

FAQs

Package last updated on 06 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc