forge/examples/ssr/helpers.tsx
2025-12-29 12:21:44 -08:00

110 lines
2.6 KiB
TypeScript

import { define, Styles } from '../../src'
export const Body = define('Body', {
base: 'body',
margin: 0,
padding: '40px 20px',
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
background: '#f3f4f6',
})
const Container = define('Container', {
maxWidth: 1200,
margin: '0 auto'
})
export const Header = define('Header', {
base: 'h1',
marginBottom: 40,
color: '#111827'
})
export const ExampleSection = define('ExampleSection', {
marginBottom: 40,
parts: {
Header: {
base: 'h2',
marginBottom: 16,
color: '#374151',
fontSize: 18
}
},
render({ props, parts: { Root, Header } }) {
return (
<Root>
<Header>{props.title}</Header>
{props.children}
</Root>
)
}
})
const Nav = define('SSR_Nav', {
base: 'nav',
display: 'flex',
gap: 20,
marginBottom: 40,
padding: 20,
background: 'white',
borderRadius: 8,
boxShadow: '0 1px 3px rgba(0,0,0,0.1)'
})
const NavLink = define('SSR_NavLink', {
base: 'a',
color: '#3b82f6',
textDecoration: 'none',
fontWeight: 500,
states: {
hover: {
textDecoration: 'underline'
}
},
selectors: {
'&[aria-current]': {
color: '#1e40af',
fontWeight: 600,
textDecoration: 'underline'
}
}
})
export const Layout = define({
render({ props }) {
const path = props.path || ''
return (
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{props.title}</title>
<link rel="stylesheet" href="/main.css" />
</head>
<Body>
<Container>
<Nav>
<NavLink href="/" aria-current={path === '/' ? 'page' : undefined}>Home</NavLink>
<NavLink href="/ssr" aria-current={path.startsWith('/ssr') && path !== '/ssr/profile' && path !== '/ssr/buttons' && path !== '/ssr/navigation' ? 'page' : undefined}>SSR Examples</NavLink>
<NavLink href="/ssr/profile" aria-current={path === '/ssr/profile' ? 'page' : undefined}>Profile</NavLink>
<NavLink href="/ssr/buttons" aria-current={path === '/ssr/buttons' ? 'page' : undefined}>Buttons</NavLink>
<NavLink href="/ssr/navigation" aria-current={path === '/ssr/navigation' ? 'page' : undefined}>Navigation</NavLink>
<NavLink href="/ssr/form" aria-current={path === '/ssr/form' ? 'page' : undefined}>Forms</NavLink>
</Nav>
<Header>{props.title}</Header>
{props.children}
</Container>
</Body>
</html>
)
}
})