Restaurant_Chatbot / sticky.py
tsrivallabh's picture
Synced repo using 'sync_with_huggingface' Github Action
c0506a3 verified
raw
history blame contribute delete
929 Bytes
from typing import Literal
import streamlit as st
MARGINS = {
"top": "0",
"bottom": "0",
}
STICKY_CONTAINER_HTML = """
<style>
div[data-testid="stVerticalBlock"] div:has(div.fixed-header-{i}) {{
position: sticky;
{position}: {margin};
background-color: white;
z-index: {z};
}}
</style>
<div class='fixed-header-{i}'/>
""".strip()
# Not to apply the same style to multiple containers
count = 0
def sticky_container(
*,
height: int | None = None,
border: bool | None = None,
mode: Literal["top", "bottom"] = "top",
margin: str | None = None,
z:int |None=None
):
if margin is None:
margin = MARGINS[mode]
global count
html_code = STICKY_CONTAINER_HTML.format(position=mode, margin=margin, i=count,z=z)
count += 1
container = st.container(height=height, border=border)
container.markdown(html_code, unsafe_allow_html=True)
return container