2.1.9 • Published 2 months ago

dotting v2.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

dotting_github

Quality Gate Status Coverage Bugs

Quick Start

Step1. Install the package

$ yarn add dotting

Step2. Place Dotting component in your project

import { Dotting } from "dotting";

const Clear = () => {
  return (
    <div>
      <Dotting width={300} height={300} />
    </div>
  );
};

Component Props

When creating a Dotting component there are multiple props prepared for easily customizing the canvas. Especially, you can set the brush you would like to use through the brushTool prop. The width and height props should be initialized with your own values.

If you would like to use the hooks for further customizing the component, you must use the ref prop and assign a refObject created with useRef<DottingRef>. An example of how to use hooks by setting a refObject is shown below.

NameDescriptiontype
width*The width of the canvas. When you assign a string to width, it should be a valid CSS length value such as 100%.string or number
height*The height of the canvas. When you assign a string to height, it should be a valid CSS length value such as 100%.string or number
styleThe style object for the canvasReact.CSSProperties
gridStrokeColorThe stroke color of the gridstring
gridStrokeWidthThe stroke width of the gridnumber
isGridVisibleIf set to true the grid lines will be visibleboolean
backgroundColorThe background color of the canvas.string
initLayersThe initial layers that you want to draw on the canvas. If nothing is passed, there will be 1 default layer, and its id will be 'layer1'LayerProps[]
isPanZoomableIf set to true the canvas will be pan and zoomableboolean
isGridFixedIf set to true the grid will not be extendableboolean
brushToolThe brush tool is for changing the brush toolBrushTool
brushColorThe brush color for drawing the grid. You can make a useState for tracking brushColor You can also use useBrush hook to change the brush color with changeBrushColor.string
indicatorDataThe indicator data that you want to draw on the canvasPixelModifyItem[]
isInteractionApplicableIf set to true the interaction will be applicable. If set to false the interaction will be disabledboolean
isDrawingEnabledIf set to true the drawing will be enabled. If set to false the drawing will be disabledboolean
gridSquareLengthThe length of the grid square. The default is 20.number
defaultPixelColorThe default pixel color.string
minScaleThe minimum scale of the canvas.color.number
maxScaleThe maximum scale of the canvas.color.number
initAutoScaleWheter to initially auto scale the canvas to fit the grids inside the canvasboolean
resizeUnitThe unit of reszie amount during extensionnumber
maxColumnCountThe max column count of the canvas. It is undefined by default. The value should be at least 3number
minColumnCountThe max column count of the canvas. It is 2 by default. The value should be at least 2number
maxRowCountThe max row count of the canvas. It is undefined by default. The value should be at least 3number
minRowCountThe min column count of the canvas. It is 2 by default. The value should be at least 2number
refThis is a ref object that must be used if you plan to use hooks for manipulating the canvas through codeRef<DottingRef>

Basic Types

There are some types that you should take notice of when using hooks or setting props for Dotting. In this section, I only cover the types that are related to Dotting props. For further details on specific types used in hooks, please check the documentation

NameDescriptiontype
LayerPropsThis contains the necessary props for creating a layer{ id: string; data: Array<Array<PixelModifyItem>>;}
PixelModifyItemThis is an item that contains the information for one pixel square. In a default canvas, the top left pixel square's rowIndex and columnIndex are both 0. The pixel square just below it has a rowIndex of 1 and a columnIndex of 0, white the pixel square just next to it has a rowIndex of 0 and a columnIndex of 1{ rowIndex: number; columnIndex: number; color: string;}
BrushToolThis is an enum containing all the tools usable in the canvas. Currently we support NONE, Pen (Dot) Tool, Eraser Tool,Paint Tool, Select Tool. The NONE allows users to only pan the canvas. Pen (Dot) Tool allows users to draw pixels. Eraser Tool allows users to erase pixels. Paint Tool allows users to paint a region. Select Tool allows users to select a certain area and move the selected region or resize the region. Tools other than NONE and Select Tool basically allows for resizing the gridBrushTool.NONE , BrushTool.DOT, BrushTool.ERASER, BrushTool.PAINT_BUCKET,BrushTool.SELECT
DottingRefThis is a ref object which you contains all the callbacks for manipulating the canvas through programming. You are free to use the callbacks directly from the ref ojbect or you can use hooks for convenienceCheck the file

Don't forget setting the width and height!

To use the canvas component, you should first use the <Dotting/> component. You must set the width and height to use it.

<Dotting width={300} height={300} />

Want to manipulate the canvas? Use hooks!

To manipulate the pixel grids programatically, you can use hooks. The provided hooks are useBrush, useData, useDotting, useGrids, useHandlers. For using the hooks, you must create a ref object with React's useRef and input the resulting ref object as a prop in the Dotting component and also pass it as a parameter to the hooks. Below is an example using the useDotting hook for clearing the pixels when button is clicked

import { Dotting, DottingRef, useDotting } from "dotting";

export const Component = () => {
  const ref = useRef<DottingRef>(null);
  const { clear } = useDotting(ref);
  return (
    <div>
      <Dotting ref={ref} width={300} height={300} />
      <button onClick={clear}>Clear Canvas</button>
    </div>
  );
};

For more details on how to use hooks, please check the documentation

For contributing

Dotting welcomes contributors! If you are interested, contact me through twitter!

Contributors ✨

Thanks goes to these incredible people!!

2.1.9

2 months ago

2.1.8

3 months ago

2.1.7

5 months ago

1.1.7

10 months ago

1.1.6

10 months ago

2.1.2

6 months ago

2.1.1

6 months ago

2.0.2

8 months ago

2.1.4

6 months ago

2.0.13

7 months ago

2.0.5

8 months ago

2.1.3

6 months ago

2.0.4

8 months ago

2.1.6

5 months ago

2.0.11

7 months ago

2.0.7

8 months ago

2.1.5

5 months ago

2.0.12

7 months ago

2.0.6

8 months ago

2.0.9

7 months ago

2.0.10

7 months ago

2.0.8

7 months ago

2.1.0

7 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.1.5

11 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.0.9

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago