1.1.1 • Published 2 years ago

react-full-screen v1.1.1

Weekly downloads
57,003
License
MIT
Repository
github
Last release
2 years ago

React Fullscreen

A React component that sets its children to fullscreen using the Fullscreen API, normalized using fscreen.

Usage

* Install.

yarn add react-full-screen

* Import component and hook

import { FullScreen, useFullScreenHandle } from "react-full-screen";

* Setup and render.

You must use one handle per full screen element. It is not possible to start in Fullscreen. Fullscreen must be enabled from a user action such as onClick.

import React, {useCallback} from 'react';
import { FullScreen, useFullScreenHandle } from "react-full-screen";

function App() {
  const handle = useFullScreenHandle();

  return (
    <div>
      <button onClick={handle.enter}>
        Enter fullscreen
      </button>

      <FullScreen handle={handle}>
        Any fullscreen content here
      </FullScreen>
    </div>
  );
}

export default App;

When you have many elements you need one handle per element.

import React, {useCallback} from 'react';
import { FullScreen, useFullScreenHandle } from "react-full-screen";

function App() {
  const screen1 = useFullScreenHandle();
  const screen2 = useFullScreenHandle();

  const reportChange = useCallback((state, handle) => {
    if (handle === screen1) {
      console.log('Screen 1 went to', state, handle);
    }
    if (handle === screen2) {
      console.log('Screen 2 went to', state, handle);
    }
  }, [screen1, screen2]);

  return (
    <div>
      <button onClick={screen1.enter}>
        First
      </button>

      <button onClick={screen2.enter}>
        Second
      </button>

      <FullScreen handle={screen1} onChange={reportChange}>
        <div className="full-screenable-node" style={{background: "red"}}>
          First
          <button onClick={screen2.enter}>
            Switch
          </button>
          <button onClick={screen1.exit}>
            Exit
          </button>
        </div>
      </FullScreen>

      <FullScreen handle={screen2} onChange={reportChange}>
        <div className="full-screenable-node" style={{background: "green"}}>
          Second
          <button onClick={screen1.enter}>
            Switch
          </button>
          <button onClick={screen2.exit}>
            Exit
          </button>
        </div>
      </FullScreen>
    </div>
  );
}

export default App;

Types

interface FullScreenHandle {
  active: boolean;
  // Specifies if attached element is currently full screen.

  enter: () => Promise<void>;
  // Requests this element to go full screen.

  exit: () => Promise<void>;
  // Requests this element to exit full screen.

  node: React.MutableRefObject<HTMLDivElement | null>;
  // The attached DOM node
}
interface FullScreenProps {
  handle: FullScreenHandle;
  // Handle that helps operate the full screen state.

  onChange?: (state: boolean, handle: FullScreenHandle) => void;
  // Optional callback that gets called when this screen changes state.
  
  className?: string;
  // Optional prop allowing you to apply a custom class name to the FullScreen container
}

CSS

Class fullscreen-enabled will be added to component when it goes fullscreen. If you want to alter child elements when this happens you can use a typical CSS statement.

.my-component {
  background: #fff;
}

.fullscreen-enabled .my-component {
  background: #000;
}

In the wild

Used with MegamanJS

@borderfreefinancial/revo-consumer@borderfreefinancial/revo-core@borderfreefinancial/revo-core-api@borderfreefinancial/revo-web-video-testreact-mindeemindee-sdk-react@dovydasbu/react-snakezenstatereact-images-tmpgatsby-theme-evelangatsby-theme-sanity-evelan@mindee/react-web-essentialsmirador-biblissimareact-image-annotate-filterablereact-presentation-renderer-libraryviveljspe-layoutsarclight-reactchinese-mirador@infinitebrahmanuniverse/nolb-react-fu@everything-registry/sub-chunk-2556ra-miradorpylon-app@rediminds/image-video-annotator@sammarks/react-editor@sampoder/holocronremark-playgroundreplay-viewer@palustris/react-images@regang/mirador@rogeliolb/react-v-playerrehype-playgroundsaurabhorionlibsairamorionlib@snakesilk/react-presenter@silentnerd/react-image-annotate@skidding/react-imagesreact-python-editorreact-image-taggerreact-images2react-image-labelingreact-imannotatereact-images-v2react-images-z-index-fixreact-images-closereact-images-fixedreact-images-lazy-loadreact-images-maintainedreact-images-no-animationreact-imagesreact-images-backdrop-fixreact-images-tsreact-multiple-image-annotatepaz-check-web-appreact-comic-viewerreact-image-bound-boxreact-image-annotate-cnreact-image-annotate-coonereact-image-annotatereact-image-annotate-2react-image-annotate-adexereact-image-annotate-customreact-image-annotate-custom-region-edit-labelreact-image-annotate-forkreact-image-annotate-masterreact-image-annotate-master-customreact-image-annotate-prabathreact-image-annotate-prop-2react-image-annotate-switchonreact-image-annotate-switchon-ratanreact-image-annotate-switchon-ratan1react-image-annotate-switchon1react-image-annotate_ns_demoreact-image-annotate_ns_demo_brushreact-videotapereact-wound-image-annotatereact_image_annotate_ns_workflow_3react_image_annotate_ns_workflow_7react_image_annotate_ns_workflow_8react_image_annotate_ns_workflow_9react_image_annotate_nsworkflow_2024react_image_annotate_ns_workflowreact-covideo-embedreact-cp-youtubereact-textgame-engine@searpent/react-image-annotate@ylzcc/video-playerthe-fit-b2b@splunk/dashboard-core@xr3ngine/client-networkingtamu-miradorgac-paviflatpageflexbiz-coregitcourse-core@dts-stn/decd-design-system@dts-stn/service-canada-design-systemmtc-react-image-annotatemodule-the-fitly-cloud-bpm-ui
1.1.1

2 years ago

1.1.0

3 years ago

1.1.0-0

3 years ago

1.0.2

3 years ago

1.0.2-0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.3.2-0

3 years ago

1.0.0-0

3 years ago

0.3.1

4 years ago

0.3.1-0

4 years ago

0.2.5

4 years ago

0.2.4

5 years ago

0.2.3

6 years ago

0.2.3-0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.0

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago