Rocket Button
A lightweight button module.
- Getting Started
- CSS Implementation
- SASS Implementation
- Javascript Initialisation
- Buttonplate Deprecated
Getting Started
Install via NPM.
npm install rocket-button
NOTE that this module has a dependency Rocket Tools (28kb) which will automatically be installed as well.
CSS Implementation
Start by including the necessary files.
Now class your button and add a modifier to gain the desired effect. For example:
Example Button
There are a variety of options for the CSS modifiers.
Class | Options | Description |
---|---|---|
_mod-style-flat-(x) |
white grey black aqua blue green orange pink purple red yellow |
Set the colour and style to flat. |
_mod-style-gradient-(x) |
white grey black aqua blue green orange pink purple red yellow |
Set the colour and style to gradient. |
_mod-style-line-(x) |
white grey black aqua blue green orange pink purple red yellow |
Set the colour and style to line. |
_mod-size-(x) |
small normal large x-large |
Set the size of the the button. |
_mod-shape-(x) |
rounded pill square |
Set the shape of the the button. |
If no modifiers are provided then the colour will default to grey, the style to flat, the size to normal and the shape to rounded.
SASS Implementation
Instead of including the CSS file above, you can import the SASS file and create your own button styles. See an example below:
; .btn-primary,.btn-secondary .btn-primary .btn-secondary
There are a variety of options for the SASS builds.
SASS | Default | Options | Description |
---|---|---|---|
mod-button-setup |
Apply to all buttons. | ||
mod-button-shape(x) |
rounded |
pill rounded square |
Set the shape of the button. |
mod-button-size(x) |
normal |
small normal large x-large |
Set the size of the button. |
mod-button-style(x, y) |
flat , white |
flat gradient line |
Set x to the style of button.Set y to the colour. |
mod-button-css(x) |
.mod-button |
Create styles for selector x . |
Javascript Initialisation
If you want to enable button loaders or dropdowns then you will need to execute the following Javascript. Start by including the necessary files. By default the dropdown target option is set to .mod-button.
Button Loader Drop Down Default Link 1 Link 2 Link 3 <!-- Include the scripts -->
The button loader returns the element instance. You can modify the loader after that.
// Start the button loaderconst btnLoader = Rocketbutton; // The button elementRocket; // Hide the loader;
Each dropdown initialisation will return an array of module objects (An array will always be returned even if the target is an id). This includes the button element itself as well as relevant methods. For example:
// By default the target option is set to '.mod-button'const buttons = Rocketbutton; // The buttons and all methodsfor let i = 0 len = buttonslength; i < len; i++ console; buttonsi; // Show the button dropdown buttonsi; // Hide the button dropdown
Alternatively if you know the button target is unique you can reference the button right away with the 0 index. For example:
const myButton = Rocketbutton0; // Reference the first item in the array right away.
Loader Options
Name | Default | Options | Description |
---|---|---|---|
element |
Provide the button element to attach the loader to. | ||
parseEvent |
Parse a click event to prevent the default action. | ||
reveal |
appear |
appear slide-down slide-up |
Set the loader reveal. |
timeout |
0 |
Set the timeout of the loader (in seconds).0 is infinite. |
Defaults
You can also overwrite the module target option globally by altering the Rocket defaults. To do so reference the defaults object property, for example:
Rocketdefaultsbuttonloaderreveal = 'slide-up';Rocketdefaultsbuttondropdowntarget = '.new-button-class';
Buttonplate Deprecated
The original library, Buttonplate, has been deprecated. The entire Webplate project is being refactored and rebranded with a new development philosophy. Buttonplate will be maintained only with bug fixes under the buttonplate branch.
Author
Created and maintained by Chris Humboldt
Website: chrishumboldt.com
Twitter: twitter.com/chrishumboldt
GitHub github.com/chrishumboldt
Copyright and License
Copyright 2018 Rocket Project
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.