generated fromuiwjs/react-monorepo-template
- Notifications
You must be signed in to change notification settings - Fork3
A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.
License
NotificationsYou must be signed in to change notification settings
uiwjs/react-back-to-top
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.
Not dependent on uiw.
npm install @uiw/react-back-to-top --save
importReactfrom"react";importBackToUpfrom'@uiw/react-back-to-top';exportdefaultfunctionApp(){return(<divclassName="container"><spanstyle={{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.
importReact,{useRef,useEffect,useState}from"react";importBackToUpfrom'@uiw/react-back-to-top';importstyledfrom'styled-components';constWarpper=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; }`;exportdefaultfunctionApp(){const$dom=useRef(null);const[element,setElement]=useState();useEffect(()=>setElement($dom.current),[])return(<Warpperref={$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><h2style={{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><BackToUptop={0}element={$dom.current}style={{float:'right'}}>Top</BackToUp></Warpper>);}
Custom button style.
importReact,{useRef,useEffect,useState}from"react";importBackToUpfrom'@uiw/react-back-to-top';importstyledfrom'styled-components';constWarpper=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; }`;exportdefaultfunctionApp(){const$dom=useRef(null);const[element,setElement]=useState();useEffect(()=>setElement($dom.current),[])return(<Warpperref={$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><BackToUptop={0}hideProgresselement={$dom.current}style={{float:'right'}}><divstyle={{border:'1px solid red',color:'red',background:'#ffeb3b'}}> Top</div></BackToUp></Warpper>);}
importReactfrom'react';exportinterfaceBackToUpPropsextendsReact.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;}exportdefaultfunctionBackToUp(props?:BackToUpProps):JSX.Element;
- Install
npm install
- To develop, run the self-reloading build:
npm run build# Compile packages 📦 @uiw/react-back-to-topnpm run watch# Real-time compilation 📦 @uiw/react-back-to-top
- Run Document Website Environment:
npm run start
- To contribute, please fork repos, add your patch and tests for it (in the
test/folder) and submit a pull request.
npm run testAs always, thanks to our amazing contributors!
Made withgithub-action.
Licensed under the MIT License.
About
A minimal lightweight react component for adding a nice scroll up (back to top) button with onScroll progress.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
