-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 [#3018] Refactor filters out of modal into checkbox-lists
- Loading branch information
1 parent
f76f455
commit 0ad0ef2
Showing
9 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/open_inwoner/components/templates/components/Filter/SearchFilter.html
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,36 @@ | ||
{% load i18n icon_tags button_tags form_tags %} | ||
|
||
<div> | ||
<fieldset class="filter" aria-label="Filter"> | ||
<a class="button filter__mobile filter--toggle button--textless button--icon button--icon-after" href="#" title="Onderwerpen" aria-label="Onderwerpen"> | ||
<span aria-hidden="true" class="material-icons ">expand_more</span> | ||
{{ field.label }} | ||
</a> | ||
<legend class="filter__title"> | ||
<span class="filter__legend-label">{{ field.label }}</span> | ||
</legend> | ||
<div class="filter__list"> | ||
|
||
<div class="filter-bar__multiselect-listbox multiselect-listbox"> | ||
<div class="multiselect-listbox__popup"> | ||
<button id="selectButton" type="button" class="button button__select selectButton" aria-haspopup="listbox" aria-expanded="false" aria-live="polite"> | ||
<span class="filter__legend-label">{{ field.label }}</span>: | ||
{% icon icon="expand_more" icon_position="after" icon_outlined=True %} | ||
</button> | ||
<div id="listboxDropdown" class="multiselect-listbox__content" role="listbox" aria-labelledby="selectButton"> | ||
<div class="multiselect-listbox__scroll" role="presentation"> | ||
{% for option in field.field.choices %} | ||
{% choice_checkbox choice=option name=field.name data=field.data index=forloop.counter form_id=form_id %} | ||
{% endfor %} | ||
</div> | ||
{# No submit button for direct query #} | ||
</div> | ||
<div class="form__reset--desktop form__actions--fullwidth form__actions--reset"> | ||
{% button bordered=False text=_("Wis alle filters") id="resetMultiSelectFilters" extra_classes="resetMultiSelectFilters" type="button" transparent=True primary=True %} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</fieldset> | ||
</div> |
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
31 changes: 31 additions & 0 deletions
31
src/open_inwoner/js/components/search/filter-dropdown-submit.js
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,31 @@ | ||
export class FilterDropdownSubmit { | ||
static selector = '.filter-dropdown' | ||
|
||
constructor(node) { | ||
this.node = node | ||
this.submitButton = node.querySelector('.filter-dropdown__submit') | ||
this.checkboxes = node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]' | ||
) | ||
|
||
if (!this.submitButton || !this.checkboxes.length) return | ||
|
||
this.checkboxes.forEach((checkbox) => { | ||
checkbox.addEventListener('change', this.updateSubmitButton.bind(this)) | ||
}) | ||
} | ||
|
||
updateSubmitButton() { | ||
const selectedCount = this.node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]:checked' | ||
).length | ||
this.submitButton.textContent = `Apply Filters (${selectedCount})` | ||
} | ||
} | ||
|
||
/** | ||
* Initialize only dropdowns with submit buttons | ||
*/ | ||
document | ||
.querySelectorAll(FilterDropdownSubmit.selector) | ||
.forEach((dropdown) => new FilterDropdownSubmit(dropdown)) |
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,59 @@ | ||
export class FilterDropdown { | ||
static selector = '.filter-dropdown' | ||
|
||
constructor(node) { | ||
this.node = node | ||
this.button = node.querySelector('.filter-dropdown__button') | ||
this.menu = node.querySelector('.filter-dropdown__menu') | ||
this.checkboxes = node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]' | ||
) | ||
this.clearButton = node.querySelector('.filter-dropdown__clear') | ||
this.filterCount = node.querySelector('.filter-count') | ||
|
||
if (!this.button || !this.menu || !this.checkboxes.length) return | ||
|
||
this.button.addEventListener('click', this.toggleDropdown.bind(this)) | ||
document.addEventListener('click', this.closeDropdown.bind(this)) | ||
|
||
this.checkboxes.forEach((checkbox) => { | ||
checkbox.addEventListener('change', this.updateFilters.bind(this)) | ||
}) | ||
|
||
if (this.clearButton) { | ||
this.clearButton.addEventListener('click', this.clearFilters.bind(this)) | ||
} | ||
} | ||
|
||
toggleDropdown(event) { | ||
event.preventDefault() | ||
this.node.classList.toggle('open') | ||
} | ||
|
||
closeDropdown(event) { | ||
if (!this.node.contains(event.target)) { | ||
this.node.classList.remove('open') | ||
} | ||
} | ||
|
||
updateFilters() { | ||
const selectedCount = this.node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]:checked' | ||
).length | ||
if (this.filterCount) { | ||
this.filterCount.textContent = `(${selectedCount})` | ||
} | ||
} | ||
|
||
clearFilters() { | ||
this.checkboxes.forEach((checkbox) => (checkbox.checked = false)) | ||
this.updateFilters() | ||
} | ||
} | ||
|
||
/** | ||
* Initialize all dropdowns | ||
*/ | ||
document | ||
.querySelectorAll(FilterDropdown.selector) | ||
.forEach((dropdown) => new FilterDropdown(dropdown)) |
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
65 changes: 65 additions & 0 deletions
65
src/open_inwoner/scss/components/Filter/FilterDropdown.scss
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,65 @@ | ||
.filter-dropdown { | ||
position: relative; | ||
display: inline-block; | ||
|
||
&__button { | ||
background: var(--color-white); | ||
color: var(--color-body); | ||
border: 1px solid var(--color-gray-dark-900); | ||
border-radius: var(--border-radius); | ||
padding: 10px 15px; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
} | ||
|
||
&__menu { | ||
position: absolute; | ||
top: 100%; | ||
left: 0; | ||
background: white; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
display: none; | ||
padding: 10px; | ||
width: 200px; | ||
z-index: 100; | ||
} | ||
|
||
&__list { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
|
||
li { | ||
margin-bottom: 5px; | ||
} | ||
} | ||
|
||
&__actions { | ||
display: flex; | ||
justify-content: space-between; | ||
margin-top: 10px; | ||
} | ||
|
||
&__submit { | ||
background: var(--color-primary); | ||
color: white; | ||
border: none; | ||
padding: 5px 10px; | ||
cursor: pointer; | ||
border-radius: 3px; | ||
} | ||
|
||
&__clear { | ||
background: none; | ||
border: none; | ||
color: var(--color-primary); | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
// Show dropdown when button is clicked | ||
.filter-dropdown.open .filter-dropdown__menu { | ||
display: block; | ||
} |
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