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

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.3",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -27,20 +27,22 @@ 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);
32
- }
33
-
34
30
  .category-title {
35
31
  width: 100%;
36
32
  }
37
33
 
34
+ .button-toggle-container {
35
+ display: flex;
36
+ gap: var(--dx-g-spacing-md);
37
+ margin-top: var(--dx-g-spacing-3xl);
38
+ }
39
+
38
40
  .category-container {
39
41
  display: flex;
40
42
  flex-wrap: wrap;
41
43
  gap: 40px;
42
44
  }
43
45
 
44
- .category-container:not(:first-of-type) {
45
- margin-top: var(--dx-g-spacing-3xl);
46
+ .category-container {
47
+ margin-top: var(--dx-g-spacing-4xl);
46
48
  }
@@ -1,21 +1,24 @@
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}>
5
- <template for:each={trials} for:item="trial">
4
+ <dx-tab-panel-list tabs={tabLabels} onchange={handleTabChange}>
5
+ <template for:each={_trialsCopy} 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={buttonLabelsForActiveTab}
14
+ for:item="buttonLabel"
15
+ >
16
+ <dx-button-toggle
17
+ label={buttonLabel}
18
+ key={buttonLabel}
19
+ ontoggle={handleFilters}
20
+ ></dx-button-toggle>
21
+ </template>
19
22
  </div>
20
23
  <template for:each={trial.categories} for:item="category">
21
24
  <div key={category.title} class="category-container">
@@ -10,38 +10,73 @@ export default class BrowseTrials extends LightningElement {
10
10
  }
11
11
  set trials(value: [{ label: string }]) {
12
12
  this._trials = toJson(value);
13
- this._tabs = this._trials.map((trial) => ({ label: trial.label }));
13
+ this._trialsCopy = toJson(value);
14
+ this.tabLabels = this._trials.map((trial) => ({ label: trial.label }));
15
+ this.buttonLabels = this._trials.map((trial) =>
16
+ trial.categories.map((category) => category.title)
17
+ );
18
+ }
19
+
20
+ get buttonLabelsForActiveTab() {
21
+ return this.buttonLabels[this.activeTabIndex];
22
+ }
23
+
24
+ get activeCategories() {
25
+ return this._trials[this.activeTabIndex].categories;
26
+ }
27
+
28
+ // we manipulate the copy of the trials to show the active tab's categories
29
+ get activeCategoriesCopy() {
30
+ return this._trialsCopy[this.activeTabIndex].categories;
31
+ }
32
+ set activeCategoriesCopy(value) {
33
+ this._trialsCopy[this.activeTabIndex].categories = value;
14
34
  }
15
35
 
16
36
  @track
17
- private _trials!: [{ label: string; categories: Array<{ title: string }> }];
18
- private buttonLabels!: Array<{ title: string }>;
37
+ private _trialsCopy!: [
38
+ { label: string; categories: Array<{ title: string }> }
39
+ ];
19
40
 
20
- private _tabs!: Array<{ label: string }>;
21
- private filters: Array<{ label: string }> = [];
41
+ private buttonLabels!: string[][];
42
+ private tabLabels!: Array<{ label: string }>;
43
+ private _trials!: [{ label: string; categories: Array<{ title: string }> }];
22
44
  private activeTabIndex = 0;
23
45
 
24
46
  handleTabChange(e: CustomEvent) {
25
47
  this.activeTabIndex = e.detail;
26
48
  }
27
49
 
50
+ addFilter(label: string) {
51
+ this.activeCategoriesCopy =
52
+ this.activeCategories.length ===
53
+ this.activeCategoriesCopy.length + 1
54
+ ? [...this.activeCategories]
55
+ : [
56
+ ...this.activeCategories.filter(
57
+ (category) => category.title === label
58
+ )
59
+ ];
60
+ }
61
+
62
+ removeFilter(label: string) {
63
+ this.activeCategoriesCopy =
64
+ this.activeCategoriesCopy.length - 1 === 0
65
+ ? [...this.activeCategories]
66
+ : [
67
+ ...this.activeCategories.filter(
68
+ (category) => category.title !== label
69
+ )
70
+ ];
71
+ }
72
+
28
73
  handleFilters(e: CustomEvent) {
29
74
  const { label, value } = e.detail;
30
75
 
31
76
  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
- );
77
+ this.addFilter(label);
38
78
  } 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
- );
79
+ this.removeFilter(label);
45
80
  }
46
81
  }
47
82
  }