Skip to content

Commit c8f8889

Browse files
committed
Add basic theme selector for ui3
1 parent d6e6711 commit c8f8889

File tree

16 files changed

+136
-20
lines changed

16 files changed

+136
-20
lines changed

src/index.html

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@
7575
background: #FFF;
7676
color: #453C4F;
7777
}
78+
header select {
79+
padding: 0.375rem 0.25rem;
80+
border-radius: 0.25rem;
81+
border: 1px solid #FFF;
82+
background: transparent;
83+
color: #FFF;
84+
margin-right: 0.5rem;
85+
font-size: 1rem;
86+
}
87+
header select option {
88+
color: #222;
89+
background: #FFF;
90+
}
7891
aside {
7992
grid-row: 2;
8093
grid-column: 1;
@@ -171,7 +184,7 @@
171184
bottom: -1px;
172185
left: -1px;
173186
border-radius: 0.25rem 0.25rem 0 0;
174-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
187+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
175188
}
176189
main > h2 > button > svg {
177190
width: 24px;
@@ -297,6 +310,29 @@
297310
container.classList.toggle('show', markdownCache[name]);
298311
});
299312
}
313+
window.addEventListener('load', () => {
314+
const themeSelect = document.getElementById('theme');
315+
function setTheme(value) {
316+
localStorage.setItem('theme', value);
317+
if (value !== '') {
318+
const s = document.createElement('link');
319+
s.setAttribute('rel', 'stylesheet');
320+
s.setAttribute('type', 'text/css');
321+
s.setAttribute('href', './theme-ui3.css');
322+
document.head.appendChild(s);
323+
}
324+
}
325+
themeSelect.addEventListener('change', (e) => {
326+
const value = e.target.value;
327+
setTheme(value);
328+
window.location.reload();
329+
});
330+
const themeCache = localStorage.getItem('theme');
331+
if (themeCache !== null) {
332+
setTheme(themeCache);
333+
themeSelect.value = themeCache;
334+
}
335+
});
300336
</script>
301337
<div class="wrapper">
302338
<header>
@@ -305,6 +341,12 @@
305341
</svg>
306342
<h1>Pictogrammers Components</h1>
307343
<span></span>
344+
<label>
345+
<select id="theme">
346+
<option value="">None</option>
347+
<option value="ui3">UI3</option>
348+
</select>
349+
</label>
308350
<a href="https://github.com/Pictogrammers/Components">
309351
<svg viewBox="0 0 24 24">
310352
<path fill="currentColor" d="M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z" />

src/pg/annoy/annoy.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ div {
6060
bottom: -1px;
6161
left: -1px;
6262
border-radius: 50%;
63-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
63+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
6464
}
6565

6666
[part=close] svg {

src/pg/button/button.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
background-color: var(--pg-button-background-color, #FFFFFF);
1414
color: var(--pg-button-color, #453C4F);
1515
padding: var(--pg-button-padding, 0.25rem 0.5rem);
16-
border-radius: 0.25rem;
16+
border-radius: var(--pg-button-border-radius, 0.25rem);
1717
outline: none;
1818
--pg-icon-color: var(--pg-button-color, #453C4F);
1919
}
@@ -42,7 +42,7 @@
4242
bottom: -1px;
4343
left: -1px;
4444
border-radius: 0.25rem;
45-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
45+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
4646
}
4747
[part="button"]:focus::before {
4848
pointer-events: none;
@@ -53,7 +53,7 @@
5353
bottom: -1px;
5454
left: -1px;
5555
border-radius: 0.25rem;
56-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.5));
56+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
5757
}
5858

5959
[part="button"].start {

src/pg/buttonLink/buttonLink.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
bottom: -1px;
4747
left: -1px;
4848
border-radius: 0.25rem;
49-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
49+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
5050
}
5151
[part="button"]:focus::before {
5252
pointer-events: none;
@@ -57,7 +57,7 @@
5757
bottom: -1px;
5858
left: -1px;
5959
border-radius: 0.25rem;
60-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.5));
60+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
6161
}
6262

6363
[part="button"].start {

src/pg/inputFileLocal/inputFileLocal.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
bottom: -1px;
4343
left: -1px;
4444
border-radius: 0.25rem;
45-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.6));
45+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
4646
}
4747

4848
[part="label"]:focus::before {
@@ -54,7 +54,7 @@
5454
bottom: -1px;
5555
left: -1px;
5656
border-radius: 0.25rem;
57-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.5));
57+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
5858
}
5959

6060
[part="file"] {

src/pg/inputPixelEditor/inputPixelEditor.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
bottom: -1px;
1818
left: -1px;
1919
border-radius: 0.125rem;
20-
box-shadow: 0 0 0 3px var(--pg-search-focus-glow, rgb(79, 143, 249, 0.5));
20+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
2121
}
2222

2323
canvas {

src/pg/menu/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ connectedCallback() {
2727
value: 'item1'
2828
}];
2929
}
30-
```
30+
```
31+
32+
## CSS Variables
33+
34+
| Variable | Default |
35+
| -------- | ------- |
36+
| `--pg-menu-padding` | `0.25rem` |
37+
| `--pg-menu-border-width` | `0` |
38+
| `--pg-menu-background-color` | `transparent` |
39+
| `--pg-menu-box-shadow` | `none` |

src/pg/menu/menu.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,25 @@ export default class PgMenu extends HTMLElement {
2929
const { index } = e.detail;
3030
this.dispatchEvent(new CustomEvent('select', {
3131
detail: { index, item }
32-
}))
32+
}));
33+
});
34+
$item.addEventListener('up', (e: any) => {
35+
const { index } = e.detail;
36+
let first = this.items[0].disabled ? 1 : 0;
37+
if (index === first) {
38+
this.focus(this.items.length - 1);
39+
} else {
40+
this.focus(index - 1);
41+
}
42+
});
43+
$item.addEventListener('down', (e: any) => {
44+
const { index } = e.detail;
45+
if (index === this.items.length - 1) {
46+
let first = this.items[0].disabled ? 1 : 0;
47+
this.focus(first);
48+
} else {
49+
this.focus(index + 1);
50+
}
3351
});
3452
}
3553
});
@@ -51,9 +69,9 @@ export default class PgMenu extends HTMLElement {
5169
getItemOffset(startIndex, endIndex): number {
5270
const computedStyle = getComputedStyle(this.$items);
5371
let height = parseInt(computedStyle.getPropertyValue('padding-top'), 10);
54-
const total = this.$items.children.length;
72+
const total = this.items.length;
5573
if (startIndex > total || endIndex > total) {
56-
throw new Error('startIndex or endIndex out of bounds');
74+
throw new Error('startIndex or endIndex not within range of items');
5775
}
5876
for (let i = startIndex; i < endIndex; i++) {
5977
const ele = this.$items.children[i] as any;
@@ -62,7 +80,15 @@ export default class PgMenu extends HTMLElement {
6280
return height;
6381
}
6482

83+
/**
84+
* Get the height of an individiaual item.
85+
* @param index Item index
86+
* @returns {number} Item height
87+
*/
6588
getItemHeight(index) {
89+
if (index > this.items.length) {
90+
throw new Error('index outside range of items');
91+
}
6692
const ele = this.$items.children[index] as any;
6793
return ele.getHeight();
6894
}

src/pg/menuItem/menuItem.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ export default class PgMenuItem extends HTMLElement {
3535
this.dispatchEvent(new CustomEvent('select', {
3636
detail: { index: this.index }
3737
}));
38-
})
38+
});
39+
this.$label.addEventListener('keydown', (e: KeyboardEvent) => {
40+
switch (e.key) {
41+
case 'ArrowDown':
42+
this.dispatchEvent(new CustomEvent('down', {
43+
detail: { index: this.index }
44+
}));
45+
break;
46+
case 'ArrowUp':
47+
this.dispatchEvent(new CustomEvent('up', {
48+
detail: { index: this.index }
49+
}));
50+
break;
51+
}
52+
});
3953
}
4054

4155
focus() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div class="example">
22
<button part="button">Create Menu Overlay</button>
33
<p>Result: <code part="result"></code></p></p>
4+
<p>input: <code part="input"></code></p></p>
45
</div>

0 commit comments

Comments
 (0)