1.0.141 • Published 11 days ago

@timus-networks/theme v1.0.141

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
11 days ago

Installation:

  1. First install package npm i @timus-networks/theme
  2. Add package to modules property in nuxt.config.js file
{
  "modules": ["@nuxtjs/axios", ["@timus-networks/theme", { "client": false, "typescript": false }]]
}
  • You can manually set the client and typescript support properties.
  • If you render this component on the client side, set the value to true.
  • If you prefer to use typescript during development, set typescript to true.
  • You can also set the namespace to define the module path's position within the .nuxt folder.
  1. Add below configuration to your nuxt.config.js file.

nuxt.config.js

tailwindcss: {
  // cssPath: '~/static/scss/main.scss',
  configPath: '@/tailwind.config.js',
  exposeConfig: false,
  exposeLevel: 2,
  config: {
    darkMode: 'class',
  },
  injectPosition: 'first',
  viewer: true,
},
  1. Add below code to your tailwind.config.js file
// tint & shade color generator
function generateColors(baseName, start = 100, end = 900, step = 100) {
  const colors = {};
  for (let i = start; i <= end; i += step) {
    colors[i] = `var(--${baseName}-${i})`;
  }
  return colors;
}

const colorNames = ['primary', 'secondary', 'gray', 'danger', 'success', 'warning', 'info'];

const colors = colorNames.reduce((acc, color) => {
  return { ...acc, [`${color}`]: generateColors(color, 100, 900) };
}, {});

module.exports = {
  content: ['./pages/**/*.{html,js}'],
  theme: {
    extend: {
      colors: colors,
    },
  },
  plugins: [],
};

Usage

Default dark theme is false

  • Change the theme on button click: this.$theme.setDarkMode(!this.$theme.isDark);

  • Register the theme change listener: this.$theme.$on('darkMode', (value) => { console.log('darkMode:', value); });

SamplePage.vue

<template>
  <div class="text-black dark:text-white dark:bg-gray-800 p-4">
    <h1>Dynamic Theming with Nuxt</h1>
    <p>Experience the power of dynamic theming. Click the button below to toggle between light and dark modes.</p>
    <button @click="toggleTheme" class="btn btn-sm btn-primary dark:btn-light mt-4">{{ buttonText }}</button>
    <div class="indicator">
      Current Theme: <strong>{{ $theme.isDark ? 'Dark' : 'Light' }}</strong>
    </div>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
  computed: {
    buttonText(): string {
      return this.$theme.isDark ? 'Switch to Light Mode' : 'Switch to Dark Mode';
    },
  },
  methods: {
    toggleTheme() {
      this.$theme.setDarkMode(!this.$theme.isDark);
    },
  },
  mounted() {
    console.log('Dark mode is:', this.$theme.isDark);
    this.$theme.$on('darkMode', (value: boolean) => {
      console.log('darkMode changed:', value);
    });
  },
});
</script>

<style scoped>
.toggle-button {
  transition: background-color 0.3s ease;
}

.indicator {
  margin-top: 20px;
}
</style>
1.0.141

11 days ago

1.0.140

16 days ago

1.0.139

25 days ago

1.0.136

26 days ago

1.0.138

25 days ago

1.0.137

26 days ago

1.0.134

1 month ago

1.0.133

1 month ago

1.0.132

1 month ago

1.0.131

1 month ago

1.0.129

1 month ago

1.0.128

1 month ago

1.0.123

1 month ago

1.0.125

1 month ago

1.0.124

1 month ago

1.0.127

1 month ago

1.0.126

1 month ago

1.0.121

2 months ago

1.0.120

2 months ago

1.0.119

2 months ago

1.0.118

2 months ago

1.0.117

2 months ago

1.0.109

2 months ago

1.0.108

2 months ago

1.0.110

2 months ago

1.0.112

2 months ago

1.0.111

2 months ago

1.0.114

2 months ago

1.0.113

2 months ago

1.0.116

2 months ago

1.0.115

2 months ago

1.0.107

2 months ago

1.0.106

2 months ago

1.0.103

2 months ago

1.0.105

2 months ago

1.0.104

2 months ago

1.0.101

2 months ago

1.0.100

2 months ago

1.0.102

2 months ago

1.0.99

2 months ago

1.0.88

2 months ago

1.0.87

2 months ago

1.0.86

2 months ago

1.0.85

2 months ago

1.0.89

2 months ago

1.0.91

2 months ago

1.0.90

2 months ago

1.0.95

2 months ago

1.0.94

2 months ago

1.0.93

2 months ago

1.0.92

2 months ago

1.0.98

2 months ago

1.0.97

2 months ago

1.0.96

2 months ago

1.0.84

2 months ago

1.0.83

2 months ago

1.0.82

2 months ago

1.0.81

2 months ago

1.0.80

2 months ago

1.0.79

2 months ago

1.0.77

2 months ago

1.0.78

2 months ago

1.0.76

3 months ago

1.0.73

3 months ago

1.0.72

3 months ago

1.0.75

3 months ago

1.0.74

3 months ago

1.0.71

3 months ago

1.0.70

3 months ago

1.0.69

3 months ago

1.0.68

3 months ago

1.0.67

4 months ago

1.0.66

4 months ago

1.0.65

4 months ago

1.0.64

4 months ago

1.0.62

4 months ago

1.0.63

4 months ago

1.0.61

4 months ago

1.0.60

4 months ago

1.0.59

4 months ago

1.0.55

4 months ago

1.0.54

4 months ago

1.0.58

4 months ago

1.0.57

4 months ago

1.0.56

4 months ago

1.0.53

4 months ago

1.0.49

5 months ago

1.0.51

5 months ago

1.0.50

5 months ago

1.0.52

5 months ago

1.0.38

5 months ago

1.0.40

5 months ago

1.0.44

5 months ago

1.0.43

5 months ago

1.0.42

5 months ago

1.0.41

5 months ago

1.0.48

5 months ago

1.0.47

5 months ago

1.0.46

5 months ago

1.0.45

5 months ago

1.0.37

5 months ago

1.0.36

5 months ago

1.0.33

5 months ago

1.0.35

5 months ago

1.0.34

5 months ago

1.0.32

5 months ago

1.0.31

5 months ago

1.0.30

5 months ago

1.0.29

5 months ago

1.0.28

5 months ago

1.0.26

5 months ago

1.0.27

5 months ago

1.0.25

5 months ago

1.0.24

5 months ago

1.0.23

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago