react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Add validation of CSS colors

Open ExplodingCabbage opened this issue 10 years ago • 5 comments

Most supported CSS properties already have some kind of validation implemented. For instance,

React.StyleSheet.create({
  thing: {
    position: 'monkey',
  },
});

yields an error:

Error: Invariant Violation: Invalid prop position of value monkey supplied to StyleSheet header, expected one of ["absolute","relative"].

However, CSS colors currently have no validation. This doesn't error out, it just produces a white background:

React.StyleSheet.create({
  thing: {
    backgroundColor: 'monkey',
  },
});

Such validation should be added to aid debugging when a developer typos a color.

ExplodingCabbage avatar Dec 10 '15 14:12 ExplodingCabbage

Hey ExplodingCabbage, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If this is a feature request or a bug that you would like to be fixed by the team, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • We welcome clear issues and PRs that are ready for in-depth discussion; thank you for your contributions!

facebook-github-bot avatar Dec 10 '15 14:12 facebook-github-bot

I'll have a pull request in a few hours for this. I would need some details whether colors like "#ABC" are valid values for react-native. Also, can anyone confirm if all the colors in this list are supported by react-native? https://developer.mozilla.org/en/docs/Web/CSS/color_value

Thanks!

shtefanntz avatar Dec 18 '15 15:12 shtefanntz

@shtefanntz hex, rgb and rgba colors are supported. not sure about others.

One quick way to verify the supported named colors will be to create a small React component on http://rnplay.org

satya164 avatar Dec 18 '15 16:12 satya164

@shtefanntz Take a look at processColor.

christopherdro avatar Dec 18 '15 17:12 christopherdro

Thanks for the tip, @christopherdro . I was going to reimplement some of the code from there :)

@satya164, forgot about this site. Thanks!

shtefanntz avatar Dec 18 '15 18:12 shtefanntz