question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow rbg and rgba , hsl and hsla as valid colors.

See original GitHub issue

https://github.com/jupyter-widgets/ipywidgets/blob/381180372b912e7780cc2d2ebd4f89e281bea3b9/ipywidgets/widgets/trait_types.py#L13-L26

Think we can use

^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((\d+%?(deg|rad|grad|turn)?[,\s]+){2,3}[\s\/]*[\d\.]+%?\))

As regex to also validate

hence change to


 _color_re = re.compile(r'#[a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?$') 
_rbg_rgba_hsl_hsla = re.compile('^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((\d+%?(deg|rad|grad|turn)?[,\s]+){2,3}[\s\/]*[\d\.]+%?\))')
  
  
 class Color(traitlets.Unicode): 
     """A string holding a valid HTML color such as 'blue', '#060482', '#A80'""" 
  
     info_text = 'a valid HTML color' 
     default_value = traitlets.Undefined 
  
     def validate(self, obj, value): 
         if value.lower() in _color_names or _color_re.match(value) or _rbg_rgba_hsl_hsla.match(color) : 
             return value 
         self.error(obj, value) 

checked with code:


import re

_rbg_rgba_hsl_hsla = re.compile('^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((\d+%?(deg|rad|grad|turn)?[,\s]+){2,3}[\s\/]*[\d\.]+%?\))')

test_list = [
    
	'rgb(255, 0, 0, 0.3)',  # red 
	'rgb(0, 255, 700)',     # green 
	'rgb(0, 0, 255)',      # blue 

	# RGBA Colors 
	'rgba(255, 0, 0, 3)',  # red with opacity 
	'rgba(0, 255, 0)',     # green with opacity 
	'rgba(0, 0, 255, 1)',  # blue with opacity 

	#  HSL Colors 
	'hsl(120, 100%, 500%)', # green 
	'hsl(120, 100%, 75)',   # light green 
	'hsl(120, 100%, 25%)', # dark green 
	'hsl(120,  60%, 70)',   # pastel green 

	# HSLA Colors 
	'hsl(120, 100%, 50%, 0.2)',   # green with opacity 
	'hsla(120, 100%, 75%, 40)',   # light green with opacity 
	'hsl(120, 100%, 70%, 0.6)',   # dark green with opacity 
	'hsla(120,  60%, 70%, 2)',    # pastel green with opacity 
]

result = []
for color in test_list: 
     result.append(_rbg_rgba_hsl_hsla.match(color))
    
dict(zip(test_list,result))

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vidartfcommented, Jan 22, 2019

Actually, I see that the tests does not include any HSL values. They might have gotten lost somewhere. Putting that as a TODO on the PR.

0reactions
DanielAristidoucommented, Jun 6, 2019

vidartf-fullcolor has been merged and closes this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS3 RGBA, HSL and HSLA Color Values - Tutorial Republic
Colors can be defined in the RGBA model (red-green-blue-alpha) using the rgba() functional notation. RGBA color model are an extension of RGB color...
Read more >
HTML HSL and HSLA Colors - W3Schools
HSLA color values are an extension of HSL with an Alpha channel (opacity). HSL Color Values. In HTML, a color can be specified...
Read more >
RGBA, HSLA and HSL Colors
RGBA & HSL/HSLA colors are introduced in CSS3. Till CSS2, we were using RGB colors ( red, green, blue ) only. RGB and...
Read more >
How to use HSL and HSLa Colors in CSS - Techstacker
HSL and HSLa are color methods in CSS that you can use as alternatives to Hex or RGB/RGBa to apply more real-world colors...
Read more >
<color> - CSS: Cascading Style Sheets - MDN Web Docs
Many designers find HSL more intuitive than RGB, since it allows hue, saturation, and lightness to each be adjusted independently. HSL can also ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found