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

Added Button component, set the theme colors and fonts #54

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

blenderskool
Copy link
Contributor

Fixes #48

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream master branch.
  • I have added/updated necessary tests/documentation (if applicable)

Changes proposed in this pull request:

  • Added the Button component to be used in the app. These are the props:
    • type: primary | secondary | flat defines the type of button used (default: primary)
    • onClick: Event when the button is clicked
    • classNames: For adding additional classes when required
  • Set the Fonts and Colors in the theme of the app, as per the style guidelines

Copy link
Collaborator

@divyamrastogi divyamrastogi left a comment

Choose a reason for hiding this comment

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

@blenderskool : Thank you for the quick pull request! Good job on your first component as well. I've requested a few changes, please do not get frustrated or discouraged.
I want you to think, make writing good quality code a habit, and you'll write wonderful code from the get go!

import { withStyles } from 'material-ui/styles';
import Button from 'material-ui/Button';

const styles = {
Copy link
Collaborator

@divyamrastogi divyamrastogi May 9, 2018

Choose a reason for hiding this comment

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

Please add a Button.scss and then import './Button.css in your file. You need to move these styles to that file.

I understand that some of you have seen a few codes where people just write CSS in JS and that works most of the time.
However, that's mostly for a very dynamic use case when you've got a lot of interactivity with your styles. There may be other schools of thought but I have always felt that separation of concerns is a good thing.

};

function CustomButton(props) {
if (props.type === 'primary' || !props.type) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Productivity hack with react: Use destructuring.
For example, you've got a few properties inside props that you'd like to use.
Use them like this:

const {
  type = 'primary',
  onClick,
  classes,
  className,
  children,
} = props;

// Now you don't have to do `prop.whatever` or `props.something` ever again!

</Button>
);
}
else if (props.type === 'secondary') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't even need these conditions 😄
You could just do something like:

<Button
  color={type}
  onClick={onClick}
  className={`${className} ${classes[type]}`}
>
  { props.children ? props.children : 'Button' }
</Button>

if else if conditions are not needed. Do something similar for type === 'flat'!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. I completely forgot about ES6 power 😉

src/App.css Outdated

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}
color: white; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a saying in the UI world.
Manners may maketh a man, but it's indentation which makes a developer!

Indent properly, move the brackets to proper places and not just your end product, but your code will look beautiful as well! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for this problem, but I think that was due to parsing the App.scss file. I will see if I can fix it though 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@divyamrastogi Sorry, I cannot fix this, since this is happening with every SCSS file being converted into CSS.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right. Everyone was facing that issue. I've added App.css to .gitignore now. Just take a pull from master and you won't have to commit your App.css.

Copy link
Contributor Author

@blenderskool blenderskool May 10, 2018

Choose a reason for hiding this comment

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

@divyamrastogi No, it isn't getting ignored. I think you should change it to src/App.css

@blenderskool
Copy link
Contributor Author

@divyamrastogi I have improved the code based on your suggestions. Please let me know your thoughts 🙂
Also, thanks for all those hacks, they really made the code simpler and would surely benefit me in the future 👍

@anurag-majumdar
Copy link
Contributor

@divyamrastogi The code suggestions look great! Thanks for the detailed review.

@divyamrastogi
Copy link
Collaborator

@blenderskool : I've made a few changes for you and made a PR to your branch. You can merge that and then we'll merge this.

@blenderskool
Copy link
Contributor Author

@divyamrastogi I see a merge conflict because of App.css file. Some help needed 😅

@saini-himanshu
Copy link
Contributor

saini-himanshu commented May 14, 2018

Same problem happened with me divyam helped me with this -

App.css was deleted from the master. So, you don't have to push it. Just run the following in you command line:

rm src/App.css && git add . && git commit
After that just save it. Then push your branch again.

@blenderskool
Copy link
Contributor Author

Thanks @saini-himanshu

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.

[Frontend] Create a Button component
4 participants