@brightspace-ui/core 2.65.0 → 2.66.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/README.md +2 -0
- package/components/demo/demo-page.js +36 -3
- package/components/demo/demo-snippet.js +2 -14
- package/mixins/rtl-mixin.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,8 +3,11 @@ import './code-view.js';
|
|
|
3
3
|
import '../colors/colors.js';
|
|
4
4
|
import '../typography/typography.js';
|
|
5
5
|
import { css, html, LitElement } from 'lit';
|
|
6
|
+
import { getDocumentLocaleSettings, supportedLocalesDetails } from '@brightspace-ui/intl/lib/common.js';
|
|
6
7
|
import { classMap } from 'lit/directives/class-map.js';
|
|
7
8
|
import { heading2Styles } from '../typography/styles.js';
|
|
9
|
+
import { inputLabelStyles } from '../inputs/input-label-styles.js';
|
|
10
|
+
import { selectStyles } from '../inputs/input-select-styles.js';
|
|
8
11
|
|
|
9
12
|
document.body.classList.add('d2l-typography');
|
|
10
13
|
|
|
@@ -27,7 +30,7 @@ class DemoPage extends LitElement {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
static get styles() {
|
|
30
|
-
return [ heading2Styles, css`
|
|
33
|
+
return [ heading2Styles, inputLabelStyles, selectStyles, css`
|
|
31
34
|
:host {
|
|
32
35
|
background-color: var(--d2l-color-sylvite);
|
|
33
36
|
display: block;
|
|
@@ -38,8 +41,18 @@ class DemoPage extends LitElement {
|
|
|
38
41
|
overflow: hidden;
|
|
39
42
|
padding: 0;
|
|
40
43
|
}
|
|
44
|
+
header {
|
|
45
|
+
align-items: center;
|
|
46
|
+
display: flex;
|
|
47
|
+
margin-bottom: 1.5rem;
|
|
48
|
+
max-width: 900px;
|
|
49
|
+
}
|
|
41
50
|
.d2l-heading-2 {
|
|
42
|
-
|
|
51
|
+
flex-grow: 1;
|
|
52
|
+
margin: 0;
|
|
53
|
+
}
|
|
54
|
+
.d2l-input-label {
|
|
55
|
+
margin-bottom: 0;
|
|
43
56
|
}
|
|
44
57
|
.d2l-demo-page-content > ::slotted(h2),
|
|
45
58
|
.d2l-demo-page-content > ::slotted(h3) {
|
|
@@ -67,9 +80,22 @@ class DemoPage extends LitElement {
|
|
|
67
80
|
const classes = {
|
|
68
81
|
'no-scroll': this._noScroll
|
|
69
82
|
};
|
|
83
|
+
const selectedLanguageCode = getDocumentLocaleSettings().language;
|
|
84
|
+
let foundSelected = false;
|
|
85
|
+
const languageOptions = supportedLocalesDetails.map((l) => {
|
|
86
|
+
const selected = !foundSelected && l.code.startsWith(selectedLanguageCode);
|
|
87
|
+
foundSelected = foundSelected || selected;
|
|
88
|
+
return html`<option value="${l.code}" ?selected="${selected}">${l.code} - ${l.name}</option>`;
|
|
89
|
+
});
|
|
70
90
|
return html`
|
|
71
|
-
<
|
|
91
|
+
<header>
|
|
72
92
|
<h1 class="d2l-heading-2">${this.pageTitle}</h1>
|
|
93
|
+
<label class="d2l-input-label">
|
|
94
|
+
Language:
|
|
95
|
+
<select class="d2l-input-select" @change="${this._handleLanguageChange}">${languageOptions}</select>
|
|
96
|
+
</label>
|
|
97
|
+
</header>
|
|
98
|
+
<main class="${classMap(classes)}">
|
|
73
99
|
<div class="d2l-demo-page-content" @d2l-demo-snippet-fullscreen-toggle="${this._handleFullscreenToggle}"><slot></slot></div>
|
|
74
100
|
</main>
|
|
75
101
|
`;
|
|
@@ -86,6 +112,13 @@ class DemoPage extends LitElement {
|
|
|
86
112
|
this._noScroll = true;
|
|
87
113
|
}
|
|
88
114
|
}
|
|
115
|
+
|
|
116
|
+
_handleLanguageChange(e) {
|
|
117
|
+
const newLanguageCode = e.target[e.target.selectedIndex].value;
|
|
118
|
+
document.documentElement.dir = newLanguageCode === 'ar-sa' ? 'rtl' : 'ltr';
|
|
119
|
+
getDocumentLocaleSettings().language = newLanguageCode;
|
|
120
|
+
}
|
|
121
|
+
|
|
89
122
|
}
|
|
90
123
|
|
|
91
124
|
customElements.define('d2l-demo-page', DemoPage);
|
|
@@ -14,7 +14,6 @@ class DemoSnippet extends LitElement {
|
|
|
14
14
|
noPadding: { type: Boolean, reflect: true, attribute: 'no-padding' },
|
|
15
15
|
overflowHidden: { type: Boolean, reflect: true, attribute: 'overflow-hidden' },
|
|
16
16
|
_code: { type: String },
|
|
17
|
-
_dir: { type: String, attribute: false },
|
|
18
17
|
_fullscreen: { state: true },
|
|
19
18
|
_hasSkeleton: { type: Boolean, attribute: false },
|
|
20
19
|
_settingsPeek: { state: true },
|
|
@@ -51,7 +50,6 @@ class DemoSnippet extends LitElement {
|
|
|
51
50
|
.d2l-demo-snippet-demo {
|
|
52
51
|
flex: 1 1 auto;
|
|
53
52
|
position: relative;
|
|
54
|
-
translate: 0; /* create stacking context to prevent demos from leaking outside their containers */
|
|
55
53
|
}
|
|
56
54
|
:host([full-width]) .d2l-demo-snippet-demo-wrapper.fullscreen .d2l-demo-snippet-demo {
|
|
57
55
|
width: 100vw;
|
|
@@ -83,6 +81,7 @@ class DemoSnippet extends LitElement {
|
|
|
83
81
|
right: 1rem;
|
|
84
82
|
top: -0.25rem;
|
|
85
83
|
translate: 0 -1.5rem;
|
|
84
|
+
z-index: 9999; /* stack on top of sticky headers */
|
|
86
85
|
}
|
|
87
86
|
@media (prefers-reduced-motion: no-preference) {
|
|
88
87
|
d2l-dropdown.settings-dropdown {
|
|
@@ -112,7 +111,6 @@ class DemoSnippet extends LitElement {
|
|
|
112
111
|
constructor() {
|
|
113
112
|
super();
|
|
114
113
|
this.fullWidth = false;
|
|
115
|
-
this._dir = document.documentElement.dir;
|
|
116
114
|
this._fullscreen = false;
|
|
117
115
|
this._hasSkeleton = false;
|
|
118
116
|
this._skeletonOn = false;
|
|
@@ -123,10 +121,8 @@ class DemoSnippet extends LitElement {
|
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
render() {
|
|
126
|
-
const dirAttr = this._dir === 'rtl' ? 'rtl' : 'ltr';
|
|
127
124
|
const skeleton = this._hasSkeleton ? html`<d2l-switch text="Skeleton" ?on="${this._skeletonOn}" @change="${this._handleSkeletonChange}"></d2l-switch>` : null;
|
|
128
125
|
const switches = html`
|
|
129
|
-
<d2l-switch text="RTL" ?on="${dirAttr === 'rtl'}" @change="${this._handleDirChange}"></d2l-switch><br />
|
|
130
126
|
<d2l-switch text="Fullscreen" ?on="${this._fullscreen}" @change="${this._handleFullscreenChange}"></d2l-switch><br />
|
|
131
127
|
${skeleton}`;
|
|
132
128
|
const settings = this.fullWidth && this._fullscreen ? html`
|
|
@@ -137,7 +133,7 @@ class DemoSnippet extends LitElement {
|
|
|
137
133
|
|
|
138
134
|
return html`
|
|
139
135
|
<div class="d2l-demo-snippet-demo-wrapper ${this._fullscreen ? 'fullscreen' : ''}">
|
|
140
|
-
<div class="d2l-demo-snippet-demo"
|
|
136
|
+
<div class="d2l-demo-snippet-demo">
|
|
141
137
|
<div class="d2l-demo-snippet-demo-padding">
|
|
142
138
|
<slot name="_demo"></slot>
|
|
143
139
|
<slot></slot>
|
|
@@ -172,9 +168,6 @@ class DemoSnippet extends LitElement {
|
|
|
172
168
|
const doApply = (nodes, isRoot) => {
|
|
173
169
|
for (let i = 0; i < nodes.length; i++) {
|
|
174
170
|
if (nodes[i].nodeType === Node.ELEMENT_NODE) {
|
|
175
|
-
/* only sprout dir on root or custom element so devs don't think that
|
|
176
|
-
[dir="rtl"].some-class will work. they must use :host([dir="rtl"]) in their
|
|
177
|
-
custom element's CSS since RTLMixin only sprouts [dir="rtl"] on host */
|
|
178
171
|
if (isRoot || nodes[i].tagName.indexOf('-') !== -1) {
|
|
179
172
|
if (typeof(value) === 'boolean') {
|
|
180
173
|
if (value) {
|
|
@@ -230,11 +223,6 @@ class DemoSnippet extends LitElement {
|
|
|
230
223
|
.replace(/=""/g, ''); // replace empty strings for boolean attributes (="")
|
|
231
224
|
}
|
|
232
225
|
|
|
233
|
-
_handleDirChange(e) {
|
|
234
|
-
this._dir = e.target.on ? 'rtl' : 'ltr';
|
|
235
|
-
this._applyAttr('dir', this._dir, true);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
226
|
async _handleFullscreenChange(e) {
|
|
239
227
|
this._fullscreen = e.target.on;
|
|
240
228
|
this._settingsPeek = this._fullscreen;
|
package/mixins/rtl-mixin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
|
2
|
+
import { getDocumentLocaleSettings } from '@brightspace-ui/intl/lib/common.js';
|
|
2
3
|
|
|
3
4
|
export const RtlMixin = dedupeMixin(superclass => class extends superclass {
|
|
4
5
|
|
|
@@ -13,9 +14,25 @@ export const RtlMixin = dedupeMixin(superclass => class extends superclass {
|
|
|
13
14
|
|
|
14
15
|
constructor() {
|
|
15
16
|
super();
|
|
17
|
+
this._localeSettings = getDocumentLocaleSettings();
|
|
18
|
+
this._handleLanguageChange = this._handleLanguageChange.bind(this);
|
|
19
|
+
this._handleLanguageChange();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
super.connectedCallback();
|
|
24
|
+
this._localeSettings.addChangeListener(this._handleLanguageChange);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
disconnectedCallback() {
|
|
28
|
+
super.disconnectedCallback();
|
|
29
|
+
this._localeSettings.removeChangeListener(this._handleLanguageChange);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_handleLanguageChange() {
|
|
16
33
|
const dir = document.documentElement.getAttribute('dir');
|
|
17
34
|
// avoid reflecting "ltr" for better performance
|
|
18
|
-
if (dir && dir !== 'ltr') {
|
|
35
|
+
if (dir && (dir !== 'ltr' || this.dir === 'rtl')) {
|
|
19
36
|
this.dir = dir;
|
|
20
37
|
}
|
|
21
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.66.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",
|