- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
🎨 [Button] Simplify code by utilizing more of UnstyledButton #3494
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
Conversation
b560e2a    to
    d7a631d      
    Compare
  
    56bd2d0    to
    d7f21dd      
    Compare
  
    | /** Disables the button, disallowing merchant interaction */ | ||
| disabled?: boolean; | ||
| /** Replaces button text with a spinner while a background action is being performed */ | ||
| loading?: boolean; | 
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.
Do you think this one makes sense here? I was debating this too. It does seem like it could be useful functionality to share, but also feels like a visual element that could behave strangely depending how the button is styled.
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.
Never mind, I see now this only handles the a11y portion in UnstyledButton. That makes a lot of sense to me.
        
          
                src/components/Button/Button.tsx
              
                Outdated
          
        
      |  | ||
| export interface ButtonProps { | ||
| export interface ButtonProps | ||
| extends Pick< | 
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.
So I just tested this in the styleguide and it doesn't show any of these props in the docs with how this is setup. I think the better way to do this would be to have a BaseButtonProps interface that both UnstyledButton and Button extend for their props similar to how we do the action types.
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.
Incredible 🙏 thank you so much for testing this! I've gone ahead and pushed a new commit with your suggestion 😺
3f4defc    to
    e449f7e      
    Compare
  
    67b5196    to
    1c7938e      
    Compare
  
    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 looking really great now!
A few answers to your questions:
(1) Do we really want
[key: string]: any;as part ofUnstyledButtonProps?
- I realize this is done so we can pass any arbitrary prop, such as
data-whatever.- But is this a bit too free-wheelin'?
I think this is ok. We do the same thing on UnstyledLink as well. If you need to add a data attribute or aria attribute that we don't support, I think you should be able to with this component. Otherwise we run the risk of people still needing to use their own <button> still.
(2) Should we pass
onClickwhenurl?
- Does this make sense? What is the execution order?
Ya, we need this for some link tracking and other events. onClick should take place before the navigation.
(3) Why do we use
toBeFalseywhen a value isundefined? Should we not be more explicit?
Great question. I actually just fixed a bunch of these in web too. It would be much better to be more explicit about these. We actually have a tslint rule against it there.
(4) Does the way I am extending
UnstyledButtonPropswithinButton.tsxaffect how descriptions get surfaced in the styleguide?
Just tested this in the style guide and it works great the way you have it setup now. 👍
* 🎨 [Button] Organize some props * 🚚 [Button] Move loading prop to UnstyledButton * 🎨 [Button] Extend UnstyledButtonProps * 👷 [ResourceItem] Increase testing criteria * 👷 [Button] Update tests * 👷 [UnstyledButton] Update tests * ⚗️ [Button] Simplify prop conditions * 🔥 [Button] Remove redundant deprecation warning * 🔥 [UnstyledButton] Remove unstyled-button prop * 📝 [UNRELEASED] Add notes * 🏷️ [BaseButton] New interface and type cleanup
The goal of this PR is to consolidate concerns between
UnstyledButtonandButton.Preamble
Not too long ago, I posted this message on Slack, which got answered by @dfmcphee - revealing that a
UnstyledButtonhad just got merged to help folks utilize the mechanics of<Button />while applying their own styling.UnstyledButtonwill allow me to do away with a custom "action" component I crafted, and instead consume the Polaris component while passing my own styles +children. There will be some more work to be done however... and I am planning to propose a few API additions / component tweaks in the near future.Before I do that, I thought it best to dig into what
UnstyledButton + Buttongive me. I realized there was some repeated code between the two files, so I set about reducing the redundancy. While at it, I realizedButton.test.tsxprobably wasn't updated afterUnstyledButtonwas introduced, so I went through the tests and did my best to clean them up.Changes
While this PR is mostly just cleaning up some code, there are a few changes worth documenting:
loadingprop was not used byUnstyledButton, but some of the side-effects of that prop looked relevant to include. So, I've addedloadingtoUnstyledButtonso that bothroleandaria-busycan be toggled.Button.tsxdid not applydata-polaris-unstyled-buttonto the<a />orUnstyledLink, butUnstyledButtondid. I've removed some redundant code paths insideButton.tsxand thedata-polaris-unstyled-buttonprop now gets applied.Questions
(1) Do we really want
[key: string]: any;as part ofUnstyledButtonProps?data-whatever.(2) Should we pass
onClickwhenurl?(3) Why do we use
toBeFalseywhen a value isundefined? Should we not be more explicit?(4) Does the way I am extending
UnstyledButtonPropswithinButton.tsxaffect how descriptions get surfaced in the styleguide?(5) Do we always want to applydata-polaris-unstyled-buttonto the<a />andUnstyledLink?`Button.tsxdid not use this attribute, so I am wondering if we should have abooleanprop forunstyledLink?Playground
Copy + Paste