howl/test/layout.tsx

296 lines
10 KiB
TypeScript

import "hono/jsx"
import { raw } from "hono/html"
type LayoutProps = {
title: string
children: any
showHomeLink?: boolean
}
export const Layout = ({ title, children, showHomeLink = true }: LayoutProps) => {
return (
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{title} - Howl UI</title>
<style>
{raw(`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg: #ffffff;
--text: #1f2937;
--border: #e5e7eb;
--code-bg: #f9fafb;
--code-border: #e5e7eb;
--toggle-bg: #e5e7eb;
--toggle-active: #3b82f6;
}
[data-theme="dark"] {
--bg: #111827;
--text: #f9fafb;
--border: #374151;
--code-bg: #1f2937;
--code-border: #374151;
--toggle-bg: #374151;
--toggle-active: #60a5fa;
}
body {
background-color: var(--bg);
color: var(--text);
transition: background-color 0.3s, color 0.3s;
font-family: system-ui, -apple-system, sans-serif;
}
.dark-mode-toggle {
position: fixed;
top: 16px;
right: 16px;
background: var(--toggle-bg);
border: 1px solid var(--border);
border-radius: 9999px;
padding: 8px 16px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 500;
transition: all 0.2s;
z-index: 1000;
}
.dark-mode-toggle:hover {
background: var(--toggle-active);
color: white;
border-color: var(--toggle-active);
}
.page-title {
position: relative;
font-size: 32px;
font-weight: bold;
padding: 24px;
border-bottom: 1px solid var(--border);
background: var(--bg);
}
.page-title:has(.home-link) {
padding-left: 80px;
}
.home-link {
position: absolute;
left: 24px;
top: 50%;
transform: translateY(-50%);
background: var(--toggle-bg);
border: 1px solid var(--border);
border-radius: 8px;
padding: 8px 12px;
text-decoration: none;
color: var(--text);
display: flex;
align-items: center;
gap: 6px;
font-size: 14px;
font-weight: 500;
transition: all 0.2s;
}
.home-link:hover {
background: var(--toggle-active);
color: white;
border-color: var(--toggle-active);
}
/* Update code example styles for dark mode */
[data-theme="dark"] .code-examples-container {
background-color: var(--code-bg) !important;
border-color: var(--code-border) !important;
}
/* Syntax highlighting colors for dark mode - even lighter for better readability */
[data-theme="dark"] .code-examples-container span[style*="color: #8b5cf6"] {
color: #e9d5ff !important; /* much lighter violet */
}
[data-theme="dark"] .code-examples-container span[style*="color: #0ea5e9"] {
color: #bfdbfe !important; /* much lighter cyan */
}
[data-theme="dark"] .code-examples-container span[style*="color: #10b981"] {
color: #a7f3d0 !important; /* much lighter emerald */
}
[data-theme="dark"] .code-examples-container span[style*="color: #f59e0b"] {
color: #fde68a !important; /* much lighter amber */
}
[data-theme="dark"] .code-examples-container span[style*="color: #ef4444"] {
color: #fecaca !important; /* much lighter red */
}
/* Dark mode for specific demo colors */
[data-theme="dark"] div[style*="#fecaca"] { background-color: #7f1d1d !important; }
[data-theme="dark"] div[style*="#bbf7d0"] { background-color: #14532d !important; }
[data-theme="dark"] div[style*="#bfdbfe"] { background-color: #1e3a8a !important; }
[data-theme="dark"] div[style*="#fef08a"] { background-color: #713f12 !important; }
[data-theme="dark"] div[style*="#e9d5ff"] { background-color: #581c87 !important; }
[data-theme="dark"] div[style*="#fbcfe8"] { background-color: #831843 !important; }
[data-theme="dark"] div[style*="#fed7aa"] { background-color: #7c2d12 !important; }
[data-theme="dark"] div[style*="#f3f4f6"] { background-color: #1f2937 !important; }
[data-theme="dark"] div[style*="#e5e7eb"] { background-color: #374151 !important; }
[data-theme="dark"] div[style*="#d1d5db"] { background-color: #4b5563 !important; }
[data-theme="dark"] div[style*="#9ca3af"] { background-color: #6b7280 !important; }
/* Dark mode for colored boxes */
[data-theme="dark"] div[style*="#ef4444"] {
background-color: #991b1b !important;
color: #fca5a5 !important;
}
[data-theme="dark"] div[style*="#22c55e"] {
background-color: #15803d !important;
color: #86efac !important;
}
[data-theme="dark"] div[style*="#3b82f6"] {
background-color: #1e40af !important;
color: #93c5fd !important;
}
/* Dark mode for button colors */
[data-theme="dark"] button[style*="#3b82f6"] { background-color: #1e40af !important; }
[data-theme="dark"] button[style*="#64748b"] { background-color: #334155 !important; }
[data-theme="dark"] button[style*="#ef4444"] { background-color: #991b1b !important; }
/* Dark mode for buttons - removed filter to maintain colors */
/* Dark mode for borders */
[data-theme="dark"] *[style*="border"] {
border-color: var(--border) !important;
}
/* Dark mode for images */
[data-theme="dark"] img {
opacity: 0.9;
}
/* Dark mode for cards and containers */
[data-theme="dark"] div[style*="border: 1px solid #d1d5db"] {
border-color: #374151 !important;
}
/* Improve text visibility - very important! */
[data-theme="dark"] p,
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] span,
[data-theme="dark"] div,
[data-theme="dark"] li {
color: var(--text);
}
/* Ensure button text is visible */
[data-theme="dark"] button {
color: white !important;
}
/* Override black text colors */
[data-theme="dark"] *[style*="color: #000000"],
[data-theme="dark"] *[style*="color:#000000"],
[data-theme="dark"] *[style*="color: black"],
[data-theme="dark"] *[style*="color:black"] {
color: var(--text) !important;
}
/* Special case for buttons with transparent or outline variants */
[data-theme="dark"] button[style*="background: transparent"],
[data-theme="dark"] button[style*="backgroundColor: transparent"] {
color: var(--text) !important;
}
/* Fix divider backgrounds in dark mode */
[data-theme="dark"] span[style*="#ffffff"] {
background-color: var(--bg) !important;
color: #9ca3af !important;
}
/* Fix any #ffffff backgrounds in dark mode */
[data-theme="dark"] *[style*="background-color: rgb(255, 255, 255)"],
[data-theme="dark"] *[style*="#ffffff"] {
background-color: var(--bg) !important;
}
/* Fix link colors in dark mode */
[data-theme="dark"] a[style*="#3b82f6"] {
color: #60a5fa !important;
}
`)}
</style>
</head>
<body>
<button class="dark-mode-toggle" onclick="toggleDarkMode()">
<span class="icon">🌙</span>
</button>
<div class="page-title">
{showHomeLink && (
<a href="/" class="home-link">
<span>🏠</span>
</a>
)}
{title}
</div>
{children}
<script>
{raw(`
const getTheme = () =>
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ?
'dark' :
'light'
const theme = getTheme()
document.documentElement.setAttribute('data-theme', theme)
updateToggleButton(theme)
if (window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
const newTheme = e.matches ? 'dark' : 'light'
document.documentElement.setAttribute('data-theme', newTheme)
updateToggleButton(newTheme)
})
}
function toggleDarkMode() {
const current = document.documentElement.getAttribute('data-theme')
const newTheme = current === 'dark' ? 'light' : 'dark'
document.documentElement.setAttribute('data-theme', newTheme)
updateToggleButton(newTheme)
}
function updateToggleButton(theme) {
const button = document.querySelector('.dark-mode-toggle')
const icon = button.querySelector('.icon')
const label = button.querySelector('.label')
if (theme === 'dark') {
icon.textContent = '☀️';
} else {
icon.textContent = '🌙';
}
}
`)}
</script>
</body>
</html>
)
}