um/README.md

86 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

2024-05-06 01:22:15 +00:00
# Um
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
> Minimal JavaScript UI Builder
2024-05-05 00:34:27 +00:00
2024-05-06 01:22:15 +00:00
Um, is an experimental composable UI builder that takes ideas from early [hyperapp](https://github.com/jorgebucaran/hyperapp) design, but does not stick to strict Elm Architecture.
2024-05-22 16:34:59 +00:00
Um, because you should think about, um, NOT using it.
2024-05-05 00:34:27 +00:00
## Features
- Real DOM
- [Non-destructive (re)Rendering](https://github.com/bryhoyt/emerj)
2024-05-05 00:34:27 +00:00
- No Build System
- No Over Engineering
- ~2kb minified
2024-05-05 00:34:27 +00:00
2024-05-22 17:31:20 +00:00
## Install
Via JSDelivr CDN
```js
import {app,h} from "https://cdn.jsdelivr.net/gh/n2geoff/um/dist/um.min.js";
```
2024-05-05 00:34:27 +00:00
## Overview
2024-05-22 16:34:59 +00:00
**Um** only has 2 exported functions, `app()` and `h()`, and the later is optional.
2024-05-05 00:34:27 +00:00
2024-05-06 01:22:15 +00:00
### app({opts})
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
The `app()` is the builder function and takes an `opts` object:
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
#### Input:
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
| Property | Default | Description |
| --------- | -------------------------- | ----------------------------------------------------------- |
| `state` | `{}` | initial data state |
| `actions` | `{}` | function object passed to view |
| `view` | `(state, actions) => null` | function that takes state and actions and returns valid dom |
2024-05-22 16:34:59 +00:00
| `mount` | `body` | valid query selector as mounting point |
2024-05-05 14:27:14 +00:00
#### Output:
2024-05-22 17:11:40 +00:00
Interface with internal state for utility expansion
2024-05-22 16:34:59 +00:00
2024-05-05 19:05:16 +00:00
| Property | Description |
| --------------- | --------------------------------------------- |
2024-05-22 17:11:40 +00:00
| `state` | internal state object |
| `update()` | function to render dom state |
2024-05-05 14:27:14 +00:00
### h(tag, [...args])
2024-05-22 16:34:59 +00:00
The `h()` is an **optional** hypertext build utility that weighs in around **~250b** and is provided as *a* way to build out your `view` DOM, but you can build your `view` using any method you like as long as it returns valid DOM.
2024-05-05 14:27:14 +00:00
## Example
2024-05-05 00:34:27 +00:00
```html
<script type="module">
2024-05-06 01:22:15 +00:00
import {app, h} from "./um.min.js";
2024-05-05 00:34:27 +00:00
const myapp = app({
state: {name: "[Your Name Here]", job: "Developer"},
view(state, actions) {
2024-05-05 00:34:27 +00:00
return h("main", [
h("strong", `Greeting from ${state.name}`),
h("div", `Your local ${state.job}`),
h("div", {id: "test"}, [
2024-05-06 01:22:15 +00:00
h("h1", "Um, Hello"),
2024-05-05 00:34:27 +00:00
h("p", 21),
h("hr")
])
]);
}
2024-05-05 14:27:14 +00:00
});
2024-05-05 00:34:27 +00:00
</script>
```
2024-05-05 13:07:17 +00:00
## Notes
2024-05-05 00:34:27 +00:00
2024-05-05 19:05:16 +00:00
> WORK-IN-PROGRESS
2024-05-22 15:06:33 +00:00
### TODO
- Some tag attributes do not work, like rowspan on td
- Rethink State Management, might be ok