2.0.0 • Published 6 years ago

z-input v2.0.0

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

z-input

Build SemVer License

A basic styled text input for your web application

Table of contents

Install

The package is available to download through npm:

npm install z-input --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-input/dist/style.css">

When bundling an web app

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

require('z-input/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 ZInput = require('z-input')(React.createElement);

// Render it on page, using JSX here :)
render(<ZInput />, 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-inputRoot containerBlock
Any containing .z-inputroot.z-input--labelMakes space for a floating labelModifier
Any containing .z-inputroot.z-input--boxRenders a block input box good for search bars and headersModifier
Any containing .z-inputroot.z-input--borderlessRenders an input box without borders, preserving browser's outlineModifier
Any containing .z-inputroot.z-input--successRenders a green border to indicate successModifier
Any containing .z-inputroot.z-input--warningRenders a yellow border to indicate warningModifier
Any containing .z-inputroot.z-input--dangerRenders a reddish border to indicate dangerModifier
Any containing .z-inputroot.z-input--errorRenders a red border to indicate errorModifier
Any containing .z-inputroot.z-input--prefixMakes room in the inpux box for a prefix elementModifier
Any containing .z-inputroot.z-input--suffixMakes room in the inpux box for a suffix elementModifier
Any containing .z-inputroot.z-input--darkMakes the input text white so it can be read easier on dark backgroundsModifier
Any containing .z-inputroot.z-input__labelRenders a floating labelElement
Any containing .z-inputroot.z-input__prefixRenders a prefix element before the input textElement
Any containing .z-inputroot.z-input__suffixRenders a suffix element after the input textElement
Any containing .z-inputroot.z-input--openForces floating label to be open in an labeled inputModifier
Any containing .z-inputroot.z-input--closedForces floating label to be closed in an labeled inputModifier

Full working example:

<div class="z-input">
  <input type="text" placeholder="Type something">
</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
borderlessbooleanPass true to render a borderless input box
boxbooleanPass true to render an input box good for search bars and headers
prefixHTMLElement or TextNodeThe prefix to render before the input text
suffixHTMLElement or TextNodeThe suffix to render after the input text
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 input is in a dark background and input text will be white
isOpenboolean or undefinedPass true or false to force the floating label to be open or closed

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

Full example (JSX):

<ZInput placeholder="Type something" />

Theming

Since 1.3.0 you can theme z-input using CSS Variables!

The list of variables available is below:

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

LICENSE

MIT

2.0.0

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago