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

mui-scroll-trigger

v0.1.1

Published

Simple and convenient scroll-based transitions for React apps using MUI v5.

Downloads

8

Readme

Basically, this component turns this...

import useScrollTrigger from '@mui/material/useScrollTrigger';
import Grow from '@mui/material/Grow

function HideOnScroll(props) {
  const { children } = props;

  const trigger = useScrollTrigger({ threshold: 400 });

  return (
    <Grow in={!trigger}>
      {children}
    </Grow>
  );
}

export default function App() {
  return (
    <HideOnScroll>
      <div>Hello</div>
    </HideOnScroll>
  )
}

...into this...

import ScrollTrigger from 'mui-scroll-trigger'

export default function App() {
  return (
    <ScrollTrigger threshold={400}>
      <div>Hello</div>
    </ScrollTrigger>
  )
}

🎉 🥳 👯‍♀️

...but with more options.

Want to use a different transition? The transition prop accepts any of the MUI v5 transitions as lowercase strings.

<ScrollTrigger transition="zoom">
  <div>Zoomed Hello</div>
</ScrollTrigger>

You can control whether the child element will transition in or out once the threshold is met with the onScroll prop. It accepts either "hide" or "show" and defaults to "hide".

<ScrollTrigger onScroll="show">
  <div>I will appear once the scroll threshold is met</div>
</ScrollTrigger>

You can conditionally disable the transition (ie. when a modal is open) and preserve it's current state with the disabled prop.

<ScrollTrigger disabled={someCondition}>
  <div>I will not transition while `someCondition` is true</div>
</ScrollTrigger>

Props

| Name | Type | Default | Description | | --------------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | children* | element | | Element that shall be transitioned... required | | disabled | bool | false | Whether or not to disable the transition. | | ignoreDirection | bool | false | Ignore the scroll direction when determining whether to apply the transition. Maps to MUI useScrollTrigger disableHysteresis option. | | onScroll | string | 'hide' | Whether to 'show' or 'hide' (transition in or out) at the scroll threshold. | | target | node | window | Target to base scroll distance on. You normally won't need to use this, unless in iframes or similar. | | threshold | number | 100 | Apply the chosen transition when the vertical scroll strictly crosses this threshold (exclusive). | | transition | string | 'grow' | MUI transition to apply at the threshold. Accepts one of 'slide', 'grow', 'zoom', 'collapse' or 'fade'. |

* required prop

Any other props (eg. easing, timeout) will be passed directly to the chosen MUI transition component. This means you can also use any of the props of the Transition component from react-transition-group.

The ignoreDirection (disableHysteresis), target and threshold props work just like in the MUI useScrollTrigger hook.

License

© benmneb

ISC License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.