streamlit-toggle-diy 1.0.1__py3-none-any.whl → 1.1.4__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. streamlit_toggle_diy/__init__.py +208 -53
  2. streamlit_toggle_diy/frontend/build/asset-manifest.json +19 -0
  3. streamlit_toggle_diy/frontend/build/bootstrap.min.css +9501 -0
  4. streamlit_toggle_diy/frontend/build/index.html +1 -0
  5. streamlit_toggle_diy/frontend/build/precache-manifest.208239bd31634c912148876425127f2c.js +22 -0
  6. streamlit_toggle_diy/frontend/build/precache-manifest.669f85f994ea2c0d193915faa9d91f97.js +22 -0
  7. streamlit_toggle_diy/frontend/build/precache-manifest.b7df6085566f07f8f27b94ee8ed2d302.js +22 -0
  8. streamlit_toggle_diy/frontend/build/service-worker.js +39 -0
  9. streamlit_toggle_diy/frontend/build/static/js/2.82cd69ef.chunk.js +3 -0
  10. streamlit_toggle_diy/frontend/build/static/js/2.82cd69ef.chunk.js.LICENSE.txt +68 -0
  11. streamlit_toggle_diy/frontend/build/static/js/2.82cd69ef.chunk.js.map +1 -0
  12. streamlit_toggle_diy/frontend/build/static/js/2.9720bf9e.chunk.js +3 -0
  13. streamlit_toggle_diy/frontend/build/static/js/2.9720bf9e.chunk.js.LICENSE.txt +68 -0
  14. streamlit_toggle_diy/frontend/build/static/js/2.9720bf9e.chunk.js.map +1 -0
  15. streamlit_toggle_diy/frontend/build/static/js/main.72a874a0.chunk.js +2 -0
  16. streamlit_toggle_diy/frontend/build/static/js/main.72a874a0.chunk.js.map +1 -0
  17. streamlit_toggle_diy/frontend/build/static/js/main.93eb9d37.chunk.js +2 -0
  18. streamlit_toggle_diy/frontend/build/static/js/main.93eb9d37.chunk.js.map +1 -0
  19. streamlit_toggle_diy/frontend/build/static/js/main.9f3c3eed.chunk.js +2 -0
  20. streamlit_toggle_diy/frontend/build/static/js/main.9f3c3eed.chunk.js.map +1 -0
  21. streamlit_toggle_diy/frontend/build/static/js/runtime-main.cc20bba3.js +2 -0
  22. streamlit_toggle_diy/frontend/build/static/js/runtime-main.cc20bba3.js.map +1 -0
  23. streamlit_toggle_diy/frontend/build/static/js/runtime-main.d76c522e.js +2 -0
  24. streamlit_toggle_diy/frontend/build/static/js/runtime-main.d76c522e.js.map +1 -0
  25. streamlit_toggle_diy/frontend/public/bootstrap.min.css +9501 -0
  26. streamlit_toggle_diy/frontend/public/index.html +25 -0
  27. streamlit_toggle_diy/frontend/src/index.tsx +11 -0
  28. streamlit_toggle_diy/frontend/src/react-app-env.d.ts +1 -0
  29. streamlit_toggle_diy/frontend/src/streamlit_toggle.tsx +170 -0
  30. streamlit_toggle_diy/frontend/src/style.css +6 -0
  31. streamlit_toggle_diy-1.1.4.dist-info/METADATA +88 -0
  32. streamlit_toggle_diy-1.1.4.dist-info/RECORD +35 -0
  33. {streamlit_toggle_diy-1.0.1.dist-info → streamlit_toggle_diy-1.1.4.dist-info}/WHEEL +1 -1
  34. streamlit_toggle_diy-1.0.1.dist-info/METADATA +0 -10
  35. streamlit_toggle_diy-1.0.1.dist-info/RECORD +0 -6
  36. {streamlit_toggle_diy-1.0.1.dist-info → streamlit_toggle_diy-1.1.4.dist-info}/LICENSE +0 -0
  37. {streamlit_toggle_diy-1.0.1.dist-info → streamlit_toggle_diy-1.1.4.dist-info}/top_level.txt +0 -0
@@ -7,7 +7,7 @@ _RELEASE = True
7
7
  if not _RELEASE:
8
8
  _component_func = components.declare_component(
9
9
  "streamlit_toggle_diy",
10
- url="http://localhost:3001",
10
+ url="http://localhost:3001", # 本地开发时的地址
11
11
  )
12
12
  else:
13
13
  parent_dir = os.path.dirname(os.path.abspath(__file__))
@@ -16,51 +16,103 @@ else:
16
16
 
17
17
 
18
18
  def st_toggle_switch(
19
- label=None,
20
- key=None,
21
- default_value=False,
22
- label_after=False,
23
- inactive_color='#D3D3D3',
24
- active_color="#11567f",
25
- track_color="#29B5E8",
26
- label_bg_color_start=None, # 新增参数
27
- label_bg_color_end=None, # 新增参数
28
- background_color_near_button_start=None, # 新增参数
29
- background_color_near_button_end=None # 新增参数
19
+ key=None,
20
+ label_start="", # 前标签文字
21
+ label_end="", # 后标签文字
22
+ justify='flex-start', # 对齐方式
23
+ default_value=False, # 默认开关状态
24
+ inactive_color='#CEE8FF',
25
+ active_color="#00668c",
26
+ track_color="#3D5A80",
27
+ label_bg_color_start="#FFFFFF",
28
+ label_bg_color_end="yellow",
29
+ background_color_near_button_start="#FFFFFF",
30
+ background_color_near_button_end="#FFFFFF",
31
+ border_radius='30px',
32
+ label_start_color="#333333",
33
+ label_end_color="red",
34
+ label_font_size="16px",
35
+ label_font_weight="bold",
36
+ switch_size="medium",
30
37
  ):
31
- if label_after:
32
- label_end = label
33
- label_start = ''
34
- justify = 'flex-start'
35
- else:
36
- label_start = label
37
- label_end = ''
38
- justify = 'flex-start'
39
- # justify = 'flex-end'
38
+ """
39
+ Streamlit 中创建一个可自定义颜色、大小的切换开关组件。
40
+
41
+ Parameters
42
+ ----------
43
+ key: str
44
+ 组件在 session_state 中的 key,用于区分多个组件实例。
45
+ label_start: str
46
+ 开关左侧标签文字。
47
+ label_end: str
48
+ 开关右侧标签文字。
49
+ justify: {'flex-start', 'center', 'flex-end'}
50
+ 标签和开关在容器中的对齐方式。
51
+ default_value: bool
52
+ 开关的默认状态,True 为打开,False 为关闭。
53
+ inactive_color: str
54
+ 开关未激活时的按钮颜色。
55
+ active_color: str
56
+ 开关激活时的按钮颜色。
57
+ track_color: str
58
+ 开关轨道(背景)的颜色。
59
+ label_bg_color_start: str
60
+ 左 / 上方标签背景色(如果需要渐变,可与 label_bg_color_end 联合使用)。
61
+ label_bg_color_end: str
62
+ 右 / 下方标签背景色(如果需要渐变,可与 label_bg_color_start 联合使用)。
63
+ background_color_near_button_start: str
64
+ 开关附近背景的起始颜色(可配合 background_color_near_button_end 做渐变)。
65
+ background_color_near_button_end: str
66
+ 开关附近背景的结束颜色(可配合 background_color_near_button_start 做渐变)。
67
+ border_radius: str
68
+ 组件的圆角,如 '4px', '8px', '50%' 等。
69
+
70
+ label_start_color: str
71
+ 前标签文字颜色(默认为 #7f1916)。
72
+ label_end_color: str
73
+ 后标签文字颜色(默认为 #FFFFFF)。
74
+ label_font_size: str
75
+ 标签文字的字体大小(如 '14px' 等)。
76
+ label_font_weight: str
77
+ 标签文字的粗细(如 'bold', 'normal', '500' 等)。
78
+ switch_size: {'small', 'medium'}
79
+ 切换开关本身的尺寸。
80
+
81
+ Returns
82
+ -------
83
+ bool
84
+ 返回切换后的状态。如果无法获取,则返回 default_value。
85
+ """
40
86
 
41
87
  toggle_value = _component_func(
42
88
  key=key,
43
89
  default_value=default_value,
44
- label_after=label_after,
45
90
  label_start=label_start,
46
91
  label_end=label_end,
47
92
  justify=justify,
48
93
  inactive_color=inactive_color,
49
94
  active_color=active_color,
50
95
  track_color=track_color,
51
- label_bg_color_start=label_bg_color_start, # 传递新增参数
52
- label_bg_color_end=label_bg_color_end, # 传递新增参数
53
- background_color_near_button_start=background_color_near_button_start, # 传递新增参数
54
- background_color_near_button_end=background_color_near_button_end # 传递新增参数
96
+ label_bg_color_start=label_bg_color_start,
97
+ label_bg_color_end=label_bg_color_end,
98
+ background_color_near_button_start=background_color_near_button_start,
99
+ background_color_near_button_end=background_color_near_button_end,
100
+ border_radius=border_radius,
101
+ label_start_color=label_start_color,
102
+ label_end_color=label_end_color,
103
+ label_font_size=label_font_size,
104
+ label_font_weight=label_font_weight,
105
+ switch_size=switch_size,
55
106
  )
56
107
  return toggle_value if toggle_value is not None else default_value
57
108
 
58
109
 
110
+ # 仅在开发环境时演示组件效果
59
111
  if not _RELEASE:
60
- st.header('Streamlit Toggle Switch')
112
+ st.header('Streamlit Toggle Switch - Dev Mode')
61
113
  st.write('---')
62
114
 
63
- # 使用 color_picker 选择颜色
115
+ # 使用 color_picker 选择不同颜色
64
116
  color1_start = st.color_picker('选择 Question 1 标签起始背景颜色', '#FFD700')
65
117
  color1_end = st.color_picker('选择 Question 1 标签结束背景颜色', '#FF8C00')
66
118
 
@@ -77,64 +129,167 @@ if not _RELEASE:
77
129
  color5_end = st.color_picker('选择 Disable Filter 标签结束背景颜色', '#00FF7F')
78
130
 
79
131
  # 新增颜色选择器用于按钮附近的背景颜色
80
- button_bg_start = st.color_picker('选择按钮附近的起始背景颜色', '#FFFFFF')
81
- button_bg_end = st.color_picker('选择按钮附近的结束背景颜色', '#FFFFFF')
132
+ button_bg_start = st.color_picker('按钮附近的起始背景颜色', '#FFFFFF')
133
+ button_bg_end = st.color_picker('按钮附近的结束背景颜色', '#FFFFFF')
134
+
135
+ # 新增圆角选择器
136
+ border_radius = st.text_input('组件圆角(如:4px, 8px, 50%)', '8px')
137
+
138
+ # 新增对齐方式选择器
139
+ justify = st.selectbox(
140
+ '标签与开关的对齐方式',
141
+ ('flex-start', 'center', 'flex-end')
142
+ )
143
+
144
+ # 新增标签文字颜色选择
145
+ label_start_color = st.color_picker("左侧标签文字颜色", "#7f1916")
146
+ label_end_color = st.color_picker("右侧标签文字颜色", "#FFFFFF")
147
+
148
+ # 标签字体大小与粗细
149
+ label_font_size = st.text_input("标签字体大小", "14px")
150
+ label_font_weight = st.text_input("标签字体粗细", "bold")
151
+
152
+ # Switch 尺寸选择器
153
+ switch_size = st.selectbox(
154
+ "Switch 尺寸",
155
+ ("small", "medium")
156
+ )
82
157
 
83
158
  columns = st.columns(3)
84
159
  with columns[0]:
85
160
  st_toggle_switch(
86
- label="Question 1",
87
161
  key='c1',
88
- label_after=False,
162
+ label_start="Question 1",
163
+ label_end="", # 不显示后标签
164
+ justify=justify,
165
+ default_value=True,
166
+ inactive_color='#D3D3D3',
167
+ active_color="#11567f",
168
+ track_color="#29B5E8",
89
169
  label_bg_color_start=color1_start,
90
170
  label_bg_color_end=color1_end,
91
- background_color_near_button_start=button_bg_start, # 传递新增参数
92
- background_color_near_button_end=button_bg_end # 传递新增参数
171
+ background_color_near_button_start=button_bg_start,
172
+ background_color_near_button_end=button_bg_end,
173
+ border_radius=border_radius,
174
+ label_start_color=label_start_color,
175
+ label_end_color=label_end_color,
176
+ label_font_size=label_font_size,
177
+ label_font_weight=label_font_weight,
178
+ switch_size=switch_size,
93
179
  )
180
+
94
181
  st_toggle_switch(
95
- label="Question 2",
96
- key='c2',
97
- label_after=False,
98
- label_bg_color_start=color2_start,
99
- label_bg_color_end=color2_end,
100
- background_color_near_button_start=button_bg_start,
101
- background_color_near_button_end=button_bg_end
182
+ key="input_toggle",
183
+ label_start="",
184
+ label_end="Question 2",
185
+ justify='flex-start',
186
+ default_value=True,
187
+ inactive_color='#95e1d3',
188
+ active_color="#f38181",
189
+ track_color="#f38181",
190
+ label_bg_color_start='white',
191
+ label_bg_color_end='black',
192
+ background_color_near_button_start='blue',
193
+ background_color_near_button_end='black',
194
+ border_radius='10px',
195
+ label_start_color="#000000",
196
+ label_end_color="#FFFFFF",
197
+ label_font_size="12px",
198
+ label_font_weight="normal",
199
+ switch_size="small",
102
200
  )
201
+
103
202
  with columns[1]:
104
203
  st_toggle_switch(
105
- label="Question 3",
106
204
  key='q2',
107
- label_after=True,
205
+ label_start="", # 不显示前标签
206
+ label_end="Question 3",
207
+ justify=justify,
108
208
  default_value=True,
209
+ inactive_color='#DDA0DD',
210
+ active_color="#9400D3",
211
+ track_color="#BA55D3",
109
212
  label_bg_color_start=color3_start,
110
213
  label_bg_color_end=color3_end,
111
214
  background_color_near_button_start=button_bg_start,
112
- background_color_near_button_end=button_bg_end
215
+ background_color_near_button_end=button_bg_end,
216
+ border_radius=border_radius,
217
+ label_start_color=label_start_color,
218
+ label_end_color=label_end_color,
219
+ label_font_size=label_font_size,
220
+ label_font_weight=label_font_weight,
221
+ switch_size=switch_size,
113
222
  )
114
223
  st_toggle_switch(
115
- label="Question 4",
116
224
  key='q3',
117
- label_after=True,
118
- default_value=True,
225
+ label_start="", # 不显示前标签
226
+ label_end="Question 4",
227
+ justify=justify,
228
+ default_value=False,
229
+ inactive_color='#FFA07A',
230
+ active_color="#FF4500",
231
+ track_color="#FF6347",
119
232
  label_bg_color_start=color4_start,
120
233
  label_bg_color_end=color4_end,
121
234
  background_color_near_button_start=button_bg_start,
122
- background_color_near_button_end=button_bg_end
235
+ background_color_near_button_end=button_bg_end,
236
+ border_radius=border_radius,
237
+ label_start_color=label_start_color,
238
+ label_end_color=label_end_color,
239
+ label_font_size=label_font_size,
240
+ label_font_weight=label_font_weight,
241
+ switch_size=switch_size,
123
242
  )
243
+
124
244
  with columns[2]:
125
- range_slider_toggle = st_toggle_switch(
126
- "Disable Filter",
245
+ st_toggle_switch(
127
246
  key='q1',
128
- label_after=False,
247
+ label_start="Disable Filter",
248
+ label_end="", # 不显示后标签
249
+ justify=justify,
129
250
  default_value=True,
251
+ inactive_color='#98FB98',
252
+ active_color="#00FF7F",
253
+ track_color="#00FA9A",
130
254
  label_bg_color_start=color5_start,
131
255
  label_bg_color_end=color5_end,
132
256
  background_color_near_button_start=button_bg_start,
133
- background_color_near_button_end=button_bg_end
257
+ background_color_near_button_end=button_bg_end,
258
+ border_radius=border_radius,
259
+ label_start_color=label_start_color,
260
+ label_end_color=label_end_color,
261
+ label_font_size=label_font_size,
262
+ label_font_weight=label_font_weight,
263
+ switch_size=switch_size,
264
+ )
265
+ range_slider_toggle = st_toggle_switch(
266
+ key='ql',
267
+ label_start="Disable Filter",
268
+ label_end="", # 不显示后标签
269
+ justify=justify,
270
+ default_value=True,
271
+ inactive_color='#98FB98',
272
+ active_color="#00FF7F",
273
+ track_color="#00FA9A",
274
+ label_bg_color_start=color5_start,
275
+ label_bg_color_end=color5_end,
276
+ background_color_near_button_start=button_bg_start,
277
+ background_color_near_button_end=button_bg_end,
278
+ border_radius=border_radius,
279
+ label_start_color=label_start_color,
280
+ label_end_color=label_end_color,
281
+ label_font_size=label_font_size,
282
+ label_font_weight=label_font_weight,
283
+ switch_size=switch_size,
134
284
  )
135
285
  range_slider = st.slider(
136
286
  label="Filter Range",
137
287
  min_value=0,
138
288
  max_value=100,
139
- disabled=range_slider_toggle
289
+ disabled=range_slider_toggle,
140
290
  )
291
+
292
+ st_toggle_switch(
293
+ key='q4',
294
+ label_start="Disable Filter",
295
+ label_end="Disable Filter",)
@@ -0,0 +1,19 @@
1
+ {
2
+ "files": {
3
+ "main.js": "./static/js/main.9f3c3eed.chunk.js",
4
+ "main.js.map": "./static/js/main.9f3c3eed.chunk.js.map",
5
+ "runtime-main.js": "./static/js/runtime-main.cc20bba3.js",
6
+ "runtime-main.js.map": "./static/js/runtime-main.cc20bba3.js.map",
7
+ "static/js/2.9720bf9e.chunk.js": "./static/js/2.9720bf9e.chunk.js",
8
+ "static/js/2.9720bf9e.chunk.js.map": "./static/js/2.9720bf9e.chunk.js.map",
9
+ "index.html": "./index.html",
10
+ "precache-manifest.b7df6085566f07f8f27b94ee8ed2d302.js": "./precache-manifest.b7df6085566f07f8f27b94ee8ed2d302.js",
11
+ "service-worker.js": "./service-worker.js",
12
+ "static/js/2.9720bf9e.chunk.js.LICENSE.txt": "./static/js/2.9720bf9e.chunk.js.LICENSE.txt"
13
+ },
14
+ "entrypoints": [
15
+ "static/js/runtime-main.cc20bba3.js",
16
+ "static/js/2.9720bf9e.chunk.js",
17
+ "static/js/main.9f3c3eed.chunk.js"
18
+ ]
19
+ }