npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openfin-react-widgets

v1.0.2

Published

Helper to create standalone child windows containing a single React component with ability to set props and trigger events

Downloads

4

Readme

openfin-react-widgets

Use this if you want to create child windows out of a single React component and not have to worry about all the plumbing and interapp event publishing.

Features:

  • Widget React component can trigger events to be consumed (and isolated to) the creator of the Widget
  • Widget creator (parent Window) can set props on the Widget
  • virtually no setup code as long as you follow a couple guidelines

Installation

npm i --save openfin-react-widgets

Create a module that contains all of your widgets associated with a unique key

export default {
  foo: MyFooWidget,
  bar: MyBarWidget
}

Add this bit of code to your app entry point (you should be using Webpack by now...)

import { initWidgetHandler } from 'openfin-react-widgets';
import myWidgets from './widgets'; // your widgets module from above

// most of this is boilerplate code required by openfin
document.addEventListener('DOMContentLoaded', function() {
  try {
    fin.desktop.main(function() {
      const root = document.getElementById('root'); // or whatever your root DOM element is for React mounting
      initWidgetHandler({
        widgets: widgets,
        appInit: () => {
          // whatever app init logic you would normally have without a widget handler
          ReactDOM.render(<App />, root);
        },
        rootElement: root
      });
    });
  } catch (e) {
    // no fin... standard browser
  }
});

initWidgetHandler options

  • widgets: (required) object containing widgets (see above for example)
  • appInit: (required) function (); any app init code (set up routers or whatever you want) if this Window is not a Widget
  • widgetInit: function (windowCustomData, WidgetClass); any code you want to execute if this Window is a Widget
  • widgetWrapper: function (widgetInstance, widgetInitRtn); return a wrapper for the widget if you need something like a Redux Provider
  • rootElement: DOM element which sould be used as the root for the Widget bindings

Opening a Widget

import { showWidget } from 'openfin-react-widgets';
...
showWidget({
  type: 'foo', // must match a key in our widgets definitions module
  options: {
    // whatever fin Window options you want - http://cdn.openfin.co/jsdocs/beta/fin.desktop.Window.html#~options
  },
  props: {
    // any initial props that you would like passed to your widget
    message: 'hello'
  },
  events: {
    // you always have the `close` event available
    close: () => { alert('the widget was closed'); },
    // any custom events you want your Widget to be able to trigger
    onSomeButtonClick: ({ message }) => { alert('the message is ' + message); }
  }
})
.then((handle) => {
  // see Widget Handle Properties
})

Widget Handle Properties

  • close: function to execute when Widget Window should be closed
  • window: the fin Window instance containing the Widget (do not use this close function)
  • setProps: call this any time to set new props on your Widget

Widget React Component

// `trigger` was provided automatically and `message` was provided by Widget creator
export default MyFooWidget ({ trigger, message }) {
  return (
    <div>
      the message is {message}.
      <br/>
      click
      <button type="button" onClick={() => trigger('onSomeButtonClick', { message: 'world' })}>
        this button
      </button>
    </div>
  );
}