1.2.5 • Published 10 months ago

react-window-renderer v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

react-window-renderer

Introducing a new feature in React that allows developers to render part of a component in a new browser tab or window. This functionality is particularly useful for displaying large content across two related windows, enhancing the user experience when working with dual screens in extended mode. Ideal for scenarios where users need to view or interact with content simultaneously across multiple screens.

Demo

Demo preview

!CAUTION This package is under development, you might face some buggy behaver

Support

support me to keep this work up by buying me a coffee

Installation

npm i react-window-renderer

Examples

example with button open/close

import { RenderInWindow, useRenderInWindow } from "react-window-renderer";

const BasicUsageExample = () => {
  const { open, setOpen, _window } = useRenderInWindow();

  return (
    <>
      <h1>React Window Renderer Basic Example</h1>
      <RenderInWindow
        open={open}
        setOpen={setOpen}
        returnWindow={(w) => (_window.current = w)}
      >
        <div>Render this content in new window</div>
      </RenderInWindow>
      <button onClick={() => setOpen(!open)}>
        {open ? "Close Window" : "Open Window"}
      </button>
    </>
  );
};

export default BasicUsageExample;

example with enable open/close icons

import { RenderInWindow, useRenderInWindow } from "react-window-renderer";

const BasicNoCssUsageExample = () => {
  const { open, setOpen, _window } = useRenderInWindow();

  return (
    <>
      <h1>React Window Renderer Basic Example</h1>
      <RenderInWindow
        open={open}
        setOpen={setOpen}
        showCloseWindowIcon
        showOpenWindowIcon
        showChilderWhenClose
        returnWindow={(w) => (_window.current = w)}
        extraHeadHTMLTags={[<style ref="" />]}
      >
        <div>Render this content in new window</div>
      </RenderInWindow>
    </>
  );
};

export default BasicNoCssUsageExample;

Props Table for RenderInWindow Component

PropDefault ValueRequired/OptionalExplanation
open-RequiredControls whether the window is currently open or closed. A boolean value indicating the state.
setOpen-RequiredA React state setter function used to toggle the window's open state. This function updates the open prop.
children-RequiredThe JSX Element(s) that will be rendered inside the new window. Must be provided for the component to function.
returnWindow-RequiredA callback function that receives the newly opened window object, allowing further manipulation if needed.
showChilderWhenClosefalseOptionalIf true, the children will be showen when the window is closed, ensuring they are displayed in the original component.
showOpenWindowIconfalseOptionalIf true, an icon will be displayed to indicate the option to open the window. Useful for improving user experience.
openWindowIconConfigsee IIconConfigOptionalConfiguration for the open window icon, allowing you to set width and height. Defaults to 30px by 30px.
showCloseWindowIconfalseOptionalIf true, an icon will be shown to allow the user to close the window. Enhances usability by providing a visual cue.
closeWindowIconConfigsee IIconConfigOptionalConfiguration for the close window icon, allowing you to set width and height. Defaults to 30px by 30px.
windowConfigsee IWindowConfigOptionalConfiguration object for the window's properties such as width, height, position, and other window features (toolbar, menubar, etc.).
extraHeadHTMLTags-Optional, ExperimentalAn array of JSX elements (e.g. <style> or <script>) that will be injected into the window's head section. Experimental and subject to change.

Props Table for IWindowConfig Object

PropDefault ValueRequired/OptionalExplanation
urlundefinedOptionalURL of the window.
left0 or screen.widthOptionalThe distance from the left of the screen to the window. Defaults to the full screen width or 0 if popup is true.
top0OptionalThe distance from the top of the screen to the window. Defaults to 0.
heightscreen.heightOptionalThe height of the window. Defaults to the full screen height.
widthscreen.widthOptionalThe width of the window. Defaults to the full screen width.
menubar"no"OptionalEnables or disables the menubar in the window.
toolbar"no"OptionalEnables or disables the toolbar in the window.
location"no"OptionalEnables or disables the location bar in the window.
status"no"OptionalEnables or disables the status bar in the window.
resizable"yes"OptionalEnables or disables the window resizing feature.
scrollbars"no"OptionalEnables or disables scrollbars in the window.
popuptrueOptionalDetermines if the window should be rendered as a popup. If false, it will render in a new tab.

Props Table for IIconConfig Object

PropDefault ValueRequired/OptionalExplanation
width30OptionalThe width of the icon in pixels.
height30OptionalThe height of the icon in pixels.

License

MIT

Author

Mohammed Ridha. M. M.

1.2.5

10 months ago

1.2.4

10 months ago

1.2.3

10 months ago

1.2.2

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago