-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from KaiVolland/introduce-buttons
Introduces buttons
- Loading branch information
Showing
26 changed files
with
1,019 additions
and
20 deletions.
There are no files selected for viewing
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
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
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,35 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import SimpleButton from './SimpleButton.jsx'; //@react-geo@ | ||
|
||
render( | ||
<div> | ||
<div className="example-block"> | ||
<span>Just a SimpleButton:</span> | ||
|
||
{/* A SimpleButton without any configuration*/} | ||
<SimpleButton /> | ||
|
||
</div> | ||
<div className="example-block"> | ||
<span>Tooltip:</span> | ||
|
||
{/* A SimpleButton with a tooltip and a tooltipPlacement*/} | ||
<SimpleButton | ||
tooltip="bottom tooltip" | ||
tooltipPlacement="bottom" | ||
/> | ||
|
||
</div> | ||
<div className="example-block"> | ||
<span>Icon:</span> | ||
|
||
{/* A SimpleButton with an icon. Just use the font-awesome name.*/} | ||
<SimpleButton | ||
icon="bullhorn" | ||
/> | ||
|
||
</div> | ||
</div>, | ||
document.getElementById('exampleContainer') | ||
); |
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,9 @@ | ||
--- | ||
layout: basic.html | ||
title: SimpleButton example | ||
description: This is a example using an SimpleButton. | ||
collection: Examples | ||
--- | ||
|
||
This demonstrates the use of SimpleButtons. Please have a look at [https://ant.design/components/button/](https://ant.design/components/button/) | ||
for more documentation and examples. |
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,101 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Button, | ||
Tooltip | ||
} from 'antd'; | ||
import { Icon } from 'react-fa'; | ||
|
||
import Logger from '../../Util/Logger'; | ||
|
||
import './SimpleButton.less'; | ||
|
||
/** | ||
* The SimpleButton. | ||
* | ||
* @class The SimpleButton | ||
* @extends React.Component | ||
*/ | ||
class SimpleButton extends React.Component { | ||
|
||
/** | ||
* The properties. | ||
* @type {Object} | ||
*/ | ||
static propTypes = { | ||
icon: PropTypes.string, | ||
fontIcon: PropTypes.string, | ||
shape: PropTypes.string, | ||
size: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
onClick: PropTypes.func, | ||
tooltip: PropTypes.string, | ||
tooltipPlacement: PropTypes.string | ||
}; | ||
|
||
/** | ||
* The default properties. | ||
* @type {Object} | ||
*/ | ||
static defaultProps = { | ||
type: 'primary', | ||
icon: '', | ||
shape: 'circle', | ||
size: 'default', | ||
disabled: false | ||
} | ||
|
||
/** | ||
* Create the SimpleButton. | ||
* | ||
* @constructs SimpleButton | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
/** | ||
* Handles the given click callback. | ||
*/ | ||
onClick = () => { | ||
if (this.props.onClick) { | ||
this.props.onClick(); | ||
} else { | ||
Logger.debug('No onClick method given. Please provide it as ' + | ||
'prop to this instance.'); | ||
} | ||
} | ||
|
||
/** | ||
* The render function. | ||
*/ | ||
render() { | ||
const { | ||
tooltip, | ||
tooltipPlacement, | ||
icon, | ||
fontIcon, | ||
...antBtnProps | ||
} = this.props; | ||
|
||
return ( | ||
<Tooltip | ||
title={tooltip} | ||
placement={tooltipPlacement} | ||
> | ||
<Button | ||
className="btn-simple" | ||
onClick={this.onClick} | ||
{...antBtnProps} | ||
> | ||
<Icon | ||
name={icon} | ||
className={fontIcon} | ||
/> | ||
</Button> | ||
</Tooltip> | ||
); | ||
} | ||
} | ||
|
||
export default SimpleButton; |
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,22 @@ | ||
@import '../../style/variables.less'; | ||
|
||
.btn-simple { | ||
color: #fff; | ||
background-color: @primary-color; | ||
border-color: @primary-color; | ||
|
||
&:focus{ | ||
background-color: lighten(@primary-color, 10); | ||
border-color: lighten(@component-background, 10); | ||
} | ||
|
||
&:hover { | ||
background-color: lighten(@primary-color, 10); | ||
border-color: lighten(@component-background, 10); | ||
} | ||
|
||
&:disabled { | ||
background-color: @component-background; | ||
border-color: darken(@component-background, 10); | ||
} | ||
} |
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,68 @@ | ||
/*eslint-env mocha*/ | ||
import expect from 'expect.js'; | ||
import sinon from 'sinon'; | ||
|
||
import TestUtils from '../../Util/TestUtils'; | ||
import Logger from '../../Util/Logger'; | ||
|
||
import SimpleButton from './SimpleButton.jsx'; | ||
|
||
describe('<SimpleButton />', () => { | ||
it('is defined', () => { | ||
expect(SimpleButton).not.to.be(undefined); | ||
}); | ||
|
||
it('can be rendered', () => { | ||
const wrapper = TestUtils.mountComponent(SimpleButton); | ||
expect(wrapper).not.to.be(undefined); | ||
}); | ||
|
||
it('allows to set some props', () => { | ||
const wrapper = TestUtils.mountComponent(SimpleButton); | ||
|
||
wrapper.setProps({ | ||
type: 'secondary', | ||
icon: 'bath', | ||
shape: 'circle', | ||
size: 'small', | ||
disabled: true | ||
}); | ||
|
||
expect(wrapper.props().type).to.equal('secondary'); | ||
expect(wrapper.props().icon).to.equal('bath'); | ||
expect(wrapper.props().shape).to.equal('circle'); | ||
expect(wrapper.props().size).to.equal('small'); | ||
expect(wrapper.props().disabled).to.equal(true); | ||
|
||
expect(wrapper.find('button.ant-btn-secondary').length).to.equal(1); | ||
expect(wrapper.find('span.fa-bath').length).to.equal(1); | ||
expect(wrapper.find('button.ant-btn-circle').length).to.equal(1); | ||
expect(wrapper.find('button.ant-btn-sm').length).to.equal(1); | ||
expect(wrapper.find({disabled: true}).length).to.equal(1); | ||
}); | ||
|
||
it('warns if no click callback method is given', () => { | ||
const wrapper = TestUtils.mountComponent(SimpleButton); | ||
const logSpy = sinon.spy(Logger, 'debug'); | ||
|
||
wrapper.find('button').simulate('click'); | ||
|
||
expect(logSpy).to.have.property('callCount', 1); | ||
|
||
Logger.debug.restore(); | ||
}); | ||
|
||
it('calls a given click callback method onClick', () => { | ||
const wrapper = TestUtils.mountComponent(SimpleButton); | ||
const onClick = sinon.spy(); | ||
|
||
wrapper.setProps({ | ||
onClick: onClick | ||
}); | ||
|
||
wrapper.find('button').simulate('click'); | ||
|
||
expect(onClick).to.have.property('callCount', 1); | ||
}); | ||
|
||
}); |
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,38 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import ToggleButton from './ToggleButton.jsx'; //@react-geo@ | ||
|
||
render( | ||
<div> | ||
<div className="example-block"> | ||
<span>Just a ToggleButton:</span> | ||
|
||
{/* A ToggleButton without any configuration*/} | ||
<ToggleButton /> | ||
|
||
</div> | ||
|
||
<div className="example-block"> | ||
<span>Initialy pressed ToggleButton:</span> | ||
|
||
{/* A ToggleButton without any configuration*/} | ||
<ToggleButton | ||
pressed={true} | ||
/> | ||
|
||
</div> | ||
|
||
<div className="example-block"> | ||
<span>pressedIcon:</span> | ||
|
||
{/* A ToggleButton with an icon and a pressedIcon*/} | ||
<ToggleButton | ||
icon="frown-o" | ||
pressedIcon="smile-o" | ||
/> | ||
|
||
</div> | ||
|
||
</div>, | ||
document.getElementById('exampleContainer') | ||
); |
Oops, something went wrong.