Update pages/type_text.py
Browse files- pages/type_text.py +0 -138
pages/type_text.py
CHANGED
@@ -10,144 +10,6 @@ import os
|
|
10 |
os.getenv("HF_TOKEN")
|
11 |
|
12 |
|
13 |
-
# --- PAGE CONFIG (Optional: Must be the first Streamlit command) ---
|
14 |
-
# st.set_page_config(layout="wide") # Example: Use wide mode
|
15 |
-
|
16 |
-
# --- NAVIGATION LOGIC ---
|
17 |
-
# Initialize session state for page navigation if it doesn't exist
|
18 |
-
if "page" not in st.session_state:
|
19 |
-
st.session_state.page = "Home"
|
20 |
-
|
21 |
-
# Function to change the current page
|
22 |
-
def set_page(page_name):
|
23 |
-
st.session_state.page = page_name
|
24 |
-
|
25 |
-
# --- CSS FOR STICKY NAVBAR ---
|
26 |
-
# You might need to adjust 'top' if Streamlit's default header is visible
|
27 |
-
# and you want your navbar to be below it. Streamlit's header is approx 3rem-3.5rem.
|
28 |
-
# If you've hidden Streamlit's default header, 'top: 0;' should work.
|
29 |
-
# Let's assume Streamlit's default header IS visible for this example.
|
30 |
-
STREAMLIT_DEFAULT_HEADER_HEIGHT = "3.5rem" # Approximate
|
31 |
-
|
32 |
-
# Define the CSS for the sticky navbar
|
33 |
-
# We will wrap our Streamlit columns/buttons in a div with class "sticky-navbar-container"
|
34 |
-
navbar_style = f"""
|
35 |
-
<style>
|
36 |
-
.sticky-navbar-container {{
|
37 |
-
position: sticky;
|
38 |
-
top: {STREAMLIT_DEFAULT_HEADER_HEIGHT}; /* Stick below Streamlit's default header */
|
39 |
-
background-color: #FFFFFF; /* Or your app's background color e.g. #F0F2F6 */
|
40 |
-
z-index: 1001; /* High z-index to keep it on top */
|
41 |
-
padding: 0.75rem 1rem; /* Adjust padding as needed */
|
42 |
-
box-shadow: 0 2px 4px -1px rgba(0,0,0,0.1); /* Optional: subtle shadow */
|
43 |
-
border-bottom: 1px solid #E0E0E0; /* Optional: subtle border */
|
44 |
-
width: 100%; /* Ensure it spans the full width */
|
45 |
-
}}
|
46 |
-
/* Optional: Style for the buttons for a more 'navbar' look */
|
47 |
-
.sticky-navbar-container .stButton>button {{
|
48 |
-
border: none; /* Remove default button border */
|
49 |
-
padding: 0.5rem 1rem; /* Adjust button padding */
|
50 |
-
margin: 0 0.25rem; /* Spacing between buttons */
|
51 |
-
/* background-color: transparent; */ /* Make button background transparent */
|
52 |
-
/* color: #31333F; */ /* Set text color */
|
53 |
-
font-weight: 500;
|
54 |
-
}}
|
55 |
-
.sticky-navbar-container .stButton>button:hover {{
|
56 |
-
/* background-color: #E0E0E0; */ /* Hover effect */
|
57 |
-
/* color: #000000; */
|
58 |
-
}}
|
59 |
-
.sticky-navbar-container .stButton>button:focus {{
|
60 |
-
/* outline: 2px solid #007bff; */ /* Focus outline */
|
61 |
-
/* box-shadow: none; */
|
62 |
-
}}
|
63 |
-
/* Style for an active-like button (if you want to highlight current page) */
|
64 |
-
.sticky-navbar-container .stButton.active-button>button {{
|
65 |
-
/* background-color: #007bff; */
|
66 |
-
/* color: white; */
|
67 |
-
font-weight: bold;
|
68 |
-
border-bottom: 2px solid #007BFF; /* Example active indicator */
|
69 |
-
}}
|
70 |
-
|
71 |
-
</style>
|
72 |
-
"""
|
73 |
-
st.markdown(navbar_style, unsafe_allow_html=True)
|
74 |
-
|
75 |
-
# --- NAVBAR HTML STRUCTURE ---
|
76 |
-
# Start the div container for the navbar
|
77 |
-
st.markdown('<div class="sticky-navbar-container">', unsafe_allow_html=True)
|
78 |
-
|
79 |
-
# Create columns for navigation items
|
80 |
-
# Adjust the column ratios as needed, e.g., for a logo or app title
|
81 |
-
nav_cols = st.columns([1, 1, 1, 1, 3]) # 4 nav items, 1 larger space for title/logo
|
82 |
-
|
83 |
-
# Navigation buttons
|
84 |
-
with nav_cols[0]:
|
85 |
-
# Add 'active-button' class conditionally for styling
|
86 |
-
active_class = "active-button" if st.session_state.page == "Home" else ""
|
87 |
-
if st.button("🏠 Home", on_click=set_page, args=("Home",), use_container_width=True, key="nav_home", type="secondary"): # type can be "primary" or "secondary"
|
88 |
-
pass # on_click handles the logic
|
89 |
-
# Applying class via JS hack (if needed, st.button doesn't directly support class attribute)
|
90 |
-
if active_class: st.markdown(f"<script>document.querySelector('[data-testid=\"stButton\"] button[key*=\"nav_home\"]').closest('.stButton').classList.add('{active_class}');</script>", unsafe_allow_html=True)
|
91 |
-
|
92 |
-
|
93 |
-
with nav_cols[1]:
|
94 |
-
active_class = "active-button" if st.session_state.page == "Dashboard" else ""
|
95 |
-
if st.button("📈 Dashboard", on_click=set_page, args=("Dashboard",), use_container_width=True, key="nav_dashboard"):
|
96 |
-
pass
|
97 |
-
if active_class: st.markdown(f"<script>document.querySelector('[data-testid=\"stButton\"] button[key*=\"nav_dashboard\"]').closest('.stButton').classList.add('{active_class}');</script>", unsafe_allow_html=True)
|
98 |
-
|
99 |
-
|
100 |
-
with nav_cols[2]:
|
101 |
-
active_class = "active-button" if st.session_state.page == "Settings" else ""
|
102 |
-
if st.button("⚙️ Settings", on_click=set_page, args=("Settings",), use_container_width=True, key="nav_settings"):
|
103 |
-
pass
|
104 |
-
if active_class: st.markdown(f"<script>document.querySelector('[data-testid=\"stButton\"] button[key*=\"nav_settings\"]').closest('.stButton').classList.add('{active_class}');</script>", unsafe_allow_html=True)
|
105 |
-
|
106 |
-
|
107 |
-
with nav_cols[3]:
|
108 |
-
active_class = "active-button" if st.session_state.page == "About" else ""
|
109 |
-
if st.button("👤 About", on_click=set_page, args=("About",), use_container_width=True, key="nav_about"):
|
110 |
-
pass
|
111 |
-
if active_class: st.markdown(f"<script>document.querySelector('[data-testid=\"stButton\"] button[key*=\"nav_about\"]').closest('.stButton').classList.add('{active_class}');</script>", unsafe_allow_html=True)
|
112 |
-
|
113 |
-
|
114 |
-
# Optional: App title or logo in the navbar
|
115 |
-
with nav_cols[4]:
|
116 |
-
st.markdown("<h3 style='text-align:right; margin:0; padding-top:0.1rem;'>My Sticky App</h3>", unsafe_allow_html=True)
|
117 |
-
|
118 |
-
# Close the div container for the navbar
|
119 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
120 |
-
|
121 |
-
|
122 |
-
# --- MAIN PAGE CONTENT ---
|
123 |
-
# Display content based on the selected page
|
124 |
-
if st.session_state.page == "Home":
|
125 |
-
st.header("🏠 Home Page")
|
126 |
-
st.write("Welcome to the home page! This navbar will stick to the top as you scroll.")
|
127 |
-
for i in range(50):
|
128 |
-
st.write(f"Home: Scrollable content line {i+1}")
|
129 |
-
elif st.session_state.page == "Dashboard":
|
130 |
-
st.header("📈 Dashboard")
|
131 |
-
st.write("This is your main dashboard. Notice the sticky navigation.")
|
132 |
-
for i in range(50):
|
133 |
-
st.write(f"Dashboard: Scrollable content line {i+1}")
|
134 |
-
elif st.session_state.page == "Settings":
|
135 |
-
st.header("⚙️ Settings")
|
136 |
-
st.write("Configure your application settings here.")
|
137 |
-
for i in range(50):
|
138 |
-
st.write(f"Settings: Scrollable content line {i+1}")
|
139 |
-
elif st.session_state.page == "About":
|
140 |
-
st.header("👤 About Us")
|
141 |
-
st.write("Information about this application and its sticky navigation feature.")
|
142 |
-
for i in range(50):
|
143 |
-
st.write(f"About: Scrollable content line {i+1}")
|
144 |
-
|
145 |
-
# --- FOOTER (Example) ---
|
146 |
-
st.markdown("---")
|
147 |
-
st.write("This is the footer of the page.")
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
#hide_streamlit_style = """
|
152 |
# <style>
|
153 |
# div[data-testid="stHeader"] {
|
|
|
10 |
os.getenv("HF_TOKEN")
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
#hide_streamlit_style = """
|
14 |
# <style>
|
15 |
# div[data-testid="stHeader"] {
|