Skip to content

Commit 44304a9

Browse files
committed
feat(color): provide param of boolean type
1 parent ec6b097 commit 44304a9

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

packages/tailwindcss-color-preset/README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,32 @@ pnpm add -D tailwindcss @leedomjs/tailwindcss-color-preset
1414

1515
### Config `tailwind.config.js`
1616

17+
> [!NOTE]
18+
> **You could provide different param:**
19+
>
20+
> 1.Object that contains some fields `element`, `naive`, `vant`.
21+
>
22+
> If your project depends on `element-ui`, `element-plus`, `naive-ui`, `vant-ui`, the color will be enable automatically. Setting to false will disable the color, otherwise will enabled.
23+
>
24+
> 2.Boolean
25+
>
26+
> If true, all options are enabled, otherwise disabled.
27+
>
28+
> 3.Empty
29+
>
30+
> Auto-detected based on deps
31+
1732
```js
1833
const color = require('@leedomjs/tailwindcss-color-preset')
1934

20-
/**
21-
* There is an object param that contains some fields `element`, `naive`, `vant`.
22-
*
23-
* These params default to dependencies that your project uses.
24-
* If your project depends on `element-ui`, `element-plus`, `naive-ui`, `vant-ui`,
25-
* the color will be enable automatically.
26-
* Setting to false will disable the color, otherwise will enabled.
27-
*
28-
*/
29-
3035
/** @type {import('tailwindcss').Config} */
3136
module.exports = {
3237
presets: [
38+
/**
39+
* color()
40+
* color(true)
41+
* color(false)
42+
*/
3343
color({
3444
element: true,
3545
naive: true,

packages/tailwindcss-color-preset/src/colors/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ export interface ColorOption {
1212
naive?: boolean
1313
vant?: boolean
1414
}
15+
16+
export type Option = ColorOption | boolean

packages/tailwindcss-color-preset/src/index.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@ import {
66
VanBackground,
77
VanColors,
88
} from './colors'
9-
import type { ColorOption } from './colors/types'
9+
import type { Option } from './colors/types'
1010

1111
const ELEMENT: boolean = isPackageExists('element-ui') || isPackageExists('element-plus')
1212
const NAIVE: boolean = isPackageExists('naive-ui')
1313
const VANT: boolean = isPackageExists('vant')
1414

15-
export default (opt: ColorOption = {
16-
element: ELEMENT,
17-
naive: NAIVE,
18-
vant: VANT,
19-
}): Config => ({
20-
content: [],
21-
theme: {
22-
extend: {
23-
colors: {
24-
...(opt.element ?? ELEMENT ? ElColors : {}),
25-
...(opt.naive ?? NAIVE ? NaiveColors : {}),
26-
...(opt.vant ?? VANT ? VanColors : {}),
27-
},
28-
backgroundImage: {
29-
...(opt.vant ?? VANT ? VanBackground : {}),
15+
export default (opt?: Option): Config => {
16+
const colors = typeof opt === 'boolean' ? (opt ? { ...ElColors, ...NaiveColors, ...VanColors } : {}) : {
17+
...(opt?.element ?? ELEMENT ? ElColors : {}),
18+
...(opt?.naive ?? NAIVE ? NaiveColors : {}),
19+
...(opt?.vant ?? VANT ? VanColors : {}),
20+
}
21+
22+
const backgroundImage = typeof opt === 'boolean' ? (opt ? { ...VanBackground } : {}) : {
23+
...(opt?.vant ?? VANT ? VanBackground : {}),
24+
}
25+
26+
return {
27+
content: [],
28+
theme: {
29+
extend: {
30+
colors,
31+
backgroundImage,
3032
},
3133
},
32-
},
33-
})
34+
}
35+
}
3436

3537
export type * from './colors/types'

0 commit comments

Comments
 (0)