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

react-viewer-soda

v1.0.6

Published

🥤 viewerjs component for react. Automatically detect changes in internal images.

Downloads

22

Readme

react-viewer-soda

NPM version NPM downloads

🥤 viewerjs component for react. Automatically detect changes in internal images.

Usage

Image

type:

export interface ImageProps extends ImgHTMLAttributes<HTMLImageElement> {
    /** You can get the instance of the viewer by passing a ref to the viewer property in props. */
    viewer?: ForwardedRef<Viewer>
    /** options for viewer */
    options?: ViewerOptions
}

Using it is just like a normal img element:

import { FC } from "react"
import { Image } from "react-viewer-soda"
import Viewer from "viewerjs" 

const App: FC = () => {
    const viewer = useRef<Viewer>(null)

    return (
        <div>
            <Image viewer={viewer} src="https://images.unsplash.com/photo-1608037521244-f1c6c7635194" width={640} />
        </div>
    )
}

export default App

ImageGroup

type:

export interface ImageGroupProps extends HTMLAttributes<HTMLDivElement> {
    /** You can get the instance of the viewer by passing a ref to the viewer property in props. */
    viewer?: ForwardedRef<Viewer>
    /** You can specify the mode for filtering images.
     * When the mode is 'exclude', img elements with 'data-no-rvs' will not be previewed.
     * When the mode is 'include', only img elements with 'data-rvs' will be previewed.
     * The default value is 'exclude'. */
    filterMode?: "exclude" | "include"
    /** options for viewer */
    options?: ViewerOptions
    /** Whether to automatically detect changes in the internal images.
     * The default value is true. */
    autoUpdate?: boolean
}

Using it is just like a normal div element:

import { FC, useRef } from "react"
import { ImageGroup } from "react-viewer-soda"
import Viewer from "viewerjs" 

const App: FC = () => {
    const viewer = useRef<Viewer>(null)

    return (
        <ImageGroup viewer={viewer}>
            <img src="https://w.wallhaven.cc/full/4o/wallhaven-4oggo9.jpg" width={640} />
            <img src="https://w.wallhaven.cc/full/nr/wallhaven-nrz77q.jpg" width={640} />
            {/* The image below will not be previewed */}
            <img data-no-rvs src="https://w.wallhaven.cc/full/4d/wallhaven-4d666l.jpg" width={640} />
        </ImageGroup>
    )
}

export default App

Tips

  1. You can provide the data-rvs-url on the img element to change the image for the preview:

    <img src="small.jpg" data-rvs-url="large.jpg" />    
  2. ImageGroup has an autoUpdate property with a default value of true. When enabled, it detects changes in the internal images and automatically calls viewer.update. If your img elements are not going to change, you can set it to false. Only these changes will be detected:

    1. The addition or deletion of img elements.
    2. The data-rvs and data-no-rvs attributes of img elements.

    If your img elements will only change attributes other than data-rvs and data-no-rvs, such as src or data-rvs-url, there is no need to enable autoUpdate.