Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit d6ef626

Browse files
Initial commit
0 parents  commit d6ef626

20 files changed

+9061
-0
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": [
3+
"@babel/plugin-proposal-class-properties"
4+
]
5+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://eslint.org/docs/user-guide/configuring
2+
3+
module.exports = {
4+
env: {
5+
browser: true,
6+
node: true,
7+
es6: true
8+
},
9+
10+
globals: {
11+
page: 'readonly'
12+
}
13+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
pkg
3+
build

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14.13.0

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.github
2+
jest
3+
.babelrc
4+
jest.config.js
5+
index.html
6+
snowpack.config.json
7+
netlify.toml
8+
.node-version
9+
.eslintrc.js
10+
src

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 120
3+
}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
## [1.0.0] - 2020-10-15
10+
11+
### Added
12+
13+
- Adding controller

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Guillaume Briday
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Stimulus Checkbox Select All
2+
3+
[![](https://img.shields.io/npm/dt/stimulus-checkbox-select-all.svg)](https://www.npmjs.com/package/stimulus-checkbox-select-all)
4+
[![](https://img.shields.io/npm/v/stimulus-checkbox-select-all.svg)](https://www.npmjs.com/package/stimulus-checkbox-select-all)
5+
[![](https://github.com/stimulus-components/stimulus-checkbox-select-all/workflows/Lint/badge.svg)](https://github.com/stimulus-components/stimulus-checkbox-select-all)
6+
[![](https://github.com/stimulus-components/stimulus-checkbox-select-all/workflows/Test/badge.svg)](https://github.com/stimulus-components/stimulus-checkbox-select-all)
7+
[![](https://img.shields.io/github/license/stimulus-components/stimulus-checkbox-select-all.svg)](https://github.com/stimulus-components/stimulus-checkbox-select-all)
8+
[![Netlify Status](https://api.netlify.com/api/v1/badges/073b5fee-358d-4dbf-b807-52034690f8ef/deploy-status)](https://stimulus-checkbox-select-all.netlify.com)
9+
10+
## Getting started
11+
12+
A Stimulus controller to check/uncheck all checkboxes.
13+
14+
## Installation
15+
16+
```bash
17+
$ yarn add stimulus-checkbox-select-all
18+
```
19+
20+
And use it in your JS file:
21+
```js
22+
import { Application } from "stimulus"
23+
import CheckboxSelectAll from "stimulus-checkbox-select-all"
24+
25+
const application = Application.start()
26+
application.register("checkbox-select-all", CheckboxSelectAll)
27+
```
28+
29+
## Usage
30+
31+
In your models:
32+
```ruby
33+
class User < ApplicationRecord
34+
has_many :teams
35+
end
36+
37+
class Team < ApplicationRecord
38+
belongs_to :user
39+
end
40+
```
41+
42+
In your controller:
43+
```ruby
44+
class UsersController < ApplicationController
45+
def update
46+
if user.update(user_params)
47+
redirect_to users_path
48+
else
49+
render :edit
50+
end
51+
end
52+
53+
private
54+
55+
def user_params
56+
params
57+
.require(:user)
58+
.permit(
59+
team_ids: []
60+
)
61+
end
62+
end
63+
```
64+
65+
In your view:
66+
```html
67+
<%= form_with model: @user, data: { controller: 'checkbox-select-all' } do |f| %>
68+
<label>
69+
<input type="checkbox" data-action="change->checkbox-select-all#toggle" />
70+
<span>Select All / Deselect All</span>
71+
</label>
72+
73+
<%= f.collection_check_boxes :team_ids, Team.all, :id, :name do |b| %>
74+
<%= b.label do %>
75+
<%= b.check_box data: { target: 'checkbox-select-all.checkbox' } %>
76+
<%= b.text %>
77+
<% end %>
78+
<% end %>
79+
<% end %>
80+
```
81+
82+
## Extending Controller
83+
84+
You can use inheritance to extend the functionality of any Stimulus components.
85+
86+
```js
87+
import CheckboxSelectAll from "stimulus-checkbox-select-all"
88+
89+
export default class extends CheckboxSelectAll {
90+
connect() {
91+
super.connect()
92+
console.log("Do what you cant here.")
93+
}
94+
}
95+
```
96+
97+
These controllers will automatically have access to targets defined in the parent class.
98+
99+
If you override the connect, disconnect or any other methods from the parent, you'll want to call `super.method()` to make sure the parent functionality is executed.
100+
101+
## Development
102+
103+
### Project setup
104+
```bash
105+
$ yarn install
106+
$ yarn dev
107+
```
108+
109+
### Linter
110+
[Prettier](https://prettier.io/) and [ESLint](https://eslint.org/) are responsible to lint and format this component:
111+
```bash
112+
$ yarn lint
113+
$ yarn format
114+
```
115+
116+
## Contributing
117+
118+
Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.
119+
120+
## License
121+
122+
This project is released under the [MIT](http://opensource.org/licenses/MIT) license.

0 commit comments

Comments
 (0)