@brightspace-ui/core 3.71.0 → 3.72.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.
@@ -6,6 +6,7 @@
6
6
  <link rel="stylesheet" href="../../demo/styles.css" type="text/css">
7
7
  <script type="module">
8
8
  import '../../demo/demo-page.js';
9
+ import '../../dialog/dialog-confirm.js';
9
10
  import '../switch.js';
10
11
  import '../switch-visibility.js';
11
12
  </script>
@@ -68,6 +69,27 @@
68
69
  </template>
69
70
  </d2l-demo-snippet>
70
71
 
72
+ <h2>On/Off (confirm)</h2>
73
+
74
+ <d2l-demo-snippet>
75
+ <template>
76
+ <d2l-switch id="switch-with-confirm" text="Dark Mode"></d2l-switch>
77
+ <d2l-dialog-confirm id="confirm" title-text="Confirm" text="Are you sure you want to change?">
78
+ <d2l-button slot="footer" primary data-dialog-action="yes">Yes</d2l-button>
79
+ <d2l-button slot="footer" data-dialog-action="no">No</d2l-button>
80
+ </d2l-dialog-confirm>
81
+ <script>
82
+ const elem = document.querySelector('#switch-with-confirm');
83
+ elem.addEventListener('d2l-switch-before-change', async e => {
84
+ e.preventDefault();
85
+ const confirmResult = await document.querySelector('#confirm').open();
86
+ if (confirmResult === 'yes') e.detail.update(!elem.on);
87
+ });
88
+ elem.addEventListener('change', e => console.log('switch changed', e.target.on));
89
+ </script>
90
+ </template>
91
+ </d2l-demo-snippet>
92
+
71
93
  </d2l-demo-page>
72
94
  </body>
73
95
  </html>
@@ -221,11 +221,11 @@ export const SwitchMixin = superclass => class extends FocusMixin(RtlMixin(super
221
221
 
222
222
  get _labelContent() {
223
223
  return html`<span
224
- @click='${this._handleClick}'
225
- @mouseenter='${this._handleSwitchHover}'
226
- @mouseleave='${this._handleSwitchHoverLeave}'>
227
- ${this.text}
228
- </span>`;
224
+ @click='${this._handleClick}'
225
+ @mouseenter='${this._handleSwitchHover}'
226
+ @mouseleave='${this._handleSwitchHoverLeave}'>
227
+ ${this.text}
228
+ </span>`;
229
229
  }
230
230
 
231
231
  _handleClick() {
@@ -252,8 +252,23 @@ export const SwitchMixin = superclass => class extends FocusMixin(RtlMixin(super
252
252
 
253
253
  _toggleState() {
254
254
  if (this.disabled) return;
255
- this.on = !this.on;
255
+
256
+ const beforeChangeEvent = new CustomEvent('d2l-switch-before-change', {
257
+ detail: { update: on => this._updateState(on) },
258
+ cancelable: true
259
+ });
260
+
261
+ this.dispatchEvent(beforeChangeEvent);
262
+ if (beforeChangeEvent.defaultPrevented) return;
263
+
264
+ this._updateState(!this.on);
265
+ }
266
+
267
+ _updateState(value) {
268
+ this.on = value;
269
+
256
270
  /** Dispatched when the `on` property is updated */
257
271
  this.dispatchEvent(new CustomEvent('change', { bubbles: true }));
258
272
  }
273
+
259
274
  };
@@ -8,6 +8,7 @@ import { SwitchMixin } from './switch-mixin.js';
8
8
  /**
9
9
  * A variant of the generic switch configured with special icons and default text for toggling "visibility".
10
10
  * @slot - Optional content that will be displayed within the "conditions" opener tooltip when the switch is on.
11
+ * @fires d2l-switch-before-change - Dispatched before on-state is updated. Can be canceled to allow the consumer to handle switching the on-state. This is useful if something needs to happen prior to the on-state being switched.
11
12
  */
12
13
  class VisibilitySwitch extends LocalizeCoreElement(SwitchMixin(LitElement)) {
13
14
 
@@ -7,6 +7,7 @@ import { SwitchMixin } from './switch-mixin.js';
7
7
  /**
8
8
  * A generic switch with on/off semantics.
9
9
  * @attr {string} text - ACCESSIBILITY: REQUIRED: Acts as the primary label for the switch. Visible unless text-position is `hidden`.
10
+ * @fires d2l-switch-before-change - Dispatched before on-state is updated. Can be canceled to allow the consumer to handle switching the on-state. This is useful if something needs to happen prior to the on-state being switched.
10
11
  */
11
12
  class Switch extends SwitchMixin(LitElement) {
12
13
 
@@ -11934,6 +11934,10 @@
11934
11934
  }
11935
11935
  ],
11936
11936
  "events": [
11937
+ {
11938
+ "name": "d2l-switch-before-change",
11939
+ "description": "Dispatched before on-state is updated. Can be canceled to allow the consumer to handle switching the on-state. This is useful if something needs to happen prior to the on-state being switched."
11940
+ },
11937
11941
  {
11938
11942
  "name": "change",
11939
11943
  "description": "Dispatched when the `on` property is updated"
@@ -12012,6 +12016,10 @@
12012
12016
  }
12013
12017
  ],
12014
12018
  "events": [
12019
+ {
12020
+ "name": "d2l-switch-before-change",
12021
+ "description": "Dispatched before on-state is updated. Can be canceled to allow the consumer to handle switching the on-state. This is useful if something needs to happen prior to the on-state being switched."
12022
+ },
12015
12023
  {
12016
12024
  "name": "change",
12017
12025
  "description": "Dispatched when the `on` property is updated"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.71.0",
3
+ "version": "3.72.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",