-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Badge] Create unstyled component & move to emotion (#23745)
- Loading branch information
Showing
35 changed files
with
1,615 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"props": { | ||
"anchorOrigin": { | ||
"type": { | ||
"name": "shape", | ||
"description": "{ horizontal: 'left'<br>| 'right', vertical: 'bottom'<br>| '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>| 'rectangular'" }, | ||
"default": "'rectangular'" | ||
}, | ||
"showZero": { "type": { "name": "bool" } }, | ||
"variant": { | ||
"type": { | ||
"name": "union", | ||
"description": "'dot'<br>| 'standard'<br>| 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
Oops, something went wrong.