All Projects → Ariel-Rodriguez → react-hook-sticky

Ariel-Rodriguez / react-hook-sticky

Licence: MIT license
react hook sticky

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-hook-sticky

jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-31.58%)
Mutual labels:  hooks
statery
Surprise-Free State Management! Designed for React with functional components, but can also be used with other frameworks (or no framework at all.)
Stars: ✭ 28 (+47.37%)
Mutual labels:  hooks
react-supabase
React Hooks library for Supabase
Stars: ✭ 168 (+784.21%)
Mutual labels:  hooks
admin-sticky-widget-areas
A simple WordPress plugin to make the widget areas on the right side at /wp-admin/widgets.php sticky.
Stars: ✭ 22 (+15.79%)
Mutual labels:  sticky
no-redux
⚛️ 🎣 Experimenting with using hooks and context instead of Redux
Stars: ✭ 79 (+315.79%)
Mutual labels:  hooks
react-use-redux
Alternative Redux bindings with upcoming React hooks
Stars: ✭ 31 (+63.16%)
Mutual labels:  hooks
stook
A minimalist design state management library for React.
Stars: ✭ 86 (+352.63%)
Mutual labels:  hooks
transition-hook
☄️ An extremely light-weight react transition animation hook which is simpler and easier to use than react-transition-group
Stars: ✭ 250 (+1215.79%)
Mutual labels:  hooks
roover
🐱 A lightweight audio library for React apps.
Stars: ✭ 70 (+268.42%)
Mutual labels:  hooks
use-detect-print
A react hook to detect when a page is being printed
Stars: ✭ 55 (+189.47%)
Mutual labels:  hooks
vue-sticky
模拟 position: sticky; 的 vue 组件
Stars: ✭ 30 (+57.89%)
Mutual labels:  sticky
angulareact
A way to seamlessly integrate React and AngularJS
Stars: ✭ 17 (-10.53%)
Mutual labels:  hooks
scala-basic-skeleton
Starting point if you want to bootstrap a project in Scala
Stars: ✭ 16 (-15.79%)
Mutual labels:  hooks
react-sticky-headroom
A React Component to hide a Header using CSS sticky position
Stars: ✭ 22 (+15.79%)
Mutual labels:  sticky
sticky-observer
A simple and basic sticky observer (or watcher) on HTMLElement's in a given container
Stars: ✭ 33 (+73.68%)
Mutual labels:  sticky
use-redux-hook
A simple react hook to get access to redux store
Stars: ✭ 13 (-31.58%)
Mutual labels:  hooks
snake-design
🐍 a react component library based React hooks
Stars: ✭ 33 (+73.68%)
Mutual labels:  hooks
use-elapsed-time
React hook to measure elapsed time using requestAnimationFrame
Stars: ✭ 42 (+121.05%)
Mutual labels:  hooks
husky-elixir
🐶 Git hooks made easy
Stars: ✭ 47 (+147.37%)
Mutual labels:  hooks
react-use-observer
Performant react hooks for WebApi Observers, useResizeObserver, useInteractionObserver, useMutationObserver
Stars: ✭ 19 (+0%)
Mutual labels:  hooks

chrome ie 10 edge firefox safari

React hook sticky

Top performant lightweight solution for sticky components. Start to collaborate and share your sticky plugin.

Provide your ideas, feel free to contribute.

Demo

sticky

react-hook-sticky-playground

Roadmap

Would you like to contribute? Here are some nice to have ideas:

  • Add plugins.
  • Storybook and examples.
  • Add development runtime invalidations for warning and error check.
  • Create Wiki Page.
  • Add unit test.
  • Add E2E tests for IE and Chrome. (Probably Puppeter)
  • Add E2E perfomance painting tests
  • Configure CI (Probably Travis)
  • Add code coverage and bundle size check.
  • Add support for Horizontal scrolling / resizing

Install

yarn add react-hook-sticky --exact

Quickstart

Basic

// sticky-component.js
import React from 'react';
// 1 - Import
import { useSticky, plugins } from 'react-hook-sticky';

const stickyConfig = {
  // Define the context for this sticky, you may have many sticky elements.
  context: 'my-sticky-1',
  // 2 - Make use of builtin plugins
  plugin: plugins.fillBetween, // you may combine with throttling or wrap as your needs throttle(plugins.fillBetween, 10),

  // Optional - Specify the proper event listener strategy for better performance over any browser.
  // default { passive: true } https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  eventListenerOptions: Modernizr.passiveeventlisteners
    ? { passive: true }
    : false,
};

export const StickyComponent = props => {
  const { createBoundary } = useSticky(stickyConfig);

  return (
    <div className="sticky-outer" ref={createBoundary('outer')}>
      {/* 3 - Register the target to become sticky */}
      <div className="sticky" ref={createBoundary('sticky')}>
        I am sticky between outer height or screen height
      </div>
    </div>
  );
};

Optional define specific boundaries

export const StickyComponent = props => {
  const { createBoundary } = useSticky(stickyConfig);

  return (
    <div className="sticky-outer">
      <h1 ref={createBoundary('top')}>Top boundary</h1>
      {/* 3 - Register the target to become sticky */}
      <div className="sticky" ref={createBoundary('sticky')}>
        I am sticky between top and bottom boundaries or screen height
      </div>
      <div ref={createBoundary('bottom')}>Bottom boundary</div>
    </div>
  );
};

Development

Contribute and create your own plug-in right away.

Quick

// You may reuse common code and tools
import {
  useMomentum,
  getClampArea,
  createStyle,
  setInlineStyle,
} from '../commons';

// Explode your creativity, create your new module sticky to later being integrated
export const bunnyJump = (context, event) => {
  const { cacheStyles, boundaries } = context;
  const stickyBoundary = boundaries.sticky;
  const clampArea = getClampArea(boundaries);

  if (!stickyBoundary || !clampArea.height) {
    return;
  }

  const nextPosition = {
    position: 'absolute',
    maxHeight: clampArea.height,
  };
  const { isGoingDown } = useMomentum(event);

  if (isGoingDown) {
    nextPosition.top = clampArea.top;
  } else {
    nextPosition.bottom = clampArea.bottom;
  }

  setInlineStyle(stickyBoundary, createStyle(nextPosition), cacheStyles);
};
  • Implement in real time in your sandbox
// 1 - Import your snippet
import { bunnyJump } from './sticky-jump-draft';

import { useSticky } from 'react-hook-sticky';

const stickyConfig = {
  context: 'stickyJump',

  // 2 - Register it!
  plugin: bunnyJump,
};

export const StickyComponent = props => {
  const { createBoundary } = useSticky(stickyConfig);

  return (
    <section ref={createBoundary('top')}>
      <div className="ad" ref={createBoundary('sticky')} />
      {/* Registering boundaries all in one collection under stickyJump context */}
      <div className="block" ref={createBoundary(['jumpMe'])} />
      <div className="block" ref={createBoundary(['jumpMe'])} />
      <div className="block" ref={createBoundary('bottom')} />
    </section>
  );
};

How to develop local

Setup

  git clone [email protected]:Ariel-Rodriguez/react-hook-sticky.git
  yarn
  # Link library
  yarn link
  # install and link library into example
  # any change done in library will be hor reloaded in example page.
  cd example && yarn && yarn link react-hook-sticky

Run examples

  yarn start

Share or contribute!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].