Electron's BrowserWindow as a react component
A react component that gives access to the encapsulating window, similarly to how react native's Statusbar component works.
By controlling the window through a react component, you give your react app canonic access to electron's BrowserWindow object. A good usecase is a multiscreen application - you can embed a <BrowserWindow />
component in each of your route components, making each one of them adjust the window to its needs without having to programatically do so throguh electron's remote
.
-
Using NPM:
$ npm install --save react-electron-browser-window
-
Using yarn:
$ yarn add react-electron-browser-window
The <BrowserWindow />
component contains the following props:
title
: String - title of the window (if not frameless)visible
: Boolean - whether to show or hide the windowicon
: Boolean - sets the window's iconwidth, height
: (Number, Number) - window's dimensions, will apply only if both are givenleft, top
: (Number, Number) - window's position, will apply only if both are givencenter
: Boolean - moves the window to the center, overrides positionanimated
: Boolean - if true, will animate window between dimensions and positions.movable
: Boolean - if true, window will be movableresizable
: Boolean - if true, window will be resizableminimizable
: Boolean - if true, window will be minisizablemaximizable
: Boolean - if true, window will be maximizablefullscreenable
: Boolean - if true, window will be fullscreenableclosable
: Boolean - if true, window will be closablealwaysOnTop
: Boolean - whether window always shows on topskipTaskbar
: Boolean - if true, window will not show on taskbarwindowState
: String - either one of the following options:normal
: default window stateminimized
: window will be minimizedmaximized
: window will be maximizedfullscreen
: window will be fullscreenkiosk
: window will show in kiosk mode
macOsVibrancy
: String - displays the window with vibrancy effect on macOS:light
,dark
,titlebar
,selection
,menu
,popover
,sidebar
,medium-light
,ultra-dark
,appearance-based
Default value policy:
The component only takes its parameters explicitly, that is, if it was not passed, it will not be touched. That is useful in cases where you want to control certain aspects of your window from other places in your code. If you only pass certain parameters through the BrowserWindow component, you can be rest assured that it will apply nothing but them.
import React, {Component} from 'react';
import BrowserWindow from 'react-electron-browser-window';
class App extends Component {
render() {
return (
<BrowserWindow title="Hello, World!" visible={true} center={true} />
)
}
}
Code is provided under MIT license.