Skip to content

Commit

Permalink
It probably works
Browse files Browse the repository at this point in the history
  • Loading branch information
kidonng committed Mar 25, 2023
1 parent a130818 commit 5fe7edc
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 106 deletions.
61 changes: 25 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Installation

```sh
npm install unocss unocss-preset-daisy @kidonng/daisyui
npm install unocss daisyui unocss-preset-daisy
```

## Usage
Expand All @@ -17,13 +17,12 @@ npm install unocss unocss-preset-daisy @kidonng/daisyui
```js
import {defineConfig} from 'vite'
import unocss from 'unocss/vite'
import {presetUno, transformerDirectives} from 'unocss'
import {presetUno} from 'unocss'
import {presetDaisy} from 'unocss-preset-daisy'

export default defineConfig({
plugins: [
unocss({
transformers: [transformerDirectives()],
presets: [presetUno(), presetDaisy()],
}),
],
Expand All @@ -35,14 +34,13 @@ export default defineConfig({
```js
import {defineConfig} from 'astro/config'
import unocss from 'unocss/vite'
import {presetUno, transformerDirectives} from 'unocss'
import {presetUno} from 'unocss'
import {presetDaisy} from 'unocss-preset-daisy'

export default defineConfig({
vite: {
plugins: [
unocss({
transformers: [transformerDirectives()],
presets: [presetUno(), presetDaisy()],
}),
],
Expand All @@ -56,13 +54,12 @@ To use UnoCSS with Nuxt, `@unocss/nuxt` must be installed as well.

```js
import {defineNuxtConfig} from 'nuxt'
import {presetUno, transformerDirectives} from 'unocss'
import {presetUno} from 'unocss'
import {presetDaisy} from 'unocss-preset-daisy'

export default defineNuxtConfig({
modules: ['@unocss/nuxt'],
unocss: {
transformers: [transformerDirectives()],
presets: [presetUno(), presetDaisy()],
},
})
Expand All @@ -76,27 +73,35 @@ After configuring the framework, add these imports to your entrypoint:
// `@unocss/reset` comes with `unocss`
// If you are using pnpm, install it separately unless you enable hoisting
import '@unocss/reset/tailwind.css'
// Import `@kidonng/daisyui` **BEFORE** `uno.css`
import '@kidonng/daisyui/index.css'
import 'uno.css'
```

### Custom themes
## Config

This preset accepts [the same config as daisyUI](https://daisyui.com/docs/config/) (except for `logs`, `prefix` and `darkTheme`).

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

> **Note**: Refer to [`@kidonng/daisyui` documentation](https://github.com/kidonng/daisyui#themes) for built-in themes.
### Custom themes

Use [UnoCSS's theming system](https://github.com/unocss/unocss#extend-theme) to customize the theme.

```js
{
// UnoCSS config
transformers: [transformerDirectives()],
presets: [presetUno(), presetDaisy()],
// Custom themes
theme: {
// This is NOT a theme name, it must be `colors`
colors: {
// Refer to https://daisyui.com/docs/colors/ for the list of color names
// Refer to https://daisyui.com/docs/colors/ for colors
neutral: 'red',
// Use camelCase instead of kebab-case (e.g. `neutral-focus`)
neutralFocus: 'green',
Expand All @@ -111,26 +116,10 @@ Use [UnoCSS's theming system](https://github.com/unocss/unocss#extend-theme) to

For details, please read [issue #9](https://github.com/kidonng/unocss-preset-daisy/issues/9#issuecomment-1452292840).

## Questions

**How to use a built-in theme / unstyled components?**

Please refer to [`@kidonng/daisyui` usage](https://github.com/kidonng/daisyui#usage).

**`@kidonng/daisyui/index.css` imports EVERYTHING!**

This entry imports all styles for easier use.

Since daisyUI is utility-first, the styles can be compressed very efficiently. Minified size of all styles is about 143 KB (as of writing), but **only 20 KB** after gzipping.

If this is unsatisfying, you can [only import the styles you actually use](https://github.com/kidonng/daisyui#usage). It may sound cumbersome but in fact not so, since they only need to be imported once globally.

You can also use [PurgeCSS](https://purgecss.com/), though it doesn't play nice with UnoCSS (or Vite in large).

**Why use `@kidonng/daisyui` instead of the official `daisyui` package?**
## Limitations

[`@kidonng/daisyui`](https://github.com/kidonng/daisyui) is a redistribution of daisyUI, to make it compatible with UnoCSS.
**This is not a full daisyUI port.** All daisyUI components/utilities should work but they may not work with some UnoCSS features:

**I'm expecting a full UnoCSS port!**
- [#14](https://github.com/kidonng/unocss-preset-daisy/issues/14): [variants](https://windicss.org/utilities/general/variants.html) do not work

Not currently, sorry. I envision a future where we don't need `@kidonng/daisyui`, which is one of the reasons this is a separate module.
**Unused styles may be imported.** This is both due to lots of hacks being used and how UnoCSS works. However, the preset try to figure out the minimum styles needed, thus the cost is trivial most of the time.
67 changes: 67 additions & 0 deletions daisyui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,70 @@ declare module 'daisyui/src/colors/index.js' {
const colors: Record<string, (options: {opacityValue?: string}) => string>
export default colors
}

declare module 'daisyui/dist/utilities.js' {
import type {CssInJs} from 'postcss-js'

const utilities: CssInJs
export default utilities
}

declare module 'daisyui/dist/base.js' {
import type {CssInJs} from 'postcss-js'

const base: CssInJs
export default base
}

declare module 'daisyui/dist/unstyled.js' {
import type {CssInJs} from 'postcss-js'

const unstyled: CssInJs
export default unstyled
}

declare module 'daisyui/dist/unstyled.rtl.js' {
import type {CssInJs} from 'postcss-js'

const unstyledRtl: CssInJs
export default unstyledRtl
}

declare module 'daisyui/dist/styled.js' {
import type {CssInJs} from 'postcss-js'

const styled: CssInJs
export default styled
}

declare module 'daisyui/dist/styled.rtl.js' {
import type {CssInJs} from 'postcss-js'

const styledRtl: CssInJs
export default styledRtl
}

declare module 'daisyui/dist/utilities-unstyled.js' {
import type {CssInJs} from 'postcss-js'

const utilitiesUnstyled: CssInJs
export default utilitiesUnstyled
}

declare module 'daisyui/dist/utilities-styled.js' {
import type {CssInJs} from 'postcss-js'

const utilitiesStyled: CssInJs
export default utilitiesStyled
}

declare module 'daisyui/src/colors/themes.js' {
const themes: Record<string, Record<string, string>>
export default themes
}

declare module 'daisyui/src/colors/functions.js' {
export function convertToHsl(
input: Record<string, string>,
): Record<string, string>
}
16 changes: 14 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ <h3 class="font-bold my-1 text-xl">Badge</h3>
<h3 class="font-bold my-1 text-xl">Card</h3>
<div class="card w-96 bg-base-100 shadow-xl">
<figure>
<img src="https://placeimg.com/400/225/arch" alt="Shoes" />
<img
src="https://daisyui.com/images/stock/photo-1606107557195-0e29a4b5b4aa.jpg"
alt="Shoes"
/>
</figure>
<div class="card-body">
<h3 class="font-bold card-title">Shoes!</h3>
Expand Down Expand Up @@ -246,6 +249,16 @@ <h3 class="font-bold my-1 text-xl">Radio</h3>
</div>
</div>

<h2 class="my-2 text-3xl">Layout</h2>

<div class="my-4">
<h3 class="font-bold my-1 text-xl">Mask</h3>
<img
class="mask mask-squircle"
src="https://daisyui.com/images/stock/photo-1567653418876-5bb0e566e1c2.jpg"
/>
</div>

<h2 class="my-2 text-3xl">Navigation</h2>

<div class="my-4">
Expand Down Expand Up @@ -382,7 +395,6 @@ <h3 class="font-bold text-lg">Congratulations random Internet user!</h3>

<script type="module">
import '@unocss/reset/tailwind.css'
import '@kidonng/daisyui/index.css'
import 'uno.css'
</script>
</body>
3 changes: 1 addition & 2 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {defineConfig} from 'vite'
// eslint-disable-next-line n/file-extension-in-import
import unocss from 'unocss/vite'
import {presetUno, presetIcons, transformerDirectives} from 'unocss'
import {presetUno, presetIcons} from 'unocss'
import {presetDaisy} from '../index.js'

export default defineConfig({
plugins: [
unocss({
transformers: [transformerDirectives()],
presets: [presetUno(), presetDaisy(), presetIcons()],
}),
],
Expand Down
Loading

0 comments on commit 5fe7edc

Please sign in to comment.