Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 16:18:48 -04:00
1 parent 5a7e921c7e
commit 22b53e9e9e
1822 files changed
+24568 -21314

No files matched your search

+33 -29
View File
@@ -6,31 +6,35 @@ import (
"github.com/egoist/mygo/ui"
mujica "mujicaui"
"github.com/ZacharyZhang-NY/MujicaUI/chart"
"github.com/ZacharyZhang-NY/MujicaUI/core"
"github.com/ZacharyZhang-NY/MujicaUI/data"
"github.com/ZacharyZhang-NY/MujicaUI/devtools"
"github.com/ZacharyZhang-NY/MujicaUI/input"
)
type devDemoSettings struct {
disabled bool
status mujica.DataStatus
status data.DataStatus
empty bool
}
func devControls(c *ui.Context, id string, log func(string), states bool) *devDemoSettings {
s := ui.Local(c.Root(), id+"-controls", func() devDemoSettings { return devDemoSettings{} })
dtControls(c, func() {
if mujica.Checkbox(c, &s.disabled, "Disabled", mujica.CheckboxOptions{}).Changed() {
if input.Checkbox(c, &s.disabled, "Disabled", input.CheckboxOptions{}).Changed() {
log("disabled changed")
}
switch id {
case "451", "454", "456", "458":
default:
if mujica.Checkbox(c, &s.empty, "Empty data", mujica.CheckboxOptions{}).Changed() {
if input.Checkbox(c, &s.empty, "Empty data", input.CheckboxOptions{}).Changed() {
log("data state changed")
}
}
if states {
options := []mujica.SelectOption[mujica.DataStatus]{{Value: mujica.DataReady, Label: "Ready"}, {Value: mujica.DataLoading, Label: "Loading"}, {Value: mujica.DataFailed, Label: "Failed"}}
if mujica.Select(c, &s.status, options, mujica.SelectOptions{Label: "Status"}).Changed() {
options := []input.SelectOption[data.DataStatus]{{Value: data.DataReady, Label: "Ready"}, {Value: data.DataLoading, Label: "Loading"}, {Value: data.DataFailed, Label: "Failed"}}
if input.Select(c, &s.status, options, input.SelectOptions{Label: "Status"}).Changed() {
log("status changed")
}
}
@@ -46,7 +50,7 @@ func devStatCardDemo(c *ui.Context, log func(string)) {
dtSection(c, "StatCard", func() {
s := devControls(c, "442", log, true)
lower := ui.Local(c.Root(), "442-lower", func() bool { return false })
if mujica.Checkbox(c, lower, "Lower is better", mujica.CheckboxOptions{}).Changed() {
if input.Checkbox(c, lower, "Lower is better", input.CheckboxOptions{}).Changed() {
log("change direction updated")
}
devPreview(c, s, func() {
@@ -55,7 +59,7 @@ func devStatCardDemo(c *ui.Context, log func(string)) {
if s.empty {
value, trend = "—", nil
}
if mujica.StatCard(c, value, mujica.StatCardOptions{Label: "Requests", Change: 0.12, HasChange: true, LowerIsBetter: *lower, Trend: trend, Status: s.status, Error: "Source unreachable"}).Changed() {
if devtools.StatCard(c, value, devtools.StatCardOptions{Label: "Requests", Change: 0.12, HasChange: true, LowerIsBetter: *lower, Trend: trend, Status: s.status, Error: "Source unreachable"}).Changed() {
log("retry requested")
}
})
@@ -65,15 +69,15 @@ func devStatCardDemo(c *ui.Context, log func(string)) {
func devAlertListDemo(c *ui.Context, log func(string)) {
dtSection(c, "AlertList", func() {
s := devControls(c, "443", log, false)
alerts := ui.Local(c.Root(), "443", func() []mujica.AlertItem {
return []mujica.AlertItem{{ID: "cpu", Title: "CPU usage high", Level: mujica.AlertWarning, Source: "worker", At: time.Now()}, {ID: "api", Title: "API unavailable", Level: mujica.AlertCritical, Source: "gateway", At: time.Now()}}
alerts := ui.Local(c.Root(), "443", func() []devtools.AlertItem {
return []devtools.AlertItem{{ID: "cpu", Title: "CPU usage high", Level: devtools.AlertWarning, Source: "worker", At: time.Now()}, {ID: "api", Title: "API unavailable", Level: devtools.AlertCritical, Source: "gateway", At: time.Now()}}
})
devPreview(c, s, func() {
shown := *alerts
if s.empty {
shown = nil
}
r := mujica.AlertList(c, shown, mujica.AlertListOptions{})
r := devtools.AlertList(c, shown, devtools.AlertListOptions{})
for i := range *alerts {
if r.Ack == (*alerts)[i].ID {
(*alerts)[i].Acked = true
@@ -91,17 +95,17 @@ func devAlertListDemo(c *ui.Context, log func(string)) {
func devIncidentCardDemo(c *ui.Context, log func(string)) {
dtSection(c, "IncidentCard", func() {
s := devControls(c, "444", log, false)
status := ui.Local(c.Root(), "444", func() mujica.IncidentStatus { return mujica.IncidentMonitoring })
choices := []mujica.SelectOption[mujica.IncidentStatus]{{Value: mujica.IncidentInvestigating, Label: "Investigating"}, {Value: mujica.IncidentIdentified, Label: "Identified"}, {Value: mujica.IncidentMonitoring, Label: "Monitoring"}, {Value: mujica.IncidentResolved, Label: "Resolved"}}
if mujica.Select(c, status, choices, mujica.SelectOptions{Label: "Incident status"}).Changed() {
status := ui.Local(c.Root(), "444", func() devtools.IncidentStatus { return devtools.IncidentMonitoring })
choices := []input.SelectOption[devtools.IncidentStatus]{{Value: devtools.IncidentInvestigating, Label: "Investigating"}, {Value: devtools.IncidentIdentified, Label: "Identified"}, {Value: devtools.IncidentMonitoring, Label: "Monitoring"}, {Value: devtools.IncidentResolved, Label: "Resolved"}}
if input.Select(c, status, choices, input.SelectOptions{Label: "Incident status"}).Changed() {
log("incident status changed")
}
devPreview(c, s, func() {
updates := []mujica.IncidentUpdate{{Status: mujica.IncidentIdentified, Text: "Slow query located"}, {Status: mujica.IncidentMonitoring, Text: "Recovery observed"}}
updates := []devtools.IncidentUpdate{{Status: devtools.IncidentIdentified, Text: "Slow query located"}, {Status: devtools.IncidentMonitoring, Text: "Recovery observed"}}
if s.empty {
updates = nil
}
mujica.IncidentCard(c, mujica.Incident{Title: "API latency", Status: *status, Impact: mujica.ImpactMinor, Updates: updates})
devtools.IncidentCard(c, devtools.Incident{Title: "API latency", Status: *status, Impact: devtools.ImpactMinor, Updates: updates})
})
})
}
@@ -109,11 +113,11 @@ func devIncidentCardDemo(c *ui.Context, log func(string)) {
func devUptimeBarDemo(c *ui.Context, log func(string)) {
dtSection(c, "UptimeBar", func() {
s := devControls(c, "445", log, true)
days := ui.Local(c.Root(), "445", func() []mujica.UptimeDay {
out := make([]mujica.UptimeDay, 30)
start := mujica.Date{Year: 2026, Month: 10, Day: 1}
days := ui.Local(c.Root(), "445", func() []devtools.UptimeDay {
out := make([]devtools.UptimeDay, 30)
start := core.Date{Year: 2026, Month: 10, Day: 1}
for i := range out {
out[i] = mujica.UptimeDay{Date: start.AddDays(i), Uptime: 1}
out[i] = devtools.UptimeDay{Date: start.AddDays(i), Uptime: 1}
}
out[7].Uptime, out[7].Note = 0.91, "2 h outage"
out[12].Uptime = 0.98
@@ -124,7 +128,7 @@ func devUptimeBarDemo(c *ui.Context, log func(string)) {
if s.empty {
data = nil
}
r := mujica.UptimeBar(c, data, mujica.UptimeBarOptions{Frame: mujica.ChartFrame{Label: "API uptime", Status: s.status, Error: "Source unreachable"}})
r := devtools.UptimeBar(c, data, devtools.UptimeBarOptions{Frame: chart.ChartFrame{Label: "API uptime", Status: s.status, Error: "Source unreachable"}})
if r.Changed() {
log(fmt.Sprintf("day %d", r.Point))
}
@@ -138,17 +142,17 @@ func devUptimeBarDemo(c *ui.Context, log func(string)) {
func devServiceStatusDemo(c *ui.Context, log func(string)) {
dtSection(c, "ServiceStatus", func() {
s := devControls(c, "446", log, false)
health := ui.Local(c.Root(), "446", func() mujica.ServiceHealth { return mujica.ServiceDegraded })
choices := []mujica.SelectOption[mujica.ServiceHealth]{{Value: mujica.ServiceOperational, Label: "Operational"}, {Value: mujica.ServiceDegraded, Label: "Degraded"}, {Value: mujica.ServiceOutage, Label: "Outage"}}
if mujica.Select(c, health, choices, mujica.SelectOptions{Label: "Search health"}).Changed() {
health := ui.Local(c.Root(), "446", func() devtools.ServiceHealth { return devtools.ServiceDegraded })
choices := []input.SelectOption[devtools.ServiceHealth]{{Value: devtools.ServiceOperational, Label: "Operational"}, {Value: devtools.ServiceDegraded, Label: "Degraded"}, {Value: devtools.ServiceOutage, Label: "Outage"}}
if input.Select(c, health, choices, input.SelectOptions{Label: "Search health"}).Changed() {
log("service health changed")
}
devPreview(c, s, func() {
data := []mujica.ServiceItem{{Name: "API", Health: mujica.ServiceOperational}, {Name: "Search", Health: *health, Note: "Search cluster"}}
data := []devtools.ServiceItem{{Name: "API", Health: devtools.ServiceOperational}, {Name: "Search", Health: *health, Note: "Search cluster"}}
if s.empty {
data = nil
}
mujica.ServiceStatus(c, data, mujica.ServiceStatusOptions{})
devtools.ServiceStatus(c, data, devtools.ServiceStatusOptions{})
})
})
}
@@ -157,15 +161,15 @@ func devResourceGaugeDemo(c *ui.Context, log func(string)) {
dtSection(c, "ResourceGauge", func() {
s := devControls(c, "449", log, true)
used := ui.Local(c.Root(), "449", func() float64 { return 45 })
if mujica.NumberInput(c, used, mujica.NumberInputOptions{Min: 0, Max: 100, Step: 5, Label: "CPU usage"}).Changed() {
if input.NumberInput(c, used, input.NumberInputOptions{Min: 0, Max: 100, Step: 5, Label: "CPU usage"}).Changed() {
log("resource reading changed")
}
devPreview(c, s, func() {
data := []mujica.ResourceReading{{Name: "CPU", Used: *used, Total: 100}, {Name: "Memory", Used: 6.4, Total: 8, Unit: "GB"}, {Name: "Disk", Used: 470, Total: 500, Unit: "GB"}}
data := []devtools.ResourceReading{{Name: "CPU", Used: *used, Total: 100}, {Name: "Memory", Used: 6.4, Total: 8, Unit: "GB"}, {Name: "Disk", Used: 470, Total: 500, Unit: "GB"}}
if s.empty {
data = nil
}
if mujica.ResourceGauge(c, data, mujica.ResourceGaugeOptions{Status: s.status, Error: "Source unreachable"}).Changed() {
if devtools.ResourceGauge(c, data, devtools.ResourceGaugeOptions{Status: s.status, Error: "Source unreachable"}).Changed() {
log("retry requested")
}
})