1.4.0 • Published 6 years ago

z-button v1.4.0

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

z-button

Build SemVer Greenkeeper badge License

A styled button component for your web application.

Table of contents

Install

The package is available to download through npm:

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

When bundling an web app

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

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

// Render it on page, using JSX here :)
render(<ZButton>Click me!</ZButton>, 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
button, aroot.z-buttonRoot containerBlock
Any containing .z-buttonroot.z-button--borderedChange the style of the button to be bordered with transparent backgroundModifier
Any containing .z-buttonroot.z-button--flatChange the style of the button to be flat with no border or backgroundModifier
Any containing .z-buttonroot.z-button--iconChange the style of the button to have a fixed size, useful for housing single iconsModifier
Any containing .z-buttonroot.z-button--blockMake the button fill all the parent's widthModifier
Any containing .z-buttonroot.z-button--roundedMake the button more roundModifier
Any containing .z-buttonroot.z-button--secondarySecondary color for the buttonModifier
Any containing .z-buttonroot.z-button--successColor the button greenModifier
Any containing .z-buttonroot.z-button--warningColor the button yellowModifier
Any containing .z-buttonroot.z-button--dangerColor the button redModifier

Full working example:

<button class="z-button z-button--rounded">Click me!</button>

Stateless Functional Component

Render the HTML by using the SFC and passing props.

Supported Props

Prop nameExpected TypeDescription
childrenHTMLElement or TextNodeButton content
borderedbooleanPass true to make change the style of the button to bordered
flatbooleanPass true to make change the style of the button to flat
iconbooleanPass true to make the button expect an icon as content
blockbooleanPass true to make the button fill the parent's container width
roundedbooleanPass true to make the button fully rounded
secondarybooleanPass true to make the button secondary
successbooleanPass true to make the button green
warningbooleanPass true to make the button yellow
dangerbooleanPass true to make the button red

Full example (JSX):

<ZButton>Click me!</ZButton>

Theming

Available since 1.2.0, now z-button supports theming through CSS Variables!

Check the list of variables used:

VariableExpected typeDescription
--primary-colorcolorThe primary background-color for the buttons
--lighter-primary-colorcolorbackground-color for the focused/hovered buttons
--darker-primary-colorcolorbackground-color for the active buttons
--secondary-colorcolorAn alternative background-color for the buttons
--lighter-secondary-colorcolorAlternative background-color for the focused/hovered buttons
--darker-secondary-colorcolorAlternative background-color for the active buttons
--success-colorcolorbackground-color indicating a success action button
--lighter-success-colorcolorbackground-color indicating a focused/hovered success action button
--darker-success-colorcolorbackground-color indicating an active success action button
--warning-colorcolorbackground-color indicating a warning action button
--lighter-warning-colorcolorbackground-color indicating a focused/hovered warning action button
--darker-warning-colorcolorbackground-color indicating an active warning action button
--danger-colorcolorbackground-color indicating a danger action button
--lighter-danger-colorcolorbackground-color indicating a focused/hovered danger action button
--darker-danger-colorcolorbackground-color indicating an active danger action button
--disabled-colorcolorbackground-color indicating a disabled button
--button-text-colorcolorText color for the button, usually light

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.0

8 years ago