-
Notifications
You must be signed in to change notification settings - Fork 579
/
Copy pathone-component.lite.tsx
62 lines (54 loc) · 1.29 KB
/
one-component.lite.tsx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { useStore } from '@builder.io/mitosis';
export interface State {
list: string[];
newItemName: string;
setItemName: any;
addItem: any;
}
export default function OneComponent(props: any) {
const state = useStore<State>({
list: ['hello', 'world'],
newItemName: 'New item',
setItemName(event: any) {
state.newItemName = (event.target as any).value;
},
addItem() {
state.list = [...state.list, state.newItemName];
},
});
return (
<div
css={{
padding: '10px',
}}
>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
<input
class="shadow-md rounded w-full px-4 py-2"
value={state.newItemName}
onChange={(event) => state.setItemName(event)}
/>
<button
class="bg-blue-500 rounded w-full text-white font-bold py-2 px-4"
css={{
margin: '10px 0',
}}
onClick={() => state.addItem()}
>
Add list item
</button>
<ul class="shadow-md rounded">
{state.list.map((item) => (
<li
class="border-gray-200 border-b"
css={{
padding: '10px',
}}
>
{item}
</li>
))}
</ul>
</div>
);
}