Sha256: b8fd952df5b8a496a844dd6d31d946ed343bb9f205eb7f075d49e8cbdeed6563

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

/* @flow */
import React from 'react'
import classnames from 'classnames'
import { Body, Caption } from '../'
import { globalProps } from '../utilities/globalProps.js'

import {
  buildAriaProps,
  buildDataProps,
} from '../utilities/props'

type TextInputProps = {
  aria?: object,
  className: String,
  dark: boolean,
  data?: object,
  error?: String,
  id?: String,
  name: String,
  label: String,
  onChange: (String) => void,
  placeholder: String,
  type: String,
  value: String | number,
  children: Node,
}

const TextInput = ({
  aria = {},
  className,
  dark = false,
  data = {},
  error,
  id,
  name,
  label,
  onChange = () => {},
  placeholder,
  type = 'text',
  value,
  children = null,
  ...props
}: TextInputProps) => {
  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const css = classnames([
    `pb_text_input_kit${dark === true ? '_dark' : ''}`,
    className,
    error ? 'error' : null,
  ])

  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={css}
    >
      <Caption
          className="pb_text_input_kit_label"
          dark={dark}
          text={label}
      />
      <div className={classnames('text_input_wrapper', globalProps(props))}>
        <If condition={children}>
          {children}
          <Else />
          <input
              {...props}
              className="text_input"
              id={id}
              name={name}
              onChange={onChange}
              placeholder={placeholder}
              type={type}
              value={value}
          />
          <If condition={error}>
            <Body
                dark={dark}
                status="negative"
                text={error}
            />
          </If>
        </If>
      </div>
    </div>
  )
}

export default TextInput

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
playbook_ui-6.1.0.pre.alpha5 app/pb_kits/playbook/pb_text_input/_text_input.jsx
playbook_ui-6.1.0.pre.alpha4 app/pb_kits/playbook/pb_text_input/_text_input.jsx
playbook_ui-6.1.0.pre.alpha3 app/pb_kits/playbook/pb_text_input/_text_input.jsx
playbook_ui-6.1.0.pre.alpha2 app/pb_kits/playbook/pb_text_input/_text_input.jsx
playbook_ui-6.1.0.pre.alpha1 app/pb_kits/playbook/pb_text_input/_text_input.jsx
playbook_ui-6.1.0 app/pb_kits/playbook/pb_text_input/_text_input.jsx
playbook_ui-6.0.1.pre.alpha6 app/pb_kits/playbook/pb_text_input/_text_input.jsx