Skip to content

Commit

Permalink
Rerun on color picker close + move out of beta (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
karriebear committed Oct 27, 2020
1 parent b9b94e3 commit 565bd72
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ With widgets, Streamlit allows you to bake interactivity directly into your apps
.. autofunction:: streamlit.date_input
.. autofunction:: streamlit.time_input
.. autofunction:: streamlit.file_uploader
.. autofunction:: streamlit.beta_color_picker
.. autofunction:: streamlit.color_picker
```

## Control flow
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ _Release date: May 05, 2020_
**Highlights:**

- 🎨 New color-picker widget! Use it with
[`st.beta_color_picker()`](https://docs.streamlit.io/en/latest/api.html#streamlit.beta_color_picker)
[`st.beta_color_picker()`](https://docs.streamlit.io/en/0.69.0/api.html#streamlit.beta_color_picker)
- 🧪 Introducing `st.beta_*` and `st.experimental_*` function prefixes, for faster
Streamlit feature releases. See
[docs](https://docs.streamlit.io/en/latest/api.html#pre-release-features) for more info.
Expand Down
4 changes: 2 additions & 2 deletions e2e/scripts/st_color_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import streamlit as st

c1 = st.beta_color_picker("Default Color")
c1 = st.color_picker("Default Color")
st.write("Color 1", c1)

c2 = st.beta_color_picker("New Color", "#EB144C")
c2 = st.color_picker("New Color", "#EB144C")
st.write("Color 2", c2)
2 changes: 1 addition & 1 deletion e2e/specs/st_color_picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

describe("st.beta_color_picker", () => {
describe("st.color_picker", () => {
before(() => {
cy.visit("http://localhost:3000/");
});
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/widgets/ColorPicker/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ class ColorPicker extends React.PureComponent<Props, State> {
}

private onChangeComplete = (color: ColorResult): void => {
this.setState(
{
value: color.hex,
},
() => this.setWidgetValue({ fromUi: true })
)
this.setState({ value: color.hex })
}

private onColorClose = (): void => {
this.setWidgetValue({ fromUi: true })
}

public render = (): React.ReactNode => {
Expand All @@ -81,6 +80,7 @@ class ColorPicker extends React.PureComponent<Props, State> {
<div className="Widget stColorPicker" style={style}>
<label>{element.label}</label>
<UIPopover
onClose={this.onColorClose}
content={() => (
<ChromePicker
color={value}
Expand Down
9 changes: 5 additions & 4 deletions lib/streamlit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ def _update_logger():
video = _main.video # noqa: E221
warning = _main.warning # noqa: E221
write = _main.write # noqa: E221
beta_color_picker = _main.beta_color_picker # noqa: E221
beta_container = _main.beta_container # noqa: E221
beta_expander = _main.beta_expander # noqa: E221
beta_columns = _main.beta_columns # noqa: E221
color_picker = _main.color_picker # noqa: E221

# Config

Expand Down Expand Up @@ -201,6 +198,10 @@ def wrapped(*args, **kwargs):


beta_set_page_config = _beta_warning(set_page_config, "2021-01-06")
beta_color_picker = _beta_warning(_main.color_picker, "January 28, 2021")
beta_container = _main.beta_container # noqa: E221
beta_expander = _main.beta_expander # noqa: E221
beta_columns = _main.beta_columns # noqa: E221


def set_option(key, value):
Expand Down
4 changes: 2 additions & 2 deletions lib/streamlit/elements/color_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class ColorPickerMixin:
def beta_color_picker(dg, label, value=None, key=None):
def color_picker(dg, label, value=None, key=None):
"""Display a color picker widget.
Note: This is a beta feature. See
Expand All @@ -33,7 +33,7 @@ def beta_color_picker(dg, label, value=None, key=None):
Example
-------
>>> color = st.beta_color_picker('Pick A Color', '#00f900')
>>> color = st.color_picker('Pick A Color', '#00f900')
>>> st.write('The current color is', color)
"""
Expand Down
8 changes: 4 additions & 4 deletions lib/tests/streamlit/color_picker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class ColorPickerTest(testutil.DeltaGeneratorTestCase):
def test_just_label(self):
"""Test that it can be called with no value."""
st.beta_color_picker("the label")
st.color_picker("the label")

c = self.get_delta_from_queue().new_element.color_picker
self.assertEqual(c.label, "the label")
Expand All @@ -32,7 +32,7 @@ def test_just_label(self):
@parameterized.expand([("#333333", "#333333"), ("#333", "#333"), (None, "#000000")])
def test_value_types(self, arg_value, proto_value):
"""Test that it supports different types of values."""
st.beta_color_picker("the label", arg_value)
st.color_picker("the label", arg_value)

c = self.get_delta_from_queue().new_element.color_picker
self.assertEqual(c.label, "the label")
Expand All @@ -41,9 +41,9 @@ def test_value_types(self, arg_value, proto_value):
def test_invalid_value_type_error(self):
"""Tests that when the value type is invalid, an exception is generated"""
with pytest.raises(StreamlitAPIException) as exc_message:
st.beta_color_picker("the label", 1234567)
st.color_picker("the label", 1234567)

def test_invalid_string(self):
"""Tests that when the string doesn't match regex, an exception is generated"""
with pytest.raises(StreamlitAPIException) as exc_message:
st.beta_color_picker("the label", "#invalid-string")
st.color_picker("the label", "#invalid-string")

0 comments on commit 565bd72

Please sign in to comment.