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

🚀 feat(button): add prop loading #705

Merged
merged 30 commits into from
Nov 23, 2023
Merged

Conversation

matheushdsbr
Copy link
Collaborator

@matheushdsbr matheushdsbr commented Oct 17, 2023

JIRA Issue

Description 📄

This is a new prop of button, now we can use loading on buttons! ✨

We can use it when we are going to perform some type of loading or request, and it will take a while to finish. That's when the loading comes into action.

Exemple:
<Button isLoading>Find an activity</Button>
<Button isLoading={false}>Find an activity</Button>

Platforms 📲

  • Web
  • Mobile

Type of change 🔍

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested? 🧪

[Enter the tips to test this PR]

  • Unit Test
  • Snapshot Test

Checklist: 🔍

  • My code follows the contribution guide of this project Contributing Guide
  • Layout matches design prototype: FIGMA
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Screenshots 📸

Default Button

Screen.Recording.2023-10-25.at.18.39.26.mov

Icon Button

Screen.Recording.2023-10-23.at.15.03.14.mov

Outline Button

Screen.Recording.2023-10-23.at.15.03.44.mov

@matheushdsbr matheushdsbr self-assigned this Oct 17, 2023
@matheushdsbr matheushdsbr marked this pull request as ready for review October 18, 2023 18:19
@matheushdsbr matheushdsbr changed the title ⚙️ [WIP] - feat(button): add button loading 🚀 feat(button): add button loading Oct 18, 2023
@frgiovanna
Copy link
Contributor

frgiovanna commented Oct 18, 2023

Why not make the isLoading an optional prop for the already existent buttons?

Example:

<Button isLoading={loading} />
<Button.Outline isLoading={loading} />
<Button.Icon isLoading={loading} />

(On one of our projects has an abstraction that does what I am suggesting, you can check the code here and the documentation here - needs VPN)

@joaopaulonsoares-gympass
Copy link

joaopaulonsoares-gympass commented Oct 18, 2023

I agree with @frgiovanna , have loading as props of the current button would be better than a new component.

@ericcleao ericcleao changed the base branch from master to feat/spinner October 19, 2023 08:52
@caiotracera
Copy link
Contributor

As said by @frgiovanna and @joaopaulonsoares-gympass, I really think that we should change this, so the loading state can be a prop instead of a whole new component.

@matheushdsbr matheushdsbr changed the title 🚀 feat(button): add button loading 🚀 feat(button): add button loading prop Oct 23, 2023
@matheushdsbr matheushdsbr changed the title 🚀 feat(button): add button loading prop 🚀 feat(button): add prop loading Oct 23, 2023
Copy link
Contributor

@frgiovanna frgiovanna left a comment

Choose a reason for hiding this comment

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

Good job so far, please check my comments

@@ -14,6 +14,14 @@ You can use all differente compounds like `<Button.Outline />` and `<Button.Text
</Box>
```

#### Inverted
Copy link
Contributor

Choose a reason for hiding this comment

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

🏅

<Link {...props} disabled={disabled} aria-disabled={disabled} />
);
// eslint-disable-next-line react/prop-types
const ButtonLink = forwardRef(({ isLoading, ...rest }, ref) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are we using this destructured isLoading?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The original idea was to use all the properties except 'isLoading' when dealing with 'Button.Link' and 'Button.Text.' However, I had to disable eslint since 'isLoading' was not being utilized; it was solely removed to prevent its use in 'Button.Link' and 'Button.Text.'

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think is scalable if you get all of the other props except the isLoading? This means every time someone adds a new value for all buttons they will need to add it here too, otherwise it will be ignored. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point 🤔

I'm just concerned that someone might misunderstand the 'button.text' and 'button.link' props and try to use them. By removing this approach, people will still be able to use isLoading, and it will work. However, it wouldn't be advisable to do so because, as far as I know, we don't have any plans for that.

But, yes I agree with you. This approach isn't scalable. It's more on the developer's side to use it correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

No no, I really got your point and I think you're right, I'm just wondering if we can handle it in another way instead of having this eslint comment

Copy link
Contributor

@frgiovanna frgiovanna Oct 24, 2023

Choose a reason for hiding this comment

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

What if you do something like this?

const ButtonLink = forwardRef(({ rest }, ref) => {

const props = Object.fromEntries(
  Object.entries(rest).filter(([key]) => key !== 'isLoading')
);

 return (
   <Link {...props} disabled={props.disabled} aria-disabled={props.disabled} ref={ref} /> 
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great suggestion!! 🚀

packages/yoga/src/Button/web/Link.jsx Show resolved Hide resolved
packages/yoga/src/Button/web/Text.jsx Show resolved Hide resolved
Base automatically changed from feat/spinner to master November 21, 2023 15:20
@matheushdsbr matheushdsbr force-pushed the feat/add-button-loading branch from f263612 to 599dea6 Compare November 21, 2023 17:50
@matheushdsbr matheushdsbr force-pushed the feat/add-button-loading branch from 599dea6 to a4f5cf6 Compare November 22, 2023 12:54
@matheushdsbr matheushdsbr merged commit 51971d4 into master Nov 23, 2023
3 checks passed
@matheushdsbr matheushdsbr deleted the feat/add-button-loading branch November 23, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants