Skip to content
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

[bar] Add right component #191

Merged
merged 1 commit into from
Aug 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 80 additions & 43 deletions src/application/bar/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,84 @@
var builder = require('focus').component.builder;
var React = require('react');
var applicationStore = require('focus').application.builtInStore();
const builder = require('focus').component.builder;
const React = require('react');
const applicationStore = require('focus').application.builtInStore();

var barMixin = {
getDefaultProps: function getCartridgeDefaultProps(){
return {
style: {}
};
},
/** @inheriteddoc */
getInitialState: function getCartridgeInitialState() {
return this._getStateFromStore();
},
/** @inheriteddoc */
componentWillMount: function cartridgeWillMount() {
applicationStore.addSummaryComponentChangeListener(this._handleComponentChange);
applicationStore.addBarContentLeftComponentChangeListener(this._handleComponentChange);
},
/** @inheriteddoc */
componentWillUnMount: function cartridgeWillUnMount(){
applicationStore.removeSummaryComponentChangeListener(this._handleComponentChange);
applicationStore.addBarContentLeftComponentChangeListener(this._handleComponentChange);
},
_getStateFromStore: function getCartridgeStateFromStore(){
return {
summaryComponent: applicationStore.getSummaryComponent() || {component: 'div', props: {}},
barContentLeftComponent: applicationStore.getBarContentLeftComponent() || {component: 'div', props:{}}
};
},
_handleComponentChange: function _handleComponentChangeBarSummary(){
this.setState(this._getStateFromStore());
},
/** @inheriteddoc */
render: function renderBar() {
var className = `bar ${this.props.style.className}`;
return (
<div className={className} data-focus='bar'>
<div data-focus='bar-content-left'><this.state.barContentLeftComponent.component {...this.state.barContentLeftComponent.props}/> </div>
<div data-focus='bar-content-right'><i className="fa fa-bell-o fa-2x"></i></div>
<div data-focus='bar-content-middle'><this.state.summaryComponent.component {...this.state.summaryComponent.props}/></div>
</div>
);
}
const barMixin = {
/**
* Default props
* @return {object} Default props
*/
getDefaultProps() {
return {
style: {}
};
},
/**
* Get initial state
* @return {object} Initial state
*/
getInitialState() {
return this._getStateFromStore();
},
/**
* Component will mount
*/
componentWillMount() {
applicationStore.addSummaryComponentChangeListener(this._handleComponentChange);
applicationStore.addBarContentLeftComponentChangeListener(this._handleComponentChange);
applicationStore.addBarContentRightComponentChangeListener(this._handleComponentChange);
},
/**
* Component will unmount
*/
componentWillUnMount() {
applicationStore.removeSummaryComponentChangeListener(this._handleComponentChange);
applicationStore.removeBarContentLeftComponentChangeListener(this._handleComponentChange);
applicationStore.removeBarContentRightComponentChangeListener(this._handleComponentChange);
},
/**
* Get state from store
* @return {object} state from store
*/
_getStateFromStore() {
return {
summaryComponent: applicationStore.getSummaryComponent(),
barContentLeftComponent: applicationStore.getBarContentLeftComponent(),
barContentRightComponent: applicationStore.getBarContentRightComponent()
};
},
/**
* Component change handler
*/
_handleComponentChange() {
this.setState(this._getStateFromStore());
},
/**
* Render the component
* @return {HTML} Rendered component
*/
render() {
const className = `bar ${this.props.style.className}`;
const {barContentLeftComponent, barContentRightComponent, summaryComponent} = this.state;
return (
<div className={className} data-focus='bar'>
<div data-focus='bar-content-left'>
{barContentLeftComponent &&
<barContentLeftComponent.component {...barContentLeftComponent.props}/>
}
</div>
<div data-focus='bar-content-right'>
{barContentRightComponent &&
<barContentRightComponent.component {...barContentRightComponent.props}/>
}
</div>
<div data-focus='bar-content-middle'>
{summaryComponent &&
<summaryComponent.component {...summaryComponent.props}/>
}
</div>
</div>
);
}
};

module.exports = builder(barMixin);