import streamlit as st | |
def style_metric_cards( | |
background_color: str = "#FFF", | |
border_size_px: int = 1, | |
border_color: str = "#CCC", | |
border_radius_px: int = 5, | |
border_left_color: str = "#9AD8E1", | |
) -> None: | |
""" | |
Applies a custom style to st.metrics in the page | |
Args: | |
background_color (str, optional): Background color. Defaults to "#FFF". | |
border_size_px (int, optional): Border size in pixels. Defaults to 1. | |
border_color (str, optional): Border color. Defaults to "#CCC". | |
border_radius_px (int, optional): Border radius in pixels. Defaults to 5. | |
border_left_color (str, optional): Borfer left color. Defaults to "#9AD8E1". | |
box_shadow (bool, optional): Whether a box shadow is applied. Defaults to True. | |
""" | |
st.markdown( | |
f""" | |
<style> | |
div[data-testid="stMetric"], | |
div[data-testid="metric-container"] {{ | |
background-color: {background_color}; | |
border: {border_size_px}px solid {border_color}; | |
padding: 5% 5% 5% 10%; | |
border-radius: {border_radius_px}px; | |
border-left: 0.5rem solid {border_left_color} !important; | |
}} | |
</style> | |
""", | |
unsafe_allow_html=True, | |
) |