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

3.0.0 Button.js #632

Merged

Conversation

onluiz
Copy link
Contributor

@onluiz onluiz commented Aug 13, 2018

Description

It closes #583 (I hope 😄 )

This PR updates Button component to work with materializecss 1.0.0-rc.2. It includes:

  • New class .btn-small
  • Now if your element has a class like .btn-large or .btn-small you no longer need the .btn class
  • A update of Button component docs (used materializecss new Button docs page as example)
  • A page for documenting Floating Action Button component (used materializecss new Button docs page as example)
  • A helper file called string-helper. It is used to captalize and add spaces to titles (for the navbar and header of the page). It was necessary since the Floating Action Component docs page had its title rendered as "FloatingActionPage" (in the header of the page and in the navbar)
  • A fix for Floating Action Button. Now it is initialized when fab prop is passed
  • A test for new class .btn-small

There is some items I would like the opinion from the others contributors:

  • I have used materializecss docs as base for those changes in our docs. Was it ok?
  • What you think about my solution for nav items with more than one word (Floating Action Button)? Any sugestion of how it could be better?
  • The fix for Floating Action Button was valid? Is it ok to initialize the component the way I have done?
  • There is any other unit tests you guys want me to add?

@petergarnaes, sorry but could you review this PR again? I have created a new clean branch. And thanks for helping me.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Manual tests using the docs
  • Unit tests

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have not generated a new package version. (the maintainers will handle that)

@onluiz onluiz changed the title Update Button from new materializecss version 3.0.0 Button.js Aug 13, 2018
@@ -35,28 +32,40 @@ const ButtonsPage = () => (
</ReactPlayground>
</Col>
<h4 className='col s12'>
Copy link
Contributor

Choose a reason for hiding this comment

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

What about an example of a Flat button, corresponding to the one in materializecss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -50,6 +50,7 @@ export default {
sideNav: require('!raw-loader!../../../examples/SideNavBasic.js'),
sliders: require('!raw-loader!../../../examples/Sliders.js'),
submitButton: require('!raw-loader!../../../examples/SubmitButton.js'),
smallButtom: require('!raw-loader!../../../examples/SmallButtom.js'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo in file name 😅

src/Button.js Outdated
if (
typeof $ !== 'undefined' &&
(typeof tooltip !== 'undefined' || typeof tooltipOptions !== 'undefined')
) {
$(this._btnEl).tooltip(tooltipOptions);
}
if (fab && this._floatingActionBtn) {
$(this._floatingActionBtn).floatingActionButton();
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot use jQuery, you should do something like: M.FloatingActionButton.init(elems, options);. Same goes for the use of jQuery right above on line 21.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also remember to destroy on componentDidUnmount, on both destroy and re-initialize on componentDidUpdate to make sure new props are used as options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alextrastero, what you think of it? componentDidUnmount actualy doesn't exist in react life cicle (at least a coudn't find it in the docs), but there is componentWillUnmount.

In that case, we would have something like:

  • componentDidMount -> M.FloatingActionButton.init
  • componentWillUnmount - > M.FloatingActionButton.destroy

In that situation, we will only have do save the instance returned in M.FloatingActionButton.init and then destroy it on componentWillUnmount.

Does it makes sense for you guys? Any tought about best ways to implement it?

@alextrastero @petergarnaes

Copy link
Contributor

Choose a reason for hiding this comment

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

You are absolutely right, componentWillUnmount is what I meant. The way you describe is exactly whas is done elsewhere.

Also remember componentDidUpdate. In my PR I destroy, and re-initialize, don't think there is any other way to give the instance new options.

Copy link
Contributor

@petergarnaes petergarnaes left a comment

Choose a reason for hiding this comment

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

Great start, you still need to remove any dependency on jQuery. Also you will need to test the new way of initializing and destroying the instance, see https://github.com/react-materialize/react-materialize/blob/3.0.0-beta.0/test/Collapsible.spec.js#L8-L44 for an example.

@alextrastero
Copy link
Member

Thanks @petergarnaes for the review :) and thanks @onluiz for this massive change well done

@onluiz
Copy link
Contributor Author

onluiz commented Aug 14, 2018

@alextrastero @petergarnaes , thanks for the feedbacks. I'll fix it all as soon as possible.

I fixed the easy ones for now.

@onluiz onluiz closed this Aug 14, 2018
@onluiz onluiz reopened this Aug 14, 2018
Copy link
Member

@alextrastero alextrastero left a comment

Choose a reason for hiding this comment

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

Please don't commit the package-lock.js file :)

@@ -2,7 +2,7 @@ import React from 'react';
import Button from '../src/Button';

export default
<Button floating fab='vertical' faicon='fa fa-plus' className='red' large style={{bottom: '45px', right: '24px'}}>
<Button floating fab='vertical' faicon='fa fa-plus' className='red' large style={{bottom: '45px', right: '24px'}}>
Copy link
Member

Choose a reason for hiding this comment

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

what does this faicon='fa fa-plus' prop do?

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 you can remove it :)

@onluiz
Copy link
Contributor Author

onluiz commented Aug 15, 2018

@alextrastero, later I will fix Button.spec and add new tests.

@petergarnaes
Copy link
Contributor

petergarnaes commented Aug 16, 2018

Nice work! However, you still need the componentDidUpdate.

Maybe we should split the Button and FloatingActionButton into two separate components? This mirrors the new materialize-css better, since in v0.100.2 it was all buttons with no javacript, but in v1.0.0-rc.2 it is now two separate pages, where FAB requires javascript and init. This would also allow you to pass options to the init call of FAB, which is missing right now (direction,hoverEnabled,toolbarEnabled). For an example of this see: https://github.com/react-materialize/react-materialize/blob/master/src/Carousel.js#L96

Hope it makes sense 😅

@onluiz
Copy link
Contributor Author

onluiz commented Aug 16, 2018

@petergarnaes nice insights. I will try it out and shows you the results.

EDIT: I will mimic the Floating Action Button from materializecss: https://materializecss.com/floating-action-button.html

@onluiz
Copy link
Contributor Author

onluiz commented Aug 16, 2018

I will be closing this PR for now. When I have all the review requests done I will open it again.

Thanks guys!

@onluiz onluiz closed this Aug 16, 2018
@alextrastero
Copy link
Member

Why close?

src/Button.js Outdated
if (!M) return;

const { tooltip, tooltipOptions, fab } = this.props;
if (tooltip || tooltipOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

If tooltipOptions is defined but there is no actual tooltip text should it still appear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed :)

@petergarnaes
Copy link
Contributor

Awesome! Is it possible to test the tooltip initialization also?

@onluiz
Copy link
Contributor Author

onluiz commented Aug 31, 2018

@petergarnaes , yes! :)

In Button.spec there is tests for tooltip (init and destroy) and for fab (init and destroy).

=)

@petergarnaes
Copy link
Contributor

Somehow missed it 😵 Great job!

Copy link
Member

@alextrastero alextrastero left a comment

Choose a reason for hiding this comment

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

Hey @onluiz, nearly there, just a few comments:

Please merge the docs of buttons and FloatingActionButtonsPage, I would rather keep the pages on the docs unified.

Did you delete package-lock? Seems like -10,106 changes is quite a lot :)

if (fab && this._floatingActionBtn) {
this.instance = M.FloatingActionButton.init(this._floatingActionBtn);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to check for this._floatingActionBtn on L23

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The -10,106 changes are actually from my commit that removes the package.lock. BUT, I may have done something wrong trying to remove the file. @alextrastero, could you help me on this? What is the proper way to remove the file? Sorry about the trouble.

Copy link
Member

Choose a reason for hiding this comment

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

No problem! You can checkout any file from any branch like so:
git checkout master package-lock.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Omg it worked 😄

Now I will work on the others tasks:

  • Remove check this._floatingActionBtn on L23
  • Merge the docs of buttons and FloatingActionButtonsPage

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)
@alextrastero

@alextrastero
Copy link
Member

@onluiz ping :octocat:

@onluiz
Copy link
Contributor Author

onluiz commented Sep 24, 2018

@alextrastero , sorry. I have been dealing with health problems and couldn't finish my PRhe. Can I finish it in the next days? 😸

@alextrastero
Copy link
Member

Of course buddy! no worries, get well!

@alextrastero
Copy link
Member

Nice! one last thing are we are done! checkout the modal snapshot from the beta branch since we are not changing that file on this PR :)

@onluiz
Copy link
Contributor Author

onluiz commented Nov 1, 2018

@alextrastero all right!

I'll sync my fork so a can let it all working.

@onluiz
Copy link
Contributor Author

onluiz commented Dec 14, 2018

@alextrastero , really sorry for the delay =(

I tried to revert the snapshot but the tests began to fail.

I'll bring more details here about the problem. And again, sorry for the delay.

@alextrastero
Copy link
Member

what if you run npm test -- -u and then commit the snapshots, wouldn't that be enough?

@onluiz
Copy link
Contributor Author

onluiz commented Dec 14, 2018

@alextrastero think it worked =)
What you think?

@alextrastero alextrastero merged commit 3defb94 into react-materialize:3.0.0-beta.0 Dec 14, 2018
@alextrastero
Copy link
Member

Great job @onluiz, thanks for the contribution. As as a next step would you like to to create a storybook story for the buttons? Have a look in here: https://github.com/react-materialize/react-materialize/tree/3.0.0-beta.0/stories

@onluiz
Copy link
Contributor Author

onluiz commented Dec 14, 2018

@alextrastero I would love to! I am having such a great learning time here 😄
Thanks for your patience 😆

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.

None yet

3 participants