feat: upgrade init starter app to showcase all DreamStack features
- Imports Card, Badge, Button from components/ - Counter with callback props, Greeting with when/else - Mood match expression with Badge, Todo dynamic lists - Full init → build flow verified (51,401 bytes, 0 errors)
This commit is contained in:
parent
9d01f1b702
commit
f63ff52e2a
1 changed files with 52 additions and 20 deletions
|
|
@ -1358,40 +1358,72 @@ fn cmd_init(name: Option<String>) {
|
||||||
|
|
||||||
// Write starter app.ds
|
// Write starter app.ds
|
||||||
let app_source = r#"-- My DreamStack App
|
let app_source = r#"-- My DreamStack App
|
||||||
|
-- Showcases: imports, components, when/else, match, each, dynamic lists
|
||||||
|
|
||||||
|
import { Card } from "./components/card"
|
||||||
|
import { Badge } from "./components/badge"
|
||||||
|
import { Button } from "./components/button"
|
||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
let name = ""
|
let name = ""
|
||||||
|
let darkMode = false
|
||||||
|
let mood = "happy"
|
||||||
|
let todos = ["Learn DreamStack", "Build something cool"]
|
||||||
|
let newTodo = ""
|
||||||
|
|
||||||
view main = column [
|
view main = column [
|
||||||
|
|
||||||
-- Header
|
-- Header
|
||||||
text "🚀 My App" { variant: "title" }
|
text "🚀 My DreamStack App" { variant: "title" }
|
||||||
text "Built with DreamStack" { variant: "subtitle" }
|
text "Built with DreamStack — edit app.ds and reload" { variant: "subtitle" }
|
||||||
|
|
||||||
-- Stats
|
-- Dashboard cards
|
||||||
row [
|
row [
|
||||||
column [
|
Card { title: "Counter", subtitle: "reactive state" } [
|
||||||
text "Users" { variant: "subtitle" }
|
text "Count: {count}" { variant: "title" }
|
||||||
text "1,247" { variant: "title" }
|
row [
|
||||||
] { variant: "card" }
|
Button { label: "+1", onClick: count += 1, variant: "primary" }
|
||||||
|
Button { label: "-1", onClick: count -= 1, variant: "secondary" }
|
||||||
column [
|
Button { label: "Reset", onClick: count = 0, variant: "ghost" }
|
||||||
text "Revenue" { variant: "subtitle" }
|
]
|
||||||
text "$8,420" { variant: "title" }
|
|
||||||
] { variant: "card" }
|
|
||||||
]
|
]
|
||||||
|
|
||||||
-- Input
|
Card { title: "Greeting", subtitle: "two-way binding" } [
|
||||||
text "Your name" { variant: "label" }
|
input { bind: name, placeholder: "Your name..." }
|
||||||
input { bind: name, placeholder: "Type here..." }
|
when name -> text "Hello, {name}! 👋"
|
||||||
text "Hello, {name}!"
|
else -> text "Type your name above"
|
||||||
|
|
||||||
-- Counter
|
|
||||||
row [
|
|
||||||
button "Count: {count}" { click: count += 1, variant: "primary" }
|
|
||||||
button "Reset" { click: count = 0, variant: "ghost" }
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- Mood selector with match
|
||||||
|
Card { title: "Mood", subtitle: "match expressions" } [
|
||||||
|
row [
|
||||||
|
button "😊 Happy" { click: mood = "happy", variant: "primary" }
|
||||||
|
button "😢 Sad" { click: mood = "sad", variant: "secondary" }
|
||||||
|
button "🔥 Fired up" { click: mood = "fired", variant: "ghost" }
|
||||||
|
]
|
||||||
|
match mood
|
||||||
|
"happy" -> Badge { label: "FEELING GREAT 🌟", variant: "success" }
|
||||||
|
"sad" -> Badge { label: "HANG IN THERE 💙", variant: "info" }
|
||||||
|
"fired" -> Badge { label: "LET'S GO 🔥", variant: "warning" }
|
||||||
|
_ -> Badge { label: "HOW ARE YOU?", variant: "info" }
|
||||||
|
]
|
||||||
|
|
||||||
|
-- Todo list with dynamic arrays
|
||||||
|
Card { title: "Todos", subtitle: "dynamic lists" } [
|
||||||
|
row [
|
||||||
|
input { bind: newTodo, placeholder: "New task..." }
|
||||||
|
button "Add" { click: todos.push(newTodo), variant: "primary" }
|
||||||
|
]
|
||||||
|
each todo in todos ->
|
||||||
|
row [
|
||||||
|
text "→ {todo}"
|
||||||
|
button "×" { click: todos.remove(_idx), variant: "ghost" }
|
||||||
|
]
|
||||||
|
button "Clear All" { click: todos = [], variant: "ghost" }
|
||||||
|
]
|
||||||
|
|
||||||
|
]
|
||||||
"#;
|
"#;
|
||||||
fs::write(project_dir.join("app.ds"), app_source).expect("Failed to write app.ds");
|
fs::write(project_dir.join("app.ds"), app_source).expect("Failed to write app.ds");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue