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

[system] Support CSS grey color in sx #34548

Merged
merged 7 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/mui-system/src/palette.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import style from './style';
import compose from './compose';

function transform(value, userValue) {
if (userValue === 'grey') {
return userValue;
}
return value;
}

export const color = style({
prop: 'color',
themeKey: 'palette',
transform,
});

export const bgcolor = style({
prop: 'bgcolor',
cssProperty: 'backgroundColor',
themeKey: 'palette',
transform,
});

export const backgroundColor = style({
prop: 'backgroundColor',
themeKey: 'palette',
transform,
});

const palette = compose(color, bgcolor, backgroundColor);
Expand Down
30 changes: 30 additions & 0 deletions packages/mui-system/src/palette.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect } from 'chai';
import palette from './palette';

const theme = {
palette: {
grey: { 100: '#f5f5f5' },
},
};

describe('palette', () => {
it('should treat grey as CSS color', () => {
const output = palette({
theme,
backgroundColor: 'grey',
});
expect(output).to.deep.equal({
backgroundColor: 'grey',
});
});

it('should treat grey.100 as theme color', () => {
const output = palette({
theme,
backgroundColor: 'grey.100',
});
expect(output).to.deep.equal({
backgroundColor: '#f5f5f5',
});
});
});
5 changes: 4 additions & 1 deletion packages/mui-system/src/style.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export interface StyleOptions<PropKey> {
* dot access in `Theme`
*/
themeKey?: string;
transform?: (cssValue: unknown) => number | string | React.CSSProperties | CSSObject;
transform?: (
cssValue: unknown,
userValue: unknown,
) => number | string | React.CSSProperties | CSSObject;
}
export function style<PropKey extends string, Theme extends object>(
options: StyleOptions<PropKey>,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-system/src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getValue(themeMapping, transform, propValueFinal, userValue = propValue
}

if (transform) {
value = transform(value);
value = transform(value, userValue);
}

return value;
Expand Down