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

Sync Label component with PVC's Label component #1797

Merged
merged 33 commits into from
Jan 25, 2022
Merged

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Jan 14, 2022

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 colebemis January 14, 2022 00:06
@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2022

🦋 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
Name Type
@primer/react Minor

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
Contributor Author

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
Copy link
Contributor

github-actions bot commented Jan 14, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 61.25 KB (0%)
dist/browser.umd.js 61.63 KB (0%)


<PropsTable>
<PropsTableRow
name="appearance"
Copy link
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

Copy link
Contributor Author

@mperrotti mperrotti Jan 14, 2022

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.

export const labelColorMap: Record<LabelColorOptions, LabelColorConfig> = {
default: {
borderColor: get('colors.border.default')
},
Copy link
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
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:

import styled from 'styled-components'
import {sx, SxProp} from './sx'
import { variant, SystemStyleObject } from 'styled-system'

const variants = {
  default: {
    borderColor: 'border.default'
  },
  primary: {
    borderColor: 'fg.default'
  },
  ...
} as const

const sizes = {
  small: {
    height: '20px',
    padding: '7px',
  },
  large: ...
} as const

export type LabelProps = {
  variant: keyof typeof variants
  size: keyof typeof sizes
} & SxProp

const Label = styled.span<LabelProps>`
  ...styles...
  ${variant({ variants })};
  ${variant({ prop: 'size', variants: sizes })};
  ${sx};
`

Label.defaultProps = {
  variant: 'default',
  size: 'small',
}

Copy link
Contributor Author

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 👍

src/Label2.tsx Outdated Show resolved Hide resolved
src/Label2.tsx Outdated Show resolved Hide resolved
src/Label2.tsx Outdated
<LabelContainer size={size} {...other}>
{children}
</LabelContainer>
)
Copy link
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
Contributor Author

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.

Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
align-items: center;
background-color: transparent;
border-width: 1px;
border-radius: 999px;
Copy link
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
Contributor Author

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.

mperrotti and others added 3 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>
Copy link
Contributor

@rezrah rezrah left a comment

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
Contributor Author

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

Sign up for free to 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