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

[Badge] Create unstyled component & move to emotion #23745

Merged
merged 60 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
1ac862b
wip
mnajdova Nov 27, 2020
cfec629
fixed typo in class prop
mnajdova Nov 27, 2020
aa327db
prettier, proptypes & docs:api
mnajdova Nov 27, 2020
53b180c
fixed test & build
mnajdova Nov 28, 2020
d15b438
isRtl fix
mnajdova Nov 28, 2020
41ee75b
framer fix
mnajdova Nov 28, 2020
8ba3c6d
fixed ts issue
mnajdova Nov 28, 2020
61131b3
build issues
mnajdova Nov 29, 2020
69d3184
prettier
mnajdova Nov 29, 2020
8907799
fixes
mnajdova Nov 30, 2020
805e893
fixed invisible issue
mnajdova Nov 30, 2020
253aa80
Updated tests & created unstyled demo
mnajdova Nov 30, 2020
da8dfed
fixed lint errors
mnajdova Nov 30, 2020
a595544
removed duplicated tests
mnajdova Nov 30, 2020
e420878
fix rtl
mnajdova Dec 1, 2020
442859d
Merge branch 'fix/docs-rtl' into feat/convert-badge-to-v5
mnajdova Dec 1, 2020
e997a55
fixes
mnajdova Dec 1, 2020
4364757
Merge branch 'next' into feat/convert-badge-to-v5
mnajdova Dec 2, 2020
169c8f7
updated Badge test
mnajdova Dec 2, 2020
4d2a062
Update packages/material-ui/src/Badge/Badge.test.js
mnajdova Dec 2, 2020
bd57973
extracted color prop to Badge, updated buildAPI
mnajdova Dec 2, 2020
5a4d4b1
Merge branch 'next' into feat/convert-badge-to-v5
mnajdova Dec 3, 2020
53e20aa
reverted some rtl changes
mnajdova Dec 3, 2020
905eb15
Merge branch 'feat/convert-badge-to-v5' into feat/badge-unstyled-remo…
mnajdova Dec 3, 2020
7572c90
wip
mnajdova Dec 3, 2020
7b3cfa7
fixes
mnajdova Dec 3, 2020
f76cef2
init
mnajdova Dec 4, 2020
3309ef1
export
mnajdova Dec 4, 2020
fbaa0c1
fixed tests
mnajdova Dec 4, 2020
b54de5e
fixes
mnajdova Dec 4, 2020
1ccef91
fixes
mnajdova Dec 4, 2020
59f13bc
fixes
mnajdova Dec 4, 2020
81dc2a0
more fixes, reverted component breaking change
mnajdova Dec 4, 2020
7cfae24
lint fixes
mnajdova Dec 4, 2020
e9b8cb9
prettier
mnajdova Dec 4, 2020
99fe280
fixes
mnajdova Dec 5, 2020
1951473
Update docs/scripts/buildApi.ts
mnajdova Dec 5, 2020
d5c47b0
Update packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyle…
mnajdova Dec 5, 2020
605aba8
Update packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyle…
mnajdova Dec 5, 2020
ee25a23
fixes
mnajdova Dec 5, 2020
67bcc4e
Merge branch 'feat/convert-badge-to-v5' of https://github.com/mnajdov…
mnajdova Dec 5, 2020
7fe9b09
prettier, docs
mnajdova Dec 5, 2020
0a51998
framer
mnajdova Dec 6, 2020
4fa4f46
prettier
mnajdova Dec 6, 2020
8be4681
fixed props order
mnajdova Dec 7, 2020
8d01617
improvements
mnajdova Dec 7, 2020
9f230b8
prettier
mnajdova Dec 7, 2020
ad64fc8
Merge branch 'feat/slider-component-prop' into feat/convert-badge-to-v5
mnajdova Dec 7, 2020
13fc0f7
Merge branch 'next' into feat/convert-badge-to-v5
mnajdova Dec 7, 2020
1402567
reverted some changes
mnajdova Dec 7, 2020
7529a8d
Merge branch 'next' into feat/convert-badge-to-v5
mnajdova Dec 7, 2020
a868f38
addressed comments
mnajdova Dec 7, 2020
2b2e218
fixed overrides
mnajdova Dec 7, 2020
75f54ce
Merge branch 'next' into feat/convert-badge-to-v5
mnajdova Dec 9, 2020
616f089
yarn docs:api
oliviertassinari Dec 9, 2020
199d7cf
reverted some changes
mnajdova Dec 9, 2020
2958c06
revert more changes
mnajdova Dec 9, 2020
3faeec9
fixed unstyled test failing
mnajdova Dec 10, 2020
3ae6bbe
reverted unnecessary docs updates
mnajdova Dec 10, 2020
733c140
updated test
mnajdova Dec 10, 2020
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
15 changes: 15 additions & 0 deletions docs/pages/api-docs/badge-unstyled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

const pageFilename = 'api/badge-unstyled';
const requireRaw = require.context('!raw-loader!./', false, /\/badge-unstyled\.md$/);

export default function Page({ docs }) {
return <MarkdownDocs docs={docs} />;
}

Page.getInitialProps = () => {
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw });
return { demos, docs };
};
71 changes: 71 additions & 0 deletions docs/pages/api-docs/badge-unstyled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
filename: /packages/material-ui-unstyled/src/BadgeUnstyled/BadgeUnstyled.js
---

<!--- This documentation is automatically generated, do not try to edit it. -->

# BadgeUnstyled API

<p class="description">The API documentation of the BadgeUnstyled React component. Learn more about the props and the CSS customization points.</p>

## Import

```js
import BadgeUnstyled from '@material-ui/unstyled/BadgeUnstyled';
// or
import { BadgeUnstyled } from '@material-ui/unstyled';
```

You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/).





## Props

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">anchorOrigin</span> | <span class="prop-type">{ horizontal: 'left'<br>&#124;&nbsp;'right', vertical: 'bottom'<br>&#124;&nbsp;'top' }</span> | <span class="prop-default">{ vertical: 'top', horizontal: 'right',}</span> | The anchor of the badge. |
| <span class="prop-name">badgeContent</span> | <span class="prop-type">node</span> | | The content rendered within the badge. |
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The badge will be added relative to this node. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'default'<br>&#124;&nbsp;'error'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'</span> | <span class="prop-default">'default'</span> | The color of the component. It supports those theme colors that make sense for this component. |
| <span class="prop-name">components</span> | <span class="prop-type">{ Badge?: elementType, Root?: elementType }</span> | <span class="prop-default">{}</span> | The components used for each slot inside the Badge. Either a string to use a HTML element or a component. |
| <span class="prop-name">componentsProps</span> | <span class="prop-type">object</span> | <span class="prop-default">{}</span> | The props used for each slot inside the Badge. |
| <span class="prop-name">invisible</span> | <span class="prop-type">bool</span> | | If `true`, the badge is invisible. |
| <span class="prop-name">max</span> | <span class="prop-type">number</span> | <span class="prop-default">99</span> | Max count to show. |
| <span class="prop-name">overlap</span> | <span class="prop-type">'circular'<br>&#124;&nbsp;'rectangular'</span> | <span class="prop-default">'rectangular'</span> | Wrapped shape the badge should overlap. |
| <span class="prop-name">showZero</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | Controls whether the badge is hidden when `badgeContent` is zero. |
| <span class="prop-name">variant</span> | <span class="prop-type">'dot'<br>&#124;&nbsp;'standard'<br>&#124;&nbsp;string</span> | <span class="prop-default">'standard'</span> | The variant to use. |

The `ref` is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

## CSS

| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiBadge-root</span> | Styles applied to the root element.
| <span class="prop-name">badge</span> | <span class="prop-name">.MuiBadge-badge</span> | Styles applied to the badge `span` element.
| <span class="prop-name">colorPrimary</span> | <span class="prop-name">.MuiBadge-colorPrimary</span> | Styles applied to the root element if `color="primary"`.
| <span class="prop-name">colorSecondary</span> | <span class="prop-name">.MuiBadge-colorSecondary</span> | Styles applied to the root element if `color="secondary"`.
| <span class="prop-name">colorError</span> | <span class="prop-name">.MuiBadge-colorError</span> | Styles applied to the root element if `color="error"`.
| <span class="prop-name">dot</span> | <span class="prop-name">.MuiBadge-dot</span> | Styles applied to the root element if `variant="dot"`.
| <span class="prop-name">standard</span> | <span class="prop-name">.MuiBadge-standard</span> | Styles applied to the root element if `variant="standard"`.
| <span class="prop-name">anchorOriginTopRightRectangular</span> | <span class="prop-name">.MuiBadge-anchorOriginTopRightRectangular</span> | Styles applied to the root element if `anchorOrigin={{ 'top', 'right' }} overlap="rectangular"`.
| <span class="prop-name">anchorOriginBottomRightRectangular</span> | <span class="prop-name">.MuiBadge-anchorOriginBottomRightRectangular</span> | Styles applied to the root element if `anchorOrigin={{ 'bottom', 'right' }} overlap="rectangular"`.
| <span class="prop-name">anchorOriginTopLeftRectangular</span> | <span class="prop-name">.MuiBadge-anchorOriginTopLeftRectangular</span> | Styles applied to the root element if `anchorOrigin={{ 'top', 'left' }} overlap="rectangular"`.
| <span class="prop-name">anchorOriginBottomLeftRectangular</span> | <span class="prop-name">.MuiBadge-anchorOriginBottomLeftRectangular</span> | Styles applied to the root element if `anchorOrigin={{ 'bottom', 'left' }} overlap="rectangular"`.
| <span class="prop-name">anchorOriginTopRightCircular</span> | <span class="prop-name">.MuiBadge-anchorOriginTopRightCircular</span> | Styles applied to the root element if `anchorOrigin={{ 'top', 'right' }} overlap="circular"`.
| <span class="prop-name">anchorOriginBottomRightCircular</span> | <span class="prop-name">.MuiBadge-anchorOriginBottomRightCircular</span> | Styles applied to the root element if `anchorOrigin={{ 'bottom', 'right' }} overlap="circular"`.
| <span class="prop-name">anchorOriginTopLeftCircular</span> | <span class="prop-name">.MuiBadge-anchorOriginTopLeftCircular</span> | Styles applied to the root element if `anchorOrigin={{ 'top', 'left' }} overlap="circular"`.
| <span class="prop-name">anchorOriginBottomLeftCircular</span> | <span class="prop-name">.MuiBadge-anchorOriginBottomLeftCircular</span> | Styles applied to the root element if `anchorOrigin={{ 'bottom', 'left' }} overlap="circular"`.
| <span class="prop-name">invisible</span> | <span class="prop-name">.MuiBadge-invisible</span> | Pseudo-class to the badge `span` element if `invisible={true}`.

You can override the style of the component thanks to one of these customization points:

- With a [global class name](/guides/interoperability/#global-css).
- With a rule name as part of the component's [`styleOverrides` property](/customization/components/#global-theme-override) in a custom theme.

11 changes: 5 additions & 6 deletions docs/pages/api-docs/badge.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ The `MuiBadge` name can be used for providing [default props](/customization/glo
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The badge will be added relative to this node. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">color</span> | <span class="prop-type">'default'<br>&#124;&nbsp;'error'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'</span> | <span class="prop-default">'default'</span> | The color of the component. It supports those theme colors that make sense for this component. |
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | <span class="prop-default">'span'</span> | The component used for the root node. Either a string to use a HTML element or a component. |
| <span class="prop-name">components</span> | <span class="prop-type">{ Badge?: elementType, Root?: elementType }</span> | <span class="prop-default">{}</span> | The components used for each slot inside the Badge. Either a string to use a HTML element or a component. |
| <span class="prop-name">componentsProps</span> | <span class="prop-type">object</span> | <span class="prop-default">{}</span> | The props used for each slot inside the Badge. |
| <span class="prop-name">invisible</span> | <span class="prop-type">bool</span> | | If `true`, the badge is invisible. |
| <span class="prop-name">max</span> | <span class="prop-type">number</span> | <span class="prop-default">99</span> | Max count to show. |
| <span class="prop-name">overlap</span> | <span class="prop-type">'circular'<br>&#124;&nbsp;'rectangular'</span> | <span class="prop-default">'rectangular'</span> | Wrapped shape the badge should overlap. |
| <span class="prop-name">showZero</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | Controls whether the badge is hidden when `badgeContent` is zero. |
| <span class="prop-name">sx</span> | <span class="prop-type">object</span> | | The system prop that allows defining system overrides as well as additional CSS styles. |
| <span class="prop-name">variant</span> | <span class="prop-type">'dot'<br>&#124;&nbsp;'standard'<br>&#124;&nbsp;string</span> | <span class="prop-default">'standard'</span> | The variant to use. |

The `ref` is forwarded to the root element.
Expand Down Expand Up @@ -67,11 +69,8 @@ Any other props supplied will be provided to the root element (native element).

You can override the style of the component thanks to one of these customization points:

- With a rule name of the [`classes` object prop](/customization/components/#overriding-styles-with-classes).
- With a [global class name](/customization/components/#overriding-styles-with-global-class-names).
- With a theme and an [`overrides` property](/customization/globals/#css).

If that's not sufficient, you can check the [implementation of the component](https://github.com/mui-org/material-ui/blob/next/packages/material-ui/src/Badge/Badge.js) for more detail.
- With a [global class name](/guides/interoperability/#global-css).
- With a rule name as part of the component's [`styleOverrides` property](/customization/components/#global-theme-override) in a custom theme.

## Demos

Expand Down
56 changes: 25 additions & 31 deletions docs/src/pages/components/badges/BadgeAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,11 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormLabel from '@material-ui/core/FormLabel';
import Radio from '@material-ui/core/Radio';
import RadioGroup from '@material-ui/core/RadioGroup';
import { makeStyles } from '@material-ui/core/styles';
import Box from '@material-ui/core/Box';
import MailIcon from '@material-ui/icons/Mail';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';

const useStyles = makeStyles((theme) => ({
root: {
width: '100%',
},
formControl: {
margin: theme.spacing(3),
},
row: {
display: 'flex',
justifyContent: 'center',
},
margin: {
margin: theme.spacing(2),
},
}));

export default function BadgeAlignment() {
const classes = useStyles();
const [horizontal, setHorizontal] = React.useState('right');
const [vertical, setVertical] = React.useState('top');

Expand All @@ -48,9 +31,17 @@ export default function BadgeAlignment() {
`;

return (
<div className={classes.root}>
<div className={classes.row}>
<FormControl component="fieldset" className={classes.formControl}>
<Box sx={{ width: '100%' }}>
<Box
sx={{
display: 'flex',
justifyContent: 'center',
'& fieldset': {
margin: 3,
},
}}
>
<FormControl component="fieldset">
<FormLabel component="legend">Vertical</FormLabel>
<RadioGroup
name="vertical"
Expand All @@ -61,7 +52,7 @@ export default function BadgeAlignment() {
<FormControlLabel value="bottom" control={<Radio />} label="Bottom" />
</RadioGroup>
</FormControl>
<FormControl component="fieldset" className={classes.formControl}>
<FormControl component="fieldset">
<FormLabel component="legend">Horizontal</FormLabel>
<RadioGroup
name="horizontal"
Expand All @@ -72,8 +63,16 @@ export default function BadgeAlignment() {
<FormControlLabel value="left" control={<Radio />} label="Left" />
</RadioGroup>
</FormControl>
</div>
<div className={classes.row}>
</Box>
<Box
sx={{
display: 'flex',
justifyContent: 'center',
'& > *': {
margin: 2,
},
}}
>
<Badge
color="secondary"
variant="dot"
Expand All @@ -82,7 +81,6 @@ export default function BadgeAlignment() {
horizontal,
vertical,
}}
className={classes.margin}
>
<MailIcon />
</Badge>
Expand All @@ -93,7 +91,6 @@ export default function BadgeAlignment() {
horizontal,
vertical,
}}
className={classes.margin}
>
<MailIcon />
</Badge>
Expand All @@ -104,7 +101,6 @@ export default function BadgeAlignment() {
horizontal,
vertical,
}}
className={classes.margin}
>
<MailIcon />
</Badge>
Expand All @@ -115,7 +111,6 @@ export default function BadgeAlignment() {
horizontal,
vertical,
}}
className={classes.margin}
>
<MailIcon />
</Badge>
Expand All @@ -127,12 +122,11 @@ export default function BadgeAlignment() {
horizontal,
vertical,
}}
className={classes.margin}
>
<MailIcon />
</Badge>
</div>
</Box>
<HighlightedCode code={jsx} language="jsx" />
</div>
</Box>
);
}
22 changes: 9 additions & 13 deletions docs/src/pages/components/badges/BadgeMax.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Box from '@material-ui/core/Box';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

const useStyles = makeStyles((theme) => ({
root: {
'& > *': {
margin: theme.spacing(2),
},
},
}));

const defaultProps = {
color: 'secondary',
children: <MailIcon />,
};

export default function BadgeMax() {
const classes = useStyles();

return (
<div className={classes.root}>
<Box
sx={{
'& > *': {
margin: 2,
},
}}
>
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
</div>
</Box>
);
}
24 changes: 9 additions & 15 deletions docs/src/pages/components/badges/BadgeMax.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import * as React from 'react';
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
import Box from '@material-ui/core/Box';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
'& > *': {
margin: theme.spacing(2),
},
},
}),
);

const defaultProps = {
color: 'secondary' as 'secondary',
children: <MailIcon />,
};

export default function BadgeMax() {
const classes = useStyles();

return (
<div className={classes.root}>
<Box
sx={{
'& > *': {
margin: 2,
},
}}
>
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
</div>
</Box>
);
}
36 changes: 13 additions & 23 deletions docs/src/pages/components/badges/BadgeOverlap.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import * as React from 'react';
import clsx from 'clsx';
import { makeStyles } from '@material-ui/core/styles';
import Box from '@material-ui/core/Box';
import Badge from '@material-ui/core/Badge';

const useStyles = makeStyles((theme) => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
},
shape: {
backgroundColor: theme.palette.primary.main,
width: 40,
height: 40,
},
shapeCircle: {
borderRadius: '50%',
},
}));
const shapeStyles = { bgcolor: 'primary.main', width: 40, height: 40 };
const shapeCircleStyles = { borderRadius: '50%' };

export default function BadgeOverlap() {
const classes = useStyles();

const rectangle = <div className={classes.shape} />;
const circle = <div className={clsx(classes.shape, classes.shapeCircle)} />;
const rectangle = <Box sx={shapeStyles} />;
const circle = <Box sx={{ ...shapeStyles, ...shapeCircleStyles }} />;

return (
<div className={classes.root}>
<Box
sx={{
'& > *': {
margin: 1,
},
}}
>
<Badge color="secondary" badgeContent=" ">
{rectangle}
</Badge>
Expand All @@ -39,6 +29,6 @@ export default function BadgeOverlap() {
<Badge color="secondary" overlap="circular" badgeContent=" " variant="dot">
{circle}
</Badge>
</div>
</Box>
);
}
Loading