Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / src / new-forms / plugins / EmailPlugin.tsx
Size: Mime:
/**
 * @todo @anto @sriaarthi
 * @todo renderIcon before @mohan
 */
import * as React from 'react'
import { observer } from 'xmobx/mobx-react'
import { errorMessageFor, isValidEmail } from '../../validators'
import { Value } from '../typings'
import { InputProps } from '../inputs/typings'
import { InputState } from '../inputs/InputState'
import { ObserverInput } from '../inputs/ObserverInput'

@observer
class EmailPlugin extends React.Component<InputProps> {
  static isSatisfiedByProps(props: { type: string }): boolean {
    return ['email'].includes(props.type)
  }

  // used by state
  static defaultState = (inputState: InputState) => {
    return {
      validator: (value: Value) =>
        isValidEmail(value as string) || errorMessageFor('email'),
    }
  }

  render() {
    return (
      <ObserverInput
        label="Email"
        data-qa="qa-email"
        required={true}
        minLength={4}
        maxLength={254}
        pattern="((.*)\@(.*)\.(.*))"
        placeholder="you@skava.com..."
        // ^ will be overwritten by props
        {...this.props}
        type="email"
        autoComplete="email"
      />
    )
  }
}

export { EmailPlugin }
export default EmailPlugin