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

Token components #1488

Merged
merged 41 commits into from
Oct 13, 2021
Merged

Token components #1488

merged 41 commits into from
Oct 13, 2021

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Sep 30, 2021

Components have been added to support different kinds of "Tokens". A Token represents a piece of data. They are typically used to show a collection of related attributes.

Screenshots

Default

Screen Shot 2021-10-04 at 8 56 34 PM

Profile

Screen Shot 2021-10-04 at 8 56 48 PM

Issue Label

Screen Shot 2021-10-04 at 8 57 05 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.

@changeset-bot
Copy link

changeset-bot bot commented Sep 30, 2021

🦋 Changeset detected

Latest commit: 83a7d40

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

This PR includes changesets to release 1 package
Name Type
@primer/components 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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 30, 2021

size-limit report 📦

Path Size
dist/browser.esm.js 59.66 KB (+7.67% 🔺)
dist/browser.umd.js 59.98 KB (+7.64% 🔺)

docs/content/Token.mdx Outdated Show resolved Hide resolved
docs/content/Token.mdx Outdated Show resolved Hide resolved

export interface TokenBaseProps
extends Omit<React.HTMLProps<HTMLSpanElement | HTMLButtonElement | HTMLAnchorElement>, 'size' | 'id'> {
as?: 'button' | 'a' | 'span'
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 support ReactRouter-like link components? Similar to ActionList.Item: https://primer.style/react/ActionList#example-with-custom-item-renderer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, probably

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just realized something...

We change the way we render the "x" button if the token is a link or a button. For example, we don't let the "x" button get focused with the keyboard, and we don't give the "x" button an aria-label.

src/Token/TokenBase.tsx Outdated Show resolved Hide resolved
src/stories/Token.stories.tsx Outdated Show resolved Hide resolved
variants: {
sm: {
fontSize: 0,
gap: 1,
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 the flexbox gap property still doesn't have support in Safari <14.1. Do we need to support Safari <14.1? https://caniuse.com/flexbox-gap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we need to support Safari <14.1. Do we have some guidelines on Primer's browser support?

src/Token/TokenBase.tsx Outdated Show resolved Hide resolved
src/Token/TokenBase.tsx Outdated Show resolved Hide resolved
src/Token/TokenLabel.tsx Outdated Show resolved Hide resolved
src/Token/_RemoveTokenButton.tsx Outdated Show resolved Hide resolved
Co-authored-by: Cole Bemis <colebemis@github.com>
src/Token/TokenBase.tsx Outdated Show resolved Hide resolved
src/Token/_tokenButtonUtils.ts Outdated Show resolved Hide resolved
Co-authored-by: Cole Bemis <colebemis@github.com>
src/Token/Token.tsx Outdated Show resolved Hide resolved
src/Token/TokenLabel.tsx Outdated Show resolved Hide resolved
@mperrotti
Copy link
Contributor Author

@colebemis - I think we should rename LabelToken to IssueLabelToken. What do you think?

@colebemis
Copy link
Contributor

@colebemis - I think we should rename LabelToken to IssueLabelToken. What do you think?

Agreed. I was actually going to suggest that 👍

export const profileToken = () => (
<ExampleCollectionContainer>
<SingleExampleContainer label="Resting">
<TokenProfile size="lg" avatarSrc="https://avatars.githubusercontent.com/mperrotti" text="Mike Perrotti" />
Copy link
Member

@siddharthkp siddharthkp Oct 5, 2021

Choose a reason for hiding this comment

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

Should we use children instead of text here?

<TokenProfile size="lg" avatarSrc="https://avatars.githubusercontent.com/mperrotti">
   Mike Perrotti
</TokenProfile>
<LabelToken fillColor="#FFF06C">Bug</LabelToken>

We can still define what we accept there by adding types for children

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I use children, I expect to be able to pass a ReactNode, so it feels a little strange to limit it to string. Also, we use text instead of children in the ActionList.Item component.

This could just be a personal preference though, so I'm open to using children if other reviewers feel like this makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with either, children feels like the way to put contents inside that already exists.

When I use children, I expect to be able to pass a ReactNode, so it feels a little strange to limit it to string.

That makes sense! I guess it's contextual. In the case of a label, you would pass a string in children. The type check is to warn us if it is stretched/misused beyond that.

Also, we use text instead of children in the ActionList.Item component.

That's another one I'd like to change, proposal coming soon 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's another one I'd like to change, proposal coming soon 😅

Good to know!

src/Token/TokenBase.tsx Outdated Show resolved Hide resolved
Co-authored-by: Cole Bemis <colebemis@github.com>
@mperrotti
Copy link
Contributor Author

Hmm, I wonder why there's still a significant bundlesize increase

I'm not sure 🤔 - it could be the color2k dependency

Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

I've got no big issues to stop this from shipping! Let's solve the size mystery and :shipit:

All I have are API consistency ideas that we'll revisit in this quarter: )

@mperrotti
Copy link
Contributor Author

mperrotti commented Oct 11, 2021

I've solved the size mystery! I’m importing something from @primer/primitives, so that’s being added to the bundle. I’ll hunt it it down and remove it.

main
Screen Shot 2021-10-11 at 1 15 16 PM

mp/token-components
Screen Shot 2021-10-11 at 1 14 00 PM

@mperrotti
Copy link
Contributor Author

mperrotti commented Oct 11, 2021

The IssueLabelToken is rendering with dark mode styles in Memex. I'm not sure if this is an issue with Memex or with the the primer-react implementation.

Investigating now...

Edit: This issue only happens when the cell is in edit mode
Edit 2: This issue mysteriously stopped happening today

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Excellent work, @mperrotti! After you add a changeset, I think this is a ready to go :shipit:

Since the discussion thread is very long, I put together a quick summary of the next steps for this PR:

Must do (in this PR)

  • Add a changeset

Should do (in follow up PRs)

  • Find Safari-compatible (<14.1) flexbox gap property alternative (comment)
  • Find alternatives for fade.* variables (comment)
  • Fix token button font (comment)

Could do

  • Use children prop instead of text prop (comment)

Co-authored-by: Cole Bemis <colebemis@github.com>
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.

None yet

3 participants