readprogress
Advanced tools
+67
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| ReadProgress: () => ReadProgress_default | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| // src/ReadProgress.tsx | ||
| var import_react = require("react"); | ||
| var ProgressBar = ({ color = "#FF0000", height = 4, scrollOffset = 0, zIndex = "999" }) => { | ||
| const [scrollProgress, setScrollProgress] = (0, import_react.useState)(scrollOffset); | ||
| (0, import_react.useEffect)(() => { | ||
| const handleScroll = () => { | ||
| const totalScrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight; | ||
| const windowScrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
| const progress = windowScrollTop / totalScrollHeight * 100; | ||
| setScrollProgress(progress); | ||
| }; | ||
| window.addEventListener("scroll", handleScroll); | ||
| return () => { | ||
| window.removeEventListener("scroll", handleScroll); | ||
| }; | ||
| }, []); | ||
| return /* @__PURE__ */ React.createElement( | ||
| "div", | ||
| { | ||
| style: { | ||
| height: `${height}px`, | ||
| left: 0, | ||
| position: "fixed", | ||
| top: 0, | ||
| width: "100%", | ||
| zIndex: `${zIndex}` | ||
| } | ||
| }, | ||
| /* @__PURE__ */ React.createElement( | ||
| "div", | ||
| { | ||
| style: { | ||
| backgroundColor: `${color}`, | ||
| height: "100%", | ||
| width: `${scrollProgress}%` | ||
| } | ||
| } | ||
| ) | ||
| ); | ||
| }; | ||
| var ReadProgress_default = ProgressBar; |
| // src/ReadProgress.tsx | ||
| import { useEffect, useState } from "react"; | ||
| var ProgressBar = ({ color = "#FF0000", height = 4, scrollOffset = 0, zIndex = "999" }) => { | ||
| const [scrollProgress, setScrollProgress] = useState(scrollOffset); | ||
| useEffect(() => { | ||
| const handleScroll = () => { | ||
| const totalScrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight; | ||
| const windowScrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
| const progress = windowScrollTop / totalScrollHeight * 100; | ||
| setScrollProgress(progress); | ||
| }; | ||
| window.addEventListener("scroll", handleScroll); | ||
| return () => { | ||
| window.removeEventListener("scroll", handleScroll); | ||
| }; | ||
| }, []); | ||
| return /* @__PURE__ */ React.createElement( | ||
| "div", | ||
| { | ||
| style: { | ||
| height: `${height}px`, | ||
| left: 0, | ||
| position: "fixed", | ||
| top: 0, | ||
| width: "100%", | ||
| zIndex: `${zIndex}` | ||
| } | ||
| }, | ||
| /* @__PURE__ */ React.createElement( | ||
| "div", | ||
| { | ||
| style: { | ||
| backgroundColor: `${color}`, | ||
| height: "100%", | ||
| width: `${scrollProgress}%` | ||
| } | ||
| } | ||
| ) | ||
| ); | ||
| }; | ||
| var ReadProgress_default = ProgressBar; | ||
| export { | ||
| ReadProgress_default as default | ||
| }; |
| /// <reference types="react" /> | ||
| type progressBarProps = { | ||
| color: string; | ||
| height: number; | ||
| scrollOffset: number; | ||
| zIndex: number; | ||
| }; | ||
| declare const ProgressBar: React.FC<progressBarProps>; | ||
| export default ProgressBar; |
| declare const _default: any; | ||
| export default _default; |
+3
-4
| { | ||
| "name": "readprogress", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "author": "Cobby <nkumsagoefredrick@gmail.com>", | ||
@@ -11,3 +11,3 @@ "description": ".A React component that shows the progress of reading a page", | ||
| "license": "MIT", | ||
| "main": "lib/ReadProgress.js", | ||
| "main": "lib/src/index.js", | ||
| "type": "module", | ||
@@ -36,5 +36,4 @@ "keywords": [ | ||
| "scripts": { | ||
| "build": "mkdir -p lib && rm -rf lib/*; tsc --declaration --emitDeclarationOnly --noEmit false && mv lib/src/*.d.ts lib/ && rmdir lib/src && rm -rf lib/test && prettier --ignore-path '' --write lib/ReadProgress.d.ts && esbuild --target=es2017 --format=esm --outfile=lib/ReadProgress.js --external:react --bundle ./src/ReadProgress.tsx", | ||
| "test": "tsc && eslint . && prettier --check " | ||
| "build": "esbuild --bundle src/index.ts --outfile=lib/index.js --target=es2017 --format=cjs --external:react" | ||
| } | ||
| } |
8840
67.11%12
50%133
923.08%