All Projects → gm0t → React Sticky El

gm0t / React Sticky El

Licence: mit

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Sticky El

react-native-value-picker
Cross-Platform iOS(ish) style picker for react native.
Stars: ✭ 18 (-89.94%)
Mutual labels:  react-component, npm-package
react-daterange-picker
A react date range picker to using @material-ui. Live Demo: https://flippingbitss.github.io/react-daterange-picker/
Stars: ✭ 85 (-52.51%)
Mutual labels:  react-component, npm-package
react-circle-flags
🚀 A React component with a collection of 300+ minimal circular SVG country flags. Wrapper of HatScripts/circle-flags
Stars: ✭ 29 (-83.8%)
Mutual labels:  react-component, npm-package
Create React Component Folder
Creates react component folder structure
Stars: ✭ 139 (-22.35%)
Mutual labels:  npm-package, react-component
React Extras
Useful components and utilities for working with React
Stars: ✭ 651 (+263.69%)
Mutual labels:  npm-package, react-component
React Router Util
Useful components and utilities for working with React Router
Stars: ✭ 320 (+78.77%)
Mutual labels:  npm-package, react-component
react-windows-ui
Build Windows fluent UI apps using ReactJS. Provides a set of accessible, reusable, and composable React components that make it super easy to create websites and apps.
Stars: ✭ 383 (+113.97%)
Mutual labels:  react-component, npm-package
React Pro Sidebar
Customizable and responsive react sidebar library with dropdown menus and unlimited number of nested submenus
Stars: ✭ 359 (+100.56%)
Mutual labels:  npm-package, react-component
React Ckeditor
CKEditor component for React with plugin and custom event listeners support
Stars: ✭ 124 (-30.73%)
Mutual labels:  npm-package, react-component
Reactopt
A CLI React performance optimization tool that identifies potential unnecessary re-rendering
Stars: ✭ 1,975 (+1003.35%)
Mutual labels:  npm-package, react-component
New Github Issue Url
Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields
Stars: ✭ 170 (-5.03%)
Mutual labels:  npm-package
Http Loader
A loader for ngx-translate that loads translations with http calls
Stars: ✭ 170 (-5.03%)
Mutual labels:  npm-package
Express Prom Bundle
express middleware with standard prometheus metrics in one bundle
Stars: ✭ 172 (-3.91%)
Mutual labels:  npm-package
React Awesome Slider
React content transition slider. Awesome Slider is a 60fps, light weight, performant component that renders an animated set of production ready UI general purpose sliders with fullpage transition support for NextJS and GatsbyJS. 🖥️ 📱
Stars: ✭ 2,343 (+1208.94%)
Mutual labels:  react-component
Fast Cli
Test your download and upload speed using fast.com
Stars: ✭ 2,178 (+1116.76%)
Mutual labels:  npm-package
Animate Css Styled Components
simple port of animate css for styled-components
Stars: ✭ 173 (-3.35%)
Mutual labels:  react-component
React Terminal Component
Terminal emulator component for React. Emulate a terminal/console with autocomplete, commands, a file-system and themes.
Stars: ✭ 169 (-5.59%)
Mutual labels:  react-component
Gulp Traceur
Traceur is a JavaScript.next to JavaScript-of-today compiler
Stars: ✭ 172 (-3.91%)
Mutual labels:  npm-package
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (-6.15%)
Mutual labels:  npm-package
React Credit Cards
Beautiful credit cards for your payment forms
Stars: ✭ 2,239 (+1150.84%)
Mutual labels:  react-component

react-sticky-el

Sticky library for React.

Demos

Installation

npm install react-sticky-el

Overview & Basic Example

The elements you actually want to "stick" should be wrapped in the <Sticky /> tag. The full list of props are available below, but typical usage will look something like so:

app.jsx

import React, {Component} from 'react';
import Sticky from 'react-sticky-el';
...

class App extends Component ({
  render() {
    return (
      ...
        <Sticky>
          <header>
            ...
          </header>
        </Sticky>
      ...
    );
  },
});

This will be rendered as:

    <div> <!-- holder element -->
        <div> <!-- wrapper element -->
            <header>
                ...
            </header>
        </div>
    </div>

'Sticky' will be - wrapper element, holder element is used to reserve space in DOM when holder element has 'fixed' position.

When the "stickiness" becomes activated, the following inline style rules are applied to the Sticky element:

  position: fixed;
  top: 0;
  left: 0;
  width: <width that was before 'stickiness'>

Note that the calculation of the Sticky element's height does not currently take margins into account. If you have margins on this element it may result in unexpected behavior.

<Sticky /> Props

mode (default: 'top')

'top' or 'bottom' - to which side element should stick

disabled (default: false)

Allows you to disable sticking by setting this prop to true

onFixedToggle (default: null)

This handler will be called right before changing fixed state.

boundaryElement (default: null)

Selector to define a boundaryElement.
It should be one of the parents of the current element.

Look at these examples

scrollElement (default: window)

Selector to define a scrollElement. All position checks will be performed according to this element, also it will be listened for 'scroll' event.

It should be one of the parents of the current element. Possible selectors: 'body', 'window', '#{id}', anything suitable for Element.matches.

Look at the Demos for an example

app.jsx

import React, {Component} from 'react';
import Sticky from 'react-sticky-el';

class App extends Component {
  render() {
    return (
      <div>
        <p>....</p>  
        <div className="scrollarea" style={{height: '200px', overflow: 'scroll'}}>
          <Sticky scrollElement=".scrollarea">
            <h1>Scroll pane</h1>
          </Sticky>
        </div>
        <p>....</p>
      </div>
    );
  }
}

positionRecheckInterval (default: 0)

If your DOM structure is mutating (you are adding/removing elements), it will be usefull to provide positionRecheckInterval greater than zero, in this case position check will be also performed using setInterval in addition to scroll events.

stickyStyle (default: {})

In the event that you wish to override the style rules applied, simply pass in the style object as a prop:

app.jsx

  <Sticky stickyStyle={customStyleObject}>
    <header />
  </Sticky>

Note: You likely want to avoid messing with the following attributes in your stickyStyle: left, top, and width.

stickyClassName (default: 'sticky')

You can also specify a class name to be applied when the element becomes sticky:

app.jsx

  <Sticky stickyClassName={customClassName}>
    <header />
  </Sticky>

topOffset (default: 0)

Sticky state will be triggered when the top of the element is topOffset pixels from the top of the scrollElement. Positive numbers give the impression of a lazy sticky state, whereas negative numbers are more eager in their attachment

app.jsx

  <Sticky topOffset={80}>
    <SomeChild />
  </Sticky>

Look at the Basic Demo for an example

bottomOffset (default: 0)

Sticky state will be triggered when the bottom of the element is bottomOffset pixels from the bottom of the scrollElement.

app.jsx

  <Sticky bottomOffset={80}>
    <SomeChild />
  </Sticky>

Look at the Basic Demo for an example

hideOnBoundaryHit (default: true)

If false then boundaryEl should have position: relative. In this case sticky element won't disappear on reaching it's boundaries. A configuration like this is implemented below.

  import Sticky from 'react-sticky-el';
  
  <div className = "block"  >

    <Sticky boundaryElement=".block" style = {{position: 'relative'}} hideOnBoundaryHit={false}>
    <SomeChild />

    </Sticky>
  </div>

Look at the Basic Demo for an example.

dontUpdateHolderHeightWhenSticky (default: false)

Controls whenever the min-height for holder element should be updated when element becomes sticky or not. You can set it to true if the height of your sticky element changes when it becomes sticky (e.g. only some part of the header is visible when it's sticky) and you want to avoid your content jumping up.

Look at the Demo for an example.

Other props

All other props (such as className, style, etc..) will be applyed to the holder element.

Advanced usage

If you want to use some custom components and have more control, then you can use RenderPropSticky:

import { RenderPropSticky } from 'react-sticky-el';

function StickyHeader() {
  return (
    <RenderPropSticky
        mode={mode}
        onFixedToggle={onFixedToggle}
        hideOnBoundaryHit={hideOnBoundaryHit}
        offsetTransforms={offsetTransforms}
        disabled={disabled}
        boundaryElement={boundaryElement}
        scrollElement={scrollElement}
        bottomOffset={bottomOffset}
        topOffset={topOffset}
        positionRecheckInterval={positionRecheckInterval}
      >
        {({ isFixed, wrapperStyles, wrapperRef, holderStyles, holderRef }) => (
          <div {...rest} ref={holderRef} style={holderStyles}>
            <div
              {...rest}
              className={`${wrapperClassName} ${isFixed ? stickyClassName : ''}`}
              style={
                isFixed ? { ...wrapperStyles, ...stickyStyles } : wrapperStyles
              }
              ref={wrapperRef}
            >
              <h1>I'm sticky!</h1>
            </div>
          </div>
        )}
      </RenderPropSticky>  
  )
}

License

MIT

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].