Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support live theme changes for searchbox color #82

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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