当然, 我可以为您的博客系统设计四套不同风格的模板。每个模板都将包含不同的颜色方案、布局和风格, 以适应不同的用户喜好。以下是四套模板的概述和实现:
- 经典简约风格 (Classic)
- 现代暗黑模式 (Modern Dark)
- 自然绿色主题 (Nature Green)
- 活力多彩风格 (Vibrant)
让我们逐一实现这些模板:
- 经典简约风格 (Classic)
src/themes/classic.ts:
export default {
name: 'Classic',
colors: {
background: 'bg-white',
text: 'text-gray-800',
primary: 'text-blue-600',
secondary: 'text-gray-600',
accent: 'text-yellow-500',
},
layout: {
container: 'max-w-3xl mx-auto px-4',
header: 'py-6 border-b border-gray-200',
main: 'py-8',
footer: 'py-6 text-center border-t border-gray-200',
},
components: {
button: 'px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700',
input: 'px-3 py-2 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500',
card: 'bg-white shadow rounded-lg overflow-hidden',
}
}- 现代暗黑模式 (Modern Dark)
src/themes/modernDark.ts:
export default {
name: 'Modern Dark',
colors: {
background: 'bg-gray-900',
text: 'text-gray-100',
primary: 'text-blue-400',
secondary: 'text-gray-400',
accent: 'text-purple-400',
},
layout: {
container: 'max-w-4xl mx-auto px-6',
header: 'py-8',
main: 'py-10',
footer: 'py-8 text-center',
},
components: {
button: 'px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600',
input: 'px-3 py-2 bg-gray-800 border border-gray-700 rounded-md focus:ring-2 focus:ring-blue-500',
card: 'bg-gray-800 rounded-lg overflow-hidden border border-gray-700',
}
}- 自然绿色主题 (Nature Green)
src/themes/natureGreen.ts:
export default {
name: 'Nature Green',
colors: {
background: 'bg-green-50',
text: 'text-gray-800',
primary: 'text-green-700',
secondary: 'text-gray-600',
accent: 'text-yellow-600',
},
layout: {
container: 'max-w-5xl mx-auto px-4',
header: 'py-6 border-b border-green-200',
main: 'py-8',
footer: 'py-6 text-center bg-green-100',
},
components: {
button: 'px-4 py-2 bg-green-600 text-white rounded-full hover:bg-green-700',
input: 'px-3 py-2 border border-green-300 rounded-md focus:ring-2 focus:ring-green-500',
card: 'bg-white shadow-md rounded-lg overflow-hidden border border-green-100',
}
}- 活力多彩风格 (Vibrant)
src/themes/vibrant.ts:
export default {
name: 'Vibrant',
colors: {
background: 'bg-gradient-to-r from-pink-300 via-purple-300 to-indigo-400',
text: 'text-gray-800',
primary: 'text-indigo-600',
secondary: 'text-pink-600',
accent: 'text-yellow-500',
},
layout: {
container: 'max-w-4xl mx-auto px-6',
header: 'py-8',
main: 'py-10',
footer: 'py-8 text-center bg-white bg-opacity-30',
},
components: {
button: 'px-6 py-3 bg-indigo-500 text-white rounded-lg hover:bg-indigo-600 transform hover:scale-105 transition duration-200',
input: 'px-4 py-3 border-2 border-purple-300 rounded-lg focus:ring-4 focus:ring-purple-400',
card: 'bg-white bg-opacity-80 backdrop-filter backdrop-blur-lg rounded-xl overflow-hidden shadow-lg',
}
}现在, 让我们更新 src/index.ts 以包含这些新主题:
Import classicTheme from './themes/classic'
import modernDarkTheme from './themes/modernDark'
import natureGreenTheme from './themes/natureGreen'
import vibrantTheme from './themes/vibrant'
const themes: Record<string, Theme> = {
classic: classicTheme,
modernDark: modernDarkTheme,
natureGreen: natureGreenTheme,
vibrant: vibrantTheme,
}
// ... 其他代码保持不变然后, 更新 src/components/Blog.tsx 以使用新的主题属性:
import React from 'react'
import { Theme } from '../types'
import { ThemeSelector } from './ThemeSelector'
interface BlogProps {
posts: Post[]
user: User | null
theme: Theme
availableThemes: string[]
}
export const Blog: React.FC<BlogProps> = ({ posts, user, theme, availableThemes }) => {
return (
<div className={`min-h-screen flex flex-col ${theme.colors.background} ${theme.colors.text}`}>
<header className={theme.layout.header}>
<div className={theme.layout.container}>
<h1 className={`text-4xl font-bold ${theme.colors.primary}`}>My Blog</h1>
<nav className="mt-4 space-x-4">
<a href="/" className={theme.colors.primary}>Home</a>
<a href="/stats" className={theme.colors.primary}>Statistics</a>
{user ? (
<span>Welcome, {user.name}! <a href="/logout" className={theme.colors.secondary}>Logout</a></span>
) : (
<a href="/login" className={theme.colors.primary}>Login</a>
)}
</nav>
<div className="mt-4">
<ThemeSelector
themes={availableThemes.map(t => ({ name: t }))}
currentTheme={theme.name}
onThemeChange={(themeName) => {
// 主题切换逻辑
}}
/>
</div>
</div>
</header>
<main className={`flex-grow ${theme.layout.main}`}>
<div className={theme.layout.container}>
{posts.map(post => (
<article key={post.id} className={`${theme.components.card} mb-8 p-6`}>
<h2 className={`text-2xl font-bold mb-2 ${theme.colors.primary}`}>{post.title}</h2>
<p className="mb-4">{post.content.substring(0, 150)}...</p>
<button className={theme.components.button}>Read More</button>
</article>
))}
</div>
</main>
<footer className={`${theme.layout.footer} ${theme.colors.secondary}`}>
<div className={theme.layout.container}>
© 2023 My Blog. All rights reserved.
</div>
</footer>
</div>
)
}这四套模板为您的博客系统提供了多样化的视觉选择:
- 经典简约风格 (Classic): 适合喜欢传统、简洁设计的用户。
- 现代暗黑模式 (Modern Dark): 适合喜欢深色主题或在夜间浏览的用户。
- 自然绿色主题 (Nature Green): 给人以自然、舒适的感觉, 适合环保或自然主题的博客。
- 活力多彩风格 (Vibrant): 适合想要吸引眼球或展示创意内容的用户。
这些模板可以进一步定制和扩展, 例如:
- 添加更多的颜色变量来细化控制。
- 为特定的页面元素 (如标题、引用等)添加独特的样式。
- 集成字体选择功能, 允许用户在不同的字体之间切换。
- 添加动画和过渡效果以增强用户体验。
- 实现响应式设计, 确保在不同设备上都有良好的显示效果。
通过这种方式, 您的博客系统现在不仅功能丰富, 而且在视觉上也更加灵活和吸引人。用户可以根据自己的喜好选择最适合他们的主题, 从而提高整体用户体验。