React-native-ui-kitten: Adding a new color (accent/secondary color)

Created on 2 Jul 2020  路  5Comments  路  Source: akveo/react-native-ui-kitten

I'm trying to figure out a way to add a new secondary/accent color to be part of my theme. By that I mean adding a new color similar to how the primary color is defined, and thus results in a new status variant which could be for called "secondary" or "accent". The reason why I want to try and add a new color is because say for example your brand consists of multiple colors, thus you can't rely on just 1 primary color and the rest of the semantic colors which are situational such as success and error colors. I want to be able to add more than 1 color to define my brand. Is that possible with the Eva Design System? I tried to read the docs but couldn't find anything related to adding multiple brand colors. Any help would be greatly appreciated!

Help wanted

Most helpful comment

There is no direct support for mutiple "primary" colors from UI Kitten itself..
However, you can use the custom mapping feature:
https://akveo.github.io/react-native-ui-kitten/docs/design-system/customize-mapping#customize-component-mapping

You can add a new variant group to the appearance property of the components, and override the colors you're interested into. For exammple, on a button, you may create this mapping:

{
    "components": {
        "Button": {
            "appearances": {
                "filled": {
                    "variantGroups": {
                        "status": {
                            "secondary": {
                                "backgroundColor": "#F00",
                                "textColor": "#FFF",
                            }
                        }
                    }
                }
            }
        }
    }
}

and use it as:

// status="primary" is defined by UI Kitten
<Button appearance="filled" status="primary" />
// status="secondary" comes from your custom mapping
<Button appearance="filled" status="secondary" />

All 5 comments

There is no direct support for mutiple "primary" colors from UI Kitten itself..
However, you can use the custom mapping feature:
https://akveo.github.io/react-native-ui-kitten/docs/design-system/customize-mapping#customize-component-mapping

You can add a new variant group to the appearance property of the components, and override the colors you're interested into. For exammple, on a button, you may create this mapping:

{
    "components": {
        "Button": {
            "appearances": {
                "filled": {
                    "variantGroups": {
                        "status": {
                            "secondary": {
                                "backgroundColor": "#F00",
                                "textColor": "#FFF",
                            }
                        }
                    }
                }
            }
        }
    }
}

and use it as:

// status="primary" is defined by UI Kitten
<Button appearance="filled" status="primary" />
// status="secondary" comes from your custom mapping
<Button appearance="filled" status="secondary" />

It is not working here as @CostachescuCristinel suggested.
It seems to me that new colors are not being accepted. If I try to override the primary color, it works. But creating a secondary color it doesn't work.

Follow my mapping.json

{
  "components": {
    "Button": {
      "appearances": {
        "filled": {
          "variantGroups": {
            "status": {
              "secondary": {
                "backgroundColor": "#693f41",
                "textColor": "#ffffff"
                }
              }
            }
          }
        }
      }
    }
  }
}

```jsx

@mateusduraes you should also declare secondary variant group in meta to make it work. The component knows nothing about particular variant, appearance or state until it's not done.

Hi @artyorsh, it works!
It makes total sense, thank you so much.

@artyorsh Hi - I just tried that and got this error:

Button: unsupported configuration.
Check one of the following prop values: {
  "appearance": "filled",
  "variants": [
    "secondary",
    "medium"
  ],
  "states": []
}

This is what my mapping.json looks like:

{
  "components": {
    "Button": {
      "meta": {
        "variantGroups": {
          "status": {
            "secondary": {
              "default": false
            }
          }
        }
      },
      "appearances": {
        "filled": {
          "variantGroups": {
            "status": {
              "secondary": {
                "backgroundColor": "#3F2B1C",
                "textColor": "#FFF"
              }
            }
          }
        }
      }
    }
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

betodasilva picture betodasilva  路  3Comments

domsterthebot picture domsterthebot  路  3Comments

nonameolsson picture nonameolsson  路  3Comments

gimli01 picture gimli01  路  3Comments

evangunawan picture evangunawan  路  3Comments