Skip to content

Commit 4a5caf2

Browse files
committed
Feat: Expand / collapse button
1 parent f134f79 commit 4a5caf2

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

packages/components/src/components/hds/filter-bar/filters-dropdown.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
{{this._syncFilters @filters}}
1212
as |D|
1313
>
14-
<D.ToggleButton @icon="filter" @text="Filter" @color="secondary" @size="small" />
14+
<D.ToggleButton
15+
@icon="filter"
16+
@text={{hds-t "hds.components.filter-bar.filters-dropdown.toggle-button" default="Add filter"}}
17+
@color="secondary"
18+
@size="small"
19+
/>
1520
<D.Generic>
1621
<Hds::FilterBar::Tabs @ariaLabel="Filter bar tabs" as |T|>
1722
{{yield

packages/components/src/components/hds/filter-bar/index.hbs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@
2020
{{/if}}
2121
<div class="hds-filter-bar__actions__right">
2222
{{yield (hash ActionsDropdown=(component "hds/dropdown"))}}
23+
{{#if this.hasActiveFilters}}
24+
<Hds::Button
25+
@text={{if
26+
this._isExpanded
27+
(hds-t "hds.components.filter-bar.expand-collapse-button.collapse" default="Collapse filters")
28+
(hds-t "hds.components.filter-bar.expand-collapse-button.expand" default="Expand filters")
29+
}}
30+
@color="secondary"
31+
@size="small"
32+
@icon={{if this._isExpanded "unfold-close" "unfold-open"}}
33+
@isIconOnly={{true}}
34+
{{on "click" this.toggleExpand}}
35+
/>
36+
{{/if}}
2337
</div>
2438
</div>
25-
{{#if this.hasActiveFilters}}
39+
{{#if (and this.hasActiveFilters this._isExpanded)}}
2640
<div class="hds-filter-bar__filters">
2741
{{#each-in @filters as |key filter|}}
2842
{{#if filter.data}}

packages/components/src/components/hds/filter-bar/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import Component from '@glimmer/component';
77
import { action } from '@ember/object';
8+
import { tracked } from '@glimmer/tracking';
89

910
import type { ComponentLike, WithBoundArgs } from '@glint/template';
1011

@@ -42,6 +43,8 @@ export interface HdsFilterBarSignature {
4243
}
4344

4445
export default class HdsFilterBar extends Component<HdsFilterBarSignature> {
46+
@tracked _isExpanded: boolean = true;
47+
4548
@action
4649
onFilter(filters: HdsFilterBarFilters): void {
4750
const { onFilter } = this.args;
@@ -66,6 +69,11 @@ export default class HdsFilterBar extends Component<HdsFilterBarSignature> {
6669
}
6770
}
6871

72+
@action
73+
toggleExpand(): void {
74+
this._isExpanded = !this._isExpanded;
75+
}
76+
6977
get hasActiveFilters(): boolean {
7078
return Object.keys(this.args.filters).length > 0;
7179
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
apply: Apply filters
22
clear: Clear all filters
3+
expand-collapse-button:
4+
expand: Expand filters
5+
collapse: Collapse filters
36
selected-filters: Filters selected
7+
toggle-button: Add filter

0 commit comments

Comments
 (0)