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,39 +1358,71 @@ fn cmd_init(name: Option<String>) {
|
|||
|
||||
// Write starter app.ds
|
||||
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 name = ""
|
||||
let darkMode = false
|
||||
let mood = "happy"
|
||||
let todos = ["Learn DreamStack", "Build something cool"]
|
||||
let newTodo = ""
|
||||
|
||||
view main = column [
|
||||
|
||||
-- Header
|
||||
text "🚀 My App" { variant: "title" }
|
||||
text "Built with DreamStack" { variant: "subtitle" }
|
||||
text "🚀 My DreamStack App" { variant: "title" }
|
||||
text "Built with DreamStack — edit app.ds and reload" { variant: "subtitle" }
|
||||
|
||||
-- Stats
|
||||
-- Dashboard cards
|
||||
row [
|
||||
column [
|
||||
text "Users" { variant: "subtitle" }
|
||||
text "1,247" { variant: "title" }
|
||||
] { variant: "card" }
|
||||
Card { title: "Counter", subtitle: "reactive state" } [
|
||||
text "Count: {count}" { variant: "title" }
|
||||
row [
|
||||
Button { label: "+1", onClick: count += 1, variant: "primary" }
|
||||
Button { label: "-1", onClick: count -= 1, variant: "secondary" }
|
||||
Button { label: "Reset", onClick: count = 0, variant: "ghost" }
|
||||
]
|
||||
]
|
||||
|
||||
column [
|
||||
text "Revenue" { variant: "subtitle" }
|
||||
text "$8,420" { variant: "title" }
|
||||
] { variant: "card" }
|
||||
Card { title: "Greeting", subtitle: "two-way binding" } [
|
||||
input { bind: name, placeholder: "Your name..." }
|
||||
when name -> text "Hello, {name}! 👋"
|
||||
else -> text "Type your name above"
|
||||
]
|
||||
]
|
||||
|
||||
-- Input
|
||||
text "Your name" { variant: "label" }
|
||||
input { bind: name, placeholder: "Type here..." }
|
||||
text "Hello, {name}!"
|
||||
|
||||
-- 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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue