Skip to content

Commit d51656c

Browse files
release: v0.1.0-dev.978 from ziex-dev/ziex
0 parents  commit d51656c

17 files changed

Lines changed: 449 additions & 0 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto eol=lf
2+
# Make .zx files be treated as .zig files on GitHub for syntax highlighting
3+
*.zx text eol=lf linguist-language=Zig

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.zig-cache/
2+
zig-out/
3+
node_modules/

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025 Nurul Huda (Apon).
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Ziex App with Node Package Managers
2+
3+
>This is a starter template for building web applications with [Ziex](https://ziex.dev), a full-stack web framework for Zig.
4+
5+
This project can be used without having to installe Zig or Ziex globally, it works with any Node package manager (npm, yarn, pnpm, bun, etc).
6+
7+
**[Documentation →](https://ziex.dev)**
8+
9+
10+
## Install Dependencies
11+
12+
You can use `bun`/`npm`/`yarn`/`pnpm` or any other Node package manager, the following guides uses Bun as an example.
13+
14+
15+
```bash
16+
bun install
17+
```
18+
19+
## Usage
20+
21+
### Development
22+
```bash
23+
bun dev
24+
```
25+
App will be available at [`http://localhost:3000`](http://localhost:3000). with hot reload enabled.
26+
27+
### Serve Production Build
28+
```bash
29+
bun serve
30+
```
31+
32+
### Exporting as Static Site
33+
```bash
34+
bun export
35+
```
36+
This will create a `dist/` directory with the static export of your app. You can deploy the contents of `dist/` to any static hosting provider (Netlify, Vercel, GitHub Pages, etc) or serve it with any static file server.
37+
38+
### Deployment
39+
40+
```bash
41+
bun bundle
42+
```
43+
44+
This will create a `bundle/` directory with the binary and static assets needed to run your app. You can deploy the contents of `bundle/` to any VPS.
45+
46+
47+
### [ZX CLI](https://ziex.dev/reference#cli) Commands
48+
```bash
49+
bun zx [command] [options]
50+
```
51+
52+
All ZX CLI commands are available under `bun zx [command]`. For example, to run auto formatter:
53+
```bash
54+
bun zx fmt .
55+
```
56+
57+
## Contributing
58+
59+
Contributions are welcome! Feel free to open issues or pull requests. For feature requests, bug reports, or questions, see the [Ziex Repo](https://github.com/ziex-dev/ziex).
60+
61+
## Links
62+
63+
- [Documentation](https://ziex.dev)
64+
- [Discord](https://ziex.dev/r/discord)
65+
- [Topic on Ziggit](https://ziex.dev/r/ziggit)
66+
- [Project on Zig Discord Community](https://ziex.dev/r/zig-discord) (Join Zig Discord first: https://discord.gg/zig)
67+
- [GitHub](https://github.com/nurulhudaapon/ziex)
68+
- [Zig Language](https://ziglang.org/)

app/assets/style.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
body {
2+
margin: 0;
3+
font-family: sans-serif;
4+
font-size: 1.4rem;
5+
line-height: 1.6;
6+
color: white;
7+
background-color: black;
8+
display: flex;
9+
flex-direction: column;
10+
align-items: center;
11+
justify-content: center;
12+
text-align: center;
13+
height: 100vh;
14+
}
15+
16+
a {
17+
color: #ffffff;
18+
font-size: 1rem;
19+
text-decoration: none;
20+
}
21+
22+
button {
23+
padding: 2px;
24+
min-width: 100px;
25+
font-size: 0.8rem;
26+
border-radius: 5px;
27+
margin: 3px;
28+
border: 1px solid #ffffff;
29+
background-color: transparent;
30+
color: #ffffff;
31+
cursor: pointer;
32+
transition: all 0.3s ease;
33+
&:hover {
34+
background-color: #ffffff;
35+
color: #000000;
36+
}
37+
}
38+
39+
.counter-row {
40+
height: 150px;
41+
margin: 10px;
42+
display: flex;
43+
gap: 20px;
44+
justify-content: center;
45+
align-items: center;
46+
}
47+
48+
.counter-row > * {
49+
min-width: 150px;
50+
}
51+
52+
.counter-plus {
53+
width: 70px;
54+
display: inline-block;
55+
}
56+
57+
.link-row {
58+
display: flex;
59+
gap: 10px;
60+
justify-content: center;
61+
align-items: center;
62+
margin: 20px;
63+
}

app/main.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const std = @import("std");
2+
const zx = @import("zx");
3+
4+
pub fn main() !void {
5+
if (zx.platform == .browser) return zx.Client.run();
6+
if (zx.platform == .edge) return zx.Edge.run();
7+
8+
var gpa = std.heap.DebugAllocator(.{}){};
9+
const allocator = gpa.allocator();
10+
defer _ = gpa.deinit();
11+
12+
const app = try zx.Server(void).init(allocator, .{}, {});
13+
defer app.deinit();
14+
15+
app.info();
16+
try app.start();
17+
}
18+
19+
pub const std_options = zx.std_options;

app/pages/actions/client/page.zx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pub fn Page(ctx: zx.PageContext) zx.Component {
2+
return (
3+
<main @allocator={ctx.arena}>
4+
<EventForm @rendering={.client} />
5+
</main>
6+
);
7+
}
8+
9+
pub fn EventForm(ctx: *zx.ComponentContext) zx.Component {
10+
const count = ctx.state(i32, 1);
11+
return (
12+
<button onclick={ctx.bind(onclick)}>
13+
Click Me {count}
14+
</button>
15+
);
16+
}
17+
18+
fn onclick(e: *zx.client.Event.Stateful) void {
19+
const c = e.state(i32);
20+
c.set(c.get() + 1);
21+
zx.log.info("Count> {d}. \n", .{c.get()});
22+
}
23+
24+
pub const options: zx.PageOptions = .{
25+
.methods = &.{ .GET, .POST },
26+
};
27+
28+
const zx = @import("zx");

app/pages/actions/page.zx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pub fn Page(ctx: zx.PageContext) zx.Component {
2+
return (
3+
<main @allocator={ctx.arena}>
4+
<LoginForm @rendering={.client} name="Ziex Client" />
5+
<LoginForm name="Ziex Server" />
6+
</main>
7+
);
8+
}
9+
10+
const LoginInput = struct { name: []const u8, id: i32 = 123 };
11+
pub fn LoginForm(ctx: *zx.ComponentCtx(LoginInput)) zx.Component {
12+
return (
13+
<form @allocator={ctx.allocator} action={handleLogin}>
14+
<input name="name" value={ctx.props.name} />
15+
<input name="id" value={ctx.props.id} />
16+
17+
<button>Submit</button>
18+
</form>
19+
);
20+
}
21+
22+
fn handleLogin(data: LoginInput) void {
23+
zx.log.info("\n\nName: {s}\nID: {d}\n", .{ data.name, data.id });
24+
}
25+
26+
pub const options: zx.PageOptions = .{
27+
.methods = &.{.POST},
28+
};
29+
30+
const zx = @import("zx");

app/pages/actions/server/page.zx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pub fn Page(ctx: zx.PageContext) zx.Component {
2+
return (
3+
<main @allocator={ctx.arena}>
4+
<EventForm @rendering={.client} />
5+
</main>
6+
);
7+
}
8+
9+
pub fn EventForm(ctx: *zx.ComponentContext) zx.Component {
10+
const count = ctx.state(i32, 1);
11+
return (
12+
<button onclick={ctx.bind(onclick)}>
13+
Click Me {count}
14+
</button>
15+
);
16+
}
17+
18+
fn onclick(e: *zx.server.Event.Stateful) void {
19+
const c = e.state(i32);
20+
c.set(c.get() + 1);
21+
zx.log.info("Count> {d}. \n", .{c.get()});
22+
}
23+
24+
pub const options: zx.PageOptions = .{
25+
.methods = &.{ .GET, .POST },
26+
};
27+
28+
const zx = @import("zx");

app/pages/client.zx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var count: *zx.State(i128) = undefined;
2+
3+
pub fn CounterComponent(ctx: *zx.ComponentCtx(struct { count: i128 })) zx.Component {
4+
count = ctx.state(i128, ctx.props.count);
5+
6+
return (
7+
<div @allocator={ctx.allocator}>
8+
<button onclick={reset}>Reset</button>
9+
<h5>{&count}</h5>
10+
<button onclick={decrement}>Decrement</button>
11+
<button onclick={increment}>Increment</button>
12+
</div>
13+
);
14+
}
15+
16+
fn increment() void {
17+
count.set(count.get() + 1);
18+
fetch("?increment=true");
19+
}
20+
21+
fn decrement() void {
22+
count.set(count.get() - 1);
23+
fetch("?decrement=true");
24+
}
25+
26+
fn reset(_: zx.client.Event) void {
27+
count.set(0);
28+
fetch("?reset=true");
29+
}
30+
31+
fn fetch(url: []const u8) void {
32+
_ = zx.fetch(.noop, zx.client_allocator, url, .{}) catch {};
33+
}
34+
35+
const zx = @import("zx");

0 commit comments

Comments
 (0)