5.0.0 • Published 2 years ago

react-scrollbar-size v5.0.0

Weekly downloads
20,837
License
MIT
Repository
github
Last release
2 years ago

React-Scrollbar-Size

React-Scrollbar-Size is a React hook designed to calculate the size of the user agent's horizontal and vertical scrollbars. It will also detect when the size of the scrollbars change, such as when the user agent's zoom factor changes.

npm package npm downloads CircleCI Code Climate Code Style Code style Dependencies Percentage of issues still open License Contributor Covenant Star on Github

Installation

React-Scrollbar-Size is available as an npm package:

$ npm install react-scrollbar-size

Usage

The useScrollbarSize custom hook returns an object with two properties:

NameDescription
widthThe current width of the vertical scrollbar
heightThe current height of the horizontal scrollbar

Examples

To see a live example, follow these instructions.

TypeScript

import { CSSProperties, FunctionComponent } from 'react';
import useScrollbarSize from 'react-scrollbar-size';

const styles: CSSProperties = {
  margin: '1rem',
  textAlign: 'center',
};

const ScrollbarSizeDemo: FunctionComponent = () => {
  const { height, width } = useScrollbarSize();

  return (
    <div style={styles}>
      <h2>React Scrollbar Size Demo</h2>
      <h4>Tip: Change browser zoom level to see scrollbar sizes change.</h4>
      <p>
        The current height of the scrollbar is {height}px.
        <br />
        The current width of the scrollbar is {width}px.
      </p>
    </div>
  );
};

JavaScript

import useScrollbarSize from 'react-scrollbar-size';

const styles = {
  margin: '1rem',
  textAlign: 'center',
};

const ScrollbarSizeDemo = () => {
  const { height, width } = useScrollbarSize();

  return (
    <div style={styles}>
      <h2>React Scrollbar Size Demo</h2>
      <h4>Tip: Change browser zoom level to see scrollbar sizes change.</h4>
      <p>
        The current height of the scrollbar is {height}px.
        <br />
        The current width of the scrollbar is {width}px.
      </p>
    </div>
  );
};

License

This project is licensed under the terms of the MIT license.

5.0.0

2 years ago

4.0.0

3 years ago

4.0.0-rc.0

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.1

4 years ago

3.0.0-rc.0

4 years ago

3.0.0

4 years ago

2.1.0

6 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago