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.

Can't use custom color from theme in Button component

See original GitHub issue

trying to use custom color from theme object in button component

That’s not working

<Button variantColor="newColor" size="md"> Button </Button>

But when using same color in Box component , it’s working:

<Box my={2} bg="newColor"> some box here </Box>

here is the example: https://codesandbox.io/s/vibrant-bush-76581

Issue Analytics

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

github_iconTop GitHub Comments

11reactions
segunadebayocommented, Oct 22, 2019

Hi @ruslan-mystore,

I should have made it clearer in the docs but to use to variantColor with a custom color, you need to create a color object of this shape:

const brand = {
  100: "",
  200: "",
  500: "", 
  ...,
  900: ""
}

The reason is that Button has interactive styles (hover, action, disabled) and we pick color values from the object to make it work out of the box.

Use a tool like https://colorbox.io or https://smart-swatch.netlify.com to generate this quickly.

In the future, we’ll make this more declarative so you’ll be in control of this behavior.

9reactions
Prottoy2938commented, Oct 10, 2020

@segunadebayo , I’ve followed what you’ve said, but still can’t seem to fix the warning and can’t use the color.

theme.tsx looks like this:

import { theme } from "@chakra-ui/core";

const customTheme = {
  ...theme,
  colors: {
    ...theme.colors,
    primary: {
      100: "#CFD1FD",
      200: "#A7ABFB",
      300: "#8388F9",
      400: "#6268F8",
      500: "#444BF7",
      600: "#262EF6",
      700: "#0B14F5",
      800: "#0911DD",
      900: "#080FC7",
    },

    grey: {
      50: "#f0f0fa",
      100: "#d1d3e1",
      200: "#b3b6c9",
      300: "#9499b4",
      400: "#777c9f",
      500: "#5d6385",
      600: "#484d69",
      700: "#34374b",
      800: "#1e212e",
      900: "#080b14",
    },
  },
};

export default customTheme;

And I’m trying to use the grey.900 color in this button

 <Button
                isLoading={loginLoading.accountCreating}
                loadingText="Creating Account"
                variantColor="grey.900" //error here. Note that
                variant="outline"
                type="submit"
                height="43px"
                width="300px"
                border="2px"
                className={styles.submitBtn}
              >
                Create Account
              </Button>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use colors from my Material UI theme in button?
I have a theme, but I cannot use a color from the theme within button. It's locked to a few different colors and...
Read more >
Changing colors - Squarespace Help Center
In any palette, you can use the Palette editor to customize each color in the palette. Change section colors. Your color palette generates ......
Read more >
Color Mode - Chakra UI
Color Mode. Chakra UI comes with built-in support for managing color mode in your apps. By default, most of Chakra's components are dark...
Read more >
Change how your site looks - Sites Help - Google Support
If you're using a custom theme · Point to a section on the page. Then, at the left, click Background Color . ·...
Read more >
Angular Material Theming System - Complete Guide
We will then add a custom theme in it and understand some important ... can also customize color and typography styles for components...
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