Skip to content

Commit

Permalink
support live theme changes for searchbox color (#82)
Browse files Browse the repository at this point in the history
* add live styles;

* fix ci

* remove apt install;
  • Loading branch information
m-wrzr authored Jan 2, 2025
1 parent 5af131b commit 1786970
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand All @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push]

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

defaults:
run:
Expand Down
23 changes: 14 additions & 9 deletions streamlit_searchbox/frontend/src/Searchbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class Searchbox extends StreamlitComponentBase<State> {
inputValue: "",
};

private style = new SearchboxStyle(
this.props.theme,
this.props.args.style_overrides?.searchbox || {},
);
private ref: any = React.createRef();

constructor(props: any) {
Expand All @@ -58,6 +54,13 @@ class Searchbox extends StreamlitComponentBase<State> {
}
}

private getStyleFromTheme = (): SearchboxStyle => {
return new SearchboxStyle(
this.props.theme,
this.props.args.style_overrides?.searchbox || {},
);
};

/**
* new keystroke on searchbox
* @param input
Expand Down Expand Up @@ -139,13 +142,15 @@ class Searchbox extends StreamlitComponentBase<State> {
}
};

const style = this.getStyleFromTheme();

// option when the clear button is shown
const clearable = this.props.args.style_overrides?.clear?.clearable;

return (
<div style={this.props.args.style_overrides?.wrapper || {}}>
{this.props.args.label && (
<div style={this.style.label}>{this.props.args.label}</div>
<div style={style.label}>{this.props.args.label}</div>
)}

<Select
Expand All @@ -166,25 +171,25 @@ class Searchbox extends StreamlitComponentBase<State> {
inputValue={editableAfterSubmit ? this.state.inputValue : undefined}
isClearable={clearable !== "never"}
isSearchable={true}
styles={this.style.select}
styles={style.select}
options={this.props.args.options}
placeholder={this.props.args.placeholder}
// component overrides
components={{
ClearIndicator: (props) =>
this.style.clearIndicator(
style.clearIndicator(
props,
this.props.args.style_overrides?.clear || {},
),
DropdownIndicator: () =>
this.style.iconDropdown(
style.iconDropdown(
this.state.menu,
this.props.args.style_overrides?.dropdown || {},
),
IndicatorSeparator: () => null,
Input: editableAfterSubmit ? Input : components.Input,
Option: (props) =>
this.style.optionHighlighted(
style.optionHighlighted(
props,
this.props.args.style_overrides?.searchbox?.option
?.highlightColor || undefined,
Expand Down

0 comments on commit 1786970

Please sign in to comment.