File size: 3,551 Bytes
7798609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'''
title: 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
''')

#Custom Function
def myclick():
    mytext.text = "You clicked "
    
def reset():
    mytext.text = "This is button"
    
    but1.type = ""
    but1.icon = ""
    but1.endIcon = ""
    but1.iconColor = "mediumseagreen"
    but1.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", 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 onradiochange2(event):
    index = event.index

    if index == 0:
        but1.icon = "mdi-account-circle"
        but1.endIcon = ""
        ss.session["iconstr"] = ' icon="mdi-account-circle",'
    elif index == 1:
        but1.icon = ""
        but1.endIcon = "mdi-alert"
        ss.session["iconstr"] = ' endIcon="mdi-alert",'
    else:
        but1.icon = ""
        but1.endIcon = ""
        ss.session["iconstr"] = ''

    
def changeColor(bkcolor):
    but1.style = f"background-color:{bkcolor}; color:white"
    but1.iconColor = "white"
    
    ss.session["style_str"] = f'style="background-color:{bkcolor}, color:white"'
    ss.session["style"] = 'style=style,'

def change_disabled(event):
    but1.disabled = event.value

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

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

    ss.write("---")
    ss.radio(["Icon(Prepend)", "Icon(Append)", "No Icon"], inline = True, onchange=onradiochange2)
    
    ss.checkbox("disabled", onchange = change_disabled)
    
    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)
```
''')


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