{"size": 984, "ext": "js", "max_stars_repo_path": "frontend/src/components/PhoneInput/index.js", "max_stars_repo_name": "marcos012/amigo-solidario", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/src/components/PhoneInput/index.js", "max_issues_repo_name": "marcos012/amigo-solidario", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/src/components/PhoneInput/index.js", "max_forks_repo_name": "marcos012/amigo-solidario", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.5945945946, "max_line_length": 108, "alphanum_fraction": 0.5945121951}
import React from 'react';
import MaskedInput from 'react-text-mask'

const phoneMask = ['(', /[1-9]/, /\d/, ')', ' ', /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/];

export function maskPhone(value) {
    if (!value) {
        return;
    }

    let valorFormatado = value;

    valorFormatado = valorFormatado.replace(/\D/g, '');
    valorFormatado = valorFormatado.replace(/^(\d{2})(\d)/g, '($1) $2');
    valorFormatado = valorFormatado.replace(/(\d)(\d{4})$/, '$1-$2');
    return valorFormatado;
}

export function unmaskPhone(value) {
    let valorSemFormatacao = value;
  
    valorSemFormatacao = valorSemFormatacao.replace(/[^0-9]+/g, '');
    return valorSemFormatacao;
}

const PhoneInput = (props) => {
    return <MaskedInput
        mask={phoneMask}
        placeholder={props.placeholder}
        id="phone-input"
        disabled={props.disabled}
        onChange={props.handleNumberChange}
        className="input"
    />;
}

export default PhoneInput;