#Color text in primary color without hard coding color code/name

9 messages · Page 1 of 1 (latest)

silk thorn
#

Consider the following:

const theme = createTheme({ primaryColor: "teal" });

<Title>
  <Text c="teal" inherit span>
    primary color text
  </Text>{" "}
  normal color text
</Title>

It seems that --mantine-color-primary-text doesn't exist, so setting c="primary" will do nothing. Is there a way I could color a text in primary color, without hard coding c="teal"?

odd agate
#

@silk thorn I believe it's by using the theme object

#

theme.colors.primaryColor

silk thorn
#

I wonder if there's a way of not accessing the theme. I'm using Next.js, and doing so means that I have to extract that rather simple code into a dedicated client component, just for the sake of accessing a context

odd agate
#

Maybe using the CSS variables like --mantine-primary-color-0

#
color="var(--mantine-primary-color-8)"
#

But it forces you to choose the right shade explicitly, and it might not be ideal in some cases.