-
Notifications
You must be signed in to change notification settings - Fork 535
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
Conversation
🦋 Changeset detectedLatest commit: 08b3e11 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 ↑ |
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.
We can remove these once #1785 is merged
size-limit report 📦
|
docs/content/drafts/Label2.mdx
Outdated
|
||
<PropsTable> | ||
<PropsTableRow | ||
name="appearance" |
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.
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
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.
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') | ||
}, |
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.
I wonder if we can use the variants
utility from styled-system to clean up all the get()
calls here.
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.
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',
}
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.
Ah - yea, this feels cleaner. I'll give it a shot 👍
src/Label2.tsx
Outdated
<LabelContainer size={size} {...other}> | ||
{children} | ||
</LabelContainer> | ||
) |
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 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?
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.
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>
… mp/label-sync-with-pvc
align-items: center; | ||
background-color: transparent; | ||
border-width: 1px; | ||
border-radius: 999px; |
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.
Should we use relative units like PVC too? 2em
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.
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.
Co-authored-by: Cole Bemis <colebemis@github.com>
Co-authored-by: Rez <rezrah@github.com>
Co-authored-by: Rez <rezrah@github.com>
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.
✅
Was the package-lock change intentional?
@rezrah - the package-lock change was not intentional. I'll just pull in whatever is on |
… mp/label-sync-with-pvc
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
Merge checklist
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