forked from javelit/javelit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleExample.java
More file actions
138 lines (118 loc) · 4.17 KB
/
Copy pathToggleExample.java
File metadata and controls
138 lines (118 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/// usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.javelit:javelit:0.76.0
import io.javelit.core.Jt;
import io.javelit.core.JtComponent;
public class ToggleExample {
public static void main(String[] args) {
Jt.title("# Toggle Component Demo").use();
Jt.markdown("## Basic Toggle").use();
boolean basicToggle = Jt.toggle("Enable notifications").use();
if (basicToggle) {
Jt.text("✅ Notifications are **enabled**").use();
} else {
Jt.text("❌ Notifications are **disabled**").use();
}
Jt.markdown("## Toggle with Help").use();
boolean helpToggle = Jt.toggle("Dark mode")
.help("Toggle between light and dark theme")
.use();
if (helpToggle) {
Jt.text("🌙 Dark mode is **on**").use();
} else {
Jt.text("☀️ Light mode is **on**").use();
}
Jt.markdown("## Toggle with Default Value").use();
boolean defaultToggle = Jt.toggle("Auto-save")
.value(true)// Default to enabled
.help("Automatically save your work")
.use();
if (defaultToggle) {
Jt.text("💾 Auto-save is **enabled** (default)").use();
} else {
Jt.text("💾 Auto-save is **disabled**").use();
}
Jt.markdown("## Disabled Toggle").use();
Jt.toggle("Premium feature")
.disabled(true)
.help("Upgrade to premium to access this feature")
.use();
Jt.text("⚪ This toggle is disabled").use();
Jt.markdown("## Label Visibility Options").use();
// Visible label (default)
boolean visibleToggle = Jt.toggle("**Visible** label toggle")
.labelVisibility(JtComponent.LabelVisibility.VISIBLE)
.use();
// Hidden label (spacer)
boolean hiddenToggle = Jt.toggle("Hidden label toggle")
.labelVisibility(JtComponent.LabelVisibility.HIDDEN)
.use();
// Collapsed label (no space)
boolean collapsedToggle = Jt.toggle("Collapsed label toggle")
.labelVisibility(JtComponent.LabelVisibility.COLLAPSED)
.use();
if (visibleToggle || hiddenToggle || collapsedToggle) {
Jt.text("At least one label visibility toggle is enabled").use();
}
Jt.markdown("## Width Options").use();
// Content width (default)
Jt.text("Content width:").use();
boolean contentWidth = Jt.toggle("Content width toggle")
.width("content")
.use();
// Stretch width
Jt.text("Stretch width:").use();
boolean stretchWidth = Jt.toggle("Stretch width toggle")
.width("stretch")
.use();
// Fixed pixel width
Jt.text("Fixed 300px width:").use();
boolean fixedWidth = Jt.toggle("Fixed width toggle")
.width(300)
.use();
Jt.markdown("## Toggle with onChange Callback").use();
Jt.toggle("Toggle with callback")
.onChange(enabled -> {
if (enabled) {
Jt.text("🎉 Callback triggered: Toggle was **ON**").use();
} else {
Jt.text("😴 Callback triggered: Toggle was **OFF**").use();
}
})
.use();
Jt.markdown("## Markdown Support in Labels").use();
Jt.toggle("Toggle with **bold**, *italic*, and `code` text").use();
Jt.toggle("Toggle with [link](https://example.com) and ~~strikethrough~~").use();
// Summary section
Jt.markdown("---").use();
Jt.markdown("### Summary").use();
int enabledCount = 0;
if (basicToggle) {
enabledCount++;
}
if (helpToggle) {
enabledCount++;
}
if (defaultToggle) {
enabledCount++;
}
if (visibleToggle) {
enabledCount++;
}
if (hiddenToggle) {
enabledCount++;
}
if (collapsedToggle) {
enabledCount++;
}
if (contentWidth) {
enabledCount++;
}
if (stretchWidth) {
enabledCount++;
}
if (fixedWidth) {
enabledCount++;
}
Jt.text("Total enabled toggles: **" + enabledCount + "**").use();
}
}