1.4.0 • Published 5 months ago

ak-react-phone-input v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

ak-react-phone-input

AkPhoneInput is a React component for rendering a phone input field with country code selection. It provides an easy-to-use interface for users to input phone numbers, format them according to selected country codes, and automatically display the country's flag and code.

Installation

To install the ak-react-phone-input package, run the following command:

npm install ak-react-phone-input
yarn add ak-react-phone-input

Usage

Here's an example of how to use the AkPhoneInput component:

import React, { useState } from 'react';
import AkPhoneInput from 'ak-react-phone-input';

const MyComponent = () => {
  const [phone, setPhone] = useState('');

  const handlePhoneChange = (value: string) => {
    setPhone(value);
  };

  return (
    <div>
      <AkPhoneInput onChange={handlePhoneChange} />
      <p>Phone Number: {phone}</p>
    </div>
  );
};

AkPhoneInput Component Documentation

Props

Prop NameTypeDefaultDescription
onChange(value: string) => voidRequiredCallback function that is called whenever the phone number input changes.
radiusnumber4The border radius for the input and dropdown (in pixels).
variant"default" or "filled""default"The variant of the input, either "default" or "filled".
mode"light" or "dark""light"The theme mode for the component, either "light" or "dark".
noShadowbooleanfalseWhether the input should have a shadow or not.

Component Internal Behavior

FeatureDescription
Country SelectionUsers can select a country from a dropdown list, which automatically updates the country code and flag.
Phone MaskBased on the selected country, the phone number input will be masked in a format appropriate for that country.
Phone Number FormattingAs users input their phone number, it is automatically formatted according to the mask for the selected country.
Responsive DropdownThe country dropdown opens either upwards or downwards depending on available space in the viewport.

Key Features

FeatureDescription
Country Flag and CodeDisplays the flag and country code of the selected country, making it easy for users to identify the country.
Searchable Country DropdownUsers can search through available countries, making it quicker to find the country they need.
Input MaskingAutomatically formats phone numbers based on the selected country's phone number format.

Styling Customization

StyleDescription
borderRadiusCustomize the input's corner radius.
variantChoose between a "default" or "filled" input style.
modeChoose between "light" or "dark" theme for the component.
noShadowDisable input shadow if set to true.

To override the default styles, you can add custom CSS in your project:

.ak-phone-input-main {
  // Your custom styles
}

.ak-phone-input-root {
  // Your custom styles
}

Example

import AkPhoneInput from 'ak-react-phone-input';
import { useState } from 'react';

const MyForm = () => {
  const [phoneNumber, setPhoneNumber] = useState('');

  const handlePhoneChange = (value: string) => {
    setPhoneNumber(value);
  };

  return (
    <div>
      <AkPhoneInput onChange={handlePhoneChange} variant="filled" mode="dark" />
      <p>Selected Phone Number: {phoneNumber}</p>
    </div>
  );
};

export default MyForm;

License

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.4.0

5 months ago

1.3.0

5 months ago

1.2.1

5 months ago

1.2.0

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago