-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major redesign
- Loading branch information
Sam Williams
committed
Jan 13, 2024
1 parent
1bcd01e
commit 409aedc
Showing
13 changed files
with
380 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = ['submitButton', 'input'] | ||
static values = { | ||
unallowed: { type: Array } | ||
} | ||
|
||
static classes = ['disabled', 'enabled'] | ||
|
||
validate () { | ||
let invalid = false | ||
this.inputTargets.forEach(input => { | ||
if (this.unallowedValue.includes(input.value)) { | ||
invalid = true | ||
} | ||
}) | ||
|
||
if (invalid) { | ||
this.submitButtonTarget.disabled = true | ||
this.submitButtonTarget.classList.add(this.disabledClass) | ||
this.submitButtonTarget.classList.remove(...this.enabledClasses) | ||
} else { | ||
this.submitButtonTarget.disabled = false | ||
this.submitButtonTarget.classList.remove(this.disabledClass) | ||
this.submitButtonTarget.classList.add(...this.enabledClasses) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
// Connects to data-controller="select-all" | ||
export default class extends Controller { | ||
static targets = ['checkboxAll', 'checkbox', 'button', 'buttonLabel'] | ||
static values = { | ||
allChecked: { type: Boolean, default: false }, | ||
buttonLabel: { type: String } | ||
} | ||
|
||
static classes = ['hidden'] | ||
|
||
toggleAll () { | ||
this.allCheckedValue = !this.allCheckedValue | ||
|
||
this.checkboxTargets.forEach(checkbox => { | ||
checkbox.checked = this.allCheckedValue | ||
}) | ||
|
||
this.toggleButton() | ||
} | ||
|
||
toggleSingle () { | ||
this.toggleCheckedAll() | ||
this.toggleButton() | ||
} | ||
|
||
toggleCheckedAll () { | ||
const numChecked = this.getNumberChecked() | ||
const numTotal = this.getTotalCheckboxes() | ||
|
||
this.allCheckedValue = numChecked === numTotal | ||
this.checkboxAllTarget.checked = this.allCheckedValue | ||
|
||
if (numChecked === 0) { | ||
this.checkboxAllTarget.indeterminate = false | ||
} else { | ||
this.checkboxAllTarget.indeterminate = numChecked < numTotal | ||
} | ||
} | ||
|
||
toggleButton () { | ||
if (this.hasButtonTarget) { | ||
const numChecked = this.getNumberChecked() | ||
if (numChecked > 0) { | ||
if (this.hasButtonLabelTarget) { | ||
let label = this.buttonLabelValue | ||
if (numChecked > 1) { | ||
label += 's' | ||
} | ||
label += ' (' + numChecked + ')' | ||
this.buttonLabelTarget.innerHTML = label | ||
} | ||
|
||
this.buttonTarget.classList.remove(this.hiddenClass) | ||
} else { | ||
this.buttonTarget.classList.add(this.hiddenClass) | ||
} | ||
} | ||
} | ||
|
||
getNumberChecked () { | ||
return this.checkboxTargets.filter((checkbox) => checkbox.checked).length | ||
} | ||
|
||
getTotalCheckboxes () { | ||
return this.checkboxTargets.length | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.