-
Notifications
You must be signed in to change notification settings - Fork 506
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
Button and ButtonLink β¨ #30
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9060132
add button component
29b4025
add ButtonLink
745797b
move scripts to top of package.json
7aa1eef
update contributors
78d460c
add onClick handler to Button
a3d877c
add click handler examples
49e8935
separate button components
00f8b05
update examples
fab588c
remove contributors
3ba597e
Merge branch 'release-0.0.1-beta' into task/button-component
jonrohan e4c4127
Build
jonrohan a48afe0
Merge branch 'release-0.0.1-beta' into task/button-component
jonrohan 4255ad4
Build again
jonrohan 28f21ef
Replacing quotes with single
jonrohan 83fad62
Merge branch 'release-0.0.1-beta' into task/button-component
jonrohan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
const Button = props => ( | ||
const Button = ({ size, disabled, block, linkStyle, onClick, children }) => ( | ||
<button | ||
{...props} | ||
disabled={disabled} | ||
onClick={onClick} | ||
type="button" | ||
className={classnames( | ||
props.className, | ||
'btn', { | ||
'btn-sm': props.small, | ||
'btn-large': props.large, | ||
{ | ||
'btn': !linkStyle, | ||
'btn-link': linkStyle, | ||
'btn-sm': size === 'small', | ||
'btn-large': size === 'large', | ||
'btn-block': block, | ||
} | ||
)} | ||
/> | ||
> | ||
{children} | ||
</button> | ||
) | ||
|
||
export default Button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
const ButtonDanger = props => ( | ||
const ButtonDanger = ({ size, disabled, block, linkStyle, onClick, children }) => ( | ||
<button | ||
{...props} | ||
disabled={disabled} | ||
onClick={onClick} | ||
type="button" | ||
className={classnames( | ||
props.className, | ||
'btn btn-danger', { | ||
'btn-sm': props.small, | ||
'btn-large': props.large, | ||
'btn-danger', | ||
{ | ||
'btn': !linkStyle, | ||
'btn-link': linkStyle, | ||
'btn-sm': size === 'small', | ||
'btn-large': size === 'large', | ||
'btn-block': block, | ||
} | ||
)} | ||
/> | ||
> | ||
{children} | ||
</button> | ||
) | ||
|
||
export default ButtonDanger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
const ButtonLink = ({ size, type, block, href, children }) => ( | ||
<button | ||
href={href} | ||
role="button" | ||
className={classnames( | ||
'btn', | ||
{ | ||
'btn-sm': size === 'small', | ||
'btn-large': size === 'large', | ||
'btn-primary': type === 'primary', | ||
'btn-danger': type === 'danger', | ||
'btn-outline': type === 'outline', | ||
'btn-block': block, | ||
} | ||
)} | ||
> | ||
{children} | ||
</button> | ||
) | ||
|
||
export default ButtonLink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
const ButtonOutline = ({ size, disabled, block, linkStyle, onClick, children }) => ( | ||
<button | ||
disabled={disabled} | ||
onClick={onClick} | ||
type="button" | ||
className={classnames( | ||
'btn-outline', | ||
{ | ||
'btn': !linkStyle, | ||
'btn-link': linkStyle, | ||
'btn-sm': size === 'small', | ||
'btn-large': size === 'large', | ||
'btn-block': block, | ||
} | ||
)} | ||
> | ||
{children} | ||
</button> | ||
) | ||
|
||
export default ButtonOutline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
const ButtonPrimary = props => ( | ||
const ButtonPrimary = ({ size, disabled, block, linkStyle, onClick, children }) => ( | ||
<button | ||
{...props} | ||
disabled={disabled} | ||
onClick={onClick} | ||
type="button" | ||
className={classnames( | ||
props.className, | ||
'btn btn-primary', { | ||
'btn-sm': props.small, | ||
'btn-large': props.large, | ||
'btn-primary', | ||
{ | ||
'btn': !linkStyle, | ||
'btn-link': linkStyle, | ||
'btn-sm': size === 'small', | ||
'btn-large': size === 'large', | ||
'btn-block': block, | ||
} | ||
)} | ||
/> | ||
> | ||
{children} | ||
</button> | ||
) | ||
|
||
export default ButtonPrimary |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I know a lot of people like do this with buttons because it feels good to dry up the code, but I think it actually makes a simpler api to keep buttons separate around their theme. It does mean there are more components to know about, but it means there are fewer props to use with a single button component.
Instead of
<Button primary block large/>
you'd do<ButtonPrimary block large />
etc.It also means we can be very intentional with which props we make available to which button themes. Later (which we will!) when we want to add new button variations or props (especially for marketing), we can be more deliberate and choose what props are available for each button. For example, we might never want to use an Octicon in a
ButtonOutline
orButtonDanger
but we do for primary and etc. (just using examples here).I think there are definitely cases where we want color themes to be props such as for States, but buttons are pretty complex and we're likely to add onto this component.