Passing color prop isn't working with custom button

import React from "react";
type ButtonProps = {
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
children?: React.ReactNode;
color?: string;
};

const Button: React.FC<ButtonProps> = function ({
disabled = false,
onClick = (e) => {
alert(
`Button with text "${e.currentTarget.innerText}" was clicked but does not have an onClick method!`
);
},
children,
color = "zinc",
}: ButtonProps) {
const buttonClass = `flex rounded-md bg-${color}-900 p-1 text-${color}-300 transition duration-300 ease-in-out hover:bg-${color}-800 hover:text-${color}-200
${disabled ? "cursor-not-allowed opacity-50" : ""}`;
return (
<button
className={buttonClass}
onClick={
!disabled
? onClick
: () => {
"do nothing";
}
}
>
{children ?? "No content"}
<br />
{buttonClass}
</button>
);
};

export default Button;
import React from "react";
type ButtonProps = {
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
children?: React.ReactNode;
color?: string;
};

const Button: React.FC<ButtonProps> = function ({
disabled = false,
onClick = (e) => {
alert(
`Button with text "${e.currentTarget.innerText}" was clicked but does not have an onClick method!`
);
},
children,
color = "zinc",
}: ButtonProps) {
const buttonClass = `flex rounded-md bg-${color}-900 p-1 text-${color}-300 transition duration-300 ease-in-out hover:bg-${color}-800 hover:text-${color}-200
${disabled ? "cursor-not-allowed opacity-50" : ""}`;
return (
<button
className={buttonClass}
onClick={
!disabled
? onClick
: () => {
"do nothing";
}
}
>
{children ?? "No content"}
<br />
{buttonClass}
</button>
);
};

export default Button;
When I pass a color that isn't zinc to this is breaks ;-; any obvoius reasons as to why
10 Replies
Hycord | @ When Replying
<Button disabled={!toggled} color="purple">
Hello, there!
</Button>
<Button disabled={!toggled} color="purple">
Hello, there!
</Button>
Hycord | @ When Replying
When I hard code purple in it works fine
Hycord | @ When Replying
wait now it's working?? wtf now it isn't I'm so confused
benten
benten2y ago
Tailwind parses your files to find classes to include in the stylesheet. Since bg-${color}-900 isn't a tailwind class, it's not going to be added to the stylesheet
Hycord | @ When Replying
Yeah I just found an answer that said that on StackOverflow lmao hmm
benten
benten2y ago
^ this will clear it all up
Hycord | @ When Replying
content: ["./src/**/*.{js,ts,jsx,tsx}"],
content: ["./src/**/*.{js,ts,jsx,tsx}"],
That's what I have now
Want results from more Discord servers?
Add your server