admin-vben/internal/tailwind-config/src/index.ts

198 lines
5.7 KiB
TypeScript
Raw Normal View History

2024-05-19 13:20:42 +00:00
import type { Config } from 'tailwindcss';
import path from 'node:path';
2024-06-08 11:49:06 +00:00
import { fs, getPackagesSync } from '@vben/node-utils';
2024-05-19 13:20:42 +00:00
import { addDynamicIconSelectors } from '@iconify/tailwind';
import formsPlugin from '@tailwindcss/forms';
2024-05-28 15:38:36 +00:00
import typographyPlugin from '@tailwindcss/typography';
2024-05-19 13:20:42 +00:00
import animate from 'tailwindcss-animate';
2024-05-28 15:38:36 +00:00
2024-06-02 12:47:50 +00:00
import { enterAnimationPlugin } from './plugins/entry';
2024-05-19 13:20:42 +00:00
// import defaultTheme from 'tailwindcss/defaultTheme';
const { packages } = getPackagesSync();
const tailwindPackages: string[] = [];
packages.forEach((pkg) => {
// apps目录下和 @vben-core/tailwind-ui 包需要使用到 tailwindcss ui
if (fs.existsSync(path.join(pkg.dir, 'tailwind.config.mjs'))) {
tailwindPackages.push(pkg.dir);
}
});
2024-06-23 11:17:31 +00:00
function createColorsPattern(name: string) {
return {
100: `hsl(var(--${name}-100))`,
200: `hsl(var(--${name}-200))`,
300: `hsl(var(--${name}-300))`,
400: `hsl(var(--${name}-400))`,
500: `hsl(var(--${name}-500))`,
600: `hsl(var(--${name}-600))`,
700: `hsl(var(--${name}-700))`,
800: `hsl(var(--${name}-800))`,
900: `hsl(var(--${name}-900))`,
1000: `hsl(var(--${name}-1000))`,
active: `hsl(var(--${name}-700))`,
background: `hsl(var(--${name}-100))`,
'background-hover': `hsl(var(--${name}-200))`,
border: `hsl(var(--${name}-300))`,
'border-hover': `hsl(var(--${name}-400))`,
foreground: `hsl(var(--${name}-foreground))`,
hover: `hsl(var(--${name}-500))`,
text: `hsl(var(--${name}-900))`,
'text-active': `hsl(var(--${name}-1000))`,
'text-hover': `hsl(var(--${name}-800))`,
};
}
2024-05-19 13:20:42 +00:00
export default {
content: [
'./index.html',
...tailwindPackages.map((item) =>
path.join(item, 'src/**/*.{vue,js,ts,jsx,tsx,svelte,astro,html}'),
),
],
darkMode: 'class',
2024-06-02 12:47:50 +00:00
plugins: [
animate,
formsPlugin,
typographyPlugin,
addDynamicIconSelectors(),
enterAnimationPlugin,
],
2024-05-19 13:20:42 +00:00
prefix: '',
safelist: ['dark'],
theme: {
container: {
center: true,
padding: '2rem',
screens: {
'2xl': '1400px',
},
},
extend: {
animation: {
'accordion-down': 'accordion-down 0.2s ease-out',
'accordion-up': 'accordion-up 0.2s ease-out',
'collapsible-down': 'collapsible-down 0.2s ease-in-out',
'collapsible-up': 'collapsible-up 0.2s ease-in-out',
float: 'float 5s linear 0ms infinite',
},
2024-06-16 07:45:15 +00:00
animationDuration: {
'2000': '2000ms',
'3000': '3000ms',
},
2024-05-19 13:20:42 +00:00
borderRadius: {
2024-06-23 06:21:27 +00:00
lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)',
xl: 'calc(var(--radius) + 4px)',
2024-05-19 13:20:42 +00:00
},
colors: {
accent: {
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--accent))',
foreground: 'hsl(var(--accent-foreground))',
hover: 'hsl(var(--accent-hover))',
2024-05-19 13:20:42 +00:00
},
2024-06-23 11:17:31 +00:00
authentication: 'hsl(var(--authentication))',
2024-06-23 06:21:27 +00:00
background: 'hsl(var(--background))',
border: 'hsl(var(--border))',
2024-05-19 13:20:42 +00:00
card: {
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--card))',
foreground: 'hsl(var(--card-foreground))',
2024-05-19 13:20:42 +00:00
},
destructive: {
2024-06-23 11:17:31 +00:00
...createColorsPattern('destructive'),
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--destructive))',
2024-05-19 13:20:42 +00:00
},
2024-06-23 11:17:31 +00:00
foreground: 'hsl(var(--foreground))',
green: {
...createColorsPattern('green'),
foreground: 'hsl(var(--success-foreground))',
},
2024-05-19 13:20:42 +00:00
heavy: {
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--heavy))',
foreground: 'hsl(var(--heavy-foreground))',
2024-05-19 13:20:42 +00:00
},
input: {
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--input))',
background: 'hsl(var(--input-background))',
2024-05-19 13:20:42 +00:00
},
muted: {
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--muted))',
foreground: 'hsl(var(--muted-foreground))',
2024-05-19 13:20:42 +00:00
},
2024-06-23 06:21:27 +00:00
overlay: 'hsl(var(--overlay))',
2024-05-19 13:20:42 +00:00
popover: {
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--popover))',
foreground: 'hsl(var(--popover-foreground))',
2024-05-19 13:20:42 +00:00
},
primary: {
2024-06-23 11:17:31 +00:00
...createColorsPattern('primary'),
DEFAULT: 'hsl(var(--primary))',
},
red: {
...createColorsPattern('red'),
foreground: 'hsl(var(--destructive-foreground))',
2024-05-19 13:20:42 +00:00
},
2024-06-23 06:21:27 +00:00
ring: 'hsl(var(--ring))',
2024-05-19 13:20:42 +00:00
secondary: {
2024-06-23 11:17:31 +00:00
DEFAULT: 'hsl(var(--secondary))',
desc: 'hsl(var(--secondary-desc))',
foreground: 'hsl(var(--secondary-foreground))',
2024-06-23 06:21:27 +00:00
},
success: {
2024-06-23 11:17:31 +00:00
...createColorsPattern('success'),
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--success))',
},
warning: {
2024-06-23 11:17:31 +00:00
...createColorsPattern('warning'),
2024-06-23 06:21:27 +00:00
DEFAULT: 'hsl(var(--warning))',
2024-06-23 11:17:31 +00:00
},
yellow: {
...createColorsPattern('yellow'),
2024-06-23 06:21:27 +00:00
foreground: 'hsl(var(--warning-foreground))',
2024-05-19 13:20:42 +00:00
},
},
fontFamily: {
sans: [
'var(--font-geist-sans)',
// ...defaultTheme.fontFamily.sans
],
},
keyframes: {
'accordion-down': {
from: { height: '0' },
to: { height: 'var(--radix-accordion-content-height)' },
},
'accordion-up': {
from: { height: 'var(--radix-accordion-content-height)' },
to: { height: '0' },
},
'collapsible-down': {
from: { height: '0' },
to: { height: 'var(--radix-collapsible-content-height)' },
},
'collapsible-up': {
from: { height: 'var(--radix-collapsible-content-height)' },
to: { height: '0' },
},
float: {
'0%': { transform: 'translateY(0)' },
'50%': { transform: 'translateY(-20px)' },
'100%': { transform: 'translateY(0)' },
},
},
zIndex: {
'100': '100',
'1000': '1000',
},
},
},
} as Config;