Git Product home page Git Product logo

react-icon-cloud's Introduction

license-shield linkedin-shield size-url size-url2 npm-v gh-shield


Logo

React Icon Cloud

React component for rendering an interactive img or word cloud on canvas
Code Sandbox Report Bug

About

An interactive 3D tag cloud component for React that renders text, images, and simple icons into a interactive 3D tag cloud

  • Built in support for rendering a cloud of Simple Icons with custom fallback color for poor contrast

  • Lazy animation of the canvas (pause animation when off screen)

Built With

Getting Started

To get a local copy up and running follow these simple steps or see the Code Sandbox.

npm i react-icon-cloud

Static icon slugs

import React from 'react'
import {Cloud, renderSimpleIcon} from 'react-icon-cloud'
import js from "simple-icons/icons/javascript"
import nextjs from "simple-icons/icons/nextdotjs"

const icons = [js,nextjs].map((icon) => {
  return renderSimpleIcon({
    icon,
    size: 42,
    aProps: {
      onClick: (e: any) => e.preventDefault()
    }
  })
})

const IconCloud = () => {
  return <Cloud>
    {icons}
    <a>
      hello world
    </a>
    <a
      href="https://emojipedia.org/globe-showing-americas/"
      target="_blank"
      rel="noopener"
    >
      <img
        height="42"
        width="42"
        alt="A globe"
        src="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/285/globe-showing-americas_1f30e.png"
      />
    </a>
  </Cloud>
}

Dynamic icon slugs

import React from 'react'
import {Cloud, renderSimpleIcon, fetchSimpleIcons, SimpleIcon} from 'react-icon-cloud'

const useIcons = (slugs: string[]) => {
  const [icons, setIcons] = React.useState()
  React.useEffect(() => {fetchSimpleIcons(slugs).then(setIcons)}, [])

  if (icons) {
    return Object.values(icons.simpleIcons).map((icon) => renderSimpleIcon({
      icon,
      size: 42,
      aProps: {
        onClick: (e: any) => e.preventDefault()
      }
    }))
  }
  
  return <a>Loading</a>
}

const slugs = [
  'amazonaws',
  'android',
  'androidstudio',
  'antdesign',
  'typescript',
  'vercel',
  'visualstudiocode'
]

const DynamicIconCloud = () => {
  const icons = useIcons(slugs)

  return <Cloud>
    {icons}
  </Cloud>
}

Props

Cloud

name type default description
canvasProps HTMLAttributes < HTMLCanvasElement > | undefined {} Attributes that will be passed to the underlying canvas element
children Tag[] [] Tags rendered using the provided renderers
containerProps HTMLAttributes < HTMLDivElement > | undefined {} Attributes passed to the root div element
id string | number | undefined uuid Should be provided when using SSR
options IOptions | undefined {} https://www.goat1000.com/tagcanvas-options.php

renderSimpleIcon

Used to create a tag for the Cloud component

name type default description
aProps HTMLAttributes < HTMLAnchorElement > | undefined {} Attributes passed to the underlying anchor element
bgHex string | undefined '#fff' The string hex of the background the icon will be rendered on. Ex: '#fff'. Used to determine if the min contrast ratio for the icons default color will be met
fallbackHex string | undefined '#000' The color of the icon if the minContrastRatio is not met Ex: '#000'
icon any undefined The simple icon object you would like to render. Ex: import icon from "simple-icons/icons/javascript";
imgProps HTMLAttributes < HTMLImageElement > | undefined {} Attributes passed to the underlying img element
minContrastRatio number | undefined 1 0 - 21 The min contrast ratio between icon and bgHex before the fallbackHex will be used for the icon color
size number | undefined 42 The size in px of the icon

fetchSimpleIcons

Used when you cant statically import simple icons during built time. Calling this will use fetch to get icons for each provided slug.

name type default description
slugs string[] Slugs to fetch svgs and colors for. The return icons may be passed to renderSimpleIcon

Examples

Tag Canvas Options

Code Sandbox

Dynamically Import Icons With Next.js SSR

Roadmap

See the open issues for a list of proposed features (and known issues).

License

See LICENSE for more information.

Contact

Teague Stockwell - LinkedIn

react-icon-cloud's People

Contributors

teaguestockwell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-icon-cloud's Issues

CSR component for simple-icons

The current implementation of IconCloud must be passed an array of simple icons. The entire simple-icons lib can be imported on the server with Nextjs, but that package is to big to import on the client with CRA.

Given

A new component to handle dynamic client side icon rendering,

When

passed an array of slugs,

Then

  1. for each slug it will GET https://cdn.jsdelivr.net/npm/simple-icons@v5/icons/SLUG.svg
  2. It will GET https://raw.githubusercontent.com/simple-icons/simple-icons/develop/_data/simple-icons.json for the icon's color
  3. It will dynamically fallback to the provided color if the default color does not satisfy the contrast ratio
  4. It will render the icons

Wrong imports ?

Hello,

I am very interested in using this package because it really looks awesome ! However I can't get it to work because imports seem broken. I tried to downgrade Simple-Icons to the same version as your code sandbox example but it still does not work, I get the following issue:
TypeError: (0 , react_icon_cloud__WEBPACK_IMPORTED_MODULE_2__.renderSimpleIcon) is not a function

My package.json setup :
[...]

   "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-icon-cloud": "^4.1.4",
    "simple-icons": "^5.12.0"

Installation Process

Hi Teague, DeAndre here. First and foremost, thank you for the effort in building this. It is exactly what I am looking for. However, I do apologise as I am just starting out learning React and I can't seem to get this to work. It shows 'NO TAGS' on my web application. Could we connect and please guide me though the process of getting this to work? Thank you for your kind attention, hope to hear from you soon.

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.