diff --git a/st_aggrid/AgGrid.py b/st_aggrid/AgGrid.py index a761b7e..7a836bc 100644 --- a/st_aggrid/AgGrid.py +++ b/st_aggrid/AgGrid.py @@ -164,6 +164,7 @@ def AgGrid( columns_state=None, theme: str | StAggridTheme = "streamlit", custom_css=None, + links: typing.List[str] = None, key: typing.Any = None, update_on=[], callback=None, @@ -281,6 +282,9 @@ def AgGrid( Custom CSS rules to be added to the component's iframe. Defaults to None. + links : typing.List[str], optional + List of URLs to external stylesheets (e.g. FontAwesome, Material Icons) to be loaded in the component. + key : typing.Any, optional Streamlit's key argument. Check Streamlit's documentation. Defaults to None. @@ -376,6 +380,7 @@ def AgGrid( try_to_convert_back_to_original_types = False custom_css = custom_css or dict() + links = links or [] if height == None: gridOptions["domLayout"] = "autoHeight" @@ -425,6 +430,7 @@ def _inner_callback(): columns_state=columns_state, theme=themeObj, custom_css=custom_css, + links=links, update_on=update_on, manual_update=manual_update, key=key, diff --git a/st_aggrid/frontend/src/AgGrid.tsx b/st_aggrid/frontend/src/AgGrid.tsx index f151633..ae2b384 100644 --- a/st_aggrid/frontend/src/AgGrid.tsx +++ b/st_aggrid/frontend/src/AgGrid.tsx @@ -41,6 +41,23 @@ import ManualUpdateButton from "./components/ManualUpdateButton" import ManualDownloadButton from "./components/ManualDownloadButton" import QuickSearch from "./components/QuickSearch" +interface CustomStylesheetProps { + url: string; +} + +function CustomStylesheet({ url }: CustomStylesheetProps) { + React.useEffect(() => { + const link = document.createElement('link'); + link.href = url; + link.rel = 'stylesheet'; + document.head.appendChild(link); + return () => { + document.head.removeChild(link); + }; + }, [url]); + return null; +} + import { getCSS, addCustomCSS, @@ -354,6 +371,9 @@ class AgGrid extends React.Component { ref={this.gridContainerRef} style={this.defineContainerHeight()} > + {this.props.args.links?.map((url: string) => ( + + ))} { } } -export default withStreamlitConnection(AgGrid) \ No newline at end of file +export default withStreamlitConnection(AgGrid)