frameless-titlebar-patch
TypeScript icon, indicating that this package has built-in type declarations

2.1.4 • Public • Published

frameless-titlebar-patch

Customizable titlebar for frameless electron windows built with React

Main

Demo App

The demo application can be found in the example folder along with more images of the different titlebar styles:

  • Overflow Menu: When menu buttons don't fit in the given titlebar space items are moved into an overflowed submenu.
  • Stacked Menu: Titlebar stacked above menu bar.
  • Vertical Menu: All menu items moved into a vertical submenu.

Install

npm install --save frameless-titlebar-patch
# or
yarn add frameless-titlebar-patch

Usage

Electron Browser SetUp

mainWindow = new BrowserWindow({
  width: 1024,
  height: 728,
  minWidth: 600, // set a min width!
  minHeight: 300, // and a min height!
  // Remove the window frame from windows applications
  frame: false,
  // Hide the titlebar from MacOS applications while keeping the stop lights
  titleBarStyle: 'hidden',
});

React App SetUp

import React from 'react'
import icon from 'path/to/icon.png';
import menu from 'path/to/menu';
import { remote } from 'electron';

import TitleBar from 'frameless-titlebar-patch'

const currentWindow = remote.getCurrentWindow();

const Example = () => {
  return (
    <div>
      <TitleBar
        iconSrc={icon} // app icon
        currentWindow={currentWindow} // electron window instance
        platform={process.platform} // win32, darwin, linux
        menu={menu}
        theme={{
          // any theme overrides specific
          // to your application :)
        }}
        title="frameless app"
        onClose={() => currentWindow.close()}
        onMinimize={() => currentWindow.minimize()}
        onMaximize={() => currentWindow.maximize()}
        // when the titlebar is double clicked
        onDoubleClick={() => currentWindow.maximize()}
      >
        {/* custom titlebar items */}
      </TitleBar>
    </div>
  )
}

Example of all of the overridable theme properties can be found in the example folder here

Use titlebar theme in children

import { useContext } from 'react';
import { TitlebarThemeContext } from 'frameless-titlebar-patch';

const CustomItem = () => {
  // access all of the current theme properties in this
  // child component
  const theme = useContext(TitlebarThemeContext);
  return (
    <div style={{ height: theme.bar.height }}>
      {/* ... */}
    </div>
  )
}

const App = () => {
  return (
    <div>
      <TitleBar>
        <CustomItem>
      </TitleBar>
    </div>
  )
}

Example of a custom TitleBarButton can be seen here

Supported Menu Item Properties

Supported menu item properties from: Electron Menu Object/Template Documentation

Name Type Description
id (optional) string Must be unique. If defined then it can be used as a reference to this item by the position attribute
type (optional) oneOf([normal, separator, submenu, checkbox, radio]) Type of supported menu items
label (optional) string Menu item label
click (optional) function(menuItem, browserWindow, event) if currentWindow is not passed in to the titlebar then, browserWindow will be null
disabled (optional) bool Enables/disables menu item from being clicked on
accelerator (optional) string Accelerator string eg CmdOrCtrl+Z
icon (optional) img The image shown to the left of the menu label
checked (optional) bool Should only be specified for checkbox or radio type menu items
submenu (optional) array : [MenuItems] Array of menu items. If submenu is specified, the type: 'submenu' can be omitted.
before (optional) string Inserts this item before the item with the specified id. If the referenced item doesn't exist the item will be inserted at the end of the menu
after (optional) string Inserts this item after the item with the specified id. If the referenced item doesn't exist the item will be inserted at the end of the menu

Keyboard accessibility

Opening Menu: Pressing Alt Key + First letter of any of the visible menu items. eg: Alt+F would open the first menu item with an F if any, such as File.

Closing Menu: Pressing Esc.

Navigating Submenus: Use arrow keys (up, down, left, right) to navigate menus once they're open.

Disclaimers

NOTE: ^v2.0.0 has a lot of breaking changes from the previous ^1.x.x releases since this was a complete re-write of frameless-titlebar-patch

Contributing

Feel free to fork and create pull requests! I'll try my best to review any code changes for the next release.

Links

Electron Remote Docs

Electron Menu Docs

License

MIT © Cristian006


Made with ❤️ + ☕ by Cristian Ponce

Readme

Keywords

none

Package Sidebar

Install

npm i frameless-titlebar-patch

Weekly Downloads

0

Version

2.1.4

License

MIT

Unpacked Size

799 kB

Total Files

86

Last publish

Collaborators

  • mathieu_andrade