diff --git a/src/streamlit_extras/metric_cards/__init__.py b/src/streamlit_extras/metric_cards/__init__.py index 520d0c6..1acacd3 100644 --- a/src/streamlit_extras/metric_cards/__init__.py +++ b/src/streamlit_extras/metric_cards/__init__.py @@ -3,11 +3,31 @@ from streamlit_extras import extra from streamlit_extras.theme import st_theme +theme = st_theme() + +DEFAULT_BACKGROUND_COLOR_LIGHT = "#FFF" +DEFAULT_BORDER_COLOR_LIGHT = "#CCC" + +DEFAULT_BACKGROUND_COLOR_DARK = "#1B1C24" +DEFAULT_BORDER_COLOR_DARK = "#292D34" + +DEFAULT_BACKGROUND_COLOR = ( + DEFAULT_BACKGROUND_COLOR_DARK + if theme.get("base") == "dark" + else DEFAULT_BACKGROUND_COLOR_LIGHT +) +DEFAULT_BORDER_COLOR = ( + DEFAULT_BORDER_COLOR_DARK + if theme.get("base") == "dark" + else DEFAULT_BORDER_COLOR_LIGHT +) + + @extra def style_metric_cards( - background_color: str = "#FFF", + background_color: str = DEFAULT_BACKGROUND_COLOR, border_size_px: int = 1, - border_color: str = "#CCC", + border_color: str = DEFAULT_BORDER_COLOR, border_radius_px: int = 5, border_left_color: str = "#9AD8E1", box_shadow: bool = True, @@ -24,13 +44,6 @@ def style_metric_cards( box_shadow (bool, optional): Whether a box shadow is applied. Defaults to True. """ - theme = st_theme() - - # When dark mode, convert background and border to be dark - if theme.get("base") == "dark": - background_color = "#1B1C24" - border_color = "#292D34" - box_shadow_str = ( "box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15) !important;" if box_shadow