Giter Site home page Giter Site logo

trendingtechnology / react-tagcloud Goto Github PK

View Code? Open in Web Editor NEW

This project forked from madox2/react-tagcloud

0.0 0.0 0.0 6.92 MB

Tag/word cloud component for react https://madox2.github.io/react-tagcloud/

License: MIT License

JavaScript 100.00%

react-tagcloud's Introduction

react-tagcloud

Simple and extensible tag/word cloud React component.

See the demo.

preview tag-cloud preview

Installation

npm install react-tagcloud

# or with yarn
yarn install react-tagcloud

# react < 16.8.0
npm install [email protected]

Basic usage

import { TagCloud } from 'react-tagcloud'

const data = [
  { value: 'JavaScript', count: 38 },
  { value: 'React', count: 30 },
  { value: 'Nodejs', count: 28 },
  { value: 'Express.js', count: 25 },
  { value: 'HTML5', count: 33 },
  { value: 'MongoDB', count: 18 },
  { value: 'CSS3', count: 20 },
]

const SimpleCloud () => (
  <TagCloud
    minSize={12}
    maxSize={35}
    tags={data}
    onClick={tag => alert(`'${tag.value}' was selected!`)}
  />
)

API

Options

<TagCloud /> component has props listed below:

Option Type Required Note
tags Array true Array of objects that represent tags (see Tag object)
maxSize Number true Maximal font size (in px) used in cloud
minSize Number true Minimal font size (in px) used in cloud
shuffle Boolean false If true, tags are shuffled. When tags are modified, cloud is re-shuffled. Default: true
randomNumberGenerator Function false Specifies a custom random number generator that is being used by shuffle algorithm. Default: Math.random
colorOptions Object false Random color options (see randomColor#options)
disableRandomColor Boolean false If true, random color is not used
renderer Function false Function used to render tag

Note: Furthermore you can pass any other prop and it will be forwarded to the wrapping <div /> component (e.g. style, className).

Tag object

Each tag is represented by object literal having following properties:

Property Type Required Note
value String true String value to be displayed
count Number true Represents frequency of the tag that is used to calculate tag size
key String false Tag element key. If it is not provided, value property will be used instead (however it can fail if you don't have unique tag values. It is highly recommeded to use key property)
color String false Represents color of the tag. If it is not provided, random color will be used instead
props Object false Props to be passed to a particular tag component

Events

Event handlers can be passed to the <TagCloud /> props. Each handler has two arguments: the first is related tag object and the second is DOM event object.

Currently supported events: onClick, onDoubleClick, onMouseMove

Note: Feel free to open issue if any other event is needed.

Styles

Default class names are tag-cloud for the wrapping container, and tag-cloud-tag for a particular tag. Styles passed to <TagCloud /> props will be applied to the wrapping container.

Renderer

Rendering of tags can be fully customized by providing custom render function and passing it to the renderer prop. By default is used defaultRenderer. Render function has three arguments - tag, size and color. For example:

import { TagCloud } from 'react-tagcloud'

const customRenderer = (tag, size, color) => {
  return (
    <span key={tag.value} style={{ color }} className={`tag-${size}`}>
      {tag.value}
    </span>
  )
}

const CustomizedCloud () => (
  <TagCloud tags={data} minSize={1} maxSize={5} renderer={customRenderer} />
)

More examples

Testing

Install dev modules:

yarn install

Run unit tests

yarn test

Run examples

cd examples
yarn install
yarn start

and open browser at http://localhost:3000

License

MIT License

react-tagcloud's People

Contributors

dependabot[bot] avatar madox2 avatar ownadi avatar rahavlussato avatar udovenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.