Skip to content

Conversation

@AndrewMusgrave
Copy link
Member

@AndrewMusgrave AndrewMusgrave commented Sep 16, 2019

WHY are these changes introduced?

Fixes #877

WHAT is this pull request doing?

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import React, {useState} from 'react';
import {SaveMinor} from '@shopify/polaris-icons';
import {Page, Card, Button, Checkbox, Stack} from '../src';

export function Playground() {
  const [selected, setSelected] = useState([
    true,
    true,
    true,
    true,
    true,
    true,
    true,
    true,
    true,
    true,
  ]);

  const handleChange = (idx) => (val) =>
    setSelected((selected) => {
      const arr = [...selected];
      arr[idx] = val;
      return arr;
    });

  return (
    <Page title="Playground">
      <Card title="Primary">
        <Card.Section>
          <Stack>
            <Button primary pressed={selected[0]}>
              Primary - Pressed
            </Button>
            <Checkbox
              label=""
              checked={selected[0]}
              onChange={handleChange(0)}
            />
          </Stack>
        </Card.Section>
      </Card>

      <Card title="Destructive">
        <Card.Section>
          <Stack>
            <Button destructive pressed={selected[1]}>
              Destructive - Pressed
            </Button>
            <Checkbox
              label=""
              checked={selected[1]}
              onChange={handleChange(1)}
            />
          </Stack>
        </Card.Section>
      </Card>

      <Card title="Destructive - outline">
        <Card.Section>
          <Stack>
            <Button destructive outline pressed={selected[2]}>
              Destructive - Outline - Pressed
            </Button>
            <Checkbox
              label=""
              checked={selected[2]}
              onChange={handleChange(2)}
            />
          </Stack>
        </Card.Section>
      </Card>

      <Card title="Outline">
        <Card.Section>
          <Stack>
            <Button pressed={selected[3]} outline>
              Outline - Pressed
            </Button>
            <Checkbox
              label=""
              checked={selected[3]}
              onChange={handleChange(3)}
            />
          </Stack>
        </Card.Section>
        <Card.Section>
          <Stack>
            <Button pressed={selected[4]} outline monochrome>
              Outline - Pressed - Monochrome
            </Button>
            <Checkbox
              label=""
              checked={selected[4]}
              onChange={handleChange(4)}
            />
          </Stack>
        </Card.Section>
      </Card>

      <Card title="Plain">
        <Card.Section>
          <Stack>
            <Button pressed={selected[5]} plain>
              Outline - Plain
            </Button>
            <Checkbox
              label=""
              checked={selected[5]}
              onChange={handleChange(5)}
            />
          </Stack>
        </Card.Section>
        <Card.Section>
          <Stack>
            <Button pressed={selected[6]} plain monochrome>
              Outline - Plain - Monochrome
            </Button>
            <Checkbox
              label=""
              checked={selected[6]}
              onChange={handleChange(6)}
            />
          </Stack>
        </Card.Section>
      </Card>

      <Card title="Regular Button">
        <Card.Section>
          <Stack>
            <Button pressed={selected[7]}>Regular - pressed</Button>
            <Checkbox
              label=""
              checked={selected[7]}
              onChange={handleChange(7)}
            />
          </Stack>
        </Card.Section>
      </Card>

      <Card title="With Icon">
        <Card.Section>
          <Stack>
            <Button icon={SaveMinor} pressed={selected[8]} />
            <Checkbox
              label=""
              checked={selected[8]}
              onChange={handleChange(8)}
            />
          </Stack>
        </Card.Section>
      </Card>
    </Page>
  );
}

🎩 checklist

@AndrewMusgrave
Copy link
Member Author

Slight delay - Waiting to pair with a designer to hammer out visual states

ariaExpanded?: boolean;
/** Tells screen reader the element is pressed */
/**
* @deprecated As of release 4.X.X, replaced by {@link https://polaris.shopify.com/components/structure/page#props-pressed}
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Edit this while merging

@AndrewMusgrave AndrewMusgrave force-pushed the add-pressed-button-state branch from 5bcf841 to 501480f Compare September 30, 2019 19:28
@mixin button-outline($outline-color) {
background: transparent;
@mixin button-filled-pressed($button-color, $focus-color) {
background: linear-gradient(
Copy link
Member Author

Choose a reason for hiding this comment

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

Grabbed styles from ToggleButton in web

@AndrewMusgrave AndrewMusgrave force-pushed the add-pressed-button-state branch 2 times, most recently from cd00ac5 to cde0f3b Compare September 30, 2019 19:58
@AndrewMusgrave AndrewMusgrave changed the title [WIP][Button] Add pressed state to [Button] Add pressed state to Sep 30, 2019
@AndrewMusgrave AndrewMusgrave marked this pull request as ready for review September 30, 2019 20:02
@tmlayton
Copy link
Contributor

tmlayton commented Oct 3, 2019

Hey @AndrewMusgrave, can we hold off on this until after we make the changes with CSS custom properties and theming in the next few months? Otherwise, let’s pair on reworking this mixin to avoid color manipulation as it makes the code for backwards compatibility kind of gross. Thanks!

Copy link

@danrosenthal danrosenthal left a comment

Choose a reason for hiding this comment

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

Can you add an example so folks can easily tophat this change and see it in use in our documentation once it's released?

@BPScott BPScott removed their request for review October 3, 2019 17:26
@BPScott
Copy link
Member

BPScott commented Oct 3, 2019

I got tagged as this is modifying the public sass API. Eventually we want to stop touching that but we've not got the time to bash out that plan. The change to that looks fine for now.

Removing myself from review as I haven't got the time to look at the rest of this

@AndrewMusgrave
Copy link
Member Author

Hey AndrewMusgrave, can we hold off on this until after we make the changes with CSS custom properties and theming in the next few months? Otherwise, let’s pair on reworking this mixin to avoid color manipulation as it makes the code for backwards compatibility kind of gross. Thanks!

A few months is a little bit longer to let this go stale, I'll remove all the sass manipulation 😄

Can you add an example so folks can easily tophat this change and see it in use in our documentation once it's released?

Good call, I'll include an example. There are a lot of button variants though. The PR description has a complex playground to see the pressed states for 🎩

@mirualves Want to spend a few minutes going over the visuals Monday for a final check?

@AndrewMusgrave AndrewMusgrave force-pushed the add-pressed-button-state branch from cde0f3b to 2e43b2c Compare October 3, 2019 21:29
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2019

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

Files modified6
Files potentially affected54

Details

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

Files potentially affected (total: 0)

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

Files potentially affected (total: 54)

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

Files potentially affected (total: 53)

📄 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)


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.

Copy link
Contributor

@tmlayton tmlayton left a comment

Choose a reason for hiding this comment

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

Didn’t do a full review, but giving an approval for the sass variable approach, thanks for doing that!

Copy link

@danrosenthal danrosenthal left a comment

Choose a reason for hiding this comment

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

Thanks for the color notes!

Make sure there's a test passing the pressed property and this should be good to go.

@AndrewMusgrave AndrewMusgrave force-pushed the add-pressed-button-state branch from 4d1305c to 66aa609 Compare October 10, 2019 16:56
@AndrewMusgrave
Copy link
Member Author

Make sure there's a test passing the pressed property and this should be good to go.

I added a few tests. Historically we haven't tested visuals, is this something we're starting to do?

@danrosenthal I moved the new mixings into Button.scss so they're not exposed

@danrosenthal
Copy link

danrosenthal commented Oct 10, 2019

I added a few tests. Historically we haven't tested visuals, is this something we're starting to do?

It's not so much about testing visuals, as it is just having coverage on all code paths. I'd even be fine with adding pressed to an existing test just to get that code path to execute. The presence of the classNames is less interesting, and can be covered by VRT. Passing a prop just to ensure nothing throws feels like a perfectly valid way to test props whose only impact is classNames.

@danrosenthal I moved the new mixings into Button.scss so they're not exposed

Fantastic!

Copy link
Contributor

@dleroux dleroux left a comment

Choose a reason for hiding this comment

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

🎉 Small suggestion on the api documentation, but looks good!

textAlign?: TextAlign;
/** Gives the button a subtle alternative to the default button styling, appropriate for certain backdrops */
outline?: boolean;
/** Demonstrates a pressed state */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** Demonstrates a pressed state */
/** Gives the button the appearance of being pressed */

@AndrewMusgrave AndrewMusgrave force-pushed the add-pressed-button-state branch from 8adbb3b to 6e2e4da Compare October 16, 2019 15:38
@AndrewMusgrave AndrewMusgrave merged commit aead592 into master Oct 16, 2019
@AndrewMusgrave AndrewMusgrave deleted the add-pressed-button-state branch October 16, 2019 15:48
@LauraAubin LauraAubin temporarily deployed to production October 22, 2019 17:39 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.

[Button] Add “pressed” state

7 participants