Skip to content

Button v2: Fix icon positions for block buttons #1733

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

Closed
wants to merge 5 commits into from

Conversation

siddharthkp
Copy link
Member

@siddharthkp siddharthkp commented Dec 14, 2021

With a block button, the icon and text alignment is a bit strange

Screenshots

image

image
Please provide before/after screenshots for any visual changes

The chromatic tests (see checks below) show that there are no visual regressions :)

Merge checklist

  • Added/updated tests
  • NA 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.

@siddharthkp siddharthkp requested review from a team and rezrah December 14, 2021 17:45
@changeset-bot
Copy link

changeset-bot bot commented Dec 14, 2021

🦋 Changeset detected

Latest commit: 601226b

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 Patch

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

@siddharthkp siddharthkp requested review from pksjce and removed request for rezrah December 14, 2021 17:46
@siddharthkp siddharthkp self-assigned this Dec 14, 2021
@siddharthkp siddharthkp changed the title Button2: Fix positions for block buttons Button2: Fix icon positions for block buttons Dec 14, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 14, 2021

size-limit report 📦

Path Size
dist/browser.esm.js 57.54 KB (+0.07% 🔺)
dist/browser.umd.js 57.83 KB (+0.06% 🔺)

@siddharthkp siddharthkp changed the title Button2: Fix icon positions for block buttons Button v2: Fix icon positions for block buttons Dec 14, 2021
siddharthkp added a commit that referenced this pull request Dec 14, 2021
@pksjce
Copy link
Contributor

pksjce commented Dec 15, 2021

Interesting..
So, if only the trailingIcon exists, then we get the text back to the middle?

image

@@ -227,6 +228,9 @@ export const getButtonStyles = (theme?: Theme) => {
},
'[data-component="trailingIcon"]': {
gridArea: 'trailingIcon'
},
'[data-component="leadingIcon"] + [data-component="text"]': {
textAlign: 'left'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this leftAlign is required tbh.

Copy link
Member Author

@siddharthkp siddharthkp Dec 15, 2021

Choose a reason for hiding this comment

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

fair, how do we make it easier for the user to override this with left align?

this would be the override, not sure if requires knowing the internal details?

<Button
  leadingIcon={EyeIcon}
  trailingIcon={TriangleDownIcon}
  sx={{ '[data-component="text"]': { textAlign: 'left' } }}
>
  Watch
</Button>

Copy link
Contributor

Choose a reason for hiding this comment

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

True :( This is where composite components would be handy. Maybe such an override usecase means we want to open up the API?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we go with the center-aligned approach I recommended, we can get rid of this style block.

@siddharthkp
Copy link
Member Author

siddharthkp commented Dec 15, 2021

Interesting.. So, if only the trailingIcon exists, then we get the text back to the middle?

Sorry, my PR was a bit rushed. This is what I'm proposing: (will make changes to the PR if we like the proposal)

image

cc @ashygee

Figma: Primer Web #sid/block-button-layout

@pksjce pksjce requested a review from langermank December 16, 2021 00:36
@colebemis colebemis requested a review from mperrotti December 16, 2021 00:51
Copy link
Contributor

@mperrotti mperrotti left a comment

Choose a reason for hiding this comment

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

I think left-aligning the leadingVisual and label when we have a trailingVisual is a bit strange. It will especially look weird if we have two stacked full-width buttons where 1 has left-aligned text, and the other has center-aligned text.

I think the "current" column of the mock you posted is what we want.

Curious to hear what @ashygee thinks

@@ -217,6 +217,7 @@ export const getButtonStyles = (theme?: Theme) => {
...getBaseStyles(theme),
display: 'grid',
gridTemplateAreas: '"leadingIcon text trailingIcon"',
gridTemplateColumns: 'min-content 1fr min-content',
Copy link
Contributor

Choose a reason for hiding this comment

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

If we decide to go with the center-aligned approach I recommended, we can remove this style and just add justify-content: center;

@siddharthkp
Copy link
Member Author

For context, this is the pattern I'm chasing:

Projects button

This is what the code looks like for positioning it correctly (ignoring the hover state for now):

To be able to override it correctly, you have to know some implementation details about it, which feels wrong :(

<NewButton
    variant="invisible"
    trailingIcon={GearIcon}
    sx={{
      width: "100%",
      justifyContent: "space-between",
      gridTemplateAreas: '"text trailingIcon"'
    }}
  >

siddharthkp added a commit that referenced this pull request Dec 21, 2021
@pksjce
Copy link
Contributor

pksjce commented Dec 21, 2021

@mperrotti - If there is a product use case then I think we should work on supporting the new mocks.
@siddharthkp - Would a boolean prop for block which takes care of this situation better? Though I'm still not sure how the alignment will work.

@pksjce
Copy link
Contributor

pksjce commented Dec 22, 2021

Since @ashygee is on holidays, I was wondering if @vdepizzol could help us with this?

@pksjce
Copy link
Contributor

pksjce commented Dec 22, 2021

This is what primer-viewcomponents looks like with block button and visuals.

image

And in primer-css
image

Center-align seems standard in our system.

@siddharthkp
Copy link
Member Author

Context:

If there is a product use case then I think we should work on supporting the new mocks.

only issues-app for now I think, but feels like a generic use case, we can also decide we want this alignment to be an override in the product instead of supporting it out of the box.

@siddharthkp - Would a boolean prop for block which takes care of this situation better? Though I'm still not sure how the alignment will work.

That could work!

Since @ashygee is on holidays, I was wondering if @vdepizzol could help us with this?

That would be nice. This can also wait, it's not a december problem :)

siddharthkp added a commit that referenced this pull request Jan 25, 2022
* add template columns and text align for text

* only align left if there's a leading Icon

* add changeset

* add warning for multiple selection with DropdownMenu

* wip: stories

* use leadingIcon with #1733

* add form to story example

* use menuitemradio + aria-checked

* fix types for selectionProperty

* it's not a property, it's an attribute

* placeholder in story

* story with placeholder

* oops, don't want forms to submit!

* selected milestone can be undefined!

* update snapshots

* Add story for controlled menu and external anchor

* add tests!

* export DropdownMenu2 as draft

* default to selectionVariant single for DropdownMenu

* dont need axe anymore

* update octicons for docs

* add docs for dropdown menu v2

* remove changes from #1733

* update snapshots for removed button

* link to button2 docs

* add changeset

* lol everybody makes mistakes

* oof!

* Use active voice in component description

Co-authored-by: Rez <rezrah@github.com>

* update snapshosts with main

* just Props

Co-authored-by: Rez <rezrah@github.com>

* Use PropsTable

* simplify code example a bit

* make controlled state more clear

* keep lockfile version 1

* remove unrelated change

Co-authored-by: Rez <rezrah@github.com>
@mperrotti
Copy link
Contributor

This came up during a Primer design pattern working session, and I like how @langermank decided to handle it

Screen Shot 2022-01-25 at 4 09 55 PM

Storybook preview deployment link: https://primer-css-goebhg4xi-primer.vercel.app/css/storybook?path=/story/explorations--example-sheet
WIP PR: primer/css#1874

@siddharthkp siddharthkp marked this pull request as draft January 26, 2022 11:36
@siddharthkp
Copy link
Member Author

This isn't the direction in which we're going ✌️

@joshblack joshblack deleted the siddharth/newbutton-gird-width branch January 19, 2023 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants