Code Monkey home page Code Monkey logo

stimulus-check-all's Introduction

Stimulus CheckAll

npm version npm downloads MIT License

A wrapper for @github/check-all as a Stimulus Controller.

Keep track of all the changes in the Changelog

Install

This package assumes that you have Stimulus installed and set up.

Install the library in your project with:

yarn add stimulus-check-all
# or
npm install --save stimulus-check-all

And register the controller in your application

import { Application } from "stimulus"
import CheckAll from "stimulus-check-all"

const application = Application.start()
application.register("check-all", CheckAll)

You can also use a UMD build directly from UNPKG, which will make the controller globally available as StimulusCheckAll (it also bundles @github/check-all)

<script src="https://unpkg.com/stimulus/dist/stimulus.umd.js"></script> <!-- Stimulus must be loaded globally -->
<script src="https://unpkg.com/stimulus-check-all@latest/dist/stimulus-check-all.umd.js"></script> <!-- or 'stimulus-check-all.umd.min.js' -->

There is also a CommonJS build on UNPKG:

https://unpkg.com/stimulus-check-all/dist/stimulus-check-all.js
https://unpkg.com/stimulus-check-all/dist/stimulus-check-all.min.js

Usage

For the most basic usage create a div with some checkboxes. In the case you want to exclude some checkboxes from the check-all features, add a data-skip attribute to those checkboxes.

<div data-controller="check-all">
  <div>Count: <span data-target="check-all.count">0</span></div> <!-- optional -->
  <label><input type="checkbox" data-target="check-all.all"> Check All</label> <!-- optional -->
  <label><input type="checkbox"> github/fetch</label>
  <label><input type="checkbox"> github/textarea-autosize</label>
  <label><input type="checkbox"> github/eventlistener-polyfill</label>
  <label><input type="checkbox"> github/quote-selection</label>
  <label><input type="checkbox" data-skip> skip-this-one</label> <!-- this one is skipped -->
</div>

Targets

All of them are optional, as they are in @github/check-all.

  • all: The checkbox used to check all of the other ones in the container
  • count: Displays the number of selected checkboxes

Extending controller

You can extend the functionality of the controller using inheritance. Just remember to call super if overriding any of the parent's methods, like connect or disconnect:

import CheckAllController from 'stimulus-check-all'

export default class extends CheckAllController {
  connect () {
    super.connect()

    // your custom code
  }
}

Apart from access to the targets defined in the parent class, the controller exposes three other properties:

  • checkboxes: All the checkboxes where the check-all feature is applied
  • checked: The checked checkboxes
  • unchecked: The unchecked checkboxes

Contributing

Bug reports and pull requests are more than welcome on GitHub.

Coding standards

This project uses Standard to minimize bike shedding related to code formatting.

Please run npm run lint prior submitting pull requests.

License

The software is available as open source under the terms of the MIT License.

stimulus-check-all's People

Contributors

dependabot[bot] avatar glaszig avatar rbague avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.