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

[Button] add support for split disclosure button #2329

Merged
merged 5 commits into from
Jan 21, 2020

Conversation

chloerice
Copy link
Member

@chloerice chloerice commented Oct 18, 2019

WHY are these changes introduced?

There is currently no way to expose merchants to related primary actions in the ContextualSaveBar or Page Header because they only support a single primary action. For example, if the primary action is to save a resource like an order, but you can also save the order as a draft.

WHAT is this pull request doing?

This PR adds support for a split button variant. This is the same UX as the split button you are probably familiar with in Gmail. It renders a disclosure button connected right which toggles a popover action list with related actions.

Split button Split button with disclosure active
Screen Shot 2019-10-18 at 4 33 15 PM Screen Shot 2019-10-18 at 4 33 46 PM
Click to view other UX considered

Another possible UX could be that the action list acts as a way to choose which action the primary button renders. You may be familiar with that type of split button if you've ever created a draft PR here on GitHub. The currently selected action has a selected state in the action list. Clicking a related action closes the popover and updates the primary action to be that clicked action.

cc @ShaniqueS @mirualves

Initial primary action Related primary action selected
Primary action Primary action updated to selected related action
Split button variants
Current Screen Shot 2019-12-05 at 6 04 33 PM
Light mode Screen Shot 2019-12-05 at 6 04 44 PM
Dark mode Screen Shot 2019-12-05 at 6 04 54 PM

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

To tophat in Chroma deployment

To tophat locally

  • git checkout button-connectedSegment && dev up && yarn dev
    • A new tab or window with the Storybook examples will open automatically
  • Open polaris-react in your text editor and copy/paste the Playground code collapsed below into /playground/Playground.tsx
    • Click "Playground" in the left navigation of the Storybook to view the playground
Copy-paste this code in playground/Playground.tsx:
import React from 'react';
import {Page, Card, ButtonGroup, Button} from '../src';

export function Playground() {
  return (
    <Page title="Playground">
      <Card sectioned>
        <ButtonGroup>
          <Button
            onClick={() => console.log('Draft purchase order saved')}
            primary
            connectedDisclosure={{
              actions: [
                {
                  content: 'Save and mark as ordered',
                  onAction: () => console.log('PO saved and marked as ordered'),
                },
              ],
            }}
          >
            Primary
          </Button>
          <Button
            onClick={() => console.log('Draft purchase order saved')}
            connectedDisclosure={{
              actions: [
                {
                  content: 'Save and mark as ordered',
                  onAction: () => console.log('PO saved and marked as ordered'),
                },
              ],
            }}
          >
            Basic
          </Button>
          <Button
            outline
            onClick={() => console.log('Draft purchase order saved')}
            connectedDisclosure={{
              actions: [
                {
                  content: 'Save and mark as ordered',
                  onAction: () => console.log('PO saved and marked as ordered'),
                },
              ],
            }}
          >
            Outline
          </Button>
          <Button
            destructive
            onClick={() => console.log('Draft purchase order saved')}
            connectedDisclosure={{
              actions: [
                {
                  destructive: true,
                  content: 'Save and mark as ordered',
                  onAction: () => console.log('PO saved and marked as ordered'),
                },
              ],
            }}
          >
            Destructive
          </Button>
          <Button
            outline
            destructive
            onClick={() => console.log('Draft purchase order saved')}
            connectedDisclosure={{
              actions: [
                {
                  destructive: true,
                  content: 'Save and mark as ordered',
                  onAction: () => console.log('PO saved and marked as ordered'),
                },
              ],
            }}
          >
            Destructive
          </Button>
        </ButtonGroup>
      </Card>
    </Page>
  );
}

🎩 checklist

@chloerice chloerice force-pushed the button-connectedSegment branch 6 times, most recently from af9fce8 to 3d87c48 Compare October 23, 2019 22:28
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2019

💦 Potential splash zone of changes introduced to src/**/*.tsx in this pull request:

Files modified29
Files potentially affected135

Details

All files potentially affected (total: 135)
📄 UNRELEASED.md (total: 0)

Files potentially affected (total: 0)

📄 locales/cs.json (total: 0)

Files potentially affected (total: 0)

📄 locales/da.json (total: 0)

Files potentially affected (total: 0)

📄 locales/de.json (total: 0)

Files potentially affected (total: 0)

📄 locales/en.json (total: 0)

Files potentially affected (total: 0)

📄 locales/es.json (total: 0)

Files potentially affected (total: 0)

📄 locales/fi.json (total: 0)

Files potentially affected (total: 0)

📄 locales/fr.json (total: 0)

Files potentially affected (total: 0)

📄 locales/hi.json (total: 0)

Files potentially affected (total: 0)

📄 locales/it.json (total: 0)

Files potentially affected (total: 0)

📄 locales/ja.json (total: 0)

Files potentially affected (total: 0)

📄 locales/ko.json (total: 0)

Files potentially affected (total: 0)

📄 locales/ms.json (total: 0)

Files potentially affected (total: 0)

📄 locales/nb.json (total: 0)

Files potentially affected (total: 0)

📄 locales/nl.json (total: 0)

Files potentially affected (total: 0)

📄 locales/pl.json (total: 0)

Files potentially affected (total: 0)

📄 locales/pt-BR.json (total: 0)

Files potentially affected (total: 0)

📄 locales/pt-PT.json (total: 0)

Files potentially affected (total: 0)

📄 locales/sv.json (total: 0)

Files potentially affected (total: 0)

📄 locales/th.json (total: 0)

Files potentially affected (total: 0)

📄 locales/tr.json (total: 0)

Files potentially affected (total: 0)

📄 locales/zh-CN.json (total: 0)

Files potentially affected (total: 0)

📄 locales/zh-TW.json (total: 0)

Files potentially affected (total: 0)

🎨 src/components/Button/Button.scss (total: 53)

Files potentially affected (total: 53)

🧩 src/components/Button/Button.tsx (total: 52)

Files potentially affected (total: 52)

📄 src/components/Button/README.md (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Button/tests/Button.test.tsx (total: 0)

Files potentially affected (total: 0)

🎨 src/styles/shared/_buttons.scss (total: 0)

Files potentially affected (total: 0)

🧩 src/types.ts (total: 135)

Files potentially affected (total: 135)


This comment automatically updates as changes are made to this pull request.
Feedback, troubleshooting: open an issue or reach out on Slack in #polaris-tooling.

@tmlayton
Copy link
Contributor

I dig this new prop!

@chloerice chloerice force-pushed the button-connectedSegment branch 2 times, most recently from 35e9e22 to f332529 Compare November 15, 2019 18:37
@chloerice chloerice marked this pull request as ready for review November 15, 2019 18:39
@chloerice chloerice force-pushed the button-connectedSegment branch from f332529 to 11fdf55 Compare November 15, 2019 20:00
Copy link

@ShaniqueS ShaniqueS left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

Copy link
Member

@kyledurand kyledurand left a comment

Choose a reason for hiding this comment

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

Code and 🎩 look great. Thanks for taking this on!


.ConnectedDisclosureWrapper {
display: flex;
flex-wrap: nowrap;
Copy link
Member

Choose a reason for hiding this comment

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

nowrap is the default so you might not need to specify here.


const connectedDisclosureActivator = (
<button
type={type}
Copy link
Member

Choose a reason for hiding this comment

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

I think we might be safer by typing this as button vs passing the prop.

Copy link
Member Author

Choose a reason for hiding this comment

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

💯

@BPScott
Copy link
Member

BPScott commented Nov 19, 2019

@dleroux has some interesting stuff coming up that might allow us to do this split style with a ButtonGroup instead of a needing a new prop, you two should talk

@chloerice
Copy link
Member Author

@dleroux has some interesting stuff coming up that might allow us to do this split style with a ButtonGroup instead of a needing a new prop, you two should talk

Thanks @BPScott! Dan reached out to me yesterday 👍 He's got some kinks to work out with the way the context works, but if it get's figured out and folks are on board with the asterisks then I'll end up closing this and opening a new PR adding a split button example to Button using the new ButtonGroup context.

@dleroux
Copy link
Contributor

dleroux commented Nov 19, 2019

It’s now ready for review #2441

@dleroux
Copy link
Contributor

dleroux commented Nov 21, 2019

It's ready for review again and much simpler #2441

@simon-callsen
Copy link

👋 Will this split action work when the button isn't Primary? We have a potential use case for this component when it's live that can be primary/not primary.
image

@chloerice
Copy link
Member Author

chloerice commented Dec 5, 2019

👋 Will this split action work when the button isn't Primary? We have a potential use case for this component when it's live that can be primary/not primary.
image

Hey @simon-callsen 👋, yes the connectedDisclosure prop can be used with any button variant (except plain) 🎉

@chloerice chloerice force-pushed the button-connectedSegment branch 3 times, most recently from 71f96b4 to 98b1c03 Compare December 5, 2019 23:04
@chloerice chloerice requested a review from BPScott as a code owner December 5, 2019 23:04
@chloerice chloerice force-pushed the button-connectedSegment branch from 98b1c03 to 3b48454 Compare December 5, 2019 23:14
@chloerice chloerice requested review from jessebc and mirualves and removed request for mirualves December 5, 2019 23:30
@chloerice chloerice force-pushed the button-connectedSegment branch 2 times, most recently from ff0b59f to 4cd4d7a Compare December 5, 2019 23:40
@@ -201,6 +201,7 @@
border-color: rgba($outline-color, 0.4);
box-shadow: none;
color: darken($outline-color, 20%);
@include recolor-icon(darken($outline-color, 20%));
Copy link
Member Author

@chloerice chloerice Dec 5, 2019

Choose a reason for hiding this comment

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

Right now, a destructive outline icon button will have a bright red icon fill and darkened text. This isn't a variant represented in the style guide or in the UI kit, so I think this was just an oversight.

Before After
Screen Shot 2019-12-05 at 6 44 14 PM Screen Shot 2019-12-05 at 6 45 27 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

On the UI kit, the icon on the basic button is two tones lighter Ink lighter while the text is Ink, so I think the example on "Before" is actually correct.
Aso, the outline seems lighter than what's in the style guide.
Screen Shot 2019-12-06 at 9 42 26 AM

Copy link
Member Author

@chloerice chloerice Dec 6, 2019

Choose a reason for hiding this comment

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

Hmmm, those screenshots are from the style guide, @mirualves is your screenshot an outline button or a monochrome button?

Copy link
Contributor

Choose a reason for hiding this comment

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

My screenshot is from the outline monochrome button (style guide). I'm sorry for the late reply!

@@ -247,6 +248,7 @@
background: transparent;
box-shadow: 0 0 0 border-width('base') var(--p-critical-border);
color: var(--p-critical-link);
@include recolor-icon(var(--p-critical-link));
Copy link
Member Author

@chloerice chloerice Dec 5, 2019

Choose a reason for hiding this comment

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

Again, parity between destructive outline button icon and text colors. cc @jessebc and @mirualves

Before After
Light mode Screen Shot 2019-12-05 at 6 49 54 PM Screen Shot 2019-12-05 at 6 50 21 PM
Dark mode Screen Shot 2019-12-05 at 6 49 44 PM Screen Shot 2019-12-05 at 6 50 31 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the after makes sense to me. The contrast looks much better in both light and dark mode.

Choose a reason for hiding this comment

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

👀 Just a random question, but why are the outline and the text for the dark mode button two separate colors?

Copy link
Contributor

@tmlayton tmlayton Dec 9, 2019

Choose a reason for hiding this comment

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

The short answer is for contrast ratios. But it is possible these colors will still be tweaked—at the moment it is more important the code is using the proper color role variable.

@chloerice chloerice force-pushed the button-connectedSegment branch from 4cd4d7a to bd4cabe Compare January 15, 2020 22:35
chloerice and others added 5 commits January 21, 2020 10:29
Update locales/hi.json

Update locales/pl.json

Update locales/pt-PT.json

Update locales/zh-TW.json

Update locales/tr.json

Update locales/zh-CN.json

Update locales/th.json

Update locales/da.json

Update locales/es.json

Update locales/fr.json

Update locales/nl.json

Update locales/ko.json

Update locales/ja.json

Update locales/pt-BR.json

Update locales/sv.json

Update locales/ms.json

Update locales/cs.json

Update locales/fi.json

Update locales/nb.json

Update locales/it.json
@chloerice chloerice force-pushed the button-connectedSegment branch from bd4cabe to 8e03336 Compare January 21, 2020 15:32
@chloerice chloerice merged commit 7001057 into master Jan 21, 2020
@chloerice chloerice deleted the button-connectedSegment branch January 21, 2020 16:10
@dleroux dleroux temporarily deployed to production January 27, 2020 13:38 Inactive
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.

10 participants