@brightspace-ui/labs 2.2.0 → 2.3.0

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
@@ -14,6 +14,7 @@
14
14
  "./components/opt-out-flyout.js": "./src/components/opt-in-flyout/opt-out-flyout.js",
15
15
  "./components/opt-out-reason.js": "./src/components/opt-in-flyout/opt-out-reason.js",
16
16
  "./components/pager-numeric.js": "./src/components/pagination/pager-numeric.js",
17
+ "./components/view-toggle.js": "./src/components/view-toggle/view-toggle.js",
17
18
  "./controllers/computed-value.js": "./src/controllers/computed-values/computed-value.js",
18
19
  "./controllers/computed-values.js": "./src/controllers/computed-values/computed-values.js",
19
20
  "./controllers/language-listener.js": "./src/controllers/language-listener/language-listener.js"
@@ -22,7 +23,7 @@
22
23
  "langs:sync": "mfv add-missing && mfv remove-extraneous",
23
24
  "langs:sort": "mfv sort",
24
25
  "lint": "npm run lint:eslint && npm run lint:style",
25
- "lint:eslint": "eslint . --ext .js,.html",
26
+ "lint:eslint": "eslint .",
26
27
  "lint:style": "stylelint \"**/*.{js,html}\"",
27
28
  "start": "web-dev-server --node-resolve --open --watch",
28
29
  "test": "npm run lint && npm run test:translations && npm run test:unit && npm run test:axe",
@@ -37,8 +38,8 @@
37
38
  "@brightspace-ui/stylelint-config": "^1",
38
39
  "@brightspace-ui/testing": "^1",
39
40
  "@web/dev-server": "^0.3",
40
- "eslint": "^8",
41
- "eslint-config-brightspace": "^1",
41
+ "eslint": "^9",
42
+ "eslint-config-brightspace": "^2",
42
43
  "messageformat-validator": "^2",
43
44
  "stylelint": "^16"
44
45
  },
@@ -53,5 +54,5 @@
53
54
  "@brightspace-ui/core": "^3",
54
55
  "lit": "^3"
55
56
  },
56
- "version": "2.2.0"
57
+ "version": "2.3.0"
57
58
  }
@@ -0,0 +1,15 @@
1
+ # d2l-labs-view-toggle
2
+
3
+ A Lit element component for toggling between views.
4
+
5
+ ## Usage
6
+
7
+ ```html
8
+ <script type="module">
9
+ import '@brightspace-ui-labs/view-toggle/view-toggle.js';
10
+ </script>
11
+ <d2l-labs-view-toggle
12
+ toggle-options='[{"text":"Bananas","val":"overall"},{"text":"Minions","val":"minios"},{"text":"Pyjamas","val":"subject"}]'
13
+ text="Toggle: "
14
+ ></d2l-labs-view-toggle>
15
+ ```
@@ -0,0 +1,143 @@
1
+ import '@brightspace-ui/core/components/icons/icon.js';
2
+ import '@brightspace-ui/core/components/colors/colors.js';
3
+ import { css, html, LitElement } from 'lit';
4
+
5
+ class ViewToggle extends LitElement {
6
+ static get properties() {
7
+ return {
8
+ text: {
9
+ type: String
10
+ },
11
+ toggleOptions: {
12
+ type: Array,
13
+ attribute: 'toggle-options'
14
+ },
15
+ selectedOption: {
16
+ type: String,
17
+ attribute: 'selected-options'
18
+ }
19
+ };
20
+ }
21
+ static get styles() {
22
+ return [
23
+ css`
24
+ button.d2l-labs-view-toggle-left {
25
+ border-end-start-radius: 0.3rem;
26
+ border-inline-end-color: transparent;
27
+ border-inline-start-color: var(--d2l-color-mica);
28
+ border-start-start-radius: 0.3rem;
29
+ }
30
+ button.d2l-labs-view-toggle-right {
31
+ border-end-end-radius: 0.3rem;
32
+ border-inline-end-color: var(--d2l-color-mica);
33
+ border-inline-start-color: transparent;
34
+ border-start-end-radius: 0.3rem;
35
+ }
36
+ button {
37
+ background-color: var(--d2l-color-sylvite);
38
+ border-color: var(--d2l-color-mica);
39
+ border-style: solid;
40
+ border-width: 1px;
41
+ box-sizing: border-box;
42
+ color: var(--d2l-color-ferrite);
43
+ cursor: pointer;
44
+ display: inline;
45
+ flex: 1;
46
+ font-family: inherit;
47
+ font-size: 0.7rem;
48
+ font-weight: 700;
49
+ margin: 0;
50
+ min-height: calc(2rem + 2px);
51
+ outline: none;
52
+ padding: 0.5rem 1.5rem;
53
+ text-align: center;
54
+ transition: box-shadow 0.2s;
55
+ -webkit-user-select: none;
56
+ -moz-user-select: none;
57
+ -ms-user-select: none;
58
+ user-select: none;
59
+ vertical-align: middle;
60
+ white-space: nowrap;
61
+ }
62
+ button:hover, button:focus {
63
+ border: 1px solid var(--d2l-color-celestine) !important;
64
+ }
65
+ button[aria-pressed="true"] {
66
+ background-color: var(--d2l-color-tungsten);
67
+ border-color: var(--d2l-color-tungsten);
68
+ color: var(--d2l-color-regolith);
69
+ }
70
+ button[aria-pressed="true"]:hover, button[aria-pressed="true"]:focus {
71
+ box-shadow: inset 0 0 0 2px #ffffff;
72
+ }
73
+ :host {
74
+ display: flex;
75
+ width: 100%;
76
+ }
77
+ .view-toggle-container {
78
+ display: none;
79
+ }
80
+ @media (min-width: 525px) {
81
+ :host {
82
+ display: block;
83
+ margin: 0 -0.9rem;
84
+ width: auto;
85
+ }
86
+ .view-toggle-container {
87
+ display: inline;
88
+ margin: 0 0.9rem;
89
+ }
90
+ }`
91
+ ];
92
+ }
93
+
94
+ render() {
95
+ return html`
96
+ <div class="view-toggle-container">
97
+ <span>${this.text}</span>
98
+ ${this.toggleOptions?.map((option, i) => this.#renderButton(option, i))}
99
+ </div>
100
+ `;
101
+ }
102
+
103
+ willUpdate(changedProperties) {
104
+ super.willUpdate(changedProperties);
105
+ if (!this.selectedOption && changedProperties.has('toggleOptions')) {
106
+ this.selectedOption = this.toggleOptions[0].val;
107
+ }
108
+ }
109
+ #isSelected(option) {
110
+ return option.val === this.selectedOption;
111
+ }
112
+ #renderButton(option, index) {
113
+ let placement = 'centre';
114
+ if (index === 0) {
115
+ placement = 'left';
116
+ }
117
+ if (this.toggleOptions && index === this.toggleOptions.length - 1) {
118
+ placement = 'right';
119
+ }
120
+ return html`<button
121
+ data-option-val="${option.val}"
122
+ aria-pressed="${this.#isSelected(option)}"
123
+ class="d2l-labs-view-toggle-${placement}"
124
+ @click="${this.#selectIndex}"
125
+ >${option.text}</button>`;
126
+ }
127
+ #selectIndex(e) {
128
+ this.selectedOption = e.target.dataset.optionVal;
129
+ this.dispatchEvent(
130
+ new CustomEvent(
131
+ 'd2l-labs-view-toggle-changed',
132
+ {
133
+ detail: {
134
+ view: this.selectedOption
135
+ },
136
+ composed: true,
137
+ bubbles: true
138
+ }
139
+ )
140
+ );
141
+ }
142
+ }
143
+ customElements.define('d2l-labs-view-toggle', ViewToggle);