Socket
Book a DemoInstallSign in
Socket

selectable-grid

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selectable-grid

selectable-grid

Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

selectable-grid

Small description

A React component library that allows you to select the desired area within a container and get the dimensions and coordinates of the selected area

Live demo

NPM JavaScript Style Guide

Example

  • Example for select area

patrick

  • Example for responsive grid

responsive patrick

Install

npm install --save selectable-grid

Usage

Example for image in the div element

import React, { useRef, useState } from 'react'

import { SelectableGrid } from 'selectable-grid'
import type { Point, AreaInfo, Size } from 'selectable-grid'
import 'selectable-grid/css'

const App = () => {
  const containerRef = useRef<HTMLDivElement>(null)
  const imgRef = useRef<HTMLImageElement>(null)
  const [imgSize, setImgSize] = useState<Size | undefined>(undefined)

  const handleLoad = ({
    currentTarget: { naturalWidth, naturalHeight }
  }: React.SyntheticEvent<HTMLImageElement>) => {
    setImgSize({
      width: naturalWidth,
      height: naturalHeight,
      aspect: naturalWidth / naturalHeight
    })
  }

  return (
    <div ref={containerRef} className='container'>
      <img
        className='img'
        ref={imgRef}
        src='https://all-t-shirts.ru/goods_images/ru110593II00039d6336575d4ab6f3960422a337e0e78.jpg'
        alt=''
        onLoad={handleLoad}
      />

      <SelectableGrid
        container={containerRef.current}
        imgSize={imgSize}
        onMouseDown={(e: React.MouseEvent, downPosition: Point) => {
          console.log('event => ', e)
          console.log('downPosition => ', downPosition)
        }}
        onMouseMove={(e: React.MouseEvent, areaInfo: AreaInfo) => {
          console.log('event => ', e)
          console.log('areaInfo => ', areaInfo)
        }}
        onMouseUp={(e: React.MouseEvent, areaInfo: AreaInfo) => {
          console.log('event => ', e)
          console.log('areaInfo => ', areaInfo)
        }}
      />
    </div>
  )
}

Props description

Prop nameProp type
containerHTMLDivElement | null
imgSize?{
width: number;
height: number;
aspect: number;
}
cellSizenumber
onMouseDown(e: React.MouseEvent, startDownPosition: Point) => void
containerHTMLDivElement | null
onMouseMove(e: React.MouseEvent, areaInfo: AreaInfo) => void
onMouseUp(e: React.MouseEvent, areaInfo: AreaInfo) => void
gridStyles{
strokeStyle?: CanvasFillStrokeStyles['strokeStyle']
lineDashOffset?: CanvasFillStrokeStyles['lineDashOffset']
lineDash?: number[]
}
selectAreaStyles{
strokeStyle?: CanvasFillStrokeStyles['strokeStyle']
fillStyle?: CanvasFillStrokeStyles['fillStyle']
lineDash?: CanvasFillStrokeStyles['lineDash']
}
cellsStyles{
strokeStyle?: CanvasFillStrokeStyles['strokeStyle']
fillStyle?: CanvasFillStrokeStyles['fillStyle']
}
  • Point: x: number, y: number;
  • AreaInfo: area: {x: number, y: number, w: number, h: number}, areaInPx: {top: number, left: number, right: number, bottom: number}, areaInPercent: {top: number, left: number, right: number, bottom: number}

Made with create-react-library

License

MIT © Pisyukaev

FAQs

Package last updated on 31 Jul 2022

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