mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-21 03:15:19 +00:00
The site drew its fences, example sources and module types through @hanzogui/code-to-html (refractor) and coloured the tokens from its own stylesheet. code.ts now highlights them at build with shiki in codeTheme from @hanzo/ui/core, Dracula on dark and GitHub Light on light, the same theme docs.hanzo.ai, hanzo.ai and platform draw. Tokens and the block's ground are written as light-dark(), so the scheme on <html> picks the palette; the .code token rules and code-to-html are gone, and nothing highlights in the browser. The CodeBlock example names codeTheme.dark rather than github-dark. The navigation menu example stops importing navigationMenuTriggerStyle, which 8.27.45 removed and which failed the site build.
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { YStack } from "@hanzo/gui"
|
|
import { CodeBlock, codeTheme } from "@hanzo/ui"
|
|
|
|
const FIBONACCI = `function fibonacci(n) {
|
|
if (n <= 1) {
|
|
return n
|
|
}
|
|
return fibonacci(n - 1) + fibonacci(n - 2)
|
|
}
|
|
|
|
const result = fibonacci(10)
|
|
console.log(result) // 55`
|
|
|
|
const CALCULATOR = `function calculateTotal(items) {
|
|
let total = 0
|
|
for (const item of items) {
|
|
total += item.price
|
|
}
|
|
if (total > 100) {
|
|
total *= 0.9 // 10% discount
|
|
}
|
|
return total
|
|
}`
|
|
|
|
/** Default — a filename, a language badge, line numbers, and a copy button that confirms itself for two seconds. */
|
|
export function Default() {
|
|
return (
|
|
<CodeBlock
|
|
code={FIBONACCI}
|
|
language="javascript"
|
|
filename="fibonacci.js"
|
|
highlightLines={[5]}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Diff — added and removed lines each carry their own sign and left-edge color, independent of the highlighted range. */
|
|
export function Diff() {
|
|
return (
|
|
<CodeBlock
|
|
code={CALCULATOR}
|
|
language="javascript"
|
|
filename="calculator.js"
|
|
theme={codeTheme.dark}
|
|
diff={{ added: [5, 6], removed: [3] }}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Themes — eight named syntax palettes, each a fixed color quartet independent of the surrounding page's own theme. */
|
|
export function Themes() {
|
|
const sample = `const greeting = "Hello, World!"\nconsole.log(greeting)`
|
|
return (
|
|
<YStack gap="$4">
|
|
<CodeBlock code={sample} language="javascript" theme="light" showLineNumbers={false} />
|
|
<CodeBlock code={sample} language="javascript" theme="dracula" showLineNumbers={false} />
|
|
<CodeBlock code={sample} language="javascript" theme="nord" showLineNumbers={false} />
|
|
</YStack>
|
|
)
|
|
}
|
|
|
|
/** Bare — no filename, no language and no copy button, so the header is dropped and only the numbered code remains. */
|
|
export function Bare() {
|
|
return (
|
|
<CodeBlock
|
|
code={FIBONACCI}
|
|
language=""
|
|
showCopyButton={false}
|
|
size="sm"
|
|
maxHeight={160}
|
|
/>
|
|
)
|
|
}
|