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-imgbox

v1.0.2

Published

A ReactJs plugin that draws a box over an image (from the makers of jquery-imgbox).

Downloads

9

Readme

react-imgbox

React component that draws a styled box over an image; react version of jquery-imgbox.

Project parts

This repo contains 2 projects:

  1. imgbox - NPM module
  2. NextJs - Demo application

Build and run locally

cd imgbox
yarn install
yarn run build
yarn link
cd ../next-app
yarn install
yarn link react-imgbox
yarn run dev

Then goto [http://localhost:3000/]

Overview

ImgBox uses coordinates bases on the real size of the src image to draw a box over the same area no matter the size of the picture. There is an edit option for you to draw the box yourself and save the coordinates for latter.

See the demo page for examples.

This plugin can be used as a drop in replacement for <img> tag and will behave similarly.

Dependencies

  1. ReactJs 18

Size

After gzip compression react-imgbox.babel.min.js is 3.2K.

Usage

Passing props

What I think is a default may not be a default for others so props may be passed as props or as part of a props.defaultSettings.

<ImgBox src="/img/pic.jpg" x="20" y="30" w="50" h="75"
    defaultSettings={{
    debug: true,
    name: 'my pic',
    markStyle: {
        border: '10px outset white'
    }
    }}
/>

is equivlient to

<ImgBox debug={true} name="my pic" markStyle={{border: '10px outset white'}}
    defaultSettings={{
        src: "/img/pic.jpg",
        x: 20,
        y: 30,
        w: 50,
        h: 75
    }}
/>

Coordinate system

The coordinate numbers are pixels across the original image. Coordinate may be passed in 2 forms:

  1. x,y with width (w) and height (h)
  2. x,y with x2, y2
  3. If you include w,h,x2,y2 they should be internally consistant as x2,y2 will take priority. x and y are effectiviely left and top and the other 2 forms are positive numbers.

Modes

If edit is false, then the component is read-only and the marker may only be changed via props. If edit is true, then click to start drawing and click again to stop drawing. saveBox will be called and passed an object containing x, y, x2, y2, w and h. After editing has finished the marker will return to the props position. So if you want the changes to be permanant you must update the props to reflect the new state.

const [coords, setCoords] = useState({{x: 10, y: 10, x2: 20, y2: 20}})

return <ImgBox x={coords.x} .... edit={true} saveBox={(newCoords) => setCoords(newCoords)}>

Options

Here's the list of available settings.

Settings

To be used in IMG tags.

Attribute | Type | Default | Description --- | --- | --- | --- id | string | null | Proxied to underlining <img> tag. className | string | null, space separated list of class names | Proxied to underlining <img> tag. src | string | null | Proxied to underlining <img> tag. alt | string | '' | Proxied to underlining <img> tag. onClick | (e) => {} | null | Proxied to underlining <img> tag, except when edit=true. onMouseMove | (e) => {} | null | Proxied to underlining <img> tag. x | number | undefined | Start CSS left (pixels) y | number | undefined | Start CSS top (pixels) x2 | number | undefined | End CSS left (pixels) y2 | number | undefined | End CSS top (pixels) w | number | undefined | CSS width (pixels) h | number | undefined | CSS height (pixels) defaultSettings | object | | see Passing Props section debug | boolean | false | Switch on logging to the console name | string | '' | used component debug markStyle | object | {} | CSS Style of marker markClass | string | '' | CSS class to describe mark edit | boolean | false | Click on image to start drawing saveBox | (coord) => {} | | Stub implementation

License

LICENCE Copyright (c) 2024 David Newcomb https://www.bigsoft.co.uk/