Skip to content

Commit

Permalink
Merge pull request #10 from ahennr/add-toolbar-container
Browse files Browse the repository at this point in the history
Adds toolbar container, its tests and examples
  • Loading branch information
ahennr authored Sep 5, 2017
2 parents 4d75792 + 501b414 commit f99b1d3
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Toolbar/Toolbar.example.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { render } from 'react-dom';
import { Button } from 'antd';
import Toolbar from './Toolbar.jsx'; //@react-geo@

render(
<div>
<Toolbar>
<Button type="primary" shape="circle" icon="search" />
<Button type="primary" shape="circle" icon="search" />
<Button type="primary" shape="circle" icon="search" />
</Toolbar>
<hr style="margin: 1em"/>
<Toolbar alignment="vertical" style={{
position: 'unset'
}}>
<Button type="primary" shape="circle" icon="info" />
<Button type="primary" shape="circle" icon="info" />
<Button type="primary" shape="circle" icon="info" />
</Toolbar>
</div>,
document.getElementById('exampleContainer')
);
8 changes: 8 additions & 0 deletions src/Toolbar/Toolbar.example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: basic.html
title: Toolbar example
description: This is a example using a toolbar having vertically and horizontally aligned child elements.
collection: Examples
---

This is a example using a toolbar having vertically and horizontally aligned child elements (buttons in this example).
61 changes: 61 additions & 0 deletions src/Toolbar/Toolbar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import PropTypes from 'prop-types';
import './Toolbar.less';

/**
* A base class representating a toolbar having n children
* The child components of this toolbar can be aligned in vertical and
* horizontal (default) way
*
* @class The Toolbar
* @extends React.Component
*/
class Toolbar extends React.Component {

/**
* The properties.
* @type {Object}
*/
static propTypes = {
/**
* The children.
* @type {Array}
*/
children: PropTypes.node,

/**
* The alignment of the sub components.
* @type {String}
*/
alignment: PropTypes.oneOf(['horizontal', 'vertical']),

/**
* An object containing style informations. Applied to Toolbar.
* @type {Boolean}
*/
style: PropTypes.object
}

/**
* The default properties.
* @type {Object}
*/
static defaultProps = {
children: [],
alignment: 'horizontal'
}

/**
* The render function
*/
render() {
const {style} = this.props;
return (
<div className={this.props.alignment + '-toolbar'} style={style}>
{this.props.children}
</div>
);
}
}

export default Toolbar;
23 changes: 23 additions & 0 deletions src/Toolbar/Toolbar.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.vertical-toolbar {
position: absolute;
right: 5px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

button {
margin-top: 5px;
}
}

.horizontal-toolbar {
line-height: 30px;
pointer-events: all;
transition: all .3s;

button {
margin-right: 5px;
top: 5px;
}
}
90 changes: 90 additions & 0 deletions src/Toolbar/Toolbar.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*eslint-env mocha*/
import React from 'react';
import expect from 'expect.js';
import Toolbar from './Toolbar.jsx';
import TestUtils from '../Util/TestUtils';

const testChildren = [
<div key="testdiv1" id="testdiv1" />,
<div key="testdiv2" id="testdiv2" />,
<div key="testdiv3" id="testdiv3" />
];

describe('<Toolbar />', () => {
let wrapper;

beforeEach(() => {
wrapper = TestUtils.mountComponent(Toolbar);
});

it('is defined', () => {
expect(Toolbar).not.to.be(undefined);
});

it('can be rendered', () => {
expect(wrapper).not.to.be(undefined);
});

it('contains div having class "horizontal-toolbar" by default', () => {
let rootDiv = wrapper.find('div.horizontal-toolbar');
expect(rootDiv).not.to.be(undefined);
expect(rootDiv.length).to.be(1);
});

});

describe('<Toolbar /> - CSS-class "vertical-toolbar"', () => {
let wrapper;

beforeEach(() => {
wrapper = TestUtils.mountComponent(Toolbar, {
alignment: 'vertical',
children: testChildren
});
});

it('can be rendered', () => {
expect(wrapper).not.to.be(undefined);
});

it('contains div having class "vertical-toolbar"', () => {
let rootDiv = wrapper.find('div.vertical-toolbar');
expect(rootDiv).not.to.be(undefined);
expect(rootDiv.length).to.be(1);
});

it('contains three child elements', () => {
let rootDivChildren = wrapper.find('div.vertical-toolbar').children();
expect(rootDivChildren).to.be.ok();
expect(rootDivChildren.nodes).to.be.an(Array);
expect(rootDivChildren.nodes).to.have.length(3);
});
});

describe('<Toolbar /> - CSS-class "horizontal-toolbar"', () => {
let wrapper;

beforeEach(() => {
wrapper = TestUtils.mountComponent(Toolbar, {
alignment: 'horizontal',
children: testChildren
});
});

it('can be rendered', () => {
expect(wrapper).not.to.be(undefined);
});

it('contains div having class "horizontal-toolbar"', () => {
let rootDiv = wrapper.find('div.horizontal-toolbar');
expect(rootDiv).not.to.be(undefined);
expect(rootDiv.length).to.be(1);
});

it('contains three child elements', () => {
let rootDivChildren = wrapper.find('div.horizontal-toolbar').children();
expect(rootDivChildren).to.be.ok();
expect(rootDivChildren.nodes).to.be.an(Array);
expect(rootDivChildren.nodes).to.have.length(3);
});
});
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {UserChip} from './UserChip/UserChip.jsx';
import {Toolbar} from './Toolbar/Toolbar.jsx';

export {UserChip};
export {
UserChip,
Toolbar
};
1 change: 1 addition & 0 deletions webpack.examples.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const commonConfig = require('./webpack.common.config.js');

commonConfig.entry = {
Toolbar: './src/Toolbar/Toolbar.example.jsx',
UserChip: './src/UserChip/UserChip.example.jsx'
};

Expand Down

0 comments on commit f99b1d3

Please sign in to comment.