Giter Club home page Giter Club logo

electron-react-titlebar's Introduction

electron-react-titlebar

A github desktop style title bar component for electron.

screenshot

Installation

npm i --save electron-react-titlebar

Example

npm run build
npm run demo

Usage

Main process

app.on('ready', () => {
  require('electron-react-titlebar/main').initialize()
})

Renderer process

If you are using webpack

import { TitleBar } from 'electron-react-titlebar/renderer'
import 'electron-react-titlebar/assets/style.css'

ReactDOM.render(
    <TitleBar menu={menuTemplate} icon={iconPath} />,
    document.querySelector('title-bar')
)

If you're not a webpack user and wants to load css directly

ReactDOM.render(
    <TitleBar menu={menuTemplate} icon={iconPath}>
      <link rel="stylesheet" type="text/css" href={require.resolve('electron-react-titlebar/assets/style.css')} />
    </TitleBar>,
    document.body
)

Options

children?: node

Elements to be rendered in between the menu and the window controls (optional).

disableMinimize?: boolean

Disable minimize button (optional).

disableMaximize?: boolean

Disable maximize button (optional).

icon?: string

Path to icon file (optional).

browserWindowId?: number

The browserWindow's id that window controls affect to. Default value is the browserWindow that renders the component (optional).

menu?: <MenuTemplate>

Menu template of Electron's Menu (optional).

Note: electron-react-titlebar is supporting a subset of Electron's MenuItem.

Supported options:

  • click - supported, but the callback only have item and event parameter, and the browserWindow parameter is removed due to restriction since Electron@14
  • type - submenu is not supported.
  • label - supported
  • enabled - supported
  • visible - supported
  • checked - supported

Breaking changes since v1.0.0

The v1.0.0 version contains following breaking changes:

  • Requires [email protected] or newer version
  • Due to the Electron's removal of remote module since version 14, electron-react-titlebar now:
    • Needs to initialize in main process (See example above)
    • The require path of component has changed to electron-react-titlebar/renderer
    • The currentWindow prop has been removed, instead you can control your browserWindow by browserWindowId prop
    • The second parameter of callback of menuItem's click handler (the browserWindow) has been removed

If you're still using Electron below 14 and don't want to take breaking changes, you can still use 0.x version of electron-react-titlebar.

electron-react-titlebar's People

Contributors

ajbeaven avatar dependabot[bot] avatar insidegen avatar kagamichan avatar kochiyaocean avatar narazaka avatar will-hart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

electron-react-titlebar's Issues

1.2.0 package on npm contains outdated bundled files

When installing [email protected] from npm, the dist directory of the installed package contains a reference to react-virtualized, while all such references were removed from src in c01ae64.

$ npm i [email protected]

added 12 packages, and audited 13 packages in 701ms

found 0 vulnerabilities
$ rg --count-matches react-virtualized node_modules/electron-react-titlebar/src
$ rg --count-matches react-virtualized node_modules/electron-react-titlebar/dist
node_modules/electron-react-titlebar/dist/renderer.js.map:3
node_modules/electron-react-titlebar/dist/renderer.js:1

I suspect a version of the package with outdated bundle files was accidentally uploaded to npm.

This affects people who import 'electron-react-titlebar/renderer' directly, because the bundle tries to access a(n outdated) dependency that is no longer referenced in package.json.

I suggest the npm package to be updated (with a version bump like 1.2.1) to distribute the up-to-date bundles.

Incompatible with electron 14

Thanks for the useful library. Unfortunately, we are unable to upgrade to electron-14 due to the following bug. This appears in our console.
Uncaught TypeError: Cannot read properties of undefined (reading 'getCurrentWindow')

The error appears to occur here: electron-react-titlebar/lib/window-controls.js:78 according to the firebug console.

We are using 0.8.2 of this package.

If you have a fix, I would be glad to test it out in our codebase. TIA!

Add OS X option

Would be awesome to have a OS X version of this titlebar considering many electron-react apps will be compiled for Mac as well as Windows.

Error using electron-react-titlebar

When I use electron-react-titlebar I get this error
in this file D:\Electron\test\node_modules\electron-react-titlebar\assets\style.css:1
Uncaught SyntaxError: Invalid or unexpected token
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.require.extensions.(anonymous function) [as .js] (D:\Electron\test\node_modules\electron-compile\lib\require-hook.js:77:14)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at file:///D:/Electron/test/app/MainWindow/HTML/main.html:26:1

I am using the code mentioned here with some edits

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { TitleBar } from 'electron-react-titlebar';
import 'electron-react-titlebar/assets/style.css';

var template = [
    {
        label: "Menu 1",
         submenu: [
             {
                 label: "Item 1",
                 click: function() {
                     console.log("Menu 1 Item 1 clicked")
                 }
             },
             {
                 label: "Item 2",
                 click: function() {
                     console.log("Menu 1 Item 2 clicked")
                 }
             }
         ]
    },
    {
        label: "Menu 2",
        submenu: [
            {
                label: "Item 1",
                click: function() {
                    console.log("Menu 2 Item 1 clicked")
                }
            },
            {
                label: "Item 2",
                click: function() {
                    console.log("Menu 2 Item 2 clicked")
                }
            }
        ]
    }
]

ReactDOM.render(
    <TitleBar menu={template} icon={"./test.png"} disableMaximize={true} />,
    document.body
)

Uncaught Error: Cannot find module 'classnames'

I get the following error when importing electron-react-titlebar:

Uncaught Error: Cannot find module 'classnames'

I believe the classnames package should be moved from devDependencies to dependencies to fix this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.