npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nice-scrollbars

v1.2.0

Published

Material-UI wrapper for OverlayScrollbars plugin

Downloads

4

Readme

Material-UI Scrollbars

Tiny React wrapper around awesome OverlayScrollbars plugin for more convenient usage with Material-UI applications. OverlayScrollbars is a javascript scrollbar plugin that hides native scrollbars, provides custom styleable overlay scrollbars, and keeps the native functionality and feeling. It enables us to implement stylish scrollbars with consistent appearance across browsers and platforms, and make our UI/UX designers happy.

Scrollable component

The Scrollable component is just a normal div element wrapped with OverlayScrollbars plugin. It exposes all div props, OverlayScrollbars props, and has additional 'classes' prop for granular customization.

Basic usage

import React from 'react';

import { makeStyles, Theme } from '@material-ui/core/styles';
import { Scrollable, ScrollableClasses } from '@vdjurdjevic/material-scrollbars';

const useStyles = makeStyles<Theme, keyof ScrollableClasses>({
	root: {
		width: 100,
		height: 100,
		borderStyle: 'solid',
		borderWidth: '2px'
	},
	verticalScroll: {
		width: 12,
		padding: 2,
		borderRadius: 4
	},
	track: {
		background: 'green'
	},
	handle: {
		background: 'red'
	}
});

export const NiceScrollbars: React.FC = ({ children }) => {
	const classes = useStyles();
	return <Scrollable classes={classes}>{children}</Scrollable>;
};

Autocomplete integration

When using Scrollable as custom ListboxComponent of Autocomplete, make sure to assign forwarded ref to viewPort element and also to set role to listbox on view port element. For that scenario, Scrollable component exposes viewPortProps property

import React from 'react';
import { Scrollable } from '@vdjurdjevic/material-scrollbars';
import { Autocomplete } from '@material-ui/lab';

export const AutocompleteScroll = React.forwardRef(({ children, ...rest }, ref) => {
    return (
        <Scrollable {...rest} viewPortProps={{ ref, role: 'listbox' }}>
            {children}
        </Scrollable>
    );
});

export const ScrollableAutocomplete = props => {
    return (
        <Autocomplete
            {...props}
            ListboxComponent: AutocompleteScroll
        />
    );
};

ScrollableTextArea component

ScrollableTextArea shares same API with Scrollable component, but renders textarea element instead of div, and provides 'inputRef' prop that can be used to integrate with FormControl and form libraries like React Hook Form

Text field integration

import { useForm } from 'react-hook-form';
import { TextField } from '@material-ui/core';
import { ScrollableTextArea } from '@vdjurdjevic/material-scrollbars';

const { register } = useForm({
	defaultValues: {
		message: 'Text area with nice scrollbar'
	}
});

<TextField
	variant='outlined'
	label='Scrollable Text Area'
	name='message'
	inputRef={register}
	InputProps={{
		inputComponent: ScrollableTextArea
	}}
/>;

Hook

For accessing OverlayScrollbars instance and programmatic scrolling, there is useScrollable hook that returns ref that can be attached to the scrollable component and has methods for scroll manipulation.

Basic usage

import React from 'react';

import { Buttom } from '@material-ui/core';
import { Scrollable, useScrollable } from '@vdjurdjevic/material-scrollbars';

export const ScrollableHookExample: React.FC = () => {
	const scrollable = useScrollable();

	return (
		<div>
			<Scrollable ref={scrollable}>Some scrollable content</Scrollable>
			<Button
				variant='contained'
				onClick={() => scrollable.current.instance().scroll({ y: '+= 40px' })}>
				Scroll
			</Button>
		</div>
	);
};

Styling

This library has @material-ui/core as a peer dependency and uses it's styling solution based on JSS. Unlike with plain OverlayScrollbars, with this wrapper, it's not necessary to import global stylesheet. Global styles are implemented with JSS also, so that components work out of the box, without additional setup.

Docs and Examples

Docs will improve over time, for now please use official OverlayScrollbars and Material UI Docs. If you would like to experiment with it, you can clone the repo, run yarn install, and yarn run dev to start storybook and use it as a playground. There are some basic examples to start with, but feel free to add yours and submit a pull request if others can benefit from it.