Skip to content

Commit 416f130

Browse files
authored
Merge pull request #557 from AnnMarieW/colorpicker
Added color picker example to docs
2 parents b37ef10 + df468db commit 416f130

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

docs/components_page/components/input.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,25 @@ If you need more granular control over checkboxes and radio buttons, you can als
9292

9393
{{example:components/input/radio_check_standalone.py:standalone_radio_check}}
9494

95+
## Color picker
96+
97+
When using `Input` with `type="color"`, the user may specify a color, either by using a visual color picker or by entering the color in a text field in #rrggbb format.
98+
99+
Note that the color picker presentation may vary substantially from one browser and/or platform to another.
100+
101+
As you drag the selector around the color picker, notice that the text color is smoothly updated. While this is a nice feature, it may cause a performance issue in your app, because the callback fires continuously.
102+
103+
This is a great use-case for a [Dash clientside callback](https://dash.plotly.com/clientside-callbacks). This example uses a clientside callback so the callback runs directly in the browser instead of making requests to the Dash server. For your reference, the regular Dash callback is shown as a comment.
104+
105+
{{example:components/input/colorpicker.py:colorpicker}}
106+
107+
95108
{{apidoc:src/components/input/Input.js}}
96109

97110
{{apidoc:src/components/input/Textarea.js}}
98111

112+
{{apidoc:src/components/input/Select.js}}
113+
99114
{{apidoc:src/components/input/RadioItems.js}}
100115

101116
{{apidoc:src/components/input/Checklist.js}}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import dash_bootstrap_components as dbc
2+
import dash_html_components as html
3+
from dash.dependencies import Input, Output
4+
5+
colorpicker = dbc.FormGroup(
6+
[
7+
dbc.Label(["Select a ", html.Span("color", id="color")]),
8+
dbc.Input(
9+
type="color",
10+
id="colorpicker",
11+
value="#000000",
12+
style={"width": 75, "height": 50},
13+
),
14+
]
15+
)
16+
17+
app.clientside_callback(
18+
"""
19+
function(color) {
20+
return {"color": color}
21+
}
22+
""",
23+
Output("color", "style"),
24+
Input("colorpicker", "value"),
25+
)
26+
27+
28+
# Regular Dash callback
29+
# @app.callback(Output("color", "style"), Input("colorpicker", "value"))
30+
# def update_text(color):
31+
# return {"color": color}

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exclude =
1515
docs/components_page/components/input/simple.py,
1616
docs/components_page/components/input/radio_check_standalone.py,
1717
docs/components_page/components/input/radio_check.py,
18+
docs/components_page/components/input/colorpicker.py,
1819
docs/components_page/components/input_group/button.py,
1920
docs/components_page/components/input_group/dropdown.py,
2021
docs/components_page/components/list_group/links.py,

0 commit comments

Comments
 (0)