npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unscatty/unocss-preset-daisy

v1.0.0

Published

UnoCSS preset for daisyUI

Downloads

47

Readme

unocss-preset-daisy

Yet another daisyUI preset for UnoCSS

Fully (i think so) compatible UnoCSS preset for daisyUI

Variants (hover, focus, breakpoints: sm, md, etc.) supported.

This is a rework of kidonng's unocss-preset-daisy to make it work with UnoCSS variants, kudos to him for the original work.

Checkout the demo!

:warning: :warning: :warning: Warning :warning: :warning: :warning:

This preset makes heavy usage of shortcuts and rules, so, when using the UnoCSS VSCode extension, editor may become laggy. I recommend disabling the extension's color preview to help with that.

// in your global settings.json or workspace settings.json
{
  "unocss.colorPreview": false
}

Auto-completion suggestions may also take a while to appear, this is due to the amount of shortcuts generated by the preset.

Installation

from version 1.0.0 onwards, daisyui package is no longer required

npm install -D unocss @unscatty/unocss-preset-daisy

Usage

Note: @unocss/reset comes with unocss. If you are using pnpm, install it separately unless you enable hoisting.

Vite

import { defineConfig } from 'vite'
import unocss from 'unocss/vite'
import { presetUno } from 'unocss'
import { presetDaisy } from '@unscatty/unocss-preset-daisy'

export default defineConfig({
  plugins: [
    unocss({
      presets: [presetUno(), presetDaisy()],
    }),
  ],
})
// main.js
import '@unocss/reset/tailwind.css'
import 'uno.css'

Astro

import { defineConfig } from 'astro/config'
import unocss from 'unocss/astro'
import { presetUno } from 'unocss'
import { presetDaisy } from '@unscatty/unocss-preset-daisy'

export default defineConfig({
  integrations: [
    unocss({
      presets: [presetUno(), presetDaisy()],
      injectReset: true,
    }),
  ],
})

Nuxt

To use UnoCSS with Nuxt, @unocss/nuxt must be installed as well.

import { defineNuxtConfig } from 'nuxt/config'
import { presetUno } from 'unocss'
import { presetDaisy } from '@unscatty/unocss-preset-daisy'

export default defineNuxtConfig({
  modules: ['@unocss/nuxt'],
  css: ['@unocss/reset/tailwind.css'],
  unocss: {
    presets: [presetUno(), presetDaisy()],
  },
})

Things to consider

Attributify mode

DaisyUI is developed primarily for TailwindCSS, so, when using daisy's components and Uno's attributify mode, remember to always place components and modifiers inside a class attribute, otherwise, they may not work.

Complex components (like drawer, modal, etc.) that have nested child components, will not work when using attributify mode, as the child components expect to be inside a class attribute.

"Simple" components (like buttons, badges, etc.) may work when using attributify mode, however, some modifiers (btn-active, btn-outline, glass, etc.) are still hardcoded as class selectors, so, they will possibly not work.

Trying to adapt this preset to use attributify mode would be almost impossible as there is no way to know all possible combinations of components and modifiers.

You can still use attributify mode for other utility classes outside of daisy's components.

<!-- This will work -->
<!-- Note you can still use attributify mode for utilities outside daisy -->
<button class="btn btn-primary" hover="normal-case">Primary</button>

<!-- This will also work -->
<button btn btn-primary hover="normal-case">Primary</button>

<!-- This won't work as expected (btn-active is hardcoded as class selector) -->
<button btn btn-active btn-accent>Accent</button>

<!-- This will simply not work -->
<h3 class="font-bold my-1 text-xl">Drawer responsive (attributify)</h3>
<div drawer lg:drawer-open>
  <input id="my-drawer" type="checkbox" drawer-toggle />
  <div drawer-content class="flex flex-col items-center justify-center">
    <!-- Page content here -->
    <label for="my-drawer" btn btn-primary btn-block drawer-button lg:hidden>
      Open drawer
    </label>
  </div>
  <div drawer-side>
    <label for="my-drawer" drawer-overlay></label>
    <ul menu class="p-4 w-80 h-full bg-base-200 text-base-content">
      <!-- Sidebar content here -->
      <li><a>Sidebar Item 1</a></li>
      <li><a>Sidebar Item 2</a></li>
    </ul>
  </div>
</div>

As a rule of thumb, if using a daisy component, always use class selectors.

Uno's variant group transformer

Same as Attributify

Z-positioning

Some components may appear on top or behind other elements, this is due to the way this preset generates shortcuts and how Uno sorts and applies the CSS code.

This can be easily fixed using the z-* classes to set the z-index of the element.

Config

This preset accepts the same config as daisyUI (except for logs and prefix).

{
	presets: [
		presetUno(),
		presetDaisy({
			styled: false,
			themes: ['light', 'dark'],
		}),
	],
}

Caveats

Unused classes, variable names and keyframes

When generating the shortcuts and rules from daisyUI, some CSS code (animation @keyframes) get generated. Some of them may not be used in your project, but they will still be generated and included in the final CSS. This is due to the way this preset generates the rules and shortcuts, I still need to figure out a way to fix this, but for now, it's not a big deal, as the unused code is not that big (mostly keyframes definitions, variables that hold data-url svg elements and themes configuration).

Other than that, code for components is generated on demand, as expected.

If you are concerned about this, you can use something like PurgeCSS to remove the unused code from the final CSS. If you use Vite to build your project, you can use the Vite plugin for PurgeCSS.

TODO

  • [ ] Make demo less ugly. Organize components in their own pages, add more components, etc.
  • [x] Fix unused code generation (move keyframes to preset config insted of preflights, convert variables to CSS object definition).
  • [ ] Make it possible to extend components using shortcuts, scoped by theme. Potentially by using the unocss-preset-theme. So, defining a new theme would be way easier.
  • [ ] Rename functions to make it more clear what they do.
  • [ ] Add tests
  • [X] Remove static daisyUI component files
  • [X] Remove unused playground dependencies (move playground dependencies to its own package.json)
  • [ ] Add prefix option
  • [ ] Make daisy-untailwind a peer dependency

Credits

Authors

  • Carlos Aguilera (@unscatty) - Creator, maintainer