Skip to content

Commit

Permalink
support custom palette
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Jan 3, 2025
1 parent 9574765 commit c2c1f95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/mui-material/src/Link/getTextDecoration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ describe('getTextDecoration', () => {
);
expect(() => getTextDecoration({ theme, ownerState: { color: 'yellow' } })).to.throw();
});

it('custom palette', () => {
const customTheme = createTheme({
colorSchemes: {
light: {
palette: {
myColor: theme.palette.augmentColor({ color: { main: '#bbbbbb' } }),
},
},
dark: {
palette: {
myColor: theme.palette.augmentColor({ color: { main: '#aaaaaa' } }),
},
},
},
});
expect(getTextDecoration({ theme: customTheme, ownerState: { color: 'myColor' } })).to.equal(
'rgba(187, 187, 187, 0.4)',
);
});
});

describe('CSS variables', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/mui-material/src/Link/getTextDecoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const getTextDecoration = <T extends Theme>({
ownerState: { color: string };
}) => {
const transformedColor = ownerState.color;
const color = (getPath(theme, `palette.${transformedColor}`, false) ||
// check the `main` color first for a custom palette, then fallback to the color itself
const color = (getPath(theme, `palette.${transformedColor}.main`, false) ||
getPath(theme, `palette.${transformedColor}`, false) ||
ownerState.color) as string;
const channelColor = getPath(theme, `palette.${transformedColor}Channel`) as string | null;
const channelColor = (getPath(theme, `palette.${transformedColor}.mainChannel`) ||
getPath(theme, `palette.${transformedColor}Channel`)) as string | null;
if ('vars' in theme && channelColor) {
return `rgba(${channelColor} / 0.4)`;
}
Expand Down

0 comments on commit c2c1f95

Please sign in to comment.