whitphx HF staff commited on
Commit
a823f42
1 Parent(s): ca2a055

Set the preset colors

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -12,12 +12,22 @@ class ThemeColor(NamedTuple):
12
  textColor: str
13
 
14
 
15
- default_color = ThemeColor(
16
- primaryColor="#ff4b4b",
17
- backgroundColor="#ffffff",
18
- secondaryBackgroundColor="#f0f2f6",
19
- textColor="#31333F",
20
- )
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  if 'primaryColor' not in st.session_state:
@@ -30,6 +40,17 @@ if 'textColor' not in st.session_state:
30
  st.session_state['textColor'] = st._config.get_option(f'theme.textColor') or default_color.textColor
31
 
32
 
 
 
 
 
 
 
 
 
 
 
 
33
  primary_color = st.color_picker('Primary color', key="primaryColor")
34
  text_color = st.color_picker('Text color', key="textColor")
35
  background_color = st.color_picker('Background color', key="backgroundColor")
 
12
  textColor: str
13
 
14
 
15
+ preset_colors: list[tuple[str, ThemeColor]] = [
16
+ ("Default light", ThemeColor(
17
+ primaryColor="#ff4b4b",
18
+ backgroundColor="#ffffff",
19
+ secondaryBackgroundColor="#f0f2f6",
20
+ textColor="#31333F",
21
+ )),
22
+ ("Default dark", ThemeColor(
23
+ primaryColor="#ff4b4b",
24
+ backgroundColor="#0e1117",
25
+ secondaryBackgroundColor="#262730",
26
+ textColor="#fafafa",
27
+ ))
28
+ ]
29
+
30
+ default_color = preset_colors[0][1]
31
 
32
 
33
  if 'primaryColor' not in st.session_state:
 
40
  st.session_state['textColor'] = st._config.get_option(f'theme.textColor') or default_color.textColor
41
 
42
 
43
+ def on_preset_color_selected():
44
+ _, color = preset_colors[st.session_state.preset_color]
45
+ st.session_state['primaryColor'] = color.primaryColor
46
+ st.session_state['backgroundColor'] = color.backgroundColor
47
+ st.session_state['secondaryBackgroundColor'] = color.secondaryBackgroundColor
48
+ st.session_state['textColor'] = color.textColor
49
+
50
+
51
+ st.selectbox("Preset colors", key="preset_color", options=range(len(preset_colors)), format_func=lambda idx: preset_colors[idx][0], on_change=on_preset_color_selected)
52
+
53
+
54
  primary_color = st.color_picker('Primary color', key="primaryColor")
55
  text_color = st.color_picker('Text color', key="textColor")
56
  background_color = st.color_picker('Background color', key="backgroundColor")