chore: move primary to colors obj and support gray override

This commit is contained in:
Benjamin Canac
2021-11-24 12:22:50 +01:00
parent 9eea64fe40
commit 50cecbf90d
2 changed files with 30 additions and 26 deletions

View File

@@ -49,28 +49,6 @@ export default defineNuxtConfig({
Options Options
</h2> </h2>
<p>- `primary`</p>
<p>Define the primary variant. Defaults to `indigo`. You can specify your own object of colors like here:</p>
<p class="font-medium">
Example:
</p>
<pre class="bg-tw-gray-900 rounded-md text-tw-white px-4">
<code class="text-sm">
import { defineNuxtConfig } from 'nuxt3'
export default defineNuxtConfig({
buildModules: [
'@nuxthq/ui'
],
ui: {
primary: 'blue'
}
})</code>
</pre>
<p>- `prefix`</p> <p>- `prefix`</p>
<p>Define the prefix of the imported components. Defaults to `u`.</p> <p>Define the prefix of the imported components. Defaults to `u`.</p>
@@ -93,6 +71,34 @@ export default defineNuxtConfig({
})</code> })</code>
</pre> </pre>
<p>- `colors.primary`</p>
<p>Define the primary variant. Defaults to `indigo`. You can specify your own object of colors like here:</p>
<p class="font-medium">
Example:
</p>
<pre class="bg-tw-gray-900 rounded-md text-tw-white px-4">
<code class="text-sm">
import { defineNuxtConfig } from 'nuxt3'
export default defineNuxtConfig({
buildModules: [
'@nuxthq/ui'
],
ui: {
colors: {
primary: 'blue'
}
}
})</code>
</pre>
<p>- `colors.gray`</p>
<p>Define the gray variant. Defaults to `zinc`. You can like the `primary` color specify your own object. https://github.com/antfu/unocss/blob/main/packages/preset-uno/src/theme/colors.ts</p>
<p>- `unocss.shortcuts`. Defaults to `[]`.</p> <p>- `unocss.shortcuts`. Defaults to `[]`.</p>
<p>Define UnoCSS shortcuts: https://github.com/antfu/unocss#shortcuts.</p> <p>Define UnoCSS shortcuts: https://github.com/antfu/unocss#shortcuts.</p>

View File

@@ -8,15 +8,13 @@ export default defineNuxtModule({
name: '@nuxthq/ui', name: '@nuxthq/ui',
configKey: 'ui', configKey: 'ui',
async setup (_options, nuxt) { async setup (_options, nuxt) {
const prefix = _options?.prefix || 'u' const { prefix = 'u', colors: { primary = 'indigo', gray = 'zinc' } = {} } = _options || {}
const primary = _options?.primary || 'indigo'
const { shortcuts = [], rules = [], variants = [], theme = {} } = _options?.unocss || {} const { shortcuts = [], rules = [], variants = [], theme = {} } = _options?.unocss || {}
const options: UnocssNuxtOptions = { const options: UnocssNuxtOptions = {
theme: { theme: {
colors: { colors: {
gray: colors?.zinc, gray: typeof gray === 'object' ? gray : (colors && colors[gray]),
primary: typeof primary === 'object' ? primary : (colors && colors[primary]) primary: typeof primary === 'object' ? primary : (colors && colors[primary])
}, },
...theme ...theme