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

@hyuchia/react-image-area

v1.1.1

Published

React component to select multiple areas/regions of images.

Downloads

5

Readme

react-image-area

react language license

React component to select multiple areas/regions of images.

Live Example

:books: Table of Contents

:package: Installation

yarn add @hyuchia/react-image-area

:rocket: Usage

Usage with types

import { AreaSelector, IArea } from '@hyuchia/react-image-area'

const ExampleComponent = () => {
    const [areas, setAreas] = useState<IArea[]>([]);

    const onChangeHandler = (areas: IArea[]) => {
        setAreas(areas);
    }

    return (
        <AreaSelector
            areas={areas}
            onChange={onChangeHandler}
        >
            <img src='my-image.jpg' alt='my image'/>
        </AreaSelector>
    )
}

:key: Features

  • Responsive (you can use pixels or percentages).
  • Touch enabled.
  • Min/max area size.
  • Custom area render

:notebook: Docs

  • Required Props

    • areas: IArea[]

      Starting with no areas:

      // ...
      const [areas,setAreas] = useState<IArea[]>([])
      // ...
      return (
          <AreaSelector
              areas={areas}
          >
              <img src='my-image.jpg' alt='my image'/>
          </AreaSelector>
      )
      // ...
    • onChange: (areas: IArea[]) => void

      A callback which happens for every change on the selection area.

      // ...
      const [areas,setAreas] = useState<IArea[]>()
      // ...
      return (
          <AreaSelector
              onChange={setAreas}
          >
              <img src='my-image.jpg' alt='my image'/>
          </AreaSelector>
      )
      // ...
  • Default Props

    • maxAreas: number

      Default: Infinity

      Set the maximum areas that can be drawn, by default there are no limit.

    • unit: 'pixel' | 'percentage'

      Default: pixel

      Set the unit you want to work with.

    • minWidth: number

      Default: 0

      Min width of the areas.

    • minHeight: number

      Default: 0

      Min height of the areas.

    • debug: boolean

      Default: false

      Display info of the current areas.

  • Optional Props

    • maxWidth: number

      Max width of the areas.

    • maxHeight: number

      Max height of the areas.

    • wrapperStyle: CSSProperties

      Apply styles to the wrapper element.

      Omited Styles: touchAction | boxSizing

      wrapperStyle={{
          border: '2px solid black'
      }}
    • globalAreaStyle: CSSProperties

      Apply global styles to the areas.

      Omited Styles: position | touchAction | top | left | width | height | boxSizing

      globalAreaStyle={{
          border: '1.5px dashed blue',
          backgroundColor: 'lightblue',
          opacity: '0.5'
      }}
    • customAreaRenderer: (areaProps: IAreaRendererProps) => ReactNode

      Custom render function to display info inside the areas. Remember to add a key

      import { AreaSelector, IAreaRendererProps } from '@bmunozg/react-image-area'
      // ...
      const customRender = (areaProps: IAreaRendererProps) => {
          if (!areaProps.isChanging) {
              return (
                  <div key={areaProps.areaNumber}>
                      {areaProps.areaNumber}
                  </div>
              );
          }
      };
      // ...
      return (
          <AreaSelector
              {/*...*/}
              customAreaRenderer={customRender}
          >
              <img src='my-image.jpg' />
          </AreaSelector>
      );
      // ...
    • mediaWrapperClassName: string

      Classname to apply to the media wrapper (image passed as children).

      // ...
      return (
          <AreaSelector>
              <img src="my-image.jpg" />
          </AreaSelector>
      );
      // ...

      inside the component :arrow_down:

      // ...
      return (
          <div {/*wrapperStyle*/}>
              <div className={mediaWrapperClassName}>
                  {/*image passed as children*/}
              </div>
              {/*...Areas*/}
          </div>
      )
      //...

:hammer_and_wrench: Support

Please open an issue for support.

:memo: Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

:scroll: License

MIT © Hyuchia