Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tailwind module integration #237

Merged
merged 9 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions docs/content/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Dark and Light mode with auto detection made easy with Nuxt 🌗
- Add `.${color}-mode` class to `<html>` for easy CSS theming
- Force a page to a specific color mode (perfect for incremental development)
- Works with client-side and universal rendering
- Works out of the box with [@nuxtjs/tailwindcss](https://github.com/nuxt-modules/tailwindcss)
- Auto detect system [color-mode](https://drafts.csswg.org/mediaqueries-5/#descdef-media-prefers-color-mode)
- Supports IE9+ 👴

Expand All @@ -39,7 +40,10 @@ Then, add `@nuxtjs/color-mode` to the `modules` section of your `nuxt.config.ts`

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@nuxtjs/color-mode']
modules: [
'@nuxtjs/color-mode'
// '@nuxtjs/tailwindcss'
]
})
```

Expand Down Expand Up @@ -163,27 +167,6 @@ Props:
- `placeholder`: `String`
- `tag`: `String`, default: `'span'`

## TailwindCSS

Tailwind v2 introduced [dark mode](https://tailwindcss.com/docs/dark-mode), in order to work with `@nuxtjs/color-mode`, you need to set `darkMode: 'class'` in your `tailwind.config.js`:

```js [tailwind.config.js]
module.exports = {
darkMode: 'class'
}
```

Then in your `nuxt.config.ts`, set the `classSuffix` option to an empty string:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@nuxtjs/color-mode'],
colorMode: {
classSuffix: ''
}
})
```

## Migrating to v3

v3 of `@nuxtjs/color-mode` requires either Nuxt Bridge or Nuxt 3. (If you are using Nuxt 2 without Bridge, you should continue to use v2.)
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
},
"dependencies": {
"@nuxt/kit": "^3.11.2",
"pathe": "^1.1.2"
"pathe": "^1.1.2",
"pkg-types": "^1.0.3",
"semver": "^7.6.0"
},
"devDependencies": {
"@commitlint/cli": "^19.2.1",
Expand All @@ -58,4 +60,4 @@
"vitest": "^1.4.0",
"@nuxt/eslint-config": "^0.3.5"
}
}
}
33 changes: 2 additions & 31 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
<template>
<div class="container">
<Meta
name="description"
content="Demo of using @nuxtjs/color-mode for Nuxt, supporting dark mode and custom colors"
/>
<p>
<NuxtLogo />
</p>
<NuxtLayout>
<NuxtPage />
<p class="note">
Demo based on <a href="https://color-mode.nuxtjs.org">@nuxtjs/color-mode</a> module.
</p>
</div>
</NuxtLayout>
</template>

<style>
p {
padding: 20px 0;
margin: 0;
}
.container {
text-align: center;
padding: 50px;
}
.note {
transition: all .3s;
display: inline-block;
padding: 15px 15px;
border-radius: 5px;
background-color: var(--bg-secondary);
color: var(--color-secondary);
}
</style>
34 changes: 34 additions & 0 deletions playground/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div class="container">
<Meta
name="description"
content="Demo of using @nuxtjs/color-mode for Nuxt, supporting dark mode and custom colors"
/>
<p>
<NuxtLogo />
</p>
<slot />
<p class="note">
Demo based on <a href="https://color-mode.nuxtjs.org">@nuxtjs/color-mode</a> module.
</p>
</div>
</template>

<style>
p {
padding: 20px 0;
margin: 0;
}
.container {
text-align: center;
padding: 50px;
}
.note {
transition: all .3s;
display: inline-block;
padding: 15px 15px;
border-radius: 5px;
background-color: var(--bg-secondary);
color: var(--color-secondary);
}
</style>
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default defineNuxtConfig({
components: { global: true, dirs: ['~/components'] },
css: ['~/assets/main.css'],
modules: ['../src/module'],
modules: ['../src/module', '@nuxtjs/tailwindcss'],
})
1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"dependencies": {
"@nuxtjs/color-mode": "latest",
"@nuxtjs/tailwindcss": "^6.11.4",
"nuxt": "^3.11.2"
}
}
6 changes: 6 additions & 0 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
light page
</NuxtLink>
</p>
<p>
Go to
<NuxtLink to="/tailwind">
tailwind integration
</NuxtLink>
</p>
</div>
</template>
21 changes: 21 additions & 0 deletions playground/pages/tailwind.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script setup>
definePageMeta({
layout: false,
})
</script>

<template>
<div class="bg-white py-4">
<div class="dark:bg-black">
<p class="dark:text-white">
hello tailwind!
</p>
<p>
<NuxtLink to="/">
Home
</NuxtLink>
</p>
<ColorModePicker />
</div>
</div>
</template>
Loading
Loading