primevue-mirror/apps/showcase/doc/theming/styled/DarkModeDoc.vue

74 lines
2.4 KiB
Vue
Raw Normal View History

<template>
<DocSectionText v-bind="$attrs">
2024-03-31 13:58:07 +00:00
<p>
PrimeVue uses the <i>system</i> as the default <i>darkModeSelector</i> in theme configuration. If you have a dark mode switch in your application, set the <i>darkModeSelector</i> to the selector you utilize such as <i>.my-app-dark</i> so
2024-09-17 11:05:37 +00:00
that PrimeVue can fit in seamlessly with your color scheme.
2024-03-31 13:58:07 +00:00
</p>
<DocSectionCode :code="code1" hideToggleCode importCode hideStackBlitz />
<p>
2024-07-25 07:21:54 +00:00
Following is a very basic example implementation of a dark mode switch, you may extend it further by involving <i>prefers-color-scheme</i> to retrieve it from the system initially and use <i>localStorage</i> to make it stateful. See this
2024-03-31 13:58:07 +00:00
<a href="https://dev.to/abbeyperini/dark-mode-toggle-and-prefers-color-scheme-4f3m" target="_blank" rel="noopener noreferrer">article</a> for more information.
</p>
<DocSectionCode :code="code2" hideToggleCode hideStackBlitz />
<DocSectionCode :code="code3" hideToggleCode importCode hideStackBlitz />
2024-07-25 07:21:54 +00:00
<p>In case you prefer to use dark mode all the time, apply the <i>darkModeSelector</i> initially and never change it.</p>
2024-09-17 11:05:37 +00:00
<DocSectionCode :code="code4" hideToggleCode hideStackBlitz />
<p>It is also possible to disable dark mode completely using <i>false</i> or <i>none</i> as the value of the selector.</p>
<DocSectionCode :code="code5" hideToggleCode importCode hideStackBlitz />
</DocSectionText>
</template>
<script>
export default {
data() {
return {
2024-03-31 13:58:07 +00:00
code1: {
basic: `
2024-03-31 13:58:07 +00:00
import PrimeVue from 'primevue/config';
2024-06-11 12:21:12 +00:00
import Aura from '@primevue/themes/aura';
2024-03-31 13:58:07 +00:00
const app = createApp(App);
app.use(PrimeVue, {
// Default theme configuration
theme: {
preset: Aura,
options: {
darkModeSelector: '.my-app-dark',
2024-03-31 13:58:07 +00:00
}
}
});
`
},
code2: {
basic: `
2024-08-12 07:30:04 +00:00
<Button label="Toggle Dark Mode" @click="toggleDarkMode()" />
2024-03-31 13:58:07 +00:00
`
},
code3: {
basic: `
2024-08-12 07:30:04 +00:00
function toggleDarkMode() {
2024-09-17 11:05:37 +00:00
document.documentElement.classList.toggle('my-app-dark');
}
`
},
code4: {
basic: `
<html class="my-app-dark">
`
},
code5: {
basic: `
theme: {
preset: Aura,
options: {
darkModeSelector: false || 'none',
}
}
`
}
};
}
};
</script>