Develop
Using ketjs-view
Server rendering, static sites and islands with Faifo Design.
Every component is a function that returns a ketjs-view TemplateResult. Where that template
is rendered decides how much JavaScript a page needs.
#Server-rendered pages
Render a view to a string on the server and send it. The components produce complete, semantic HTML, so the page is usable as it arrives:
import { renderToString } from '@ketvietlab/ketjs-view'
import { DataTable, ListPage } from 'faifo-design'
type Order = { id: string; customer: string; total: string }
export const ordersPage = (orders: Order[]) =>
renderToString(
<div data-faifo-design>
<ListPage
title="Orders"
body={
<DataTable
rows={orders}
id={(order) => order.id}
columns={[
{ key: 'id', label: 'Order', cell: (order) => order.id },
{ key: 'customer', label: 'Customer', cell: (order) => order.customer },
{ key: 'total', label: 'Total', align: 'end', cell: (order) => order.total },
]}
/>
}
/>
</div>,
)State that a reader can link to belongs in the URL: a filter, a sort, a page, a tab. The
collection controls build those URLs with withQueryState, which preserves the query state a
control does not own.
#Static sites
A static site is the same views rendered at build time by @ketvietlab/ketjs-view-tools. This
documentation is built that way:
// File: ket-view.config.ts
import { defineConfig } from '@ketvietlab/ketjs-view-tools'
export default defineConfig({
pages: 'pages',
styles: ['site/styles.css'],
islands: { 'site-app': 'site/app.tsx' },
base: '/',
})// File: pages/index.tsx
import { definePage } from '@ketvietlab/ketjs-view-tools'
import { EmptyState } from 'faifo-design'
export default definePage({
head: { title: 'Orders' },
view: () => (
<main data-faifo-design>
<EmptyState visual="start" title="No orders yet" message="Create the first order to see it here." />
</main>
),
})ket-view build writes plain HTML for every page and bundles the stylesheet with its fonts.
Add the runtime with a head.scripts entry so server-rendered components get their behaviour.
#Islands
An island is a part of the page that keeps state in the browser. The design system ships a few whose behaviour cannot be a progressive enhancement:
| Island | Factory | What it owns |
|---|---|---|
| Editable grid | faifoGrid | Cell editing, keyboard movement, paste, validation |
| Collection table | faifoTable | Selection across pages, sorting, grouping, paging |
| Search filter | searchFilter | The query, filter rules, grouping, saved searches |
| Relation select | relationSelect | Search as you type, create in place |
| Lightbox | lightbox | Zoom, pan, pinch and paging over a set of pictures |
Register the factory with the island system your host uses, under a name of your choice, and
render it with the matching create…View function or the component of the same family. In a
ket-view static site that is an entry in islands and a call to island():
import { island } from '@ketvietlab/ketjs-view-tools'
import { faifoGrid, type FaifoGridIslandConfig } from 'faifo-design'
export const Lines = (props: { config: FaifoGridIslandConfig }) =>
island('order-lines', faifoGrid, { id: 'order-lines', config: props.config }, { key: ['id'] })An island that renders design-system markup of its own calls
attachDesignSystemInteractions(root) on its element when it mounts and disposes it when it
unmounts, so menus and pickers inside the island behave as they do on the rest of the page.
#Fragments and navigation
When the host is a KetJS server, page patterns cooperate with its fragment navigation: they mark
the slots a navigation replaces (data-ket-slot), and a link that must load a whole new document
opts out with data-ket-reload. Those attributes and the ket:navigation-* events belong to the
framework and keep its spelling. A static site ignores them.