frontend/config/tailwind-config/README.md
A comprehensive Tailwind CSS configuration package for the Coze design system, providing consistent theming, color palettes, and semantic design tokens across all applications.
coz-fg-primary, coz-bg-secondary# Install the package in your workspace
pnpm add @coze-arch/tailwind-config@workspace:*
# Update Rush to install dependencies
rush update
In your tailwind.config.js:
const cozeConfig = require('@coze-arch/tailwind-config');
module.exports = {
...cozeConfig,
content: [
'./src/**/*.{js,ts,jsx,tsx}',
// your content paths
],
// extend or override as needed
theme: {
extend: {
...cozeConfig.theme.extend,
// your custom extensions
},
},
};
For semantic utilities and CSS variables:
const cozePlugin = require('@coze-arch/tailwind-config/coze');
module.exports = {
// ... your config
plugins: [
cozePlugin,
// other plugins
],
};
Convert design tokens to Tailwind configuration:
import { designTokenToTailwindConfig, getPackagesContents } from '@coze-arch/tailwind-config/design-token';
const tokenConfig = designTokenToTailwindConfig(yourDesignTokens);
module.exports = {
content: [
'./src/**/*.{js,ts,jsx,tsx}',
...getPackagesContents(), // Auto-discover package contents
],
theme: {
extend: tokenConfig,
},
};
The default export provides a complete Tailwind configuration with:
// Brand colors
'text-brand-5' // Primary brand color
'bg-brand-1' // Light brand background
'border-brand-3' // Brand border
// Semantic colors
'text-foreground-3' // Primary text
'text-foreground-2' // Secondary text
'bg-background-1' // Primary background
'bg-background-0' // Secondary background
// Functional colors
'text-red-5' // Error/danger
'text-yellow-5' // Warning
'text-green-5' // Success
// Semantic spacing
'p-normal' // 32px padding
'm-small' // 20px margin
'gap-mini' // 16px gap
// Precise spacing
'w-320px' // 320px width
'h-240px' // 240px height
'p-24px' // 24px padding
// Font sizes
'text-mini' // 10px
'text-base' // 12px
'text-lg' // 14px
'text-xl' // 15px
'text-xxl' // 16px
'text-24px' // 24px
The Coze plugin adds semantic utility classes and CSS variables:
// Semantic foreground classes
'coz-fg-primary' // Primary text color
'coz-fg-secondary' // Secondary text color
'coz-fg-hglt' // Highlight text color
// Semantic background classes
'coz-bg-primary' // Primary background
'coz-bg-secondary' // Secondary background
'coz-mg-hglt' // Highlight background
// Component-specific classes
'coz-btn-rounded-normal' // Button border radius
'coz-input-height-large' // Input height
'coz-shadow-large' // Large shadow
designTokenToTailwindConfig(tokenJson)Converts design tokens to Tailwind configuration:
const tokenConfig = designTokenToTailwindConfig({
palette: {
light: { 'primary-500': '#3b82f6' },
dark: { 'primary-500': '#60a5fa' }
},
tokens: {
color: {
light: { 'primary-color': 'var(primary-500)' },
dark: { 'primary-color': 'var(primary-500)' }
},
spacing: {
'spacing-sm': '8px',
'spacing-md': '16px'
}
}
});
getPackagesContents(subPath?)Auto-discovers package source files for content configuration:
const contents = getPackagesContents();
// Returns: [
// '/path/to/package1/src/**/*.{ts,tsx}',
// '/path/to/package2/src/**/*.{ts,tsx}',
// ...
// ]
src/
āāā index.js # Main Tailwind configuration
āāā coze.js # Coze plugin with semantic utilities
āāā design-token.ts # Design token conversion utilities
āāā light.js # Light theme CSS variables
āāā dark.js # Dark theme CSS variables
The package uses CSS variables for theming:
:root {
--coze-brand-5: 81, 71, 255;
--coze-fg-3: 15, 21, 40;
--coze-bg-1: 247, 247, 252;
}
.dark {
--coze-brand-5: 166, 166, 255;
--coze-fg-3: 255, 255, 255;
--coze-bg-1: 24, 28, 43;
}
Colors are defined as RGB values to support alpha transparency:
.text-brand-5 {
color: rgba(var(--coze-brand-5), 1);
}
.bg-brand-1 {
background-color: rgba(var(--coze-brand-1), var(--coze-brand-1-alpha));
}
light.js and dark.jsindex.jscoze.js if needed# Run linting
pnpm lint
# Build (no-op for this package)
pnpm build
This package is part of the Coze architecture and follows the project's licensing terms.