feat: component library, validation and Shell layout #2
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/components"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds three things to the fork, each with its own commit:
@garage44/mithril/componentsandcomponents.css: form fields and elements that all take their state as amodelsignal, with a light/dark theme built onlight-dark()tokens and Bun's CSS bundling.@garage44/mithril/validation:validation($signal, [rules]), chainable, gathered into a$vgroup with$valid/$validate(); fields take it as avalidationprop.Shell,NavGroup,NavItem: nav, main and context panels on one grid that responds to its own width through container queries.A sandbox in
examples/componentsshows all of it (bun run dev). Notes indocs/notes/components.mdanddocs/notes/validation.md.bun run lintandbun test(997 pass) are green. Rendered in headless Chrome only.`@garage44/mithril/validation`: `validation($signal, [required, email])` holds one model's rules and chains more (`.minLength(3).maxLength(20)`); `validations({...})` gathers a form's into `$v`, whose `$valid`, `$validate()`, `$reset()` and `$errors` act on all of them. Rules: required, email, url, minLength, maxLength, min, max, integer, pattern, oneOf, matches, minItems, maxItems and check, with replaceable default messages. Every field takes an entry as its `validation` prop, which replaces the `validate` callback added with the components: whether a field was touched now lives on the validation as a signal, so `$v.$validate()` at submit can show every field's error at once, and a submit button bound to `$v.$valid` redraws as the form fills in. A `required` rule marks the field required. Nothing is cached: an error is recomputed on each read, which is what makes a view reading `$valid` subscribe to every model, including the other model a `matches` rule reads. Chained methods are typed by value, so `.email()` on a number model is a compile error. Lengths count graphemes rather than code points, so an emoji is one character. The sandbox gains a sign-up form; docs/notes/validation.md has the rest.