Skip to content

Commit

Permalink
feat: configuring UnoCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 26, 2023
1 parent d29625c commit 19d3ad7
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ const Customizations = [
text: 'Configure Vite',
link: '/custom/config-vite',
},
{
text: 'Configure UnoCSS',
link: '/custom/config-unocss',
},
{
text: 'Configure Windi CSS',
link: '/custom/config-windicss',
Expand Down
2 changes: 1 addition & 1 deletion addons/write-an-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An addon can contribute to the following points:
- Global styles (use with caution has it is more the role of [themes](/themes/use))
- Provide custom layouts or override the existing one
- Provide custom components or override the existing one
- Extend Windi CSS configurations
- Extend UnoCSS/Windi CSS configurations
- Configure tools like Monaco and Prism

## Conventions
Expand Down
44 changes: 44 additions & 0 deletions custom/config-unocss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Configure UnoCSS

<Environment type="node" />

[UnoCSS](https://unocss.dev) is now the default CSS framework for Slidev since v0.42.0. UnoCSS is an fast atomic CSS engine that has full flexibility and extensibility.

By default, Slidev enables the following presets out-of-box:

- [@unocss/preset-uno](https://unocss.dev/presets/uno) - Tailwind / Windi CSS compatible utilities
- [@unocss/preset-attributify](https://unocss.dev/presets/attributify) - Attributify mode
- [@unocss/preset-icons](https://unocss.dev/presets/icons) - Use any icons as class
- [@unocss/preset-web-fonts](https://unocss.dev/presets/web-fonts) - Use web fonts at ease
- [@unocss/transformer-directives](https://unocss.dev/transformers/directives) - Use `@apply` in CSS

You can therefore style your content the way you want. For example:

```html
<div class="grid pt-4 gap-4 grid-cols-[100px,1fr]">

### Name

- Item 1
- Item 2

</div>
```

## Configurations

You can create `uno.config.ts` under the root of your project to extend the builtin configurations

```ts
import { defineConfig } from 'unocss'

export default defineConfig({
shortcuts: {
// custom the default background
'bg-main': 'bg-white text-[#181818] dark:(bg-[#121212] text-[#ddd])',
},
// ...
})
```

Learn more about [UnoCSS configurations](https://unocss.dev/guide/config-file)
13 changes: 12 additions & 1 deletion custom/config-windicss.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

<Environment type="node" />

Markdown naturally supports embedded HTML markups. You can therefore style your content the way you want. To provide some convenience, we have [Windi CSS](https://github.com/windicss/windicss) built-in, so you can style markup directly using class utilities.
::: warning
Since Slidev v0.42.0, [UnoCSS](/custom/config-unocss) become the default CSS framework for Slidev.

You can still use Windi CSS by setting `css: windicss` in the frontmatter.
```md
---
css: windicss
---
```
:::

Markdown naturally supports embedded HTML markups. You can therefore style your content the way you want.

For example:

Expand Down
2 changes: 1 addition & 1 deletion custom/directory-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import './code.css'
import './layouts.css'
```

Styles will be processed by [Windi CSS](https://windicss.org/) and [PostCSS](https://postcss.org/), so you can use css nesting and [at-directives](https://windicss.org/features/directives.html) out-of-box. For example:
Styles will be processed by [UnoCSS](https://unocss.dev/) and [PostCSS](https://postcss.org/), so you can use css nesting and [at-directives](https://windicss.org/features/directives.html) out-of-box. For example:

```less
.slidev-layout {
Expand Down
3 changes: 2 additions & 1 deletion custom/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Customizations

Slidev is fully customizable, from styling to tooling configurations. It allows you to configure the tools underneath ([Vite](/custom/config-vite), [Windi CSS](/custom/config-windicss), [Monaco](/custom/config-monaco), etc.)
Slidev is fully customizable, from styling to tooling configurations. It allows you to configure the tools underneath ([Vite](/custom/config-vite), [UnoCSS](/custom/config-unocss), [Monaco](/custom/config-monaco), etc.)

## Frontmatter Configures

Expand Down Expand Up @@ -118,6 +118,7 @@ Refer to the [Directory Structure](/custom/directory-structure) section.
- [Highlighters](/custom/highlighters)
- [Configure Vue](/custom/config-vue)
- [Configure Vite](/custom/config-vite)
- [Configure UnoCSS](/custom/config-unocss)
- [Configure Windi CSS](/custom/config-windicss)
- [Configure Monaco](/custom/config-monaco)
- [Configure KaTeX](/custom/config-katex)
Expand Down
2 changes: 1 addition & 1 deletion guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Since Slidev is based on the Web, you can apply any grid layouts as you want. [CSS Grids](https://css-tricks.com/snippets/css/complete-guide-grid/), [flexboxes](https://css-tricks.com/snippets/css/a-guide-to-flexbox/), or even [Masonry](https://css-tricks.com/native-css-masonry-layout-in-css-grid/), you get the full controls.

Since we have [Windi CSS](https://windicss.org/) built-in, here is one simple way for you to reference:
Since we have [UnoCSS](https://windicss.org/) built-in, here is one simple way for you to reference:

```html
<div class="grid grid-cols-2 gap-4">
Expand Down
2 changes: 1 addition & 1 deletion guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can learn more about the rationale behind the project in the [Why Slidev](/g
- 📝 [**Markdown-based**](/guide/syntax.html) - use your favorite editors and workflow
- 🧑‍💻 [**Developer Friendly**](/guide/syntax.html#code-blocks) - built-in syntax highlighting, live coding, etc.
- 🎨 [**Themable**](/themes/gallery.html) - theme can be shared and used with npm packages
- 🌈 [**Stylish**](/guide/syntax.html#embedded-styles) - on-demand utilities via [Windi CSS](https://windicss.org/) or [UnoCSS](https://github.com/unocss/unocss).
- 🌈 [**Stylish**](/guide/syntax.html#embedded-styles) - on-demand utilities via [UnoCSS](https://github.com/unocss/unocss) or [Windi CSS](https://windicss.org/).
- 🤹 [**Interactive**](/custom/directory-structure.html#components) - embedding Vue components seamlessly
- 🎙 [**Presenter Mode**](/guide/presenter-mode.html) - use another window, or even your phone to control your slides
- 🎨 [**Drawing**](/guide/drawing.html) - draw and annotate on your slides
Expand Down
4 changes: 2 additions & 2 deletions guide/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Slides are written within **a single markdown file** (by default `./slides.md`).

You can use [the Markdown features](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) as you normally would, with the additional support of inlined HTML and Vue Components. Styling using [Windi CSS](https://windicss.org) is also supported. Use `---` padded with a new line to separate your slides.
You can use [the Markdown features](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) as you normally would, with the additional support of inlined HTML and Vue Components. Styling using [UnoCSS](/custom/config-unocss) is also supported. Use `---` padded with a new line to separate your slides.

~~~md
# Slidev
Expand Down Expand Up @@ -185,7 +185,7 @@ h1 {

`<style>` tag in Markdown is always [scoped](https://vuejs.org/api/sfc-css-features.html#scoped-css). As an outstanding result, a selector with the child combinator (`.a > .b`) is unusable as such; see the previous link. To have global style overrides, check out the [customization section](/custom/directory-structure#style).

Powered by [Windi CSS](https://windicss.org), you can directly use nested css and [directives](https://windicss.org/features/directives.html) (e.g. `@apply`)
Powered by [UnoCSS](/custom/config-unocss), you can directly use nested css and [directives](https://windicss.org/features/directives.html) (e.g. `@apply`)

```md
# Slidev
Expand Down
2 changes: 1 addition & 1 deletion guide/why.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Learn more about [highlighters](/custom/highlighters) and [Monaco configuration]

## Fast

Slidev is powered by [Vite](https://vitejs.dev/), [Vue 3](https://v3.vuejs.org/) and [Windi CSS](https://windicss.org/), which give you the most wonderful authoring experience. Every change you made will reflect to your slides **instantly**.
Slidev is powered by [Vite](https://vitejs.dev/), [Vue 3](https://v3.vuejs.org/) and [UnoCSS](https://unocss.dev/), which give you the most wonderful authoring experience. Every change you made will reflect to your slides **instantly**.

Find more about [our tech stack](/guide/#tech-stack).

Expand Down
2 changes: 1 addition & 1 deletion themes/write-a-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A theme can contribute to the following points:
- Provide default configurations (fonts, color schema, highlighters, etc.)
- Provide custom layouts or override the existing one
- Provide custom components or override the existing one
- Extend Windi CSS configurations
- Extend UnoCSS/Windi CSS configurations
- Configure tools like Monaco and Prism

## Conventions
Expand Down

0 comments on commit 19d3ad7

Please sign in to comment.