From 4707a26748db58204032ddae3d8c0582801d72a6 Mon Sep 17 00:00:00 2001 From: Javi Velasco Date: Mon, 16 Nov 2015 21:55:21 +0100 Subject: [PATCH 1/6] Allow children for buttons and use it as link where there is href prop --- components/button/index.jsx | 30 ++++++++++++++++-------------- components/button/style.scss | 30 +++++++++++++++++++----------- spec/components/button.jsx | 9 +++++++++ spec/style.scss | 8 ++------ 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/components/button/index.jsx b/components/button/index.jsx index c18a0910..05a43bae 100644 --- a/components/button/index.jsx +++ b/components/button/index.jsx @@ -39,26 +39,28 @@ class Button extends React.Component { render () { let className = style[this.props.kind]; - const {label, icon, loading, ripple, primary, accent, mini, kind, tooltip, ...others} = this.props; + const {label, icon, loading, ripple, primary, accent, mini, kind, tooltip, href, ...others} = this.props; + const element = href ? 'a' : 'button'; + if (this.props.className) className += ` ${this.props.className}`; if (!primary && !accent) className += ` ${style.primary}`; if (primary) className += ` ${style.primary}`; if (accent) className += ` ${style.accent}`; if (mini) className += ` ${style.mini}`; - return ( - + const props = { + ...others, + href, + className, + disabled: this.props.disabled || this.props.loading, + onMouseDown: this.handleMouseDown + }; + + return React.createElement(element, props, + ripple ? : null, + tooltip ? : null, + icon ? : null, + label ? label : this.props.children ); } } diff --git a/components/button/style.scss b/components/button/style.scss index 4cb89d86..fb5ae8fa 100644 --- a/components/button/style.scss +++ b/components/button/style.scss @@ -7,7 +7,9 @@ display: inline-block; height: $button-height; flex-direction: row; + align-content: center; align-items: center; + justify-content: center; color: $button-default-text-color; text-align: center; text-decoration: none; @@ -16,18 +18,29 @@ border: 0; outline: none; transition: box-shadow .2s $animation-curve-fast-out-linear-in, - background-color .2s $animation-curve-default, - color .2s $animation-curve-default; - align-content: center; - justify-content: center; - + background-color .2s $animation-curve-default, + color .2s $animation-curve-default; &::-moz-focus-inner { border: 0; } + > span { + @include typo-button(); + display: inline-block; + line-height: $button-height; + vertical-align: middle; + } + > svg { + display: inline-block; + width: 1em; + height: 1em; + margin-right: .5 * $unit; + font-size: 120%; + vertical-align: middle; + fill: currentColor; + } > * { pointer-events: none; } - [data-react-toolbox="ripple"] { overflow: hidden; } @@ -50,11 +63,6 @@ cursor: auto; } -.label { - @include typo-button(); - line-height: $button-height; -} - .flat { @extend %button; @extend %squared; diff --git a/spec/components/button.jsx b/spec/components/button.jsx index ee576e68..fa71b106 100644 --- a/spec/components/button.jsx +++ b/spec/components/button.jsx @@ -1,10 +1,19 @@ import React from 'react'; import Button from '../../components/button'; +const GithubIcon = () => ( + + + +); + const ButtonTest = () => (
Buttons

lorem ipsum...

+ - +
diff --git a/docs/app/components/layout/install/install.md b/docs/app/components/layout/install/install.md index 0c6fed71..f8842c43 100644 --- a/docs/app/components/layout/install/install.md +++ b/docs/app/components/layout/install/install.md @@ -21,7 +21,7 @@ import React from 'react'; import Button from 'react-toolbox/lib/button'; const CustomButton = () => ( - - + - +