Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/app-starter

A basic TanStack app with a design system, light and dark, sign-in, and storage already wired up.

FollowFork

Files

ui.tsx

48 lines · 1.4 KB · TypeScript
import type { ButtonHTMLAttributes, InputHTMLAttributes, ReactNode } from 'react'
import { useId } from 'react'

export function Button({
	variant = 'secondary',
	...props
}: ButtonHTMLAttributes<HTMLButtonElement> & { variant?: 'primary' | 'secondary' }) {
	return <button className="button" data-variant={variant} {...props} />
}

/** A text input that always has a visible label tied to it. */
export function TextField({
	label,
	...props
}: InputHTMLAttributes<HTMLInputElement> & { label: string }) {
	const id = useId()
	return (
		<div className="field">
			<label htmlFor={id}>{label}</label>
			<input id={id} {...props} />
		</div>
	)
}

export function Alert(props: { title: string; children?: ReactNode }) {
	return (
		<div className="alert" role="alert">
			<strong>{props.title}</strong>
			{props.children ? <div>{props.children}</div> : null}
		</div>
	)
}

/** Placeholder rows shown while data loads, announced to screen readers. */
export function LoadingRows(props: { label: string; rows?: number }) {
	return (
		<div role="status" aria-live="polite" style={{ display: 'grid', gap: 8 }}>
			<span className="visually-hidden">{props.label}</span>
			{Array.from({ length: props.rows ?? 3 }, (_, index) => (
				<div key={index} className="skeleton" aria-hidden="true" />
			))}
		</div>
	)
}

export function EmptyState(props: { children: ReactNode }) {
	return <p className="muted">{props.children}</p>
}