1.4.0 • Published 6 years ago

z-checkbox v1.4.0

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

z-checkbox

Build SemVer Greenkeeper badge License

A styled checkbox component for your web application.

Table of contents

Install

The package is available to download through npm:

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

When bundling an web app

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

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

// Render it on page, using JSX here :)
render(<ZCheckbox />, 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
divroot.z-checkboxRoot containerBlock
div.z-checkbox.z-checkbox__boxThe box containing the checkboxElement
input of type checkbox.z-checkbox__box.z-checkbox__inputThe standard HTML checkbox inputElement
div.z-checkbox__box.z-checkbox__containerThe visually styled checkbox that the user seesElement
Any containing .z-checkbox__container.z-checkbox__container--secondary.z-checkbox__containerChange the background color of the the checkbox to the secondary colorModifier
Any containing .z-checkbox__container.z-checkbox__container--success.z-checkbox__containerChange the background color of the the checkbox to greenModifier
Any containing .z-checkbox__container.z-checkbox__container--warning.z-checkbox__containerChange the background color of the the checkbox to yellowModifier
Any containing .z-checkbox__container.z-checkbox__container--error.z-checkbox__containerChange the background color of the the checkbox to red, useful for errorsModifier
Any containing .z-checkbox__container.z-checkbox__container--danger.z-checkbox__containerChange the background color of the the checkbox to a lighter redModifier
label.z-checkbox.z-checkbox__labelThe optional label that describes the checkbox, the default position is on the right side of the .z-checkbox__box elementElement
Any containing .z-checkbox__label.z-checkbox.z-checkbox__label--topChange the label position to be above the .z-checkbox__box element, label must be declared before the .z-checkbox__box elementModifier
Any containing .z-checkbox__label.z-checkbox.z-checkbox__label--leftChange the label position to be on the left side of the .z-checkbox__box element, label must be declared before the .z-checkbox__box elementModifier
Any containing .z-checkbox__label.z-checkbox.z-checkbox__label--bottomChange the label position to be below the .z-checkbox__box element, label must be declared after the .z-checkbox__box elementModifier

Full working example:

<div class="z-checkbox">
  <div class="z-checkbox__box">
    <input id="example" type="checkbox" class="z-checkbox__input">
    <div class="z-checkbox__container"></div>
  </div>
  <label for="example" class="z-checkbox__label">Example checkbox</label>
</div>

Stateless Functional Component

Render the HTML by using the SFC and passing props.

Supported Props

Prop nameExpected TypeDescription
labelstringThe text description of the checkbox
labelPositionstringPass top, left or bottom to change the label position, the default is right
secondarybooleanChange the background color of the checkbox to the secondary color
successbooleanChange the background color of the checkbox to green
warningbooleanChange the background color of the checkbox to yellow
errorbooleanChange the background color of the checkbox to red, useful for errors
dangerbooleanChange the background color of the checkbox to a lighter red

Note: You can pass any input attribute to ZCheckbox, like disabled, checked and so on, it will pass through.

Full example (JSX):

<ZCheckbox id="example" label="Label" labelPosition="top" />

Theming

1.2.0 version of z-checkbox brings theming support via CSS Variables.

Below is the list of variables available to use:

VariableExpected typeDescription
--primary-colorcolorThe primary background-color of the checkbox
--secondary-colorcolorThe secondary background-color of the checkbox
--success-colorcolorA success indicating background-color of the checkbox
--warning-colorcolorA warning indicating background-color of the checkbox
--danger-colorcolorA danger indicating background-color of the checkbox
--error-colorcolorAn error indicating background-color of the checkbox
--neutral-border-colorcolorThe default border-color of the checkbox
--focused-border-colorcolorThe border-color of the focused checkbox
--checkbox-label-colorcolorThe color of the checkbox label text
--checkbox-sizepx, em or remThe size of the ticker box, always squared

LICENSE

MIT

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago