Skip to content

Commit

Permalink
feat(uno): add unocss config
Browse files Browse the repository at this point in the history
  • Loading branch information
chengpeiquan committed Aug 5, 2023
1 parent f706212 commit a05f42a
Show file tree
Hide file tree
Showing 7 changed files with 607 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["escaperegexp"]
"cSpell.words": ["Attributify", "escaperegexp", "Windi", "withtypes"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"prettier": "^3.0.0",
"simple-git-hooks": "^2.8.1",
"tsx": "^3.12.7",
"unocss": "^0.54.1",
"vite": "^4.4.2",
"vite-plugin-banner": "^0.7.0",
"vite-plugin-commonjs-externals": "^0.1.3",
Expand Down
117 changes: 117 additions & 0 deletions packages/uno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# @bassist/uno

<p>
<a href='https://www.npmjs.com/package/@bassist/uno'>
<img src="https://img.shields.io/npm/v/@bassist/uno?color=f43f5e&label=npm" />
</a>
<a href="https://www.npmjs.com/package/@bassist/uno" target="__blank">
<img src="https://img.shields.io/npm/dm/@bassist/uno?color=f43f5e&label=" />
</a>
<a href="https://github.com/chengpeiquan/bassist/tree/main/packages/uno" target="__blank">
<img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20demos&color=f43f5e" />
</a>
<a href="https://github.com/chengpeiquan/bassist" target="__blank">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/chengpeiquan/bassist?style=social" />
</a>
</p>

Custom configuration for [UnoCSS](https://unocss.dev/) by [@chengpeiquan](https://github.com/chengpeiquan) .

## Usage

With npm(or yarn, or pnpm):

```bash
npm install -D unocss @bassist/uno
```

Yeah, this is a UnoCSS configuration, so you need to install UnoCSS at the same time.

## Configuration

Create a configuration file named `uno.config.ts` (or `.js` ) in the root path of the project.

```ts
// uno.config.ts
import { defineConfig } from '@bassist/uno'

export default defineConfig()
```

See: [Integrations](https://unocss.dev/integrations/) to integrate UnoCSS into your frameworks.

## Overwrite

You can overwrite or merge your custom configuration.

e.g. Specify a theme color as a Hex value.

```ts
// uno.config.ts
import { defineConfig } from '@bassist/uno'

export default defineConfig({
theme: {
colors: {
primary: '#065f46',
},
},
})
```

e.g. Specify a theme color as a CSS Variable.

```ts
// uno.config.ts
import { defineConfig } from '@bassist/uno'

export default defineConfig({
theme: {
colors: {
primary: 'var(--c-primary)',
},
},
})
```

e.g. Specify a theme color as a set of color palettes.

```ts
// uno.config.ts
import { defineConfig } from '@bassist/uno'

export default defineConfig({
theme: {
colors: {
primary: {
100: '#d1fae5',
200: '#a7f3d0',
300: '#6ee7b7',
400: '#34d399',
500: '#10b981',
600: '#059669',
700: '#047857',
800: '#065f46',
900: '#064e3b',
DEFAULT: '#065f46',
},
},
},
})
```

For more configuration, please refer to the documentation.

## Documentation

Based on the preset foundation of [Tailwind CSS](https://tailwindcss.com) and [Windi CSS](https://windicss.org) , some commonly used default configurations are built in, you can refer to their documentation for detailed usage.

What are the commonly used default configurations? See: [Source Code](https://github.com/chengpeiquan/bassist/tree/main/packages/uno/src/index.ts) .

## VS Code Extension

See: [VS Code Extension](https://unocss.dev/integrations/vscode)

## License

MIT License © 2023-PRESENT [chengpeiquan](https://github.com/chengpeiquan)
37 changes: 37 additions & 0 deletions packages/uno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@bassist/uno",
"version": "0.1.0",
"description": "Custom configuration for UnoCSS by @chengpeiquan .",
"author": "chengpeiquan <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/chengpeiquan/bassist/tree/main/packages/uno",
"files": [
"lib",
"types"
],
"main": "./lib/index.min.js",
"module": "./lib/index.mjs",
"types": "./types/index.d.ts",
"exports": {
".": {
"import": "./lib/index.mjs",
"require": "./lib/index.cjs",
"types": "./types/index.d.js"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/chengpeiquan/bassist.git"
},
"keywords": [
"uno",
"unocss",
"unocss config"
],
"devDependencies": {
"unocss": "^0.54.1"
},
"peerDependencies": {
"unocss": "^0.54.1"
}
}
61 changes: 61 additions & 0 deletions packages/uno/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
mergeConfigs,
presetAttributify,
presetTypography,
presetUno,
transformerDirectives,
transformerVariantGroup,
} from 'unocss'

export type Config = ReturnType<typeof mergeConfigs>

export function defineConfig(configs: Config | Config[] = []): Config {
return mergeConfigs([
{
presets: [
/**
* This preset attempts to provide a common superset
* of the popular utility-first frameworks,
* including Tailwind CSS, Windi CSS, Bootstrap, Tachyons, etc.
*
* @see https://unocss.dev/presets/uno
*/
presetUno(),

/**
* This enables the attributify mode for other presets.
*
* @see https://unocss.dev/presets/attributify
*/
presetAttributify(),

/**
* Provides a set of prose classes
* you can use to add typographic defaults to vanilla HTML.
*
* @see https://unocss.dev/presets/typography
*/
presetTypography(),
],
transformers: [
/**
* You can use a combination of directives and CSS to take advantage of the available utilities.
*
* @see https://unocss.dev/transformers/directives
*/
transformerDirectives({
applyVariable: ['--at-apply', '--uno-apply', '--uno'],
}),

/**
* Apply utilities for the same variant by grouping them with a parenthesis.
*
* @see https://unocss.dev/transformers/variant-group
*/
transformerVariantGroup(),
],
exclude: ['node_modules'],
},
...(Array.isArray(configs) ? configs : [configs]),
])
}
4 changes: 4 additions & 0 deletions packages/uno/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"exclude": ["./lib", "./types"]
}
Loading

0 comments on commit a05f42a

Please sign in to comment.