All files / source/label label.js

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90                                          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 Label extends React.Component {
  // Render method.
  render () {
    // Props.
    const {
      classNameForAbbr,
      classNameForLabel,
      label,
      required,
      styleForAbbr,
      styleForLabel,
      id: htmlFor
    } = this.props
 
    // Props for label.
    const propsForLabel = {
      htmlFor,
      style: styleForLabel,
 
      // Build class name.
      className: trim(
        [
          't7-input__label',
          classNameForLabel
        ].join(' ')
      )
    }
 
    // Props for abbr.
    const propsForAbbr = {
      children: '*',
      title: 'Required',
      style: styleForAbbr,
 
      // Build class name.
      className: trim(
        [
          't7-input__label__abbr',
          classNameForAbbr
        ].join(' ')
      )
    }
 
    // Expose UI.
    return (
      <Render if={label}>
 
        <label {...propsForLabel}>
 
          {label}
 
          <Render if={required}>
            {' '}
            <abbr
              {...propsForAbbr}
            />
          </Render>
 
        </label>
 
        <br />
 
      </Render>
    )
  }
}
 
// Validation.
Label.propTypes = {
  classNameForAbbr: PropTypes.string,
  classNameForLabel: PropTypes.string,
  id: PropTypes.string,
  label: PropTypes.string,
  required: PropTypes.bool,
  styleForAbbr: PropTypes.object,
  styleForLabel: PropTypes.object
}
 
// Export.
export default Label