Skip to content

UnoCSS Preset

@wot-ui/unocss-preset is the UnoCSS preset we provide to map wot-ui design tokens and theme variables into ready-to-use atomic classes.

After integrating it, you can directly use wot- prefixed classes in templates for colors, spacing, radius, font weights, typography, opacity, and strokes, without maintaining an extra layer of CSS variable mappings by hand.

html
<view class="wot-bg-filled-oppo wot-rounded-xl wot-p-loose">
  <text class="wot-text-title-large wot-text-text-main wot-font-semibold">
    Wot UI UnoCSS Preset
  </text>
</view>

When to Use It

@wot-ui/unocss-preset is a good fit if any of the following applies:

  • Your project already uses UnoCSS
  • You want to directly reuse wot-ui design tokens and theme variables
  • You want to build uni-app / Vue page styles quickly with atomic classes

What It Provides

This preset mainly provides three capabilities:

CapabilityDescription
themeMaps wot-ui semantic colors and base colors into the UnoCSS theme for color-related utilities
rulesGenerates atomic rules such as wot-text-*, wot-bg-*, wot-m-*, wot-p-*, and wot-rounded-*
preflightsAutomatically injects wot-ui CSS variables so these atomic classes resolve to the correct values

By default, the class prefix is wot-, for example:

  • wot-text-primary
  • wot-bg-danger-surface
  • wot-m-main
  • wot-rounded-md
  • wot-text-body-main

Installation

bash
npm i -D unocss
npm i @wot-ui/unocss-preset
bash
yarn add -D unocss
yarn add @wot-ui/unocss-preset
bash
pnpm add -D unocss
pnpm add @wot-ui/unocss-preset

Usage

Create or update unocss.config.ts in the project root:

ts
import { presetWot } from '@wot-ui/unocss-preset'
import { defineConfig } from 'unocss'

export default defineConfig({
  presets: [
    presetWot(),
  ],
})

After configuration, you can directly use wot- prefixed atomic classes in templates:

vue
<template>
  <view class="wot-bg-filled-oppo wot-rounded-lg wot-p-main">
    <view class="wot-text-title-large wot-text-text-main">Title</view>
    <view class="wot-mt-tight wot-text-body-main wot-text-text-secondary">
      Use wot-ui design tokens to organize page styles quickly
    </view>
  </view>
</template>

Configuration

You can pass options to presetWot() to customize its behavior:

ts
presetWot({
  prefix: 'wot',
  preflight: true,
  baseTokens: false,
})
OptionDefaultDescriptionExample
prefixwotUtility class prefixwot-text-primary, wot-m-main
preflighttrueWhether to automatically inject wot-ui CSS variablespresetWot({ preflight: true })
baseTokensfalseWhether to expose base palettes and raw token class namespresetWot({ baseTokens: true })

prefix

Controls the atomic class prefix. The default value is wot, so generated classes follow the wot-* format.

ts
presetWot({
  prefix: 'wot',
})

preflight

When enabled, wot-ui CSS variables are injected automatically. In most cases, you should keep the default value true. If you disable it, you need to ensure those variables are already available in your project, otherwise the classes may exist but render no visible styles.

baseTokens

By default, the preset mainly exposes semantic tokens. When baseTokens is enabled, it additionally exposes base palettes and raw token class names for scenarios that need finer-grained control.

Supported Rules

Rule TypePatternExample
Colorswot-text-* / wot-bg-* / wot-border-*wot-text-primary, wot-bg-danger-surface, wot-border-border-main
Spacingwot-m-* / wot-gap-*wot-m-main, wot-gap-tight, wot-gap-x-loose
Paddingwot-p-*wot-p-main, wot-px-tight, wot-pb-loose
Radiuswot-rounded-*wot-rounded-md, wot-rounded-full
Font Weightwot-font-*wot-font-medium, wot-font-semibold
Typographywot-text-*wot-text-body-main, wot-text-title-large
Opacitywot-opacity-*wot-opacity-disabled
Strokewot-border-stroke-*wot-border-stroke-main

Available Values

The following sections list the main values supported by each group of atomic classes. Use them by appending the value to the corresponding rule prefix.

Color Utilities

ItemContent
Applicable Prefixeswot-text-*, wot-bg-*, wot-border-*
Primaryprimary, primary-1 ~ primary-10
Dangerdanger, danger-main, danger-hover, danger-clicked, danger-disabled, danger-particular, danger-surface
Successsuccess, success-main, success-hover, success-clicked, success-disabled, success-particular, success-surface
Warningwarning, warning-main, warning-hover, warning-clicked, warning-disabled, warning-particular, warning-surface
Text Colorstext-main, text-secondary, text-auxiliary, text-disabled, text-placeholder, text-white
Icon Colorsicon-main, icon-secondary, icon-auxiliary, icon-disabled, icon-placeholder, icon-white
Border Colorsborder-extra-strong, border-strong, border-main, border-light, border-white, border-zero
Filled Colorsfilled-extra-strong, filled-strong, filled-content, filled-bottom, filled-oppo, filled-zero
Dividersdivider-main, divider-light, divider-strong, divider-white
Feedback Colorsfeedback-hover, feedback-active, feedback-accent
Translucent Fillsopacfilled-tooltip-toast-cover, opacfilled-main-cover, opacfilled-light-cover
Picker View Maskpicker-view-mask-start, picker-view-mask-end
Categorized Colorsclassify-yellow-bg, classify-yellow-border, classify-yellow-content, classify-cyan-bg, classify-cyan-border, classify-cyan-content, classify-purple-bg, classify-purple-border, classify-purple-content, classify-grape-bg, classify-grape-border, classify-grape-content, classify-pink-bg, classify-pink-border, classify-pink-content
Examplewot-text-primary, wot-bg-filled-oppo, wot-border-border-main, wot-bg-classify-purple-content

Spacing Utilities

ItemContent
Applicable Prefixeswot-m-*, wot-mx-*, wot-my-*, wot-mt-*, wot-mr-*, wot-mb-*, wot-ml-*, wot-gap-*, wot-gap-x-*, wot-gap-y-*
Available Valueszero, ultra-tight, super-tight, extra-tight, tight, main, loose, extra-loose, super-loose, ultra-loose, spacious, extra-spacious, super-spacious, ultra-spacious
Examplewot-m-main, wot-mt-tight, wot-gap-x-loose

Padding Utilities

ItemContent
Applicable Prefixeswot-p-*, wot-px-*, wot-py-*, wot-pt-*, wot-pr-*, wot-pb-*, wot-pl-*
Available Valueszero, ultra-tight, super-tight, extra-tight, tight, main, loose, extra-loose, super-loose, ultra-loose, spacious, extra-spacious, super-spacious, ultra-spacious
Examplewot-p-main, wot-px-tight, wot-pb-loose

Radius Utilities

ItemContent
Applicable Prefixwot-rounded-*
Available Valueszero, sm, md, lg, xl, 2xl, 3xl, full
Examplewot-rounded-md, wot-rounded-full

Font Weight Utilities

ItemContent
Applicable Prefixwot-font-*
Available Valuesultra-light, thin, light, regular, medium, semibold, bold
Examplewot-font-medium, wot-font-semibold

Typography Utilities

ItemContent
Applicable Prefixwot-text-*
Titletitle-main, title-large, title-extra-large
Bodybody-main, body-large, body-extra-large, body-super-large, body-ultra-large
Labellabel-super-small, label-extra-small, label-small, label-main, label-large
Examplewot-text-body-main, wot-text-title-large, wot-text-label-large

Opacity Utilities

ItemContent
Applicable Prefixwot-opacity-*
Available Valuesdisabled, dimmer, overlay, main, backdrop
Examplewot-opacity-disabled, wot-opacity-main

Stroke Utilities

ItemContent
Applicable Prefixwot-border-stroke-*
Available Valueszero, light, main, bold
Examplewot-border-stroke-main, wot-border-stroke-bold

Available When baseTokens Is Enabled

When baseTokens: true is enabled, base palettes and raw tokens are additionally exposed.

ItemContent
Base Colorsbase-black, base-white, base-transparent
Color Familiesblue-*, lightblue-*, pink-*, red-*, volcano-*, orange-*, yellow-*, green-*, cyan-*, purple-*, grape-*, coolgrey-*, neutralgrey-*, warmgrey-*
Scale RangeEach family supports 1 ~ 10
Extra Transparent ColorsNon-grey families additionally support *-opac
Opacity Scalesopac-1_02, opac-2_04, opac-3_08, opac-4_15, opac-5_20, opac-6_30, opac-7_45, opac-7_55, opac-8_65, opac-9_75, opac-10_85
White Opacity Scalesopacwhite-1_02, opacwhite-2_04, opacwhite-3_08, opacwhite-4_15, opacwhite-5_20, opacwhite-6_30, opacwhite-7_45, opacwhite-7_55, opacwhite-8_65, opacwhite-9_75, opacwhite-10_85
Examplewot-bg-base-black, wot-text-blue-6, wot-border-opac-3_08

Exports

The package exports presetWot by default and also exposes the following token maps for reuse in business projects:

  • SEMANTIC_COLOR_MAP
  • BASE_COLOR_MAP
  • SPACING_MAP
  • PADDING_MAP
  • RADIUS_MAP
  • FONT_WEIGHT_MAP
  • TYPOGRAPHY_MAP
  • OPACITY_MAP
  • STROKE_MAP

Released under the MIT License.

Released under the MIT License.