npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-tagcloud

v2.3.3

Published

Tag/word cloud component for react

Downloads

30,451

Readme

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

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:

| 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| |colorOptions |Object |false|Random color options (see randomColor#options)| |disableRandomColor |Boolean |false|If true, random color is not used| |randomSeed |Number |false|Random seed used to shuffle tags and generate color| |renderer |Function|false|Function used to render tag| |randomNumberGenerator|Function|false|DEPRECATED, 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:

| 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