Skip to content

Commit

Permalink
[Badge] Create unstyled component & move to emotion (#23745)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored Dec 10, 2020
1 parent 189e875 commit a4b6a96
Show file tree
Hide file tree
Showing 35 changed files with 1,615 additions and 349 deletions.
23 changes: 23 additions & 0 deletions docs/pages/api-docs/badge-unstyled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import ApiPage from 'docs/src/modules/components/ApiPage';
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations';
import jsonPageContent from './badge-unstyled.json';

export default function Page(props) {
const { descriptions, pageContent } = props;
return <ApiPage descriptions={descriptions} pageContent={pageContent} />;
}

Page.getInitialProps = () => {
const req = require.context(
'docs/translations/api-docs/badge-unstyled',
false,
/badge-unstyled.*.json$/,
);
const descriptions = mapApiPageTranslations(req);

return {
descriptions,
pageContent: jsonPageContent,
};
};
74 changes: 74 additions & 0 deletions docs/pages/api-docs/badge-unstyled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"props": {
"anchorOrigin": {
"type": {
"name": "shape",
"description": "{ horizontal: 'left'<br>&#124;&nbsp;'right', vertical: 'bottom'<br>&#124;&nbsp;'top' }"
},
"default": "{\n vertical: 'top',\n horizontal: 'right',\n}"
},
"badgeContent": { "type": { "name": "node" } },
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" }, "default": "{}" },
"component": { "type": { "name": "elementType" } },
"components": {
"type": { "name": "shape", "description": "{ Badge?: elementType, Root?: elementType }" },
"default": "{}"
},
"componentsProps": { "type": { "name": "object" }, "default": "{}" },
"invisible": { "type": { "name": "bool" } },
"max": { "type": { "name": "number" }, "default": "99" },
"overlap": {
"type": { "name": "enum", "description": "'circular'<br>&#124;&nbsp;'rectangular'" },
"default": "'rectangular'"
},
"showZero": { "type": { "name": "bool" } },
"variant": {
"type": {
"name": "union",
"description": "'dot'<br>&#124;&nbsp;'standard'<br>&#124;&nbsp;string"
},
"default": "'standard'"
}
},
"name": "BadgeUnstyled",
"styles": {
"classes": [
"root",
"badge",
"dot",
"standard",
"anchorOriginTopRightRectangular",
"anchorOriginBottomRightRectangular",
"anchorOriginTopLeftRectangular",
"anchorOriginBottomLeftRectangular",
"anchorOriginTopRightCircular",
"anchorOriginBottomRightCircular",
"anchorOriginTopLeftCircular",
"anchorOriginBottomLeftCircular",
"invisible"
],
"globalClasses": {
"root": "MuiBadge-root",
"badge": "MuiBadge-badge",
"dot": "MuiBadge-dot",
"standard": "MuiBadge-standard",
"anchorOriginTopRightRectangular": "MuiBadge-anchorOriginTopRightRectangular",
"anchorOriginBottomRightRectangular": "MuiBadge-anchorOriginBottomRightRectangular",
"anchorOriginTopLeftRectangular": "MuiBadge-anchorOriginTopLeftRectangular",
"anchorOriginBottomLeftRectangular": "MuiBadge-anchorOriginBottomLeftRectangular",
"anchorOriginTopRightCircular": "MuiBadge-anchorOriginTopRightCircular",
"anchorOriginBottomRightCircular": "MuiBadge-anchorOriginBottomRightCircular",
"anchorOriginTopLeftCircular": "MuiBadge-anchorOriginTopLeftCircular",
"anchorOriginBottomLeftCircular": "MuiBadge-anchorOriginBottomLeftCircular",
"invisible": "MuiBadge-invisible"
},
"name": null
},
"spread": true,
"forwardsRefTo": "HTMLSpanElement",
"filename": "/packages/material-ui-unstyled/src/BadgeUnstyled/BadgeUnstyled.js",
"inheritance": null,
"demos": "",
"styledComponent": true
}
24 changes: 15 additions & 9 deletions docs/pages/api-docs/badge.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,41 @@
},
"badgeContent": { "type": { "name": "node" } },
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } },
"classes": { "type": { "name": "object" }, "default": "{}" },
"color": {
"type": {
"name": "enum",
"description": "'default'<br>&#124;&nbsp;'error'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'"
},
"default": "'default'"
},
"component": { "type": { "name": "elementType" } },
"components": {
"type": { "name": "shape", "description": "{ Badge?: elementType, Root?: elementType }" },
"default": "{}"
},
"componentsProps": { "type": { "name": "object" }, "default": "{}" },
"invisible": { "type": { "name": "bool" } },
"max": { "type": { "name": "number" }, "default": "99" },
"overlap": {
"type": { "name": "enum", "description": "'circular'<br>&#124;&nbsp;'rectangular'" },
"default": "'rectangular'"
},
"showZero": { "type": { "name": "bool" } },
"sx": { "type": { "name": "object" } },
"variant": {
"type": {
"name": "union",
"description": "'dot'<br>&#124;&nbsp;'standard'<br>&#124;&nbsp;string"
},
"default": "'standard'"
}
},
"component": { "type": { "name": "elementType" } }
},
"name": "Badge",
"styles": {
"classes": [
"root",
"badge",
"colorPrimary",
"colorSecondary",
"colorError",
"dot",
"standard",
"anchorOriginTopRightRectangular",
Expand All @@ -51,15 +54,18 @@
"anchorOriginBottomRightCircular",
"anchorOriginTopLeftCircular",
"anchorOriginBottomLeftCircular",
"invisible"
"invisible",
"colorPrimary",
"colorSecondary",
"colorError"
],
"globalClasses": {},
"name": "MuiBadge"
},
"spread": true,
"forwardsRefTo": "HTMLSpanElement",
"filename": "/packages/material-ui/src/Badge/Badge.js",
"inheritance": null,
"inheritance": { "component": "BadgeUnstyled", "pathname": "/api/badge-unstyled/" },
"demos": "<ul><li><a href=\"/components/avatars/\">Avatars</a></li>\n<li><a href=\"/components/badges/\">Badges</a></li></ul>",
"styledComponent": false
"styledComponent": true
}
8 changes: 4 additions & 4 deletions docs/src/pages/components/badges/CustomizedBadges.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as React from 'react';
import Badge from '@material-ui/core/Badge';
import { withStyles } from '@material-ui/core/styles';
import { experimentalStyled as styled } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import ShoppingCartIcon from '@material-ui/icons/ShoppingCart';

const StyledBadge = withStyles((theme) => ({
badge: {
const StyledBadge = styled(Badge)(({ theme }) => ({
'& .MuiBadge-badge': {
right: -3,
top: 13,
border: `2px solid ${theme.palette.background.paper}`,
padding: '0 4px',
},
}))(Badge);
}));

export default function CustomizedBadges() {
return (
Expand Down
22 changes: 10 additions & 12 deletions docs/src/pages/components/badges/CustomizedBadges.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import * as React from 'react';
import Badge from '@material-ui/core/Badge';
import { Theme, withStyles, createStyles } from '@material-ui/core/styles';
import Badge, { BadgeProps } from '@material-ui/core/Badge';
import { experimentalStyled as styled } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import ShoppingCartIcon from '@material-ui/icons/ShoppingCart';

const StyledBadge = withStyles((theme: Theme) =>
createStyles({
badge: {
right: -3,
top: 13,
border: `2px solid ${theme.palette.background.paper}`,
padding: '0 4px',
},
}),
)(Badge);
const StyledBadge = styled(Badge)<BadgeProps>(({ theme }) => ({
'& .MuiBadge-badge': {
right: -3,
top: 13,
border: `2px solid ${theme.palette.background.paper}`,
padding: '0 4px',
},
}));

export default function CustomizedBadges() {
return (
Expand Down
82 changes: 82 additions & 0 deletions docs/src/pages/components/badges/UnstyledBadge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as React from 'react';
import { experimentalStyled as styled } from '@material-ui/core/styles';

import BadgeUnstyled from '@material-ui/unstyled/BadgeUnstyled';
import Box from '@material-ui/core/Box';

const StyledBadge = styled(BadgeUnstyled)`
box-sizing: border-box;
margin: 0;
padding: 0;
color: rgba(0, 0, 0, 0.85);
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-feature-settings: 'tnum';
position: relative;
display: inline-block;
line-height: 1;
& .MuiBadge-badge {
z-index: auto;
min-width: 20px;
height: 20px;
padding: 0 6px;
color: #fff;
font-weight: 400;
font-size: 12px;
line-height: 20px;
white-space: nowrap;
text-align: center;
background: #ff4d4f;
border-radius: 10px;
box-shadow: 0 0 0 1px #fff;
}
& .MuiBadge-dot {
padding: 0;
z-index: auto;
min-width: 6px;
width: 6px;
height: 6px;
background: #ff4d4f;
border-radius: 100%;
box-shadow: 0 0 0 1px #fff;
}
& .MuiBadge-anchorOriginTopRightCircular {
position: absolute;
top: 0;
right: 0;
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`;

const BadgeContent = () => {
return (
<Box
sx={{
width: 42,
height: 42,
borderRadius: '2px',
background: '#eee',
display: 'inline-block',
verticalAlign: 'middle',
}}
/>
);
};

export default function UnstyledBadge() {
return (
<Box>
<StyledBadge badgeContent={5} overlap="circular" sx={{ mr: 2 }}>
<BadgeContent />
</StyledBadge>
<StyledBadge badgeContent={5} variant="dot" overlap="circular">
<BadgeContent />
</StyledBadge>
</Box>
);
}
88 changes: 88 additions & 0 deletions docs/src/pages/components/badges/UnstyledBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from 'react';
import { experimentalStyled as styled, Theme } from '@material-ui/core/styles';
import { SxProps } from '@material-ui/system';
import BadgeUnstyled, {
BadgeUnstyledProps,
} from '@material-ui/unstyled/BadgeUnstyled';
import Box from '@material-ui/core/Box';

interface StyledBadgeProps extends BadgeUnstyledProps {
sx?: SxProps<Theme>;
}

const StyledBadge: React.FC<StyledBadgeProps> = styled(BadgeUnstyled)`
box-sizing: border-box;
margin: 0;
padding: 0;
color: rgba(0, 0, 0, 0.85);
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-feature-settings: 'tnum';
position: relative;
display: inline-block;
line-height: 1;
& .MuiBadge-badge {
z-index: auto;
min-width: 20px;
height: 20px;
padding: 0 6px;
color: #fff;
font-weight: 400;
font-size: 12px;
line-height: 20px;
white-space: nowrap;
text-align: center;
background: #ff4d4f;
border-radius: 10px;
box-shadow: 0 0 0 1px #fff;
}
& .MuiBadge-dot {
padding: 0;
z-index: auto;
min-width: 6px;
width: 6px;
height: 6px;
background: #ff4d4f;
border-radius: 100%;
box-shadow: 0 0 0 1px #fff;
}
& .MuiBadge-anchorOriginTopRightCircular {
position: absolute;
top: 0;
right: 0;
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`;

const BadgeContent = () => {
return (
<Box
sx={{
width: 42,
height: 42,
borderRadius: '2px',
background: '#eee',
display: 'inline-block',
verticalAlign: 'middle',
}}
/>
);
};

export default function UnstyledBadge() {
return (
<Box>
<StyledBadge badgeContent={5} overlap="circular" sx={{ mr: 2 }}>
<BadgeContent />
</StyledBadge>
<StyledBadge badgeContent={5} variant="dot" overlap="circular">
<BadgeContent />
</StyledBadge>
</Box>
);
}
Loading

0 comments on commit a4b6a96

Please sign in to comment.