@straw-hat/react-fullscreen
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

@straw-hat/react-fullscreen

A React hook for interacting with the Fullscreen API.

Usage

  • Reference guides Please use yarn docs:reference to generate the reference docs.

An example of a fullscreen button using https://material-ui.com/.

import IconButton from '@material-ui/core/IconButton';
import FullscreenIcon from '@material-ui/icons/Fullscreen';
import FullscreenExitIcon from '@material-ui/icons/FullscreenExit';
import * as React from 'react';

// 1. Import the dependency.
import { useFullscreen } from '@straw-hat/react-fullscreen';

export function FullscreenButton() {
  // 2. Create a `ref` that with the targeted element that will display in
  // fullscreen mode.
  const target = React.useRef(window.document.body);

  // 3. Pass the targeted element to the hook
  const { isFullscreen, toggleFullscreen } = useFullscreen(target);

  // 4. Use the exposed API in your component.
  return (
    <IconButton color="inherit" onClick={toggleFullscreen}>
      {isFullscreen ? <FullscreenExitIcon /> : <FullscreenIcon />}
    </IconButton>
  );
}

Package Sidebar

Install

npm i @straw-hat/react-fullscreen

Weekly Downloads

21

Version

4.0.0

License

MIT

Unpacked Size

7.29 kB

Total Files

5

Last publish

Collaborators

  • ubi