@brightspace-ui/core 3.70.0 → 3.72.0
Sign up to get free protection for your applications and to get access to all the features.
- package/components/inputs/demo/input-text.html +2 -2
- package/components/inputs/docs/input-text.md +1 -0
- package/components/inputs/input-text.js +4 -2
- package/components/switch/demo/switch.html +22 -0
- package/components/switch/switch-mixin.js +21 -6
- package/components/switch/switch-visibility.js +1 -0
- package/components/switch/switch.js +1 -0
- package/custom-elements.json +12 -4
- package/mixins/localize/README.md +33 -0
- package/package.json +1 -1
@@ -132,9 +132,9 @@
|
|
132
132
|
<h2>Inline Help</h2>
|
133
133
|
<d2l-demo-snippet>
|
134
134
|
<template>
|
135
|
-
<d2l-input-text label="
|
135
|
+
<d2l-input-text label="Alphabet" pattern="[a-z]*" pattern-failure-text="Must be a lowercase letter from a to z">
|
136
136
|
<div slot="inline-help">
|
137
|
-
|
137
|
+
Enter only lowercase letters from the alphabet.
|
138
138
|
</div>
|
139
139
|
</d2l-input-text>
|
140
140
|
</template>
|
@@ -81,6 +81,7 @@ The `<d2l-input-text>` element is a simple wrapper around the native `<input typ
|
|
81
81
|
| `name` | String | Name of the input |
|
82
82
|
| `novalidate` | Boolean | Disables the built-in validation |
|
83
83
|
| `pattern` | String | Regular expression pattern to validate the value |
|
84
|
+
| `pattern-failure-text` | String | Text to display when input fails validation against the pattern. If a list of characters is included in the message, use `LocalizeMixin`'s `localizeCharacter`. |
|
84
85
|
| `prevent-submit` | Boolean | Prevents pressing ENTER from submitting forms |
|
85
86
|
| `readonly` | Boolean | Makes the input read-only |
|
86
87
|
| `required` | Boolean | Indicates that a value is required |
|
@@ -102,12 +102,12 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
|
|
102
102
|
*/
|
103
103
|
minlength: { type: Number },
|
104
104
|
/**
|
105
|
-
* Regular expression pattern to validate the value
|
105
|
+
* ADVANCED: Regular expression pattern to validate the value
|
106
106
|
* @type {string}
|
107
107
|
*/
|
108
108
|
pattern: { type: String },
|
109
109
|
/**
|
110
|
-
* Text to display when input fails validation against the pattern
|
110
|
+
* ADVANCED: Text to display when input fails validation against the pattern. If a list of characters is included in the message, use `LocalizeMixin`'s `localizeCharacter`.
|
111
111
|
*/
|
112
112
|
patternFailureText: { type: String, attribute: 'pattern-failure-text' },
|
113
113
|
/**
|
@@ -332,6 +332,8 @@ class InputText extends InputInlineHelpMixin(PropertyRequiredMixin(FocusMixin(La
|
|
332
332
|
} else if (this.type === 'url') {
|
333
333
|
return this.localize('components.form-element.input.url.typeMismatch');
|
334
334
|
}
|
335
|
+
} else if (this.validity.patternMismatch && (typeof this.patternFailureText === 'string')) {
|
336
|
+
return this.patternFailureText;
|
335
337
|
}
|
336
338
|
return super.validationMessage;
|
337
339
|
}
|
@@ -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
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|
-
|
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
|
|
package/custom-elements.json
CHANGED
@@ -6847,12 +6847,12 @@
|
|
6847
6847
|
},
|
6848
6848
|
{
|
6849
6849
|
"name": "pattern",
|
6850
|
-
"description": "Regular expression pattern to validate the value",
|
6850
|
+
"description": "ADVANCED: Regular expression pattern to validate the value",
|
6851
6851
|
"type": "string"
|
6852
6852
|
},
|
6853
6853
|
{
|
6854
6854
|
"name": "pattern-failure-text",
|
6855
|
-
"description": "Text to display when input fails validation against the pattern",
|
6855
|
+
"description": "ADVANCED: Text to display when input fails validation against the pattern. If a list of characters is included in the message, use `LocalizeMixin`'s `localizeCharacter`.",
|
6856
6856
|
"type": "string"
|
6857
6857
|
},
|
6858
6858
|
{
|
@@ -7013,13 +7013,13 @@
|
|
7013
7013
|
{
|
7014
7014
|
"name": "pattern",
|
7015
7015
|
"attribute": "pattern",
|
7016
|
-
"description": "Regular expression pattern to validate the value",
|
7016
|
+
"description": "ADVANCED: Regular expression pattern to validate the value",
|
7017
7017
|
"type": "string"
|
7018
7018
|
},
|
7019
7019
|
{
|
7020
7020
|
"name": "patternFailureText",
|
7021
7021
|
"attribute": "pattern-failure-text",
|
7022
|
-
"description": "Text to display when input fails validation against the pattern",
|
7022
|
+
"description": "ADVANCED: Text to display when input fails validation against the pattern. If a list of characters is included in the message, use `LocalizeMixin`'s `localizeCharacter`.",
|
7023
7023
|
"type": "string"
|
7024
7024
|
},
|
7025
7025
|
{
|
@@ -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"
|
@@ -152,6 +152,39 @@ this.localizeHTML('octopus', {
|
|
152
152
|
});
|
153
153
|
```
|
154
154
|
|
155
|
+
### Common Resources
|
156
|
+
|
157
|
+
Some localization resources are common and shared across D2L applications. To use these resources, set the `loadCommon` option:
|
158
|
+
|
159
|
+
```javascript
|
160
|
+
static get localizeConfig() {
|
161
|
+
return {
|
162
|
+
loadCommon: true
|
163
|
+
};
|
164
|
+
}
|
165
|
+
```
|
166
|
+
|
167
|
+
#### localizeCharacter
|
168
|
+
|
169
|
+
The localized value of the following characters can be accessed using `localizeCharacter(char)`:
|
170
|
+
* `'` (apostrophe)
|
171
|
+
* `&` (ampersand)
|
172
|
+
* `*` (asterisk)
|
173
|
+
* `\` (backslash)
|
174
|
+
* `:` (colon)
|
175
|
+
* `,` (comma)
|
176
|
+
* `>` (greater-than sign)
|
177
|
+
* `<` (less-than sign)
|
178
|
+
* `#` (number sign)
|
179
|
+
* `%` (percent sign)
|
180
|
+
* `|` (pipe)
|
181
|
+
* `?` (question mark)
|
182
|
+
* `"` (quotation mark)
|
183
|
+
|
184
|
+
```javascript
|
185
|
+
this.localizeCharacter('&'); // -> 'ampersand' in en-US
|
186
|
+
```
|
187
|
+
|
155
188
|
## Off-Stack Language Overrides
|
156
189
|
|
157
190
|
To enable OSLO, map the project's localization resources to a language collection in Brightspace by defining `osloCollection` in `localizeConfig`:
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.
|
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",
|