mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
feat(module): generate tailwindcss theme colors (#2967)
Co-authored-by: HugoRCD <hugo.richard@epitech.eu> Co-authored-by: Sébastien Chopin <seb@nuxt.com>
This commit is contained in:
@@ -18,9 +18,17 @@ export default defineNuxtPlugin({
|
||||
}
|
||||
}
|
||||
|
||||
function updateBlackAsPrimary() {
|
||||
const blackAsPrimary = localStorage.getItem('nuxt-ui-black-as-primary')
|
||||
if (blackAsPrimary) {
|
||||
appConfig.theme.blackAsPrimary = blackAsPrimary === 'true'
|
||||
}
|
||||
}
|
||||
|
||||
updateColor('primary')
|
||||
updateColor('neutral')
|
||||
updateRadius()
|
||||
updateBlackAsPrimary()
|
||||
}
|
||||
|
||||
if (import.meta.server) {
|
||||
@@ -31,10 +39,12 @@ export default defineNuxtPlugin({
|
||||
|
||||
if (localStorage.getItem('nuxt-ui-primary')) {
|
||||
const primaryColor = localStorage.getItem('nuxt-ui-primary');
|
||||
html = html.replace(
|
||||
/(--ui-color-primary-\\d{2,3}:\\s*var\\()--color-${appConfig.ui.colors.primary}-(\\d{2,3}\\))/g,
|
||||
\`$1--color-\${primaryColor}-$2\`
|
||||
);
|
||||
if (primaryColor !== 'black') {
|
||||
html = html.replace(
|
||||
/(--ui-color-primary-\\d{2,3}:\\s*var\\()--color-${appConfig.ui.colors.primary}-(\\d{2,3}\\))/g,
|
||||
\`$1--color-\${primaryColor}-$2\`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (localStorage.getItem('nuxt-ui-neutral')) {
|
||||
const neutralColor = localStorage.getItem('nuxt-ui-neutral');
|
||||
@@ -56,6 +66,14 @@ export default defineNuxtPlugin({
|
||||
`.replace(/\s+/g, ' '),
|
||||
type: 'text/javascript',
|
||||
tagPriority: -1
|
||||
}, {
|
||||
innerHTML: `
|
||||
if (localStorage.getItem('nuxt-ui-black-as-primary') === 'true') {
|
||||
document.querySelector('style#nuxt-ui-black-as-primary').innerHTML = ':root { --ui-primary: black; } .dark { --ui-primary: white; }';
|
||||
} else {
|
||||
document.querySelector('style#nuxt-ui-black-as-primary').innerHTML = '';
|
||||
}
|
||||
`.replace(/\s+/g, ' ')
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user