Skip to content

Commit 8162927

Browse files
wbrgssjonmmease
authored andcommitted
Enable DDK compatibility (#1541)
* Accept `var(--*)` as valid colors * Add var(--*) values to color validator acceptance tests
1 parent ec67e96 commit 8162927

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

_plotly_utils/basevalidators.py

+6
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ class ColorValidator(BaseValidator):
10331033
"""
10341034
re_hex = re.compile('#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})')
10351035
re_rgb_etc = re.compile('(rgb|hsl|hsv)a?\([\d.]+%?(,[\d.]+%?){2,3}\)')
1036+
re_ddk = re.compile('var\(\-\-.*\)')
10361037

10371038
named_colors = [
10381039
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
@@ -1229,6 +1230,11 @@ def perform_validate_coerce(v, allow_number=None):
12291230
# Valid rgb(a), hsl(a), hsv(a) color
12301231
# (e.g. rgba(10, 234, 200, 50%)
12311232
return v
1233+
elif fullmatch(ColorValidator.re_ddk, v_normalized):
1234+
# Valid var(--*) DDK theme variable, inspired by CSS syntax
1235+
# (e.g. var(--accent) )
1236+
# DDK will crawl & eval var(-- colors for Graph theming
1237+
return v
12321238
elif v_normalized in ColorValidator.named_colors:
12331239
# Valid named color (e.g. 'coral')
12341240
return v

_plotly_utils/tests/validators/test_color_validator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def validator_aok_colorscale():
2828
# Array not ok, numbers not ok
2929
# ----------------------------
3030
@pytest.mark.parametrize('val',
31-
['red', 'BLUE', 'rgb(255, 0, 0)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
31+
['red', 'BLUE', 'rgb(255, 0, 0)', 'var(--accent)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
3232
'hsv(0, 100%, 100%)', 'hsva(0, 100%, 100%, 50%)'])
3333
def test_acceptance(val, validator):
3434
assert validator.validate_coerce(val) == val
@@ -58,7 +58,7 @@ def test_rejection(val, validator):
5858
# ------------------------
5959
# ### Acceptance ###
6060
@pytest.mark.parametrize('val',
61-
['red', 'BLUE', 23, 15, 'rgb(255, 0, 0)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
61+
['red', 'BLUE', 23, 15, 'rgb(255, 0, 0)', 'var(--accent)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
6262
'hsv(0, 100%, 100%)', 'hsva(0, 100%, 100%, 50%)'])
6363
def test_acceptance_colorscale(val, validator_colorscale):
6464
assert validator_colorscale.validate_coerce(val) == val

0 commit comments

Comments
 (0)