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

[Chip] Add chip classes #33801

Merged
merged 4 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/pages/material-ui/api/chip.json
Expand Up @@ -44,8 +44,12 @@
"root",
"sizeSmall",
"sizeMedium",
"colorError",
"colorInfo",
"colorPrimary",
"colorSecondary",
"colorSuccess",
"colorWarning",
"disabled",
"clickable",
"clickableColorPrimary",
Expand Down
20 changes: 20 additions & 0 deletions docs/translations/api-docs/chip/chip.json
Expand Up @@ -28,6 +28,16 @@
"nodeName": "the root element",
"conditions": "<code>size=\"medium\"</code>"
},
"colorError": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>color=\"error\"</code>"
},
"colorInfo": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>color=\"info\"</code>"
},
"colorPrimary": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
Expand All @@ -38,6 +48,16 @@
"nodeName": "the root element",
"conditions": "<code>color=\"secondary\"</code>"
},
"colorSuccess": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>color=\"success\"</code>"
},
"colorWarning": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>color=\"warning\"</code>"
},
"disabled": {
"description": "State class applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
Expand Down
28 changes: 28 additions & 0 deletions packages/mui-material/src/Chip/Chip.test.js
Expand Up @@ -71,6 +71,34 @@ describe('<Chip />', () => {
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorSecondary);
});

it('should render with the root and the info class', () => {
const { container } = render(<Chip color="info" />);

const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorInfo);
});

it('should render with the root and the error class', () => {
const { container } = render(<Chip color="error" />);

const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorError);
});

it('should render with the root and the warning class', () => {
const { container } = render(<Chip color="warning" />);

const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorWarning);
});

it('should render with the root and the success class', () => {
const { container } = render(<Chip color="success" />);

const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorSuccess);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should render with the root and the info class', () => {
const { container } = render(<Chip color="info" />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorInfo);
});
it('should render with the root and the error class', () => {
const { container } = render(<Chip color="error" />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorError);
});
it('should render with the root and the warning class', () => {
const { container } = render(<Chip color="warning" />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorWarning);
});
it('should render with the root and the success class', () => {
const { container } = render(<Chip color="success" />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorSuccess);
});
it('should render with the color class name based on the color prop', () => {
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);
['error', 'success', 'info', 'warning'].map((color) => {
const { container } = render(<Chip color={color} />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes[`color${capitalize(color)}`]);
});

Can we simplify maybe to something like this (I haven't run, there could be some issues with the code :))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Thanks for the suggestion. I have updated the unit tests for color classes.

});

describe('clickable chip', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/mui-material/src/Chip/chipClasses.ts
Expand Up @@ -7,10 +7,18 @@ export interface ChipClasses {
sizeSmall: string;
/** Styles applied to the root element if `size="medium"`. */
sizeMedium: string;
/** Styles applied to the root element if `color="error"`. */
colorError: string;
/** Styles applied to the root element if `color="info"`. */
colorInfo: string;
/** Styles applied to the root element if `color="primary"`. */
colorPrimary: string;
/** Styles applied to the root element if `color="secondary"`. */
colorSecondary: string;
/** Styles applied to the root element if `color="success"`. */
colorSuccess: string;
/** Styles applied to the root element if `color="warning"`. */
colorWarning: string;
/** State class applied to the root element if `disabled={true}`. */
disabled: string;
/** Styles applied to the root element if `onClick` is defined or `clickable={true}`. */
Expand Down Expand Up @@ -95,8 +103,12 @@ const chipClasses: ChipClasses = generateUtilityClasses('MuiChip', [
'root',
'sizeSmall',
'sizeMedium',
'colorError',
'colorInfo',
'colorPrimary',
'colorSecondary',
'colorSuccess',
'colorWarning',
'disabled',
'clickable',
'clickableColorPrimary',
Expand Down