-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (40 loc) · 1.89 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {a, br, button, code, details, div, h1, i, li, p, span, summary, Tag, ul, useState} from './lib/naked.js'
import {Line} from "./line.js" // import a component
let items = ['foo', 'bar', 'baz']
export let App = Tag(({}) => {
// use hooks, see https://reactjs.org/docs/hooks-intro.html
let [count, setCount] = useState(0)
let rawItemArray = ['...and inline primitive arrays: ', ...items.map(x => ' ' + x)]
return div(
// naked <h1><i>p</i>react ...
h1`naked ${i`p`}react`,
span`Web development should be simple. Uses (p)react+hooks, ES2021, no compilers.`,
p`Wrap components with Tag(), forget JSX. See ${code`index.html`} and ${code`app.js`} for examples.`,
"The rest of this file is self-documenting. Preact devtools work as expected, too.",
// tag with props as optional first parameter
details({open: false, style: {background: '#dee'}},
summary("if you don't have props you can still always stick to the call-like syntax"),
Line(), // equivalent to Line`` or <Line /> in JSX
ul(items.map(item => li(item))),
// components can return VNode[] as well
InlineArray({prefix: "array item"})
),
"some buttons for dynamic stuff:",
button({onClick: _ => setCount(++count)}, `increment ${count}`),
button({onClick: _ => setCount(0)}, 'reset'),
p("you can use plain JS primitives for 1: text ", 2, ": numbers",br``,
// as well as arrays, no need for React.Fragment or <> ... </>
rawItemArray),
Line``,
Author``
)
// optional name for devtools if anonymous functions are used
}, 'App')
// names from named functions are preserved
export let InlineArray = Tag(function InlineArray({prefix}) {
return items.map(item => p`${prefix} ${item}`)
})
export let Author = Tag(() => [
a({href:'https://github.com/wizzard0/naked-preact'},'naked-preact@github'),", by ",
a({href:'[email protected]'},'[email protected]'),
])