File size: 4,728 Bytes
936e0a7
591017d
936e0a7
 
 
 
 
591017d
936e0a7
 
 
 
 
 
591017d
 
 
 
 
 
 
 
936e0a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
139
140
141
142
143
144
145
146
147
148
149
150
### Button
import simplestart as ss

ss.md('''
## ss.button
''')
ss.md('''
[Online Help](https://www.simplestart.cc/doc_form/ss-button.html)
''')
ss.space()
ss.md('''
#### πŸ”… Example
''')


def testme():
    #ss.openpage("002 Form Component/demo_button", lang="zh")
    #ss.openpage("main", lang="zh")
    ss.send_message("change_locale", {"locale":"zh"});
    
ss.button("testme", onclick = testme)

#Custom Function
def myclick():
    mytext.text = "You clicked "
    
def reset():
    mytext.text = "This is button"
    but1.type = ""
    ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
    ss.getcm().components[but1.id]["content"]["options"]["endicon"] = ""
    ss.getcm().components[but1.id]["content"]["options"]["icon_color"] = "mediumseagreen"
    ss.getcm().components[but1.id]["content"]["options"]["style"] = "background-color:initial;color:initial"
    ss.session["iconstr"] = ''
    ss.session["style_str"] = ''
    ss.session["style"] = ''

    
#Basic Usage
cols = ss.columns([40,"flex:60"], design=True)
with cols[0]:
    mytext = ss.text("This is button")
    but1 = ss.button("Click it", icon = "mdi-account-circle", onclick=myclick)

def onradiochange(event):
    value = event.value
    if value == "default":
        but1.type = ""
        ss.session["buttonstyle"] = ""
    elif value == "outlined":
        but1.type = "outlined"
        ss.session["buttonstyle"] = 'type = "outlined\",'
    elif value == "flat":
        but1.type = "tonal"
        ss.session["buttonstyle"] = 'type = "flat\",'
    elif value == "text":
        but1.type = "text"
        ss.session["buttonstyle"] = 'type = "text\",'
    elif value == "plain":
        but1.type = "plain"
        ss.session["buttonstyle"] = 'type = "plain\",'

def oncheckbox_change(state, value):
    if value == True:
        ss.getcm().components[but1.id]["content"]["options"]["icon"] = "aim"
        ss.session["iconstr"] = ' icon="search",'
    else:
        ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
        ss.session["iconstr"] = ''
    but1.update()

def onradiochange2(event):
    index = event.index

    if index == 0:
        ss.getcm().components[but1.id]["content"]["options"]["icon"] = "mdi-account-circle"
        ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = ""
        ss.session["iconstr"] = ' icon="mdi-account-circle",'
    elif index == 1:
        ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
        ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = "mdi-alert"
        ss.session["iconstr"] = ' endIcon="mdi-alert",'
    else:
        ss.getcm().components[but1.id]["content"]["options"]["icon"] = ""
        ss.getcm().components[but1.id]["content"]["options"]["endIcon"] = ""
        ss.session["iconstr"] = ''
    but1.update()

    
def changeColor(bkcolor):
    ss.getcm().components[but1.id]["content"]["options"]["style"] = f"background-color:{bkcolor}; color:white"
    ss.getcm().components[but1.id]["content"]["options"]["icon_color"] = "white"
    ss.session["style_str"] = f'style="background-color:{bkcolor}, color:white"'
    ss.session["style"] = 'style=style,'
    but1.update()


with cols[1]:
    ss.text("Test")

    ss.write("---")
    ss.radio(["default", "outlined", "flat", "text", "plain"], "default", inline = True, onchange=onradiochange)

    ss.write("---")
    ss.radio([(1, "Icon(Prepend)"), (2, "Icon(Append)"), (3, "No Icon")], inline = True, onchange=onradiochange2)
    
    
    ss.write("---")
    ss.button("", type = "flat", size = "small", style="background-color:#409eff", onclick=lambda:changeColor('#409eff'))
    ss.button("", type = "flat", size = "small", style="background-color:#67c23a", onclick=lambda:changeColor('#67c23a'))
    ss.button("", type = "flat", size = "small", style="background-color:#e6a23c", onclick=lambda:changeColor('#e6a23c'))
    ss.button("", type = "flat", size = "small", style="background-color:#f56c6c", onclick=lambda:changeColor('#f56c6c'))
    ss.button("", type = "flat", size = "small", style="background-color:#909399", onclick=lambda:changeColor('#909399'))
    
    
    ss.space()
    ss.button("Reset", onclick=reset)


ss.space("mt-8")

ss.write("#### πŸ”Ž Code")

ss.md('''
```python
import simplestart as ss

def clickme():
    mytext.text = "You clicked"
    
mytext = ss.text("This is button")
@style_str
ss.button("Click it", @buttonstyle @iconstr @style onclick=clickme)
```
''')

ss.md('''
::: tip
  Function Call
  ss.button(label, type, color, size, icon, onclick)   
:::
''')

def onPageLoad():
    ss.session["buttonstyle"] = ""
    ss.session["iconstr"] = ""
    ss.session["style"] = ""
    ss.session["style_str"] = ""