7.1.13 • Published 2 years ago

bpk-component-phone-input-css v7.1.13

Weekly downloads
244
License
Apache-2.0
Repository
github
Last release
2 years ago

bpk-component-phone-input

Backpack phone input component.

Installation

npm install bpk-component-phone-input --save-dev

Usage

import React, { Component } from 'react';
import BpkPhoneInput from 'bpk-component-phone-input';
import BpkImage from 'bpk-component-image';

const DIALING_CODE_TO_ID_MAP = {
  '44': 'uk',
  '55': 'br',
};

const getFlag = dialingCode => {
  const countryCode = DIALING_CODE_TO_ID_MAP[dialingCode];
  const url = `/resources/${countryCode}.png`;

  return <BpkImage altText="Flag" height={38} width={50} src={url} />;
};

export default class extends Component {
  constructor(props) {
    super(props);
    this.state = { dialingCode: '44', phoneNumber: '' };
  }

  onChange = evt => {
    this.setState({ phoneNumber: evt.target.value });
  };

  onDialingCodeChange = evt => {
    this.setState({ dialingCode: evt.target.value });
  };

  render() {
    return (
      <BpkPhoneInput
        id="phone-input-id"
        name="Telephone input"
        label="Telephone number"
        onChange={this.onChange}
        onDialingCodeChange={this.onDialingCodeChange}
        value={this.state.phoneNumber}
        dialingCode={this.state.dialingCode}
        dialingCodes={[
          { code: '44', description: '+44' },
          { code: '55', description: '+55' },
        ]}
        dialingCodeProps={{
          id: 'dialing-code',
          name: 'Dialing code',
          label: 'Dialing code',
          'aria-label': 'Dialing code',
          image: getFlag(this.state.dialingCode),
        }}
      />
    );
  }
}

Props

PropertyPropTypeRequiredDefault Value
dialingCodestringtrue-
dialingCodePropsshape({ id: string, name: string, label: string })true-
dialingCodesarrayOf(shape({ code: string, description: string }))true-
idstringtrue-
namestringtrue-
labelstringtrue-
onChangefunctrue-
onDialingCodeChangefunctrue-
valuestringtrue-
classNamestringfalsenull
dialingCodeMaskbooleanfalsenull
disabledbooleanfalsefalse
largebooleanfalsefalse
validbooleanfalsenull
wrapperPropsobjectfalse{}

dialingCodeProps

Note that id, name and label are required but more properties can be provided, e.g. dialingCodeProps={{ id: 'id', name: 'name', label: 'label', className: 'some-class' }}. All properties will be forwarded to the underlying BpkSelect component.

dialingCodes

The same is true for dialingCodes. Each object must have a code and description, but can have more properties and those will be forwarded the the option element they represent. Note that, when using the dialingCodeMask option, all dialingCodes values must have a numberPrefix attribute.

7.1.13

2 years ago

7.1.11

2 years ago

7.1.7

2 years ago

7.1.9

2 years ago

7.1.6

2 years ago

7.1.5

2 years ago

7.1.3

2 years ago

7.1.2

2 years ago

7.1.1

2 years ago

7.0.6

2 years ago

7.0.4

2 years ago

7.0.3

2 years ago

7.0.13

2 years ago

7.0.19

2 years ago

7.0.16

2 years ago

7.0.14

2 years ago

7.0.1

3 years ago

6.0.1

3 years ago

5.0.16

3 years ago

5.0.14

3 years ago

5.0.13

3 years ago

5.0.12

3 years ago

5.0.10

3 years ago

5.0.11

3 years ago

5.0.9

3 years ago

5.0.8

3 years ago

5.0.7

3 years ago

5.0.6

3 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.2.6

3 years ago

4.2.8

3 years ago

4.2.5

3 years ago

4.2.4

3 years ago

4.2.3

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.133

3 years ago

4.1.132

3 years ago

4.1.130

3 years ago

4.1.131

3 years ago

4.1.129

3 years ago

4.1.125

3 years ago

4.1.126

3 years ago

4.1.127

3 years ago

4.1.124

3 years ago

4.1.123

3 years ago

4.1.122

3 years ago

4.1.120

3 years ago

4.1.121

3 years ago

4.1.119

3 years ago

4.1.117

3 years ago

4.1.118

3 years ago

4.1.116

3 years ago

4.1.115

3 years ago

4.1.113

3 years ago

4.1.114

3 years ago

4.1.111

3 years ago

4.1.112

3 years ago

4.1.110

3 years ago

4.1.109

3 years ago

4.1.108

3 years ago

4.1.107

3 years ago

4.1.106

3 years ago

4.1.105

3 years ago

4.1.104

3 years ago

4.1.103

3 years ago

4.1.102

3 years ago

4.1.100

3 years ago

4.1.101

3 years ago

4.1.99

3 years ago

4.1.98

3 years ago

4.1.97

3 years ago

4.1.96

3 years ago

4.1.95

3 years ago

4.1.94

3 years ago

4.1.92

3 years ago

4.1.93

3 years ago

4.1.90

3 years ago

4.1.91

3 years ago

4.1.87

3 years ago

4.1.86

3 years ago

4.1.85

3 years ago

4.1.83

4 years ago

4.1.84

4 years ago

4.1.82

4 years ago

4.1.81

4 years ago

4.1.80

4 years ago

4.1.79

4 years ago

4.1.78

4 years ago

4.1.76

4 years ago

4.1.75

4 years ago

4.1.74

4 years ago

4.1.72

4 years ago

4.1.73

4 years ago

4.1.71

4 years ago

4.1.70

4 years ago

4.1.69

4 years ago

4.1.68

4 years ago

4.1.67

4 years ago

4.1.65

4 years ago

4.1.64

4 years ago

4.1.63

4 years ago

4.1.58

4 years ago

4.1.55

4 years ago

4.1.53

4 years ago

4.1.52

4 years ago

4.1.51

4 years ago

4.1.50

4 years ago