@salesforcedevs/dw-components 1.1.2-alpha.2 → 1.1.2-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.1.2-alpha.2",
3
+ "version": "1.1.2-alpha.5",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -27,12 +27,20 @@ dx-tab-panel-list {
27
27
  --dx-c-tab-panel-list-horizontal-padding: 0;
28
28
  }
29
29
 
30
- .button-toggle-container {
31
- margin-bottom: var(--dx-g-spacing-4xl);
30
+ .category-text-container {
31
+ width: 100%;
32
32
  }
33
33
 
34
- .category-title {
35
- width: 100%;
34
+ .category-subtitle {
35
+ color: var(--dx-g-font-sans);
36
+ margin-top: var(--dx-g-spacing-smd);
37
+ max-width: 560px;
38
+ }
39
+
40
+ .button-toggle-container {
41
+ display: flex;
42
+ gap: var(--dx-g-spacing-md);
43
+ margin-top: var(--dx-g-spacing-3xl);
36
44
  }
37
45
 
38
46
  .category-container {
@@ -41,6 +49,6 @@ dx-tab-panel-list {
41
49
  gap: 40px;
42
50
  }
43
51
 
44
- .category-container:not(:first-of-type) {
45
- margin-top: var(--dx-g-spacing-3xl);
52
+ .category-container {
53
+ margin-top: var(--dx-g-spacing-4xl);
46
54
  }
@@ -1,27 +1,42 @@
1
1
  <template>
2
2
  <div class="panel-list-container">
3
3
  <h2 class="title">{title}</h2>
4
- <dx-tab-panel-list tabs={_tabs} onchange={handleTabChange}>
4
+ <dx-tab-panel-list tabs={tabLabels} onchange={handleTabChange}>
5
5
  <template for:each={trials} for:item="trial">
6
6
  <dx-tab-panel key={trial.label}>
7
7
  <div
8
8
  key={trial.label}
9
9
  class="button-toggle-container"
10
10
  if:false={trial.hideFilters}
11
- for:each={buttonLabels}
12
- for:item="buttonLabel"
13
11
  >
14
- <dx-button-toggle
15
- label={buttonLabel.title}
16
- key={buttonLabel.title}
17
- ontoggle={handleFilters}
18
- ></dx-button-toggle>
12
+ <template
13
+ for:each={buttonToggleStates}
14
+ for:item="buttonToggleState"
15
+ >
16
+ <dx-button-toggle
17
+ label={buttonToggleState.label}
18
+ key={buttonToggleState.label}
19
+ value={buttonToggleState.value}
20
+ ontoggle={handleFilters}
21
+ ></dx-button-toggle>
22
+ </template>
19
23
  </div>
20
- <template for:each={trial.categories} for:item="category">
24
+ <template for:each={filteredCategories} for:item="category">
21
25
  <div key={category.title} class="category-container">
22
- <h2 class="dx-text-heading-4 category-title">
23
- {category.title}
24
- </h2>
26
+ <div
27
+ if:true={category.title}
28
+ class="category-text-container"
29
+ >
30
+ <h2 class="dx-text-heading-4 category-title">
31
+ {category.title}
32
+ </h2>
33
+ <p
34
+ if:true={category.subtitle}
35
+ class="category-subtitle"
36
+ >
37
+ {category.subtitle}
38
+ </p>
39
+ </div>
25
40
  <template for:each={category.cards} for:item="card">
26
41
  <template if:true={card.hasModal}>
27
42
  <dx-card-trial
@@ -8,40 +8,97 @@ export default class BrowseTrials extends LightningElement {
8
8
  get trials() {
9
9
  return this._trials;
10
10
  }
11
- set trials(value: [{ label: string }]) {
11
+ set trials(
12
+ value: [{ label: string; hideFilters: boolean; buttonLabels: string[] }]
13
+ ) {
12
14
  this._trials = toJson(value);
13
- this._tabs = this._trials.map((trial) => ({ label: trial.label }));
15
+ this.tabLabels = this._trials.map((trial) => ({ label: trial.label }));
16
+ this.buttonLabels = this._trials.map((trial) =>
17
+ !trial.hideFilters ? trial.buttonLabels : []
18
+ );
19
+ this._filteredTitles = this._trials.map(() => []);
20
+ this._filteredCategories = this._trials.map(
21
+ (trial) => trial.categories
22
+ );
23
+ }
24
+
25
+ get buttonToggleStates() {
26
+ return this.buttonLabels[this.activeTabIndex].map((label) => ({
27
+ label,
28
+ value: this.activeFilteredTitles.includes(label)
29
+ }));
30
+ }
31
+
32
+ get activeFilteredTitles() {
33
+ return this._filteredTitles[this.activeTabIndex];
34
+ }
35
+ set activeFilteredTitles(value: string[]) {
36
+ this._filteredTitles[this.activeTabIndex] = value;
37
+ }
38
+
39
+ get activeCategories() {
40
+ return this._trials[this.activeTabIndex].categories;
41
+ }
42
+
43
+ get filteredCategories() {
44
+ return this._filteredCategories[this.activeTabIndex];
45
+ }
46
+ set filteredCategories(value: any) {
47
+ this._filteredCategories[this.activeTabIndex] = value;
14
48
  }
15
49
 
16
50
  @track
17
- private _trials!: [{ label: string; categories: Array<{ title: string }> }];
18
- private buttonLabels!: Array<{ title: string }>;
51
+ private _filteredCategories!: Array<any>;
19
52
 
20
- private _tabs!: Array<{ label: string }>;
21
- private filters: Array<{ label: string }> = [];
22
53
  private activeTabIndex = 0;
54
+ private buttonLabels!: string[][];
55
+ private _filteredTitles!: string[][];
56
+ private tabLabels!: Array<{ label: string }>;
57
+ private _trials!: [
58
+ {
59
+ label: string;
60
+ hideFilters: boolean;
61
+ buttonLabels: string[];
62
+ categories: Array<{ title: string }>;
63
+ }
64
+ ];
23
65
 
24
66
  handleTabChange(e: CustomEvent) {
25
67
  this.activeTabIndex = e.detail;
26
68
  }
27
69
 
70
+ filterCategories() {
71
+ this.filteredCategories = this.activeCategories.filter((category) =>
72
+ this.activeFilteredTitles.includes(category.title)
73
+ );
74
+ }
75
+
76
+ addLabelToFilter(label: string) {
77
+ this.activeFilteredTitles.push(label);
78
+ this.filterCategories();
79
+ }
80
+
81
+ removeLabelFromFilter(label: string) {
82
+ this.activeFilteredTitles = this.activeFilteredTitles.filter(
83
+ (filterTitle) => filterTitle !== label
84
+ );
85
+ this.filterCategories();
86
+ }
87
+
88
+ resetFilters() {
89
+ this.activeFilteredTitles = [];
90
+ this.filteredCategories = this.activeCategories;
91
+ }
92
+
28
93
  handleFilters(e: CustomEvent) {
29
94
  const { label, value } = e.detail;
30
95
 
31
96
  if (value) {
32
- this.filters.push(label);
33
- this._trials[this.activeTabIndex].categories = this._trials[
34
- this.activeTabIndex
35
- ].categories.filter((category) =>
36
- this.filters.includes(category.title)
37
- );
97
+ this.addLabelToFilter(label);
98
+ } else if (this.activeFilteredTitles.length !== 1) {
99
+ this.removeLabelFromFilter(label);
38
100
  } else {
39
- this.filters = this.filters.filter((filter) => filter !== label);
40
- this._trials[this.activeTabIndex].categories = this._trials[
41
- this.activeTabIndex
42
- ].categories.filter(
43
- (category) => !this.filters.includes(category.title)
44
- );
101
+ this.resetFilters();
45
102
  }
46
103
  }
47
104
  }