@things-factory/setting-ui 8.0.0-beta.9 → 8.0.2

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.
@@ -0,0 +1,80 @@
1
+ import '@operato/i18n/ox-i18n.js'
2
+ import '@material/web/radio/radio.js'
3
+
4
+ import { css, html, LitElement } from 'lit'
5
+ import { customElement, property } from 'lit/decorators.js'
6
+
7
+ import { i18next, localize } from '@operato/i18n'
8
+ import { clientSettingStore } from '@operato/shell'
9
+ import { MdRadio } from '@material/web/radio/radio.js'
10
+ import { setThemeMode } from '../set-theme-mode.js'
11
+
12
+ @customElement('theme-mode-setting-let')
13
+ export class ThemeModeSettingLet extends localize(i18next)(LitElement) {
14
+ static styles = [
15
+ css`
16
+ label {
17
+ display: flex;
18
+ gap: 10px;
19
+ align-items: center;
20
+
21
+ font: var(--label-font);
22
+ color: var(--md-sys-color-on-surface);
23
+ text-transform: var(--label-text-transform);
24
+ }
25
+
26
+ div[slot='content'] {
27
+ display: flex;
28
+ gap: 10px;
29
+ }
30
+ `
31
+ ]
32
+
33
+ @property({ type: String, attribute: 'theme-mode' }) themeMode: 'dark' | 'light' | 'auto' = 'light'
34
+
35
+ render() {
36
+ const themeMode = this.themeMode
37
+
38
+ return html`
39
+ <setting-let>
40
+ <ox-i18n slot="title" msgid="title.theme setting"></ox-i18n>
41
+
42
+ <div slot="content" @change=${(e: Event) => this.onChangeThemeMode(e)}>
43
+ <md-radio id="dark-mode" name="theme-mode" value="dark" ?checked=${themeMode == 'dark'}></md-radio>
44
+ <label for="dark-mode">dark mode</label>
45
+
46
+ <md-radio id="light-mode" name="theme-mode" value="light" ?checked=${themeMode == 'light'}></md-radio>
47
+ <label for="light-mode">light mode</label>
48
+
49
+ <md-radio id="auto-mode" name="theme-mode" value="auto" ?checked=${themeMode == 'auto'}></md-radio>
50
+ <label for="auto-mode">auto mode</label>
51
+ </div>
52
+ </setting-let>
53
+ `
54
+ }
55
+
56
+ async firstUpdated() {
57
+ this.themeMode = ((await clientSettingStore.get('theme'))?.value || {}).mode || 'light'
58
+ }
59
+
60
+ async onChangeThemeMode(e: Event) {
61
+ const target = e.target as MdRadio
62
+ const value = target.value
63
+ const mode = (this.querySelector('md-radio[checked]') as MdRadio)?.value || value
64
+
65
+ if (mode) {
66
+ try {
67
+ await clientSettingStore.put({
68
+ key: 'theme',
69
+ value: {
70
+ mode
71
+ }
72
+ })
73
+
74
+ setThemeMode(mode)
75
+ } catch (e) {
76
+ console.error(e)
77
+ }
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,32 @@
1
+ body {
2
+ --setting-background: var(--md-sys-color-background);
3
+
4
+ --setting-let-background: var(--md-sys-color-on-primary);
5
+ --setting-let-margin: var(--margin-wide);
6
+ --setting-let-border-radius: var(--border-radius);
7
+ --setting-let-border: var(--border-dim-color);
8
+
9
+ --setting-title-font: var(--subtitle-font);
10
+ --setting-title-color: var(--subtitle-text-color);
11
+
12
+ --setting-content-padding: var(--padding-wide);
13
+ --setting-content-font: normal 0.9em var(--theme-font);
14
+ --setting-content-color: var(--md-sys-color-secondary);
15
+
16
+ --setting-info-content-padding: 10px 15px;
17
+ --setting-info-background-color: #f0f0f0;
18
+ --setting-info-font: normal 14px/14px var(--theme-font);
19
+ --setting-info-color: #666;
20
+ --setting-info-appname-color: var(--md-sys-color-primary);
21
+
22
+ --setting-icon-height: 170px;
23
+ --setting-icon-margin: 40px 0 5px 0;
24
+ }
25
+ @media screen and (max-width: 460px) {
26
+ body {
27
+ --setting-let-margin: var(--margin-default);
28
+ --setting-content-padding: var(--padding-default);
29
+ --setting-icon-height: 140px;
30
+ --setting-icon-margin: var(--margin-wide) 0;
31
+ }
32
+ }