All files / source/error_message error_message.js

100% Statements 6/6
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                30x   30x 30x     30x                             30x                     24x                
// Dependencies.
import React from 'react'
import Render from '@t7/render'
import PropTypes from 'prop-types'
 
// Utility methods.
import { trim } from '@t7/utils'
 
// Define class.
class ErrorMessage extends React.Component {
  // Render method.
  render () {
    // Props.
    const {
      classNameForError,
      styleForError
    } = this.props
 
    let { errorMessage } = this.props
    errorMessage = trim(errorMessage)
 
    // Props for error.
    const propsForError = {
      children: errorMessage,
      style: styleForError,
      title: errorMessage,
 
      // Build class name.
      className: trim(
        [
          classNameForError,
          't7-input__error'
        ].join(' ')
      )
    }
 
    // Expose UI
    return (
      <Render if={errorMessage}>
        <span
          {...propsForError}
        />
      </Render>
    )
  }
}
 
// Validation.
ErrorMessage.propTypes = {
  classNameForError: PropTypes.string,
  errorMessage: PropTypes.string,
  styleForError: PropTypes.object
}
 
// Export.
export default ErrorMessage