Skip to content

Commit 6afa70d

Browse files
committed
feat(demo): state
1 parent 0fa74bf commit 6afa70d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

demo/state/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en" class="color-scheme-auto bg-background font-vazirmatn">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Gecut Snack Bar</title>
7+
<link rel="icon" href="/favicon.ico" sizes="any" />
8+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
9+
<link rel="manifest" href="/manifest.json" />
10+
<script type="module" src="../main/global.ts"></script>
11+
<script type="module" src="./scripts.ts"></script>
12+
</head>
13+
<body class="bg-surface max-w-screen-sm mx-auto p-4"></body>
14+
</html>

demo/state/scripts.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {GecutState} from '@gecut/lit-helper';
2+
import {render, html} from 'lit/html.js';
3+
4+
const str = new GecutState('string', '');
5+
const num = new GecutState('number', 0);
6+
const bool = new GecutState('boolean', false);
7+
8+
render(
9+
html`
10+
<div class="mx-auto max-w-sm flex flex-col gap-4 relative h-full w-full">
11+
<ol class="*:cursor-pointer *:select-none">
12+
<li @click=${() => (str.value += 'Hello ')}>String: ${str.hydrate((data) => data)}</li>
13+
<li @click=${() => (num.value = (num.value ?? 0) + 1_000)}>
14+
Number: ${num.hydrate((data) => data.toLocaleString('Fa-Ir'))}
15+
</li>
16+
<li @click=${() => (bool.value = !bool.value)}>Boolean: ${bool.hydrate((data) => JSON.stringify(data))}</li>
17+
</ol>
18+
</div>
19+
`,
20+
document.body,
21+
);

0 commit comments

Comments
 (0)