这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@0b10
Copy link

@0b10 0b10 commented Aug 23, 2019

Make the parsing option more robust by also parsing RGB and RGBA strings.

This option is disabled by default, and is evaluated by a single conditional within the main export. When enabled, it will also accept RGB and RGBA strings, and behave in a similar manner to parsing hex strings.

When the input is RGB, and 'a' is undefined, return the RGB string.
When the input is RGB, and 'a' is defined, return an RGBA string.
When the input is RGBA. and 'a' is undefined, use the alpha that's part of the string, and return an RGBA string.
When the input is RGBA and 'a' is defined, overwrite the alpha value, and return an RGBA string.

Behavior
The original behavior is intact, and this feature must be explicitly enabled. The interface is identical, and the results for hex strings are also identical. This introduces no breaking changes.

Why?
The intended behavior is to get an RGB(A) string from an input value. This feature still does exactly that, but accepts a wider range of input.

Use case:
Th React library material-ui can be a little unpredictable when it comes to themes. When overriding a color, sometimes it's in the form '#FFF', rgb(), or rgba(). This feature makes the function more robust, while still producing the intended behavior - an RGB(A) string that reflects, an alpha channel, or lack of.

@misund
Copy link
Owner

misund commented Sep 12, 2019

I'm considering whether I'd prefer this in here or if it would be better to make this extension in a separate package.

@0b10
Copy link
Author

0b10 commented Sep 12, 2019

Let me know what you prefer, I'll refactor it if necessary. It makes sense to make it an extension, to keep "hex" to rgba a pure concept.

@0b10
Copy link
Author

0b10 commented Sep 25, 2019

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants