Allow children for buttons and use it as link where there is href prop

old
Javi Velasco 2015-11-16 21:55:21 +01:00
parent b351237fb3
commit 4707a26748
4 changed files with 46 additions and 31 deletions

View File

@ -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 (
<button
data-react-toolbox='button'
{...others}
className={className}
disabled={this.props.disabled || this.props.loading}
onMouseDown={this.handleMouseDown}
>
{ ripple ? <Ripple ref='ripple' loading={loading}/> : null }
{ icon ? <FontIcon className={style.icon} value={icon}/> : null }
{ label ? <abbr className={style.label}>{label}</abbr> : null }
{ tooltip ? <Tooltip label={tooltip}/> : null }
</button>
const props = {
...others,
href,
className,
disabled: this.props.disabled || this.props.loading,
onMouseDown: this.handleMouseDown
};
return React.createElement(element, props,
ripple ? <Ripple ref='ripple' loading={loading}/> : null,
tooltip ? <Tooltip label={tooltip}/> : null,
icon ? <FontIcon className={style.icon} value={icon}/> : null,
label ? label : this.props.children
);
}
}

View File

@ -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;

View File

@ -1,10 +1,19 @@
import React from 'react';
import Button from '../../components/button';
const GithubIcon = () => (
<svg viewBox="0 0 284 277">
<g><path d="M141.888675,0.0234927555 C63.5359948,0.0234927555 0,63.5477395 0,141.912168 C0,204.6023 40.6554239,257.788232 97.0321356,276.549924 C104.12328,277.86336 106.726656,273.471926 106.726656,269.724287 C106.726656,266.340838 106.595077,255.16371 106.533987,243.307542 C67.0604204,251.890693 58.7310279,226.56652 58.7310279,226.56652 C52.2766299,210.166193 42.9768456,205.805304 42.9768456,205.805304 C30.1032937,196.998939 43.9472374,197.17986 43.9472374,197.17986 C58.1953153,198.180797 65.6976425,211.801527 65.6976425,211.801527 C78.35268,233.493192 98.8906827,227.222064 106.987463,223.596605 C108.260955,214.426049 111.938106,208.166669 115.995895,204.623447 C84.4804813,201.035582 51.3508808,188.869264 51.3508808,134.501475 C51.3508808,119.01045 56.8936274,106.353063 65.9701981,96.4165325 C64.4969882,92.842765 59.6403297,78.411417 67.3447241,58.8673023 C67.3447241,58.8673023 79.2596322,55.0538738 106.374213,73.4114319 C117.692318,70.2676443 129.83044,68.6910512 141.888675,68.63701 C153.94691,68.6910512 166.09443,70.2676443 177.433682,73.4114319 C204.515368,55.0538738 216.413829,58.8673023 216.413829,58.8673023 C224.13702,78.411417 219.278012,92.842765 217.804802,96.4165325 C226.902519,106.353063 232.407672,119.01045 232.407672,134.501475 C232.407672,188.998493 199.214632,200.997988 167.619331,204.510665 C172.708602,208.913848 177.243363,217.54869 177.243363,230.786433 C177.243363,249.771339 177.078889,265.050898 177.078889,269.724287 C177.078889,273.500121 179.632923,277.92445 186.825101,276.531127 C243.171268,257.748288 283.775,204.581154 283.775,141.912168 C283.775,63.5477395 220.248404,0.0234927555 141.888675,0.0234927555" /></g>
</svg>
);
const ButtonTest = () => (
<section>
<h5>Buttons</h5>
<p>lorem ipsum...</p>
<Button href='http://github.com/javivelasco' target='_blank' kind='raised'>
<GithubIcon /> Github Profile
</Button>
<Button kind='raised' primary label='Bookmark' icon='bookmark' />
<Button kind='flat' accent label='Inbox' icon='inbox' />
<Button kind='floating' primary icon='add' />

View File

@ -5,12 +5,12 @@
$offset: 1.8 * $unit;
.app {
padding: (8.2 * $unit) $offset $offset $offset;
padding: (8.2 * $unit) $offset $offset;
background-color: #f5f5f5;
> section {
padding: $offset;
margin-bottom: $offset;
background-color: white;
background-color: #fff;
box-shadow: 0 1px 2px rgba(0,0,0, 0.25);
> h5 {
color: rgb(48, 63, 159);
@ -48,7 +48,3 @@ $offset: 1.8 * $unit;
}
}
}
.logo {
// height: $unit;
}