add pico, pico + reset to default layout

This commit is contained in:
Chris Wanstrath 2025-11-29 14:14:17 -08:00
parent 275527e30e
commit ebcce8dea1
4 changed files with 57 additions and 8 deletions

View File

@ -10,12 +10,16 @@
░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░
░▒▓███████████████████████████████████████████████▓▒░
`hype` wraps `hono` with useful defaults:
`hype` wraps `hono` with useful features for fast prototyping:
- HTTP logging (disable with `NO_HTTP_LOG` env variable)
- Static files served from `pub/`
- Page-based routing to `.tsx` files that export a `JSX` function in `./src/pages`
- Transpile `.ts` files in `src/js/blah.ts` via `website.com/js/blah.ts`
- Helpers like `css` and `js` template tags.
- Default, simple HTML5 layout with working frontend transpilation/bundling, or supply your own.
- Optional CSS reset.
- Optional pico.css.
## Overview
@ -60,6 +64,9 @@ To put a file in `./src/pages` but prevent it from being server, preface it with
`hype` will wrap everything in a simple default layout unless `./src/pages/_layout.tsx` exists,
in which case it'll use the default export in that file.
Using the default layout, you can put TS in `./src/js/main.ts` and css in `./src/css/main.css`
and they'll automatically work in your app.
Here's a starting point:
```tsx
@ -80,6 +87,22 @@ export default ({ children, title }: any) => (
)
```
### pico.css
To use pico.css with the default layout, create `Hype` with `{ pico: true }`:
`````typescript
import { Hype } from 'hype'
const app = new Hype({ pico: true })
```
You can also use pico in your custom layouts:
```html
<link href="/css/pico.css" rel="stylesheet" />
```
### css
CSS can be accessed via `/css/main.css`:
@ -107,7 +130,15 @@ export default () => (
### css reset
`hype` includes a css reset for your convenience:
To use reset.css with the default layout, create `Hype` with `{ reset: true }`:
````typescript
import { Hype } from 'hype'
const app = new Hype({ reset: true })
You can also use the css reset in your custom layouts:
```html
<link href="/css/reset.css" rel="stylesheet" />
@ -233,3 +264,4 @@ export default app.defaults
bun install
bun test
```
`````

View File

@ -9,14 +9,23 @@ import defaultLayout from './layout'
const SHOW_HTTP_LOG = true
const CSS_RESET = await Bun.file(join(import.meta.dir, '/reset.css')).text()
const PICO_CSS = await Bun.file(join(import.meta.dir, '/pico.css')).text()
export * from './utils'
export type HypeProps = {
pico?: boolean
reset?: boolean
}
export class Hype extends Hono {
routesRegistered = false
props: HypeProps = {}
constructor() {
constructor(props?: HypeProps) {
super()
if (props) this.props = props
}
registerRoutes() {
@ -55,9 +64,10 @@ export class Hype extends Hono {
}
// css reset
this.get('/css/reset.css', async c => new Response(CSS_RESET, {
headers: { 'Content-Type': 'text/css' }
}))
this.get('/css/reset.css', async c => new Response(CSS_RESET, { headers: { 'Content-Type': 'text/css' } }))
// pico
this.get('/css/pico.css', async c => new Response(PICO_CSS, { headers: { 'Content-Type': 'text/css' } }))
// serve transpiled js
this.on('GET', ['/js/:path{.+}', '/shared/:path{.+}'], async c => {
@ -93,7 +103,7 @@ export class Hype extends Hono {
const page = await import(path + `?t=${Date.now()}`)
const innerHTML = typeof page.default === 'function' ? <page.default req={c.req} /> : page.default
const withLayout = Layout ? <Layout>{innerHTML}</Layout> : innerHTML
const withLayout = Layout ? <Layout props={this.props}>{innerHTML}</Layout> : innerHTML
return c.html(withLayout)
})
}

View File

@ -1,12 +1,15 @@
import { type FC } from 'hono/jsx'
const Layout: FC = ({ children, title }) =>
const Layout: FC = ({ children, title, props }) =>
<html lang="en">
<head>
<title>{title ?? 'hype'}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
{props.reset && <link href="/css/reset.css" rel="stylesheet" />}
{props.pico && <link href="/css/pico.css" rel="stylesheet" />}
<link href="/css/main.css" rel="stylesheet" />
<script src="/js/main.ts" type="module"></script>
</head>

4
src/pico.css Normal file

File diff suppressed because one or more lines are too long