Skip to content

Commit

Permalink
feat: add reset for individual filters (#413)
Browse files Browse the repository at this point in the history
* feat: introduce reset filterObject

* feat: change reset-btn to slot + style btn as icon

* fix: icon size

* fix: reset search results

* fix: reset icon size

* chore: replace icon

* fix(style): harmonize individual reset & reset all buttons

---------

Co-authored-by: silvester-pari <[email protected]>
  • Loading branch information
A-Behairi and silvester-pari authored Nov 29, 2023
1 parent 74eb5e8 commit a415adc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
8 changes: 8 additions & 0 deletions elements/itemfilter/src/filters/_expandcontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export class EOxItemFilterExpandContainer extends LitElement {
);
}

_resetFilter() {
const filterEl = this.querySelector(`[slot='filter']`) as Element & {
reset: () => void;
};
filterEl.reset();
}

render() {
return html`
<style>
Expand All @@ -39,6 +46,7 @@ export class EOxItemFilterExpandContainer extends LitElement {
style="${!this.filterObject.title && "text-transform: capitalize"}"
>
${this.filterObject.title || this.filterObject.key || "Filter"}
<slot name="reset-button"></slot>
</span>
</summary>
<div class="scroll">
Expand Down
26 changes: 24 additions & 2 deletions elements/itemfilter/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,28 @@ export class EOxItemFilter extends TemplateElement {
.unstyled=${this.unstyled}
@details-toggled=${this.toggleAccordion}
>
${when(
filterObject.dirty,
() => html`
<button
slot="reset-button"
class="reset-icon icon"
@click=${(e: MouseEvent) => {
(<Element & { reset: () => void }>(
(<HTMLButtonElement>(
e.target
)).parentElement.querySelector(
"[slot=filter]"
)
)).reset();
this.search();
this.requestUpdate();
}}
>
${this.unstyled ? "Reset" : nothing}
</button>
`
)}
<eox-itemfilter-${unsafeStatic(filterObject.type)}
slot="filter"
data-type="filter"
Expand All @@ -447,11 +469,11 @@ export class EOxItemFilter extends TemplateElement {
() => html`
<button
id="filter-reset"
class="outline small"
class="outline small icon-text reset-icon"
data-cy="filter-reset"
@click=${() => this.resetFilters()}
>
Reset filters
Reset all
</a>
`
)}
Expand Down
21 changes: 13 additions & 8 deletions elements/itemfilter/src/style.eox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ button#filter-reset {
position: absolute;
top: 4px;
right: 0;
text-indent: -9999px;
line-height: 0;
}
button#filter-reset:after {
content: "Reset";
text-indent: 0px;
line-height: initial;
}
.scroll {
max-height: calc(100% - 30px);
Expand Down Expand Up @@ -162,4 +155,16 @@ eox-itemfilter-range {
.range-after {
margin-left: .5rem;
}
`;
button.reset-icon:before {
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Eclose%3C/title%3E%3Cpath d='M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z' /%3E%3C/svg%3E");
}
eox-itemfilter-expandcontainer button.reset-icon {
margin-left: 4px;
margin-top: 1px;
}
eox-itemfilter-expandcontainer button.reset-icon:before {
height: 16px;
width: 16px;
}
`;

0 comments on commit a415adc

Please sign in to comment.