I defined reusable Manage button in a react library with below code
ManageButton.tsx
interface ManageButtonProps {
size?: 'small' | 'medium' | 'large';
name?: string;
dataCy?: string;
startIcon?: React.ReactNode;
onClick: () => void;
children?: React.ReactNode;
}
export function ManageButton(props: ManageButtonProps) {
return (
<Button
name={props.name}
data-cy={props.dataCy ?? 'manage-button'}
className="pushRight"
onClick={() => props.onClick()}
variant="contained"
color="primary"
size={props.size ?? 'large'}
startIcon={props.startIcon ?? <SettingsIcon />}>
{props.children ? props.children : 'Manage'}
</Button>
);
}
In my application I try to use as
<ManageButton onClick={() => console.log('Button clicked')}>Library Button</ManageButton>
The application themed via CSS variables and I created theme by overwriting default color palette. But in my app I see default primary color instead of overwritten color
:root {
--primary-color: #153d77;
}
theme.ts
import {createTheme} from '@mui/material/styles';
export function getCssVariable(variable: string): string {
return getComputedStyle(document.documentElement).getPropertyValue(variable).trim();
}
declare module '@mui/material/styles' {
interface BreakpointOverrides {
xs: true;
sm: true;
md: true;
lg: true;
xl: true;
xxl: true;
xxxl: true;
}
}
// A custom theme for this app
const theme = createTheme({
cssVariables: true,
breakpoints: {
values: {
xs: 0,
sm: 600,
md: 900,
lg: 1200,
xl: 1536,
xxl: 1920,
xxxl: 2200,
},
},
palette: {
primary: {
// Removed getCssVariable('--primary-color') and replaced with a color for testing
main: '#153d77'
}
}
});
export default theme;
Github: https://github.com/pavankjadda/mui-css-variables Here is the Stackblitz demo that reproduces the issue: https://stackblitz.com/~/github.com/pavankjadda/mui-css-variables