From 17869709dc105442c3148923adf3aa99cada4293 Mon Sep 17 00:00:00 2001 From: m-wrzr Date: Thu, 2 Jan 2025 16:28:26 +0100 Subject: [PATCH] support live theme changes for searchbox color (#82) * add live styles; * fix ci * remove apt install; --- .github/workflows/ci.yml | 6 ++--- .github/workflows/frontend.yml | 2 +- .../frontend/src/Searchbox.tsx | 23 +++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 335caa1..7acffb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: [push] jobs: pre-commit: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: python-version: ["3.9", "3.11", "3.12"] @@ -19,7 +19,7 @@ jobs: types: needs: [pre-commit] - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: python-version: ["3.9", "3.11", "3.12"] @@ -34,7 +34,7 @@ jobs: tests: needs: [pre-commit, types] - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: python-version: ["3.9", "3.12"] diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 184e632..0c211a8 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -5,7 +5,7 @@ on: [push] jobs: lint: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 defaults: run: diff --git a/streamlit_searchbox/frontend/src/Searchbox.tsx b/streamlit_searchbox/frontend/src/Searchbox.tsx index 82b29b2..00d9e91 100644 --- a/streamlit_searchbox/frontend/src/Searchbox.tsx +++ b/streamlit_searchbox/frontend/src/Searchbox.tsx @@ -40,10 +40,6 @@ class Searchbox extends StreamlitComponentBase { inputValue: "", }; - private style = new SearchboxStyle( - this.props.theme, - this.props.args.style_overrides?.searchbox || {}, - ); private ref: any = React.createRef(); constructor(props: any) { @@ -58,6 +54,13 @@ class Searchbox extends StreamlitComponentBase { } } + private getStyleFromTheme = (): SearchboxStyle => { + return new SearchboxStyle( + this.props.theme, + this.props.args.style_overrides?.searchbox || {}, + ); + }; + /** * new keystroke on searchbox * @param input @@ -139,13 +142,15 @@ class Searchbox extends StreamlitComponentBase { } }; + const style = this.getStyleFromTheme(); + // option when the clear button is shown const clearable = this.props.args.style_overrides?.clear?.clearable; return (
{this.props.args.label && ( -
{this.props.args.label}
+
{this.props.args.label}
)}