Socket
Socket
Sign inDemoInstall

react-tagcloud

Package Overview
Dependencies
4
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-tagcloud

Tag/word cloud component for react


Version published
Weekly downloads
8.2K
decreased by-10.74%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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 add react-tagcloud

# react < 16.8.0
npm install react-tagcloud@1.4

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!`)}
  />
)

React Native

In react native projects import tag cloud from the package relative path react-tagcloud/rn.

import React from 'react';

import { Alert } from 'react-native';
import { TagCloud } from 'react-tagcloud/rn'

const data = [
  // ...
]

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

API

Options

<TagCloud /> component has props listed below:

OptionTypeRequiredNote
tagsArraytrueArray of objects that represent tags (see Tag object)
maxSizeNumbertrueMaximal font size (in px) used in cloud
minSizeNumbertrueMinimal font size (in px) used in cloud
shuffleBooleanfalseIf true, tags are shuffled. When tags are modified, cloud is re-shuffled. Default: true
colorOptionsObjectfalseRandom color options (see randomColor#options)
disableRandomColorBooleanfalseIf true, random color is not used
randomSeedNumberfalseRandom seed used to shuffle tags and generate color
rendererFunctionfalseFunction used to render tag
randomNumberGeneratorFunctionfalseDEPRECATED, use randomSeed instead. Specifies a custom random number generator that is being used by shuffle algorithm. Default: Math.random

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:

PropertyTypeRequiredNote
valueStringtrueString value to be displayed
countNumbertrueRepresents frequency of the tag that is used to calculate tag size
keyStringfalseTag 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)
colorStringfalseRepresents color of the tag. If it is not provided, random color will be used instead
propsObjectfalseProps 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

Keywords

FAQs

Last updated on 22 Oct 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc