0.0.8 • Published 7 years ago

react-text-input v0.0.8

Weekly downloads
334
License
MIT
Repository
github
Last release
7 years ago

React Text Input

npm version

Live Demo

Motivation

  • Use arbitrary markup in placeholder even icons, animation etc.
  • Customize scrollbars for TextArea. Done with help of react-scroll-box.
  • Enable vertical and horizontal autogrow that is fully controlled from CSS for Input and TextArea.
  • Use components in either controlled or uncontrolled way.

Usage

var TextArea = require('react-text-input').TextArea; // ES5

import {Input, TextArea, GenericInput} from 'react-text-input'; // ES6

<TextArea defaultValue="Hello world!"/>

Components

This pakage provides three React components:

GenericInput

Abstract component that expects arbitrary editing control as a child. Manages placeholder and autogow.

Prop NameTypeDefaultDescription
valueStringValue represented by this GenericInput.
disabledBooleanfalseToggles component disabled with .text-input--disabled.
placeholder*Any value including React element, that is displayed if value is empty.
classNameStringStyle class name added to root element.

Input

One line text input component. Generally behaves like regular input. Inherits all properties from GenericInput and regular input.

Prop NameTypeDefaultDescription
valueStringValue represented by this Input if it is controlled.
defaultValueStringDefault value represented by this Input if it is uncontrolled.
fitLineLengthBooleanfalseShould.

Uncontrolled input component markup:

<Input type="search"
       defaultValue="Christmas gifts"
       placeholder={<span><i className="fa fa-search"/> Search</span>}
       fitLineLength={true}/>

TextArea

Autogrowing text area implementation. Has all the same properties as Input.

<TextArea fitLineLength={true}
          onChange={e => console.log(e.target.value)}/>

Styles

By default, components have no visual decoration, so you need to provide a custom class name (like form-control from Bootstrap) to make it them visible.

In most cases you should change styling only for the root DOM element. Styles applied to Input and TextArea behave just like regular input and textare elements do.

Class NameDescription
.text-inputRoot style class for both Input and TextArea
.text-input--filledAdded when component stores a non-empty value.
.text-input--disabledAdded when component is disabled.
.textinputfitlinelengthAdded when component should grow horizontally.
.text-input--textModifier that matches type of input control. For example, input[type="password"] would have .text-input--password` specified.
.text-input--text-areaAdded for textarea control.
.text-input__controlHTML UI element input or textarea.
.text-input__placeholderPlaceholder container. Content of the placeholder prop is rendered inside this container.
.text-input__contentContainer that stores input text. Required for autogrow.

Autogrowing

By default, TextArea has height of a single line of text and grows vertically without any limit. You can constraint vertical expansion with min-height and max-height.

.vertical-constraint {
  min-height: 100px;
  max-height: 200px;
}

Then provide this modifier as a className value.

<TextArea className="vertical-constraint"/>

Horizontal constraints work in the same way for both Input and TextArea when fitLineLength={true} specified.

.horizontal-constraint {
  min-width: 100px;
  max-width: 200px;
}

License

The code is available under MIT licence.

0.0.8

7 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago