Socket
Book a DemoInstallSign in
Socket

@scrollmeter/react

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scrollmeter/react

React hooks and components for Scrollmeter - A lightweight JavaScript library that visually displays scroll progress on web pages

latest
Source
npmnpm
Version
1.3.1
Version published
Maintainers
0
Created
Source

Scrollmeter React

npm version downloads license

React hook for Scrollmeter, a lightweight library that visually displays the scroll progress of web pages.

✨ Key Features

  • 🎯 Display scroll progress with an intuitive progress bar
  • 📊 Timeline feature for quick document structure overview (h1 tags only)
  • 🔍 Quick content preview functionality
  • 💡 Tooltip providing current position information
  • 🎨 Various customization options
  • 📱 Responsive design support

🚀 Installation

npm install @scrollmeter/react

or

yarn add @scrollmeter/react

🔧 Usage

In a React environment, use the useScrollmeter hook which provides a targetRef.

import { useScrollmeter } from '@scrollmeter/react'
import '@scrollmeter/core/dist/index.css'

function App() {
    const { targetRef } = useScrollmeter<HTMLDivElement>({
        useTimeline: true,
        useTooltip: true,
        usePreview: true,
        barOptions: {
            color: 'rgba(74, 144, 226, 0.9)',
            height: 10,
            background: 'rgba(0, 0, 0, 0)',
        },
        // ... rest of the options ...
    })

    return <div ref={targetRef}>{/* Your content here */}</div>
}

💡 For Vanilla JavaScript users, please check out @scrollmeter/core package.

⚙️ Configuration Options

  • useTimeline: Enable/disable timeline feature showing document structure
  • useTooltip: Show/hide tooltip displaying current scroll position
  • usePreview: Enable/disable content preview feature
    • ⚠️ Preview feature requires useTooltip to be set to true
    • ⚠️ External images are not included in previews due to CORS restrictions

🎨 Style Customization

import { useScrollmeter, UseScrollmeterOptions } from '@scrollmeter/react'
import '@scrollmeter/core/dist/index.css'

function App() {
    const [scrollOptions, setScrollOptions] = useState<UseScrollmeterOptions>({
        useTimeline: true,
        useTooltip: true,
        usePreview: true,
        barOptions: {
                color: 'rgba(74, 144, 226, 0.9)',
                height: 10,
                background: 'rgba(0, 0, 0, 0)',
            },
            timelineOptions: {
                color: '#838383',
                width: 4,
            },
            tooltipOptions: {
                background: '#333',
                fontColor: 'white',
                fontSize: 12,
                paddingInline: 8,
                paddingBlock: 6,
                width: 150,
        },
    })

    const { targetRef } = useScrollmeter<HTMLDivElement>(scrollOptions)

    return <div ref={targetRef}>{/* Your content here */}</div>
}

barOptions

PropertyTypeDescriptionDefault
colorstringProgress bar colorrgba(74, 144, 226, 0.9)
heightnumberProgress bar height10
backgroundstringProgress bar backgroundrgba(0, 0, 0, 0)

timelineOptions

PropertyTypeDescriptionDefault
colorstringTimeline color#838383
widthnumberTimeline width4

tooltipOptions

PropertyTypeDescriptionDefault
backgroundstringTooltip background#333
fontColorstringTooltip text colorwhite
fontSizenumberTooltip font size12
paddingInlinenumberTooltip inline padding8
paddingBlocknumberTooltip block padding6
widthnumberTooltip width150

🌟 Demo

Demo

📝 License

MIT License

Copyright (c) 2024 suhyeon-jeon

FAQs

Package last updated on 21 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts