0.0.32 • Published 5 months ago

react-remote-svg v0.0.32

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

RemoteSVG

RemoteSVG is a React component for efficiently loading SVG icons from remote sources.

Features

  • Lazy loading: Icons are fetched only when they become visible on the screen, improving performance.

  • Customizable colors and effects: Supports customization of the icon appearance in different states - default, hover, active, and disabled.

  • Dark mode support: Ability to specify different icon variants for light and dark themes.

  • Flexible dimensions: Allows customization of the width and height of the icon.

  • Accessibility: Supports setting the alt text and title attributes for better accessibility.

Installation

# Using npm
npm install react-remote-svg

# Using yarn
yarn add react-remote-svg

Usage

import React from 'react';
import RemoteSVG from 'react-remote-svg';

const MyComponent = () => (
  <div>
    <RemoteSVG  
      url="icon.svg"
      dark
      isDisabled
      useDisabledImage
      alt="My Icon" 
      width={24}
      height={24}
      disabledEffect={{ filter: 'grayscale(100%)' }} 
    />
  </div> 
);

export default MyComponent;

Props

PropTypeDescription
urlstringThe URL of the SVG icon.
altstringAlternative text for accessibility.
titlestringTitle text for accessibility.
widthnumber|stringWidth of the icon.
heightnumber|stringHeight of the icon.
activeEffectCSSPropertiesStyles for active state.
disabledEffectCSSPropertiesStyles for disabled state.
hoverEffectCSSPropertiesStyles for hover state.
darkbooleanWhether to use dark theme variant.
useDisabledImagebooleanWhether to use disabled image variant.
useActiveImagebooleanWhether to use active image variant.
useHoverImagebooleanWhether to use hover image variant.
lazyLoadbooleanEnable lazy loading when visible.

Testing

To test components that depend on RemoteSVG, you can use a mock component in your tests. Here's how you can do it:

  1. In your test setup file (e.g., jest.setup.js), add the following line to import and use the mock component:
require('react-remote-svg/mock');
  1. Now, you can use the RemoteSVG component in your tests to verify the behavior of components that depend on RemoteSVG.
0.0.32

5 months ago

0.0.31

8 months ago

0.0.30

10 months ago

0.0.29

10 months ago

0.0.28

10 months ago

0.0.27

10 months ago

0.0.26

10 months ago

0.0.25

10 months ago

0.0.24

10 months ago

0.0.23

10 months ago

0.0.22

10 months ago

0.0.21

10 months ago

0.0.20

10 months ago

0.0.19

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago