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 all 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
18 changes: 7 additions & 11 deletions packages/mui-material/src/Chip/Chip.test.js
Expand Up @@ -58,18 +58,14 @@ describe('<Chip />', () => {
expect(chip).not.to.have.class(classes.deletableColorSecondary);
});

it('should render with the root and the primary class', () => {
const { container } = render(<Chip color="primary" />);
it('should render with the color class name based on the color prop', () => {
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);

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

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

const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorSecondary);
['primary', 'secondary', 'info', 'error', 'warning', 'success'].forEach((color) => {
const { container } = render(<Chip color={color} />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes[`color${capitalize(color)}`]);
});
});
});

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