-
Notifications
You must be signed in to change notification settings - Fork 675
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
add display names to components #817
Merged
hasparus
merged 10 commits into
system-ui:develop
from
dburles:components-display-names
Dec 16, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1ae38e1
add display names to components
dburles e2c5454
add emotion label property to components
dburles ecb9cdf
appears to be unavoidable
dburles 2885f38
Merge branch 'master' into components-display-names
dburles 821f51b
Merge branch 'master' into components-display-names
dburles 422364e
optional
dburles 0a7e75e
remove label
dburles d4a66d6
add displayName to non-forwardRef components
dburles 18349e2
add function names to Switch and Paragraph
dburles 95f6ea8
Merge remote-tracking branch 'upstream/develop' into components-displ…
dburles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Alert = React.forwardRef((props, ref) => ( | ||
<Box | ||
ref={ref} | ||
variant="primary" | ||
{...props} | ||
__themeKey="alerts" | ||
__css={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
px: 3, | ||
py: 2, | ||
fontWeight: 'bold', | ||
color: 'white', | ||
bg: 'primary', | ||
borderRadius: 4, | ||
}} | ||
/> | ||
)) | ||
export const Alert = React.forwardRef(function Alert(props, ref) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
variant="primary" | ||
{...props} | ||
__themeKey="alerts" | ||
__css={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
px: 3, | ||
py: 2, | ||
fontWeight: 'bold', | ||
color: 'white', | ||
bg: 'primary', | ||
borderRadius: 4, | ||
}} | ||
/> | ||
) | ||
}) |
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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import React from 'react' | ||
import { Image } from './Image' | ||
|
||
export const Avatar = React.forwardRef(({ size = 48, ...props }, ref) => ( | ||
<Image | ||
ref={ref} | ||
width={size} | ||
height={size} | ||
variant="avatar" | ||
{...props} | ||
__css={{ | ||
borderRadius: 9999, | ||
}} | ||
/> | ||
)) | ||
export const Avatar = React.forwardRef(function Avatar( | ||
{ size = 48, ...props }, | ||
ref | ||
) { | ||
return ( | ||
<Image | ||
ref={ref} | ||
width={size} | ||
height={size} | ||
variant="avatar" | ||
{...props} | ||
__css={{ | ||
borderRadius: 9999, | ||
}} | ||
/> | ||
) | ||
}) |
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Badge = React.forwardRef((props, ref) => ( | ||
<Box | ||
ref={ref} | ||
variant="primary" | ||
{...props} | ||
__themeKey="badges" | ||
__css={{ | ||
display: 'inline-block', | ||
verticalAlign: 'baseline', | ||
fontSize: 0, | ||
fontWeight: 'bold', | ||
whiteSpace: 'nowrap', | ||
px: 1, | ||
borderRadius: 2, | ||
color: 'white', | ||
bg: 'primary', | ||
}} | ||
/> | ||
)) | ||
export const Badge = React.forwardRef(function Badge(props, ref) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
variant="primary" | ||
{...props} | ||
__themeKey="badges" | ||
__css={{ | ||
display: 'inline-block', | ||
verticalAlign: 'baseline', | ||
fontSize: 0, | ||
fontWeight: 'bold', | ||
whiteSpace: 'nowrap', | ||
px: 1, | ||
borderRadius: 2, | ||
color: 'white', | ||
bg: 'primary', | ||
}} | ||
/> | ||
) | ||
}) |
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 |
---|---|---|
|
@@ -35,4 +35,6 @@ export const Box = styled('div', { | |
(props) => props.css | ||
) | ||
|
||
Box.displayName = 'Box' | ||
|
||
export default 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 |
---|---|---|
@@ -1,26 +1,28 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Button = React.forwardRef((props, ref) => ( | ||
<Box | ||
ref={ref} | ||
as="button" | ||
variant="primary" | ||
{...props} | ||
__themeKey="buttons" | ||
__css={{ | ||
appearance: 'none', | ||
display: props.hidden ? undefined : 'inline-block', | ||
textAlign: 'center', | ||
lineHeight: 'inherit', | ||
textDecoration: 'none', | ||
fontSize: 'inherit', | ||
px: 3, | ||
py: 2, | ||
color: 'white', | ||
bg: 'primary', | ||
border: 0, | ||
borderRadius: 4, | ||
}} | ||
/> | ||
)) | ||
export const Button = React.forwardRef(function Button(props, ref) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
as="button" | ||
variant="primary" | ||
{...props} | ||
__themeKey="buttons" | ||
__css={{ | ||
appearance: 'none', | ||
display: props.hidden ? undefined : 'inline-block', | ||
textAlign: 'center', | ||
lineHeight: 'inherit', | ||
textDecoration: 'none', | ||
fontSize: 'inherit', | ||
px: 3, | ||
py: 2, | ||
color: 'white', | ||
bg: 'primary', | ||
border: 0, | ||
borderRadius: 4, | ||
}} | ||
/> | ||
) | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Card = React.forwardRef((props, ref) => ( | ||
<Box ref={ref} variant="primary" {...props} __themeKey="cards" /> | ||
)) | ||
export const Card = React.forwardRef(function Card(props, ref) { | ||
return <Box ref={ref} variant="primary" {...props} __themeKey="cards" /> | ||
}) |
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Container = React.forwardRef((props, ref) => ( | ||
<Box | ||
ref={ref} | ||
variant="container" | ||
{...props} | ||
__themeKey="layout" | ||
__css={{ | ||
width: '100%', | ||
maxWidth: 'container', | ||
mx: 'auto', | ||
}} | ||
/> | ||
)) | ||
export const Container = React.forwardRef(function Container(props, ref) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
variant="container" | ||
{...props} | ||
__themeKey="layout" | ||
__css={{ | ||
width: '100%', | ||
maxWidth: 'container', | ||
mx: 'auto', | ||
}} | ||
/> | ||
) | ||
}) |
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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Divider = React.forwardRef((props, ref) => ( | ||
<Box | ||
ref={ref} | ||
as="hr" | ||
variant="styles.hr" | ||
{...props} | ||
__css={{ | ||
color: 'gray', | ||
m: 0, | ||
my: 2, | ||
border: 0, | ||
borderBottom: '1px solid', | ||
}} | ||
/> | ||
)) | ||
export const Divider = React.forwardRef(function Divider(props, ref) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
as="hr" | ||
variant="styles.hr" | ||
{...props} | ||
__css={{ | ||
color: 'gray', | ||
m: 0, | ||
my: 2, | ||
border: 0, | ||
borderBottom: '1px solid', | ||
}} | ||
/> | ||
) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding: is the named
function
syntax still necessary with the Emotionlabel
property added below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, holy smokes! I don't think I realized the
label
property would work more generally in thesx
prop – that's probably worth putting in a guide in the docs or mentioning somewhere 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for React devtools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the
displayName
static property no longer work for React devtools?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does but just not when you’re using
forwardRef
https://reactjs.org/docs/forwarding-refs.html#displaying-a-custom-name-in-devtoolsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thought I'd double check it, it does indeed work with
forwardRef
! Strange, I am sure that it wasn't working at the time, anyway, I'd probably stick with this approach as it's what's recommended and is more concise.