Skip to content

Commit

Permalink
[Chip] Add chip classes (mui#33801)
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikkarad authored and alexfauquette committed Oct 14, 2022
1 parent aae28a1 commit 5f84edc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
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

0 comments on commit 5f84edc

Please sign in to comment.