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

@uiw/react-back-to-top

v1.2.3

Published

A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.

Downloads

572

Readme

React Back To Top

Build & Deploy Coverage Status NPM Downloads NPM Version

A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.

React Back To Top

Install

Not dependent on uiw.

npm install @uiw/react-back-to-top --save

Usage

import React from "react";
import BackToUp from '@uiw/react-back-to-top';

export default function App() {
  return (
    <div className="container">
      <span style={{ color: 'red' }}>
        Please check the button in the lower right corner of your web page.
      </span>
      <BackToUp>Top</BackToUp>
    </div>
  );
}

Support adding <BackToUp /> buttons to the partial scrollable area.

import React, { useRef, useEffect, useState } from "react";
import BackToUp from '@uiw/react-back-to-top';
import styled from 'styled-components';

const Warpper = styled.div`
  overflow: auto;
  white-space: normal;
  width: 300px;
  height: 300px;
  &::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 7px;
    background: #00000038;
  }
  &::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background-color: #595959;
  }
  p {
    display: inline;
    background: rgba(0, 0, 0, 0.12);
    color: transparent;
  }
`;

export default function App() {
  const $dom = useRef(null);
  const [element, setElement]= useState();
  useEffect(() => setElement($dom.current), [])
  return (
    <Warpper ref={$dom}>
      <h1>React simple scroll up with onScroll progress</h1>
      <p>React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.</p>
      <h2>Scroll down ↓</h2>
      <p>Declarative views make your code more predictable and easier to debug.</p>
      <h2 style={{ height: 1200 }}>Scroll down ↓</h2>
      <p>Build encapsulated components that manage their own state, then compose them to make complex UIs. </p>
      <p>Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.</p>
      <BackToUp top={0} element={$dom.current} style={{ float: 'right' }}>Top</BackToUp>
    </Warpper>
  );
}

Custom button style.

import React, { useRef, useEffect, useState } from "react";
import BackToUp from '@uiw/react-back-to-top';
import styled from 'styled-components';

const Warpper = styled.div`
  overflow: auto;
  white-space: normal;
  width: 300px;
  height: 300px;
  &::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 7px;
    background: #00000038;
  }
  &::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background-color: #595959;
  }
  p {
    display: inline;
    background: rgba(0, 0, 0, 0.12);
    color: transparent;
  }
`;

export default function App() {
  const $dom = useRef(null);
  const [element, setElement]= useState();
  useEffect(() => setElement($dom.current), [])
  return (
    <Warpper ref={$dom}>
      <h1>React simple scroll up with onScroll progress</h1>
      <p>React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.</p>
      <h2>Scroll down ↓</h2>
      <p>Declarative views make your code more predictable and easier to debug.</p>
      <h2>Scroll down ↓</h2>
      <p>Build encapsulated components that manage their own state, then compose them to make complex UIs. </p>
      <p>Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.</p>
      <BackToUp top={0} hideProgress element={$dom.current} style={{ float: 'right' }}>
        <div style={{ border: '1px solid red', color: 'red', background: '#ffeb3b' }}>
          Top
        </div>
      </BackToUp>
    </Warpper>
  );
}

Props

import React from 'react';
export interface BackToUpProps extends React.AllHTMLAttributes<HTMLDivElement> {
  prefixCls?: string;
  /** Scroll bar area @default document.documentElement **/
  element?: HTMLElement;
  /** Whether to use smooth scrolling* @default true */
  smooth?: boolean;
  /** Classname to add/override styling (note, !important for overrides might be needed) */
  className?: string;
  /** Object to add/override styling */
  style?: React.CSSProperties;
  /** Height after page scroll to be visible @default 120 **/
  top?: number;
  /** The Button width & height @default 35 */
  size?: number;
  /** the width of the progress bar */
  strokeWidth?: number;
  /** hide progress icon */
  hideProgress?: boolean;
}
export default function BackToUp(props?: BackToUpProps): JSX.Element;

Development

  1. Install
npm install
  1. To develop, run the self-reloading build:
npm run build  # Compile packages      📦 @uiw/react-back-to-top
npm run watch  # Real-time compilation 📦 @uiw/react-back-to-top
  1. Run Document Website Environment:
npm run start
  1. To contribute, please fork repos, add your patch and tests for it (in the test/ folder) and submit a pull request.
npm run test

Contributors

As always, thanks to our amazing contributors!

Made with github-action.

License

Licensed under the MIT License.