Skip to content

Commit a4bbdb7

Browse files
committed
feat(color): theme can be optional & automatically enable according to deps
1 parent 955bc8c commit a4bbdb7

File tree

10 files changed

+85
-23
lines changed

10 files changed

+85
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"build:mp": "pnpm --dir ./packages/tailwindcss-miniprogram-preset build",
2727
"build:preset": "pnpm --dir ./packages/tailwindcss-preset build",
2828
"build": "pnpm build:color && pnpm build:mp && pnpm build:preset",
29-
"release": "bumpp -r && pnpm -r publish --access public",
29+
"release": "pnpm build && bumpp -r && pnpm -r publish --access public",
3030
"prepare": "simple-git-hooks"
3131
},
3232
"simple-git-hooks": {

packages/tailwindcss-color-preset/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,21 @@ pnpm add -D tailwindcss @leedomjs/tailwindcss-color-preset
1919

2020
const color = require('@leedomjs/tailwindcss-color-preset')
2121

22+
23+
/**
24+
* There is an object param that contains some fields `element`, `naive`, `vant`.
25+
*
26+
* These params default to false, setting to true will enable the color.
27+
* If your project depends on `element-ui`, `element-plus`, `naive-ui`, `vant-ui`, the color will be enable automatically, even though you set value to false.
28+
*
29+
*/
2230
module.exports = {
2331
presets: [
24-
color,
32+
color({
33+
element: true,
34+
naive: true,
35+
vant: true,
36+
}),
2537
],
2638
content: [...],
2739
theme: {

packages/tailwindcss-color-preset/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"tailwindcss": ">=2.2.19"
4444
},
4545
"dependencies": {
46+
"local-pkg": "^0.5.0",
4647
"tailwindcss": "^3.4.3"
4748
},
4849
"devDependencies": {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,16 @@ export type Color = string | { [key: string]: string }
3131
export interface ColorConfig {
3232
[key: string]: Color
3333
}
34+
35+
/**
36+
* select color
37+
* @example
38+
* {
39+
* element: true
40+
* }
41+
*/
42+
export interface ColorOption {
43+
element?: boolean
44+
naive?: boolean
45+
vant?: boolean
46+
}
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1+
import { isPackageExists } from 'local-pkg'
12
import {
23
ElColors,
34
NaiveColors,
45
VanBackground,
56
VanColors,
67
} from './colors'
8+
import type { ColorOption } from './colors/types'
79

8-
export default {
10+
const ELEMENT: boolean = isPackageExists('element-ui') || isPackageExists('element-plus')
11+
const NAIVE: boolean = isPackageExists('naive-ui')
12+
const VANT: boolean = isPackageExists('vant')
13+
14+
export default (opt: ColorOption = {
15+
element: false,
16+
naive: false,
17+
vant: false,
18+
}) => ({
919
theme: {
1020
extend: {
1121
colors: {
12-
...ElColors,
13-
...NaiveColors,
14-
...VanColors,
22+
...((opt.element || ELEMENT) ? ElColors : {}),
23+
...((opt.naive || NAIVE) ? NaiveColors : {}),
24+
...((opt.vant || VANT) ? VanColors : {}),
1525
},
1626
backgroundImage: {
17-
...VanBackground,
27+
...((opt.vant || VANT) ? VanBackground : {}),
1828
},
1929
},
2030
},
21-
}
31+
})
2232

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

packages/tailwindcss-preset/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ const preset = require('@leedomjs/tailwindcss-preset')
2424
module.exports = {
2525
presets: [
2626
/**
27-
* You can also set an object param that contains a field called `mp`.
27+
* There is an object param that contains some fields `mp`, `element`, `naive`, `vant`.
28+
*
2829
* `mp` defaults to `false`, setting `mp` be `true` will enable the preset,
29-
* otherwise will enable default config of tailwindcss and disable the preset meanwhile
30+
* otherwise will enable default config of tailwindcss and disable the preset meanwhile.
31+
*
32+
* `element`, `naive`, `vant`, these params default to false, setting to true will enable the color.
33+
* If your project depends on `element-ui`, `element-plus`, `naive-ui`, `vant-ui`, the color will be enable automatically, even though you set value to false.
3034
*
31-
* preset({ mp: true })
3235
*/
33-
preset(),
36+
preset({
37+
mp: true,
38+
element: true,
39+
naive: true,
40+
vant: true,
41+
}),
3442
],
3543
content: [...],
3644
theme: {

packages/tailwindcss-preset/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
},
3131
"exports": {
3232
".": {
33-
"types": "./dist/index.d.ts",
3433
"import": "./dist/index.mjs",
3534
"require": "./dist/index.cjs"
3635
}
3736
},
3837
"module": "./dist/index.mjs",
39-
"types": "./dist/index.d.ts",
4038
"peerDependencies": {
4139
"tailwindcss": ">=2.2.19"
4240
},

packages/tailwindcss-preset/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
import type { ColorOption } from '@leedomjs/tailwindcss-color-preset'
12
import color from '@leedomjs/tailwindcss-color-preset'
23
import mp from '@leedomjs/tailwindcss-miniprogram-preset'
34

4-
export default (opt = { mp: false }) => ({
5+
const colors: ColorOption = {
6+
element: false,
7+
naive: false,
8+
vant: false,
9+
}
10+
export default (opt = { mp: false, ...colors }) => ({
511
presets: [
6-
color,
12+
color({
13+
element: opt.element,
14+
naive: opt.naive,
15+
vant: opt.vant,
16+
}),
717
mp({
818
enable: opt.mp,
919
}),

pnpm-lock.yaml

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tailwind.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import preset from '@leedomjs/tailwindcss-preset'
33
/** @type {import('tailwindcss').Config} */
44
export default {
55
presets: [
6-
preset({ mp: false }),
6+
preset({
7+
mp: true,
8+
element: true,
9+
naive: true,
10+
vant: true,
11+
}),
712
],
813
content: ['./fixtures/index.html'],
914
theme: {

0 commit comments

Comments
 (0)