-
Notifications
You must be signed in to change notification settings - Fork 10
Parse RGB(A) Strings Too #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0b10
wants to merge
24
commits into
misund:main
Choose a base branch
from
0b10:parse-rgba-str
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Owner
|
I'm considering whether I'd prefer this in here or if it would be better to make this extension in a separate package. |
Author
|
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. |
Author
|
Any update on this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.