Skip to content
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

Custom colors in Typescript projects cause constant log errors #559

Open
samhepburn-98 opened this issue Jan 11, 2024 · 1 comment
Open

Comments

@samhepburn-98
Copy link

samhepburn-98 commented Jan 11, 2024

The types for component colors do not allow for customisation.

  • Added customColor to tailwind.config.ts
  • Added customColor to valid array in MT Theme
  • Added customColor to styles array in MT Theme

The component does accept the prop and render correctly, but these warnings appear constantly in the console.

Screenshot 2024-01-11 at 12 49 44

I know these are warnings and not errors, but the console noise is incredibly annoying for every component to be clogging my logs with warnings telling me that a color that DOES exist, doesn't exist.
(This is the same for other components too)

The prop type of color should allow for all custom values defined in valid and not log any errors.

I am using Next.js 14, with Tailwind 3.4.1

My tailwind.config.ts

import type { Config } from "tailwindcss";
import withMT from "@material-tailwind/react/utils/withMT";

const config: Config = {
    content: [
        "./src/**/*.{js,ts,jsx,tsx,mdx}",
    ],
    theme: {
        extend: {
            colors: {
                customColor: {
                    light: "#395363",
                    DEFAULT: "#08293C",
                    dark: "#051c2a",
                    contrast: "#ffffff"
                },
            },
        },
    },
    plugins: [],
};
export default withMT(config);

My Theme Provider:

"use client";

import { PropsWithChildren } from "react";
import { ThemeProvider } from "@material-tailwind/react";

const MTProvider = ({ children }: PropsWithChildren) => {
    const theme = {
        typography: {
            defaultProps: {
                variant: "bodyMedium",
                color: "inherit",
                textGradient: false,
                className: "",
            },
            valid: {
                colors: [
                    "customColor",
                ]
            },
            styles: {
                colors: {
                    "customColor": {
                        color: "text-customColor",
                    },
                }
            }
        }
    };

    return (
        <ThemeProvider value={theme}>
            {children}
        </ThemeProvider>
    );
};

export default MTProvider;

My Typography component

"use client";

import { Typography as MtTypography } from "@material-tailwind/react";
import { PropsWithChildren } from "react";

const Typography = ({ children }: PropsWithChildren) => {
    return (
        <MtTypography
           color="customColor"
        >
            {children}
        </MtTypography>
    );
};

export default Typography;
@samhepburn-98 samhepburn-98 changed the title Cannot use custom colors in Typescript projects Custom colors in Typescript projects cause constant log errors Jan 11, 2024
@sajadevo
Copy link
Collaborator

sajadevo commented Feb 7, 2024

@samhepburn-98 the issue is with PropTypes and we can't pass custom value to it this issue will be fixed on v3 since we've dropped the PropTypes library and only rely on the typescript types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants