// Tabs whose state is a Datastar signal. createTabs() makes a set for one signal and the tab it
// starts on, so the page is rendered showing that tab, and Datastar switches tabs from there:
//
// const { Tabs, TabsList, TabsTrigger, TabsContent } = createTabs('plan', 'monthly')
//
//
//
// Monthly
// Yearly
//
// …
// …
//
//
// $plan is the open tab's value, for the rest of the page to read or set.
import type { Child, Html } from '../lib/jsx/jsx-runtime.ts'
import css from './tabs.css' with { type: 'text' }
export const TABS_CSS = css
type Props = Record & { children?: Child }
export function createTabs(signal: string, defaultValue: string) {
let id = (part: string, value: string) => `${signal}-${part}-${value}`
let is = (value: string) => `$${signal} === ${JSON.stringify(value)}`
function Tabs(props: Props): Html {
let { children, ...attributes } = props
return (
{children}
)
}
function TabsList(props: Props): Html {
let { children, ...attributes } = props
return (
{children}
)
}
function TabsTrigger(props: Props & { value: string }): Html {
let { value, children, ...attributes } = props
return (
)
}
function TabsContent(props: Props & { value: string }): Html {
let { value, children, ...attributes } = props
return (