Giter Site home page Giter Site logo

strapi-plugin-react-icons's Introduction

Strapi plugin react-icons

A plugin for strapi to select react icons.

grafik react-icons grafik

Installation

To install this plugin, you need to add an NPM dependency to your Strapi application:

# Using Yarn
yarn add strapi-plugin-react-icons

# Or using NPM
npm install strapi-plugin-react-icons

Then, you'll need to build your admin panel:

# Using Yarn
yarn build

# Or using NPM
npm run build

Strapi plugins config file

Add "react-icons": true, in you strapi plugins file.

If you do not have this file, create a file:

# in TypeScript: "/config/plugins.ts"
export default ({ env }) => ({ "react-icons": true, });

# in JavaScript: "/config/plugins.js"
module.exports = ({ env }) => ({ "react-icons": true, });

Usage

Usage in strapi

  • Select your prefered icon libraries on the settings page.
  • Add react-icon as custom field to your content type.
  • Press the search icon to select an icon from any of the selected icon libraries.

Usage in React / Next.js

Create the following IconComponent to dynamically show the icon:

Show code
'use client';

import { DOMAttributes } from 'react';

export type IReactIcon = string;

import loadable from '@loadable/component';
import { IconType } from 'react-icons';

const iconComponents = {
  Ai: () => import('react-icons/ai'),
  Bs: () => import('react-icons/bs'),
  Bi: () => import('react-icons/bi'),
  Ci: () => import('react-icons/ci'),
  Di: () => import('react-icons/di'),
  Fi: () => import('react-icons/fi'),
  Fc: () => import('react-icons/fc'),
  Fa: () => import('react-icons/fa6'),
  Gi: () => import('react-icons/gi'),
  Go: () => import('react-icons/go'),
  Gr: () => import('react-icons/gr'),
  Hi: () => import('react-icons/hi2'),
  Im: () => import('react-icons/im'),
  Lia: () => import('react-icons/lia'),
  Io: () => import('react-icons/io5'),
  Lu: () => import('react-icons/lu'),
  Md: () => import('react-icons/md'),
  Pi: () => import('react-icons/pi'),
  Rx: () => import('react-icons/rx'),
  Ri: () => import('react-icons/ri'),
  Si: () => import('react-icons/si'),
  Sl: () => import('react-icons/sl'),
  Tb: () => import('react-icons/tb'),
  Tfi: () => import('react-icons/tfi'),
  Ti: () => import('react-icons/ti'),
  Vsc: () => import('react-icons/vsc'),
  Wi: () => import('react-icons/wi'),
  Cg: () => import('react-icons/cg'),
} as unknown as { [x: string]: () => Promise<{ [key: string]: IconType }> };

export interface IDynamicReactIcon extends DOMAttributes<SVGElement> {
  name: IReactIcon;
}

const DynamicReactIcon: React.FC<IDynamicReactIcon> = ({
  name,
  ...rest
}: IDynamicReactIcon) => {
  const lib = name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').split(' ')[0];
  const iconComponent = iconComponents[lib];

  if (!iconComponent) return <></>;

  const DynamicIcon = loadable(iconComponent, {
    resolveComponent: (el) => el[name],
  }) as IconType;

  return <DynamicIcon {...rest} />;
};

export default DynamicReactIcon;

Planned features

  • custom field for react-icons
  • selection modal for the custom field
  • settings page for enabling / disabling icon libraries
  • default selection for icon library
  • search in the selection modal

Contributing and developing

Feel free to post any PR or issues :)

strapi-plugin-react-icons's People

Contributors

alexian-moins avatar buenoc6 avatar danielpantle avatar davidserodio avatar davidserodio-linkwithus avatar dulajdeshan avatar ecebeci avatar yusuf-saydullayev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

strapi-plugin-react-icons's Issues

[BUG] Failed to install with current node LTS version: 20.9.0

Bug report

The current LTS version is 20.9.0

This module is broken on all our servers using strapi

Required System information

  • Node.js version: 20.9.0 LTS
  • NPM version: 10.2.1
  • Strapi version: 4.15.0
  • Database: MySQL
  • Operating system: Tested on: Linux & Mac
  • Project Javascript

Describe the bug

failed to install

yarn install or npm install

Steps to reproduce the behavior

Expected behavior

Need to bump up the plugin packages

Screenshots

NA

Code snippets

NA

Additional context

It would be nice to have some automatic process to test all strapi marketplace plugins before bumping versions with the latest LTS. It does not make sense to have a marketplace plugin with limited versions that are less than the current strapi version. It's breaking servers.

I will add to the marketplace a field test on LTS: version(s) and date so at least before upgrading the node version we will know.

Add lucide icons

I have installed the plugin and also enabled it in plugin file but unable to see it inside the custom component fields in admin panel.

bug: where's the 0.2.0 code

Hello. I'm trying to install the plugin, which seems great.

npm registry states that the latest version available is 0.2.0 but the last commit here is a publish of the 0.1.6 (there's also a v0.1.7 which isn't versioned here).

the package.json of the 0.2.0 has dependencies to react@17 whereas until the 0.1.7 it was react@18.

i'm saying all this because there a few dependency issues when installing this package. could you provide some help/information?

performance: Proposed dynamic icon component contains all icons

Hey!

thanks for the plugin! Really cool!

I was looking at the code in the README you proposed:

import * as ReactIcons from "react-icons/all";

interface IIconComponent {
  icon: string;
  size?: number;
}
type IReactIcon = keyof typeof ReactIcons;

const IconComponent: React.FC<IIconComponent> = ({ icon, size }) => {
  const DynamicIconComponent = ReactIcons[icon as IReactIcon];

  if (undefined === DynamicIconComponent) return <></>;

  return <DynamicIconComponent size={size} />;
};

This will include all icons in the final bundle and hence blow it up in size quite significantly. Are you aware of any alternative?

feature: implement lazy loading

Currently, the IconSelect is quite slow. Implement a loading screen while the icons are loaded. The goal is to display the IconSelector popup immediately instead of after a few seconds.

Npm error in strapi v4.11.0

npm ERR! Found: [email protected]
npm ERR! node_modules/styled-components
npm ERR! styled-components@"5.3.3" from @strapi/[email protected]
npm ERR! node_modules/@strapi/admin
npm ERR! @strapi/admin@"4.11.0" from @strapi/[email protected]
npm ERR! node_modules/@strapi/strapi
npm ERR! peer @strapi/strapi@"^4.3.4" from @strapi/[email protected]
npm ERR! 5 more (@strapi/data-transfer, @strapi/plugin-color-picker, ...)
npm ERR! peer styled-components@"^5.2.1" from @strapi/[email protected]
npm ERR! node_modules/@strapi/design-system
npm ERR! @strapi/design-system@"1.8.0" from @strapi/[email protected]
npm ERR! node_modules/@strapi/admin
npm ERR! @strapi/admin@"4.11.0" from @strapi/[email protected]
npm ERR! node_modules/@strapi/strapi
npm ERR! peer @strapi/strapi@"^4.3.4" from @strapi/[email protected]
npm ERR! 5 more (@strapi/data-transfer, @strapi/plugin-color-picker, ...)
npm ERR! peer @strapi/design-system@"1.8.0" from @strapi/[email protected]

Input field of component is not selectable or is disabled

Running strapi v4.10.4. Had the same issue with v4.9.2 as well.

I've installed the plugin via npm which installs v0.1.3 and then I imported all the fonts as described in the documentation but the input field for the added component is not selectable or is disabled:

screencast-localhost_1337-2023.05.17-14_09_52.webm

Thanks.

Support Node 20

Strapi now supports Node 20, so it would be nice to update the compatible engines in package.json to include node 20

Dynamic icon code block not working

I have been trying to use the following code block provided in README.md but it seems to be not working. It shows error that the module react-icons/all not found with the latest version of react-icons. Please update the snippet or just provide the solution to fix this issue.

import * as ReactIcons from "react-icons/all";

interface IIconComponent {
  icon: string;
  size?: number;
}
type IReactIcon = keyof typeof ReactIcons;

const IconComponent: React.FC<IIconComponent> = ({ icon, size }) => {
  const DynamicIconComponent = ReactIcons[icon as IReactIcon];

  if (undefined === DynamicIconComponent) return <></>;

  return <DynamicIconComponent size={size} />;
};

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.