Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AdelBeit committed May 22, 2023
2 parents cb57f04 + 7de8ad1 commit 9b09ac5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# React Icon Ether

[![license-shield]][license-url] [![linkedin-shield]][linkedin-url] ![size-url] ![size-url2]![npm-v]][npm-url]![gh-shield]][gh-url]
[![license-shield]][license-url] [![linkedin-shield]][linkedin-url] ![size-url] ![size-url2] [![npm-v]][npm-url] [![gh-shield]][gh-url]

[license-shield]: https://img.shields.io/github/license/adelbeit/react-icon-ether.svg
[license-url]: /LICENSE
Expand Down Expand Up @@ -42,9 +42,9 @@ yarn add react-icon-ether
## Usage

```tsx
import React from 'react';
import React from "react";

const icons = ['typescript', 'javascript', 'nextdotjs', 'react'];
const icons = ["typescript", "javascript", "nextdotjs", "react"];

const App = () => {
return (
Expand Down Expand Up @@ -112,7 +112,7 @@ function loadImage(url: string): Promise<HTMLImageElement> {
const img = new Image(30, 30);
return new Promise((res, rej) => {
img.onload = () => res(img);
img.onerror = () => rej(new Error('Failed to load ' + url));
img.onerror = () => rej(new Error("Failed to load " + url));
img.src = url;
});
}
Expand Down Expand Up @@ -141,8 +141,8 @@ function loadImage(url: string): Promise<HTMLImageElement> {

```js
const response = await fetch(url);
const contentType = response.headers.get('content-type');
const isImage = !!contentType?.startsWith('image/');
const contentType = response.headers.get("content-type");
const isImage = !!contentType?.startsWith("image/");
```
### 4. Publishing to npm, adding typescript and other modules
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.15",
"version": "1.0.16",
"description": "A React component that renders any number of pregenerated HTMLImageElements that move about randomly.",
"name": "react-icon-ether",
"license": "MIT",
Expand Down
10 changes: 6 additions & 4 deletions src/utils/preLoadImages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import urlExists from "./urlExists";
// import { urlExists } from "./index";

/**
* TODO: fix url exists
* Returns a URL string to the Simple Icons (SI) CDN with the given icon name and color.
* Icon name must match SI icon name, if name doesn't match SI or doesn't exist on SI, the fallback folder is checked for icon with exact name.
* Fallback icons folder must be structure like so: [project root dir]/public/fallback_icons/*.svg
Expand All @@ -11,10 +12,11 @@ import urlExists from "./urlExists";
export async function simpleIconsCDN(icon: string, color: string = "#33FF00") {
color = color.replace("#", "");
const simpleIconsCDN = `https://cdn.simpleicons.org/${icon}/${color}`;
if (await urlExists(simpleIconsCDN)) return simpleIconsCDN;
return simpleIconsCDN;
// if (await urlExists(simpleIconsCDN)) return simpleIconsCDN;

const fallbackURL = `./fallback_icons/${icon}.svg`;
if (await urlExists(fallbackURL)) return fallbackURL;
// const fallbackURL = `./fallback_icons/${icon}.svg`;
// if (await urlExists(fallbackURL)) return fallbackURL;

const event = new CustomEvent("IconLoadFailed", { detail: icon });
document.dispatchEvent(event);
Expand Down

0 comments on commit 9b09ac5

Please sign in to comment.