fluentui-webcomponents 0.0.2 → 0.0.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/AGENTS.md +27 -8
- package/README.md +9 -4
- package/core/fluent-element.js +6 -6
- package/package.json +1 -1
- package/theme/theme-picker.js +24 -5
- package/tokens.css +487 -696
package/AGENTS.md
CHANGED
|
@@ -127,21 +127,40 @@ Semantic tokens alias these stops:
|
|
|
127
127
|
--colorBrandBackgroundPressed → --brand-40
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
###
|
|
130
|
+
### Theme Switching (light-dark() + color-scheme)
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
Tokens use CSS `light-dark(lightValue, darkValue)` — a single declaration per token. No duplicate dark blocks, no `@media` queries, no `.dark` classes.
|
|
133
|
+
|
|
134
|
+
```css
|
|
135
|
+
:host, :root {
|
|
136
|
+
color-scheme: light dark;
|
|
137
|
+
--accent-base: light-dark(#0f6cbd, #479ef5);
|
|
138
|
+
--neutral-base: light-dark(#808080, #b0b0b0);
|
|
139
|
+
--colorNeutralBackground1: light-dark(white, var(--neutral-shade-24));
|
|
140
|
+
}
|
|
134
141
|
```
|
|
135
142
|
|
|
136
|
-
|
|
143
|
+
Palette stops (`--neutral-10`…`160`, `--brand-10`…`160`, tints, shades) auto-adapt from the `light-dark()` base colors via `color-mix()` — no changes needed.
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
Page-level overrides use the `color-scheme` CSS property on `:root`:
|
|
139
146
|
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
```js
|
|
148
|
+
// Light mode
|
|
149
|
+
document.documentElement.style.colorScheme = 'light';
|
|
150
|
+
// Dark mode
|
|
151
|
+
document.documentElement.style.colorScheme = 'dark';
|
|
152
|
+
// Follow system
|
|
153
|
+
document.documentElement.style.colorScheme = 'light dark';
|
|
143
154
|
```
|
|
144
155
|
|
|
156
|
+
### Runtime Accent Change
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
document.documentElement.style.setProperty('--accent-base', '#e3008c');
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
One line. Overrides the `light-dark()` value. Entire palette and all dependent tokens update instantly. Zero JS math.
|
|
163
|
+
|
|
145
164
|
## Form Association
|
|
146
165
|
|
|
147
166
|
```js
|
package/README.md
CHANGED
|
@@ -31,12 +31,16 @@ Open `http://localhost:3000/gallery.html` — a single-page showcase of all 26 c
|
|
|
31
31
|
:root { --accent-base: #e3008c; }
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
The entire 16-stop brand palette derives from this single CSS variable via `color-mix(in
|
|
34
|
+
The entire 16-stop brand palette derives from this single CSS variable via `color-mix(in srgb, ...)`. All component colors update automatically.
|
|
35
35
|
|
|
36
|
-
**Dark theme
|
|
37
|
-
```
|
|
38
|
-
|
|
36
|
+
**Dark theme** (via `color-scheme` CSS property):
|
|
37
|
+
```css
|
|
38
|
+
:root { color-scheme: dark; }
|
|
39
|
+
```
|
|
40
|
+
```js
|
|
41
|
+
document.documentElement.style.colorScheme = 'dark';
|
|
39
42
|
```
|
|
43
|
+
Tokens use `light-dark(lightValue, darkValue)` — no class toggling needed.
|
|
40
44
|
|
|
41
45
|
**Theme picker** (optional):
|
|
42
46
|
```html
|
|
@@ -77,6 +81,7 @@ The entire 16-stop brand palette derives from this single CSS variable via `colo
|
|
|
77
81
|
fluentui-webcomponents/
|
|
78
82
|
├── tokens.css # All design tokens (colors, spacing, type, shadows...)
|
|
79
83
|
├── gallery.html # Component showcase
|
|
84
|
+
├── standalone-example.html # Minimal usage (no page CSS needed)
|
|
80
85
|
├── core/
|
|
81
86
|
│ └── fluent-element.js # Base class (~30 lines)
|
|
82
87
|
├── components/
|
package/core/fluent-element.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
class FluentElement extends HTMLElement {
|
|
2
|
-
static stylesUrl =
|
|
3
|
-
static template =
|
|
2
|
+
static stylesUrl = "";
|
|
3
|
+
static template = "";
|
|
4
4
|
|
|
5
5
|
constructor() {
|
|
6
6
|
super();
|
|
7
|
-
this._root = this.attachShadow({ mode:
|
|
7
|
+
this._root = this.attachShadow({ mode: "open" });
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
connectedCallback() {
|
|
11
11
|
if (this.constructor.stylesUrl) {
|
|
12
|
-
const link = document.createElement(
|
|
13
|
-
link.rel =
|
|
12
|
+
const link = document.createElement("link");
|
|
13
|
+
link.rel = "stylesheet";
|
|
14
14
|
link.href = this.constructor.stylesUrl;
|
|
15
15
|
this._root.appendChild(link);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const tmpl = document.createElement(
|
|
18
|
+
const tmpl = document.createElement("template");
|
|
19
19
|
tmpl.innerHTML = this.constructor.template;
|
|
20
20
|
this._root.appendChild(tmpl.content.cloneNode(true));
|
|
21
21
|
}
|
package/package.json
CHANGED
package/theme/theme-picker.js
CHANGED
|
@@ -18,7 +18,7 @@ class FluentThemePicker extends HTMLElement {
|
|
|
18
18
|
<select id="theme-select" title="Theme">
|
|
19
19
|
<option value="light">Light</option>
|
|
20
20
|
<option value="dark">Dark</option>
|
|
21
|
-
<option value="system">System</option>
|
|
21
|
+
<option value="system" selected>System</option>
|
|
22
22
|
</select>
|
|
23
23
|
Theme
|
|
24
24
|
</label>
|
|
@@ -26,12 +26,31 @@ class FluentThemePicker extends HTMLElement {
|
|
|
26
26
|
this.querySelector('#accent-picker').addEventListener('input', e => {
|
|
27
27
|
document.documentElement.style.setProperty('--accent-base', e.target.value);
|
|
28
28
|
});
|
|
29
|
-
this.querySelector('#theme-select')
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const themeSelect = this.querySelector('#theme-select');
|
|
30
|
+
|
|
31
|
+
const applyTheme = (theme) => {
|
|
32
|
+
const root = document.documentElement;
|
|
33
|
+
if (theme === 'system') {
|
|
34
|
+
root.style.colorScheme = 'light dark';
|
|
35
|
+
} else {
|
|
36
|
+
root.style.colorScheme = theme;
|
|
33
37
|
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
themeSelect.addEventListener('change', e => {
|
|
41
|
+
applyTheme(e.target.value);
|
|
34
42
|
});
|
|
43
|
+
|
|
44
|
+
if (window.matchMedia) {
|
|
45
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
|
46
|
+
if (themeSelect.value === 'system') {
|
|
47
|
+
applyTheme('system');
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Initialize with the current selection
|
|
53
|
+
applyTheme(themeSelect.value);
|
|
35
54
|
}
|
|
36
55
|
}
|
|
37
56
|
|