Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-scrollbar-size

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-scrollbar-size

React component to calculate the size of browser scrollbars

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-6.9%
Maintainers
3
Weekly downloads
 
Created
Source

React-Scrollbar-Size

React-Scrollbar-Size is a React component 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 Dependabot Status Dependencies PeerDependencies DevDependencies 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

Props

NameDescription
onChangeCallback which will fire when the scrollbar sizes change.

The callback accepts an object which will be updated with the following 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 React, { CSSProperties, FunctionComponent, useState } from 'react';
import ScrollbarSize from 'react-scrollbar-size';

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

const ScrollbarSizeDemo: FunctionComponent = () => {
  const [currentHeight, setHeight] = useState(0);
  const [currentWidth, setWidth] = useState(0);

  const scrollbarSizeChange = ({ height, width }: ScrollbarSizeChangeHandlerParams) => {
    if (height !== currentHeight) {
      setHeight(height);
    }

    if (width !== currentWidth) {
      setWidth(width);
    }
  };

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

JavaScript

import React, { useState } from 'react';
import ScrollbarSize from 'react-scrollbar-size';

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

const ScrollbarSizeDemo = () => {
  const [currentHeight, setHeight] = useState(0);
  const [currentWidth, setWidth] = useState(0);

  const scrollbarSizeChange = ({ height, width }) => {
    if (height !== currentHeight) {
      setHeight(height);
    }

    if (width !== currentWidth) {
      setWidth(width);
    }
  };

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

License

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

Keywords

FAQs

Package last updated on 07 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc