Welcome to mirror list, hosted at ThFree Co, Russian Federation.

themeSwitch.html « component « xui « html « web - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7cbedecfe5d8387de142f9fac28b261cc8ee9b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{{define "component/themeSwitchTemplate"}}
<template>
  <a-switch :default-checked="themeSwitcher.isDarkTheme"
            checked-children="☀"
            un-checked-children="🌙"
            @change="themeSwitcher.toggleTheme()">
  </a-switch>
</template>
{{end}}

{{define "component/themeSwitcher"}}
<script>
  const colors = {
    dark: {
      bg: "#242c3a",
      text: "hsla(0,0%,100%,.65)"
    },
    light: {
      bg: '#f0f2f5',
      text: "rgba(0, 0, 0, 0.7)",
    }
  }

  function createThemeSwitcher() {
    const isDarkTheme = localStorage.getItem('dark-mode') === 'true';
    const theme = isDarkTheme ? 'dark' : 'light';
    return {
      isDarkTheme,
      bgStyle: `background: ${colors[theme].bg};`,
      textStyle: `color: ${colors[theme].text};`,
      darkClass: isDarkTheme ? 'ant-dark' : '',
      darkCardClass: isDarkTheme ? 'ant-card-dark' : '',
      darkDrawerClass: isDarkTheme ? 'ant-drawer-dark' : '',
      get currentTheme() {
        return this.isDarkTheme ? 'dark' : 'light';
      },
      toggleTheme() {
        this.isDarkTheme = !this.isDarkTheme;
        this.theme = this.isDarkTheme ? 'dark' : 'light';
        localStorage.setItem('dark-mode', this.isDarkTheme);
        this.bgStyle = `background: ${colors[this.theme].bg};`;
        this.textStyle = `color: ${colors[this.theme].text};`;
        this.darkClass = this.isDarkTheme ? 'ant-dark' : '';
        this.darkCardClass = this.isDarkTheme ? 'ant-card-dark' : '';
        this.darkDrawerClass = this.isDarkTheme ? 'ant-drawer-dark' : '';
      },
    };
  }

  const themeSwitcher = createThemeSwitcher();

  Vue.component('theme-switch', {
    props: [],
    template: `{{template "component/themeSwitchTemplate"}}`,
    data: () => ({ themeSwitcher }),
  });
</script>
{{end}}