unpreset / unocss-preset-theme

The dynamic theme presets for UnoCSS.
https://unocss-preset-theme.todev.cc
123 stars 11 forks source link

type definition errors on presetTheme #4

Closed therealokoro closed 1 year ago

therealokoro commented 1 year ago

Tried using this plugin, but vscode keeps shouting at me about this image

Dunqing commented 1 year ago

You also need to set the theme type for unocss

Please refer to the following https://github.com/Dunqing/unocss-preset-theme/blob/f2419617670bdcb5eb12b4b4850e2af49418ec75/playground/vite.config.ts#L10

therealokoro commented 1 year ago

Uhm... So i'm using unocss with nuxt 3 and my config lies in an unocss.config.ts file not in vite.config.ts. This means that the unocss export from vite is not needed. So how do I then use this preset?

How about you try using this preset with nuxt 3.

Here's an example of my config.

export default defineConfig({
  theme: {},
  presets: [
    presetUno(),
    presetAttributify(),
    presetIcons({ scale: 1.2 }),
    presetForms(),
    presetTheme<Theme>({
      theme: {
        dark: {
          colors: {
            primary: "#1668dc",
            "primary-border": "#1668dc",
            border: "#424242"
          }
       }
    }),
  transformers: [transformerDirectives(), transformerVariantGroup()]
})
Dunqing commented 1 year ago

Just like this

export default defineConfig<Theme>({...})
therealokoro commented 1 year ago

Works like a charm👌. Nice one

So one more thing. I think it would be nice if the plugin could convert colors to rgba so as to respect a opacity when available.

Currently when you pass in a color value(except for color names) to the color property in the default theme option of unocss, It's converted to rgba so if in usage, an opacity is passed, then it can be used.

See examples below.

Default

image one image

Notice how the rgb color value passed to the color property in the config was converted rgba so it could respect opacity.

With this preset

image image

Notice that it ignores the possibility of have opacity.

I do hope that this is clear enough. Thanks

therealokoro commented 1 year ago

Beautiful work @Dunqing.