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 / PasswordPlugin / PasswordPlugin.tsx
Size: Mime:
import * as React from 'react'
import { observer } from 'xmobx/mobx-react'
import { InputProps } from '../../inputs'
import { StyledShowPasswordIcon, PasswordPluginWrap } from './styled'
import { ObserverInput } from '../../inputs/ObserverInput'

export type PasswordAutoComplete =
  | 'current-password'
  | 'new-password'
  | 'password'

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

  /**
   * @todo can also do this 1 level up and toggle for both confirm and normal
   */
  handleToggle = (event?: any) => {
    console.debug('[PasswordPlugin] toggle')
    const { state } = this.props
    state.setIsVisible(!state.isVisible)
    state.setType(state.type === 'password' ? 'text' : 'password')
  }

  // aka, reset
  componentWillUnmount() {
    const { state } = this.props
    state.setIsVisible(false)
    state.setType('password')
  }

  render() {
    const { state, ...remainingProps } = this.props

    return (
      <PasswordPluginWrap>
        <ObserverInput
          label="Password"
          {...remainingProps}
          placeholder="ReactDemo#0-100"
          type={state.type}
          state={state}
        />
        <StyledShowPasswordIcon
          isVisible={state.isVisible}
          onClick={this.handleToggle}
          children="o.o"
        />
      </PasswordPluginWrap>
    )
  }
}

export { PasswordPlugin }
export default PasswordPlugin