-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc(ui): add custom component for cards
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import contextlib | ||
import dataclasses | ||
import typing | ||
|
||
import streamlit as st | ||
from streamlit.delta_generator import DeltaGenerator | ||
|
||
CARD_CLASS: str = "testgen_card" | ||
CARD_HEADER_CLASS: str = "testgen_card-header" | ||
CARD_TITLE_CLASS: str = "testgen_card-title" | ||
CARD_SUBTITLE_CLASS: str = "testgen_card-subtitle" | ||
CARD_ACTIONS_CLASS: str = "testgen_card-actions" | ||
|
||
|
||
@contextlib.contextmanager | ||
def card( | ||
title: str = "", | ||
subtitle: str = "", | ||
border: bool = True, | ||
extra_css_class: str = "", | ||
) -> typing.Generator["CardContext", None, None]: | ||
with st.container(border=border): | ||
st.html(f'<i class="{CARD_CLASS} {extra_css_class}"></i>') | ||
|
||
title_column, actions_column = st.columns([.5, .5], vertical_alignment="center") | ||
if title or subtitle: | ||
with title_column: | ||
header_html: str = f'<div class="{CARD_HEADER_CLASS}">' | ||
if title: | ||
header_html += f'<h4 class="{CARD_TITLE_CLASS}">{title}</h4>' | ||
if subtitle: | ||
header_html += f'<small class="{CARD_SUBTITLE_CLASS}">{subtitle}</small>' | ||
header_html += '</div>' | ||
st.html(header_html) | ||
|
||
actions_column.html(f'<i class="{CARD_ACTIONS_CLASS}"></i>') | ||
|
||
yield CardContext(actions=actions_column) | ||
|
||
|
||
@dataclasses.dataclass | ||
class CardContext: | ||
actions: DeltaGenerator |