Code Monkey home page Code Monkey logo

react-popout-component's Introduction

React Popout Component

Build Status npm

This is a React component designed for React 16 with complete Typescript support.

Features

  1. This is developed along side with the React 16 fix to allow mounting across frames even for Edge and IE browsers
  2. Typescript support for all the options (especially hard to remember window features)
  3. Reflects style-loader injected styles from the main window to the children window

Installation

npm install react-popout-component

or

yarn add react-popout-component

Usage

import * as React from 'react';
import {Popout} from 'react-popout-component';

export default class App extends React.Component<any, any> {
    constructor(props: any) {
        super(props);
        this.state = {showPopout: false};
    }

    onClick = () => {
        this.setState({showPopout: true});
    }

    render() {
        return (
            <div>
                <h1>Now you too have the power to POP OUT</h1>
                <button onClick={this.onClick}>POP IT OUT!</button>
                {this.state.showPopout && (
                    <Popout>
                        <div>You can put anything here!</div>
                    </Popout>
                )}
            </div>
        );
    }
}

API

PopOut Component has the following props:

export interface PopoutProps {
    hidden?: boolean;
    name?: string;
    onClose?: () => void;
    onBeforeUnload?: (evt: BeforeUnloadEvent) => string | null | undefined;
    children?: any;
    options?: Partial<WindowFeaturesOptions>;
    html?: string;
}

The options prop is of the following type:

export interface WindowFeaturesOptions {
    left: number;
    top: number;
    height: number;
    width: number;
    menubar: boolean;
    toolbar: boolean;
    location: boolean;
    status: boolean;
    resizable: boolean;
    scrollbars: boolean;
}

Injection Mode

This component works well for both modes of style loading:

  1. Appending Style blocks (e.g. style-loader)
  2. Manual insertRule() into a CSSStyleSheet

For the second case with insertRule(), since there is nothing that can observe the insert event, a callback must be registered when a rule is inserted. For an example usage with the Microsoft Office Fabric, set it up as a global like so:

import {insertPopoutStylesheetRule} from 'react-popout-component';

window.FabricConfig = {
    mergeStyles: {
        onInsertRule: insertPopoutStylesheetRule
    }
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

react-popout-component's People

Contributors

kenotron avatar lego6245 avatar microsoftopensource avatar msftgits avatar peterblazejewicz avatar smikula 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

Watchers

 avatar  avatar  avatar  avatar

react-popout-component's Issues

Cannot compile with typescript starter

While there are typings for all the lib files, the index.js file doesn't have a corresponding index.d.ts file which causes the readme example code to fail.

Steps to replicate:

create-react-app my-app --scripts-version=react-scripts-ts
  • Install this module via yarn:
yarn add react-popout-component
  • Cut and paste the App.tsx from the readme

  • Try running yarn start

Expected Result

The module compiles correctly and you can run the example

Actual Result

The module does not compile and errors out:

Failed to compile.

./src/App.tsx
(2,22): error TS7016: Could not find a declaration file for module 'react-popout-component'. '/Users/cetra/Desktop/my-app/node_modules/react-popout-component/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-popout-component` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-popout-component';`

Injecting styles with relative url paths

I've just come across this library and I really like it: it's quite a bit simpler than the solution I had come up with.

I've tried it in my project, but I've hit an issue in that I have some fonts which I refer to their font source using relative path urls... something like this:

@font-face {
  font-family: 'Lato';
  font-weight: 300;
  font-style: normal;
  src:  
    url('../fonts/lato-light.woff2') format('woff2'),
    url('../fonts/lato-light.woff') format('woff');
}

These font files aren't loaded in due to the pop out window url being "about:blank". Is there anyway I can get this working?

window is not defined

using

  • react 16.2
  • es2018
ReferenceError: window is not defined
at Object.set (/[somedir]//node_modules/react-popout-component/lib/globalContext.js:6:5)
at Object.<anonymous> (/[somedir]/node_modules/react-popout-component/lib/childWindowMonitor.js:28:15)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> ( /[somedir]/node_modules/react-popout-component/lib/Popout.js:19:1)

Style injection appears to be broken

In a new React app, the component styles don't load correctly for me in the new window in development (I have not tried a full build):

Screen Shot 2020-04-26 at 10 57 33 AM

Styles work correctly throughout the rest of the application. There's nothing special about the Popout usage, just a "hello world" example.

Possibly relevant versions:

"react": "^16.13.1",
"node-sass": "^4.14.0",

Persistent Popout

I'm currently developing a chat application using reacjts (it is a plugin to a wordpress site), and I've implemented the ability to pop out a chat window from our main page using this component. The popout is created based off user action and it only contains the chat window they popped out, not the rest of the application.

The problem with this is that the application needs to pass data to and from that chat window, so there is still a connection to the rest of the site. When a user loads a new page on the site, the popout closes and this is something that we can't afford happening.

Is there any approach we can take to keep the popout open even if the user navigates away from the page that they were on when they loaded the popout? Would we have to load the whole react plugin into the popout window in order to avoid this happening? Or is there an easier approach to it?

What is a popout?

Hi there, I came across this repo and was wondering what a popout is? I am familiar with popover and popup but was wondering if there is a diagram or explanation that might be helpful in disambiguation of these terms. Cheers.

Popup Blockers aren't really handled elegantly.

I think there's an issue in Popouts.tsx where we both don't bypass the rest of the window setup logic if we detect a dead window, and later when we try to render into a container that's never set. Both of those cause React component level errors, which are a Bad ThingTM.

Demo on how to inject style sheets

Hi guys,

Great library, but I have no idea how to inject my stylesheet into this bad boy. Is there any chance you could make a demo or just reply here with how to inject your stylesheet or some style elements into the Popout?

Thanks

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.