1.0.5 • Published 11 months ago

react-rough-notation v1.0.5

Weekly downloads
1,195
License
MIT
Repository
github
Last release
11 months ago

Rough Notation React (Wrapper)

npm

This is a React wrapper for RoughNotation, a small JavaScript library to create and animate annotations on a web page.

Rough Notation logo

Table of contents

Installation

You can add rough-notation to your project via npm.

npm install --save react-rough-notation

Then just import the components you need.

import { RoughNotation, RoughNotationGroup } from "react-rough-notation";

RoughNotation Component

This is the main component, is a span element by default but you can change the tag name by anything you want using the customElement prop.

Usage

<RoughNotation type="underline" show={state.show}>
  Hello RoughNotation
</RoughNotation>

Props

Any unlisted prop will be pass to the component so you can use any react prop to handle interactions or styling.

nametypedefaultdescription
animatebooleantrueTurn on/off animation when annotating
animationDelaynumber0Delay in animation in milliseconds
animationDurationnumber800Duration of the animation in milliseconds
bracketsenum or enum from left, right, top, bottomrightValue could be a string or an array of strings, each string being one of these values: left, right, top, bottom. When drawing a bracket, this configures which side(s) of the element to bracket.
colorstringString value representing the color of the annotation sketch
customElementstringspanElement wrapper tagName
getAnnotationObjectfunction(annotation) => {}Callback function called after annotation init, it will receive the javascript annotation object as a param
iterationsnumber2By default annotations are drawn in two iterations, e.g. when underlining, drawing from left to right and then back from right to left. Setting this property can let you configure the number of iterations.
multilinebooleanfalseThis property only applies to inline text. To annotate multiline text (each line separately), set this property to true.
ordernumber, stringAnnotation order to animate if is inside an Annotation Group
paddingnumber, [top, right, bottom, left], [vertical, horizontal]5Padding in pixels between the element and roughly where the annotation is drawn. If you wish to specify different top, left, right, bottom paddings, you can set the value to an array akin to CSS style padding [top, right, bottom, left] or just [top & bottom, left & right]
showbooleanfalseShow/hide the annotation
strokeWidthnumber1Width of the annotation strokes
typeenum from (Type values)#type-valuesunderlineIt sets the annotation style

Type values

valuedescription
underlineCreate a sketchy underline below an element
boxThis style draws a box around the element
circleDraw a circle around the element
highlightCreates a highlight effect as if maked by a highlighter
strike-throughThis style draws a box around the element
crossed-offThis style draws a box around the element

Updating Styles

Some props can be changed after the initialization without re-rendering the annotation. i.e: if you like to change the color, just change the color prop, here is the complete list:

Prop
animated
animationDuration
color
padding
strokeWidth

Note: the type of the annotation cannot be changed. Create a new annotation for that.

RoughNotationGroup Component

This is a wrapper for multiple annotations, it will trigger the show() method on every child annotation after the prev annotation animation is complete. It does not render any HTML element.

Usage

<RoughNotationGroup show={state.show}>
  <RoughNotation type="underline">Hello,</RoughNotation>
  <RoughNotation type="underline">This is</RoughNotation>
  <RoughNotation type="underline">a Test</RoughNotation>
</RoughNotationGroup>

Props

nametypedefaultdescription
showbooleanshow/hides the annotations

Custom order

If you need to trigger annotations in a specific order, use the order prop in each RoughAnnotation component.

i.e: Reverse order

<RoughNotationGroup show={state.show}>
  <RoughNotation type="underline" order="3">
    Hello,
  </RoughNotation>
  <RoughNotation type="underline" order="2">
    This is
  </RoughNotation>
  <RoughNotation type="underline" order="1">
    a Test
  </RoughNotation>
</RoughNotationGroup>

Note: It will annotate first the components with the order prop, and then the ones without it.

Playground

You can find a CodeSandbox demo here

TODO

  • Auto compile and publish to npm
  • Testing
1.0.5

11 months ago

1.0.4

11 months ago

1.0.4-beta.1

11 months ago

1.0.4-beta.2

11 months ago

1.0.4-beta.3

11 months ago

1.0.4-beta.4

11 months ago

1.0.4-beta.5

11 months ago

1.0.3

2 years ago

1.0.3-beta.0

2 years ago

1.0.3-beta.1

2 years ago

1.0.3-beta.4

2 years ago

1.0.3-beta.3

2 years ago

1.0.2

2 years ago

1.0.2-beta.0

2 years ago

1.0.1

3 years ago

1.0.1-beta.0

3 years ago

1.0.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago