Skip to content

Sync Label component with PVC's Label component - #1797

Merged
mperrotti merged 33 commits into
mainfrom
mp/label-sync-with-pvc
Jan 25, 2022
Merged

Sync Label component with PVC's Label component#1797
mperrotti merged 33 commits into
mainfrom
mp/label-sync-with-pvc

Conversation

@mperrotti

@mperrottimperrotti commented Jan 14, 2022

Copy link
Copy Markdown
Contributor

Instead of introducing a breaking change to the existing Label component, I'm proposing that we take the same path we did with ActionList, Button, and others: introduce a "draft" component.

Screenshots

Screen Shot 2022-01-13 at 7 00 46 PM

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

Reference

Issue: https://github.com/github/primer/issues/568
PVC's Label component: https://primer.style/view-components/components/label

@mperrotti
mperrotti requested review from a team and colebemisJanuary 14, 2022 00:06
@changeset-bot

changeset-botBot commented Jan 14, 2022

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 08b3e11

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
@primer/reactMinor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR


```javascript live noinline
// import {Label} from '@primer/react/drafts'
const {Label} = drafts // ignore docs silliness; import like that ↑

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove these once #1785 is merged

@github-actions

github-actionsBot commented Jan 14, 2022

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js61.25 KB (0%)
dist/browser.umd.js61.63 KB (0%)

Comment threaddocs/content/drafts/Label2.mdx Outdated

<PropsTable>
<PropsTableRow
name="appearance"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this prop is called scheme in the code.

Also, I'm curious if we should call this prop variant to be consistent with the Button API: https://primer.style/react/drafts/Button2#button

@mperrottimperrottiJan 14, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this is just a mistake. Good catch!

Agreed on changing to variant too. I was just copying the PVC API.

Comment threadsrc/Label2.tsx
export const labelColorMap: Record<LabelColorOptions, LabelColorConfig> = {
default: {
borderColor: get('colors.border.default')
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can use the variants utility from styled-system to clean up all the get() calls here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this:

importstyledfrom'styled-components'import{sx,SxProp}from'./sx'import{variant,SystemStyleObject}from'styled-system'constvariants={default: {borderColor: 'border.default'},primary: {borderColor: 'fg.default'},
...
}asconstconstsizes={small: {height: '20px',padding: '7px',},large: ...
}asconstexporttypeLabelProps={variant: keyoftypeofvariantssize: keyoftypeofsizes}&SxPropconstLabel=styled.span<LabelProps>` ...styles...${variant({ variants })};${variant({prop: 'size',variants: sizes})};${sx};`Label.defaultProps={variant: 'default',size: 'small',}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - yea, this feels cleaner. I'll give it a shot 👍

Comment threadsrc/Label2.tsx Outdated
Comment threadsrc/Label2.tsx Outdated
Comment threadsrc/Label2.tsx Outdated
<LabelContainer size={size} {...other}>
{children}
</LabelContainer>
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is equivalent to:

const Label: React.FC<Props> = props => <LabelContainer {...props} />

Is there a reason we need to have this proxy Label component? What if we exported the styled component directly?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is leftover from a more complex implementation where we handled a leadingVisual. We can just use the styled component directly.

Good catch.

Comment threaddocs/content/drafts/Label2.mdx Outdated
Co-authored-by: Cole Bemis <colebemis@github.com>
@mperrottimperrotti self-assigned this Jan 19, 2022
Comment threadsrc/drafts.ts Outdated
export * from './ActionList2'
export * from './Button2'
export * from './ActionMenu2'
export {default as Label} from './Label2'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this export doesn't follow the same pattern as the others (i.e export * from './Label2')?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was because Label was the default export. I changed it.

Comment threaddocs/content/drafts/Label2.mdx Outdated
Comment threaddocs/content/drafts/Label2.mdx Outdated
Comment threaddocs/content/drafts/Label2.mdx Outdated
Comment threaddocs/content/drafts/Label2.mdx Outdated
Comment threadsrc/Label2.tsx
align-items: center;
background-color: transparent;
border-width: 1px;
border-radius: 999px;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use relative units like PVC too? 2em

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The border-radius isn't relative to anything - it's just a really high number to make it perfectly round.

border-width is also not relative to anything, it's just 1px.

Comment threadsrc/__tests__/Label2.test.tsx
mperrottiand others added 4 commits January 24, 2022 11:34
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Rez <rezrah@github.com>
Co-authored-by: Rez <rezrah@github.com>
@mperrotti
mperrotti requested a review from rezrahJanuary 24, 2022 17:20

@rezrahrezrah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the package-lock change intentional?

@mperrotti

Copy link
Copy Markdown
ContributorAuthor

@rezrah - the package-lock change was not intentional. I'll just pull in whatever is on main

@mperrotti
mperrotti merged commit 8b376b9 into mainJan 25, 2022
@mperrotti
mperrotti deleted the mp/label-sync-with-pvc branch January 25, 2022 16:33
@primer-cssprimer-css mentioned this pull request Jan 25, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mperrotti@colebemis@rezrah