# react-full-screen

> Component and Hook for handling full screen components

Latest version **1.1.1** (published 2022-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-full-screen
pnpm add react-full-screen
yarn add react-full-screen
bun add react-full-screen
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-06-01 |
| First published | 2017-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 295 |
| Author | pomle |
| Maintainers | pomle |
| Keywords | react, fullscreen, full screen |

## Links

- npm: https://www.npmjs.com/package/react-full-screen
- Repository: https://github.com/snakesilk/react-fullscreen
- Homepage: https://github.com/snakesilk/react-fullscreen#readme
- Issues: https://github.com/snakesilk/react-fullscreen/issues
- npm.io page: https://npm.io/package/react-full-screen

## Dependencies (1)

- [fscreen](https://npm.io/package/fscreen.md) ^1.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2022-06-01
- 0.2.5 (beta) — 2020-06-03
- 1.1.0 — 2021-07-30
- 1.1.0-0 — 2021-07-30
- 1.0.2 — 2021-03-22
- 1.0.2-0 — 2021-03-22
- 1.0.1 — 2021-02-05
- 1.0.0 — 2021-02-04
- 0.3.2-0 — 2020-12-18
- 1.0.0-0 — 2020-12-18
- 0.3.1 — 2020-07-22
- 0.3.1-0 — 2020-07-17
- 0.2.4 — 2019-02-25
- 0.2.3 — 2018-08-22
- 0.2.3-0 — 2018-08-22
- … 12 more at https://npm.io/package/react-full-screen/versions

## README

# React Fullscreen

A React component that sets its children to fullscreen using the Fullscreen API, normalized using [fscreen](https://github.com/rafrex/fscreen).

## Usage

### * Install.
```bash
yarn add react-full-screen
```

### * Import component and hook
```js
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`.

```jsx
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.
```jsx
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

```ts
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
}
```

```ts
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.

```css
.my-component {
  background: #fff;
}

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

## In the wild

Used with [MegamanJS](http://megaman.pomle.com/)

---
_Source: https://npm.io/package/react-full-screen · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
