5.46.0 • Published 10 months ago

@s-ui/react-atom-input v5.46.0

Weekly downloads
2,510
License
MIT
Repository
github
Last release
10 months ago

AtomInput

Inputs are the text fields that users fill in with different types of information. These include dates, passwords or even short answers. It’s a field where users can write alphanumeric texts.

documentation issue npm

Issues open NPM

Installation

ƛ npm install @s-ui/react-atom-input --save

Usage

Add styles

To use the component's own styles, create a .scss file and import them inside.

@import '~@s-ui/react-atom-input/lib/index';

If you want to customize your components, create your own theme and add it to your component just before.

@import 'custom-settings';
@import '~@s-ui/react-atom-input/lib/index';

You can use native types like this

import AtomInput from '@s-ui/react-atom-input'

return <AtomInput type="number" /> // possible type options: text, number, date and password

Non native Inputs

SUI-Password

In order to use SUI defined Password Input pass the prop type='sui-password' to the Input component.

import AtomInput from '@s-ui/react-atom-input'

return <AtomInput type="sui-password" />

Mask

Wraps the https://unmanner.github.io/imaskjs/ lib, used if the input must follow a regex or a specific format/pattern . Using type='mask' activates this input, which will be expecting the mask prop type to be passed by.

const bankAccountMask = {
  // checkout all options here https://unmanner.github.io/imaskjs/guide.html
  mask: 'ES00 0000 0000 00 0000000000'
}

return <AtomInput type="mask" mask={bankAccountMask} placeholder="ES00 0000 0000 00 0000000000" />

Sizes

There are defined 3 sizes (MEDIUM, SMALL and XSMALL) available at the exported object inputSizes and that can be set through the prop size

Related size Sass vars are:

$h-atom-input--m: 40px;
$h-atom-input--s: 32px;
$h-atom-input--xs: 24px;
<AtomInput size={inputSizes.SMALL} name="first" placeholder="Small input" />

Addons

What are addons?

Addons are passed as prop, use leftAddon or rightAddon in order to set the position inside the Input

Addon usage

import AtomInput from '@s-ui/react-atom-input'

return <AtomInput leftAddon="http://" rightAddon="@schibsted.com" />

Icons

Icons are passed as prop, use leftIcon or rightIcon in order to set the position inside the Input

import AtomInput from '@s-ui/react-atom-input'

const logo = 'my_logo.svg'
const leftIcon = () => <img src={logo} />

<AtomInput leftIcon={leftIcon} />

You can also pass a handler for each Icon using the props onClickLeftIcon or onClickRightIcon

<AtomInput
  name="second"
  placeholder="Medium Input"
  leftIcon={LeftIcon}
  rightIcon={IconLocation}
  onClickRightIcon={e => alert('clicked right icon')}
/>

Error states

There are 3 error states:

  • error state = true, will show a red border around the input field
  • error state = false, will show a green border around the input field
  • error state = null, will show the by default border around the input field
<AtomInput name="second" placeholder="Success input" errorState={false} />

Input states

There are 3 error states:

  • input state = 'error', will show a red border around the input field
  • input state = 'success', will show a green border around the input field
  • input state = 'alert', will show a orange border around the input field
  • input state = null, will show the by default border around the input field
<AtomInput name="second" placeholder="Success input" state="alert" />

Form Usage

Each field returns its value on every onChange event so you can save it inside your form state.

import React from 'react'
import ReactDOM from 'react-dom'
import Input from '@s-ui/react-atom-input'
import Button from '@s-ui/react-atom-button'

class SimpleLoginForm extends React.Component {
  constructor() {
    super()
    this.state = {
      email: {
        value: '',
        errorState: null
      },
      password: {
        value: '',
        errorState: null
      }
    }

    this.onChange = this.onChange.bind(this)
    this.onSubmit = this.onSubmit.bind(this)
    this.onBlur = this.onBlur.bind(this)
  }

  isEmail(value) {
    return /(.+)@(.+){2,}\.(.+){2,}/.test(value)
  }

  onChange({value, field}) {
    this.setState(
      Object.assign({}, this.state, {
        [field]: {
          value,
          errorState: null
        }
      })
    )
  }

  onBlur({value, field}) {
    let errorState = !this.isEmail(value)
    this.setState({
      [field]: {errorState, value}
    })
  }

  onSubmit(ev) {
    ev.preventDefault()
    ev.stopPropagation()

    window.alert(JSON.stringify(this.state))
  }

  render() {
    const {email, password} = this.state
    return (
      <form>
        <Input
          type="text"
          value={email.value}
          onChange={({ev, value}) => this.onChange({value, field: 'email', ev})}
          onBlur={ev => this.onBlur({value: ev.target.value, field: 'email'})}
          errorState={this.state.email.errorState}
        />
        <Input
          type="sui-password"
          value={password.value}
          onChange={({ev, value}) => this.onChange({value, field: 'password', ev})}
        />
        <Button onClick={this.onSubmit}>Login</Button>
      </form>
    )
  }
}
5.39.0

1 year ago

5.46.0

10 months ago

5.42.0

1 year ago

5.43.0

1 year ago

5.44.0

1 year ago

5.40.0

1 year ago

5.38.0

1 year ago

5.45.0

10 months ago

5.41.0

1 year ago

5.37.0

2 years ago

5.34.0

2 years ago

5.35.0

2 years ago

5.36.0

2 years ago

5.29.0

3 years ago

5.27.0

3 years ago

5.32.0

3 years ago

5.30.0

3 years ago

5.28.0

3 years ago

5.33.0

3 years ago

5.31.0

3 years ago

5.26.0

3 years ago

5.25.0

3 years ago

5.24.0

3 years ago

5.23.0

3 years ago

5.22.0-beta.0

3 years ago

5.22.0

3 years ago

5.21.0-beta.4

3 years ago

5.21.0-beta.3

3 years ago

5.21.0

4 years ago

5.21.0-beta.5

3 years ago

5.21.0-beta.0

3 years ago

5.21.0-beta.2

3 years ago

5.21.0-beta.1

3 years ago

5.18.0

4 years ago

5.19.0

4 years ago

5.17.0

4 years ago

5.20.0

4 years ago

5.16.0

4 years ago

5.15.0

4 years ago

5.13.0

4 years ago

5.14.0

4 years ago

5.12.0

4 years ago

5.11.0

4 years ago

5.10.0

4 years ago

5.8.0

4 years ago

5.9.0

4 years ago

5.7.0

4 years ago

5.6.0

4 years ago

5.5.0

4 years ago

5.4.0

5 years ago

5.3.0

5 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.24.0

5 years ago

4.23.0

5 years ago

4.22.0

6 years ago

4.21.0

6 years ago

4.20.0

6 years ago

4.19.0

6 years ago

4.18.0

6 years ago

4.17.0

6 years ago

4.16.0

6 years ago

4.15.0

6 years ago

4.13.0

6 years ago

4.14.0

6 years ago

4.12.0

6 years ago

4.11.0

6 years ago

4.10.0

6 years ago

4.9.0

6 years ago

4.8.0

6 years ago

4.7.0

6 years ago

4.6.0

6 years ago

4.5.0

6 years ago

4.4.0

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.14.0

6 years ago

3.13.0

6 years ago

3.12.0

7 years ago

3.11.0

7 years ago

3.10.0

7 years ago

3.9.0

7 years ago

3.8.0

7 years ago

3.5.0

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.16.0

7 years ago

1.15.0

7 years ago

1.14.0

7 years ago

1.13.0

7 years ago

1.12.0

7 years ago

1.11.0

7 years ago

1.10.0

7 years ago

1.9.0

7 years ago

1.8.0

8 years ago

1.7.0

8 years ago

1.1.0

8 years ago