2.0.1 • Published 10 years ago
titlebar-react v2.0.1
titlebar-react
Emulate OS X window title bar. Extracted from mafintosh/playback and then forked from kapetan/titlebar.
See the live demo (Without React).
npm install titlebar-reactvar React = require('react');
var Titlebar = require('titlebar-react');
var Window = React.createClass({
handleClose: function(e) {
console.log('closing');
},
handleMinimize: function(e) {
console.log('minimize');
},
handleMaximize: function(e) {
console.log('maximize');
},
handleFullScreen: function(e) {
console.log('fullscreen');
},
render: function() {
return (
<div className="r-win">
<Titlebar
draggable={true}
handleClose={this.handleClose}
handleMinimize={this.handleMinimize}
handleMaximize={this.handleMaximize}
handleFullScreen={this.handleFullScreen}>
/* any other React component here */
</Titlebar>
</div>
);
}
});
// then simply add to DOM
React.render({
<Window />,
document.body
});Usage
The returned instance emits four events: close, minimize, fullscreen (each corresponding to one of the stoplight buttons) and maximize when double clicking on the title bar area, or holding down alt key and clicking fullscreen.
Instead of emitting four events, you get to define what each event will do by passing callbacks to this.props.
<Titlebar
handleClose={this.handleClose}
handleMinimize={this.handleMinimize}
handleMaximize={this.handleMaximize}
handleFullScreen={this.handleFullScreen} />available props
draggable(defaultfalse): Enable dragging.handleClose: called when close is clickedhandleMinimize: called when minimized is clickedhandleMaximize: called when maximize is clickedhandleFullScreen: called when fullscreen is clicked