1.2.0 • Published 5 years ago

z-textarea v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

z-textarea

Build SemVer License

A basic styled textarea for your web application

Table of contents

Install

The package is available to download through npm:

npm install z-textarea --save

Import as HTML/CSS component

The simple case

The package will be located inside the node_modules folder, you can import it into the HTML document as follows:

<link rel="stylesheet" href="node_modules/z-textarea/dist/style.css">

When bundling an web app

For bundlers that support CSS, like Webpack, you can use it like this:

require('z-textarea/dist/style.css');

Import as a Stateless Functional Component (SFC)

The package does not include the renderer, you can use any renderer that supports SFCs. You could use React, Preact, Inferno, etc.

Notice: This package contains CSS styling, you may need a bundler that's capable of requiring CSS files like Webpack with css-loader.

Once you have chosen the renderer you can include the package in your project as follows:

// Assuming the React renderer is being used
const React = require('react');
const render = require('react-dom').render;

// Passing the render function when importing
const ZTextarea = require('z-textarea')(React.createElement);

// Render it on page, using JSX here :)
render(<ZTextarea />, document.body);

How to use

CSS component

Just add the HTML structure and CSS classes to reproduce the UI component.

Class hierarchy

Recommended HTML tagsParentClassDescriptionType
div, section, main, article, fieldsetroot.z-textareaRoot containerBlock
Any containing .z-textarearoot.z-textarea--labelMakes space for a floating labelModifier
Any containing .z-textarearoot.z-textarea--successRenders a green border to indicate successModifier
Any containing .z-textarearoot.z-textarea--warningRenders a yellow border to indicate warningModifier
Any containing .z-textarearoot.z-textarea--dangerRenders a reddish border to indicate dangerModifier
Any containing .z-textarearoot.z-textarea--errorRenders a red border to indicate errorModifier
Any containing .z-textarearoot.z-textarea--darkMakes the textarea text white so it can be read easier on dark backgroundsModifier
Any containing .z-textarearoot.z-textarea__labelRenders a floating labelElement

Full working example:

<div class="z-textarea">
  <textarea placeholder="Type something"></textarea>
</div>

Stateless Functional Component

Render the HTML by using the SFC and passing props.

Supported Props

Prop nameExpected TypeDescription
labelstring or TextNodeThe floating label to render
colorstringA custom border color that you might pass to override the defaults
successbooleanPass true to indicate success and render a green border
warningbooleanPass true to indicate warning and render a yellow border
dangerbooleanPass true to indicate danger and render a reddish border
errorbooleanPass true to indicate error and render a red border
darkbooleanPass true to indicate the textarea is in a dark background and text will be white

Note that you can pass any attribute compatible with textarea that it will be automatically passed through.

Full example (JSX):

<ZTextarea placeholder="Type something" />

Theming

You can theme z-textarea using CSS Variables!

The list of variables available is below:

VariableExpected typeDescription
--primary-colorcolorThe border-color for selected textarea
--success-colorcolorThe border-color for selected success textarea
--warning-colorcolorThe border-color for selected warnings textarea
--danger-colorcolorThe border-color for selected danger textarea
--error-colorcolorThe border-color for selected errored textarea
--neutral-border-colorcolorThe border-color for idle textarea
--neutral-colorcolorThe text color for placeholders/floating labels
--dark-colorcolorThe background color for textarea labels

LICENSE

MIT

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago