From 12a26125b2a3d76fba77b1e2fbc77b8d3d50b0f7 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 12 Jun 2019 12:24:12 -0400 Subject: [PATCH 1/8] Added optional support for React Icons --- docs/intro.md | 2 +- package.json | 5 ++++- src/alert/icon.jsx | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/docs/intro.md b/docs/intro.md index fd139b8..aea3587 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -10,4 +10,4 @@ import { AlertList, Alert, AlertContainer } from "react-bs-notifier"; This package exports three components, `AlertList`, `Alert`, & `AlertContainer`. Depending on your use-case, one or a combination of these components might work better for you. -These components makes use of [Bootstrap](https://getbootstrap.com/) & [Font Awesome](http://fontawesome.io/), but do not take direct dependencies on either. It assumes the CSS classes are available (e.g. just include the stylesheets). If bootstrap isn't available, the component won't look like much. If font awesome isn't available, it just won't add the icons to the alerts. \ No newline at end of file +These components makes use of [Bootstrap](https://getbootstrap.com/) & either [Font Awesome](http://fontawesome.io/) or [React Icons](https://www.npmjs.com/package/react-icons), but do not take direct dependencies on either. It assumes the CSS classes are available for Font Awesome (e.g. just include the stylesheets), or that the React Icons module has been added to your project. If bootstrap isn't available, the component won't look like much. If Font Awesome or React Icons isn't available, it just won't add the icons to the alerts. diff --git a/package.json b/package.json index 6f3718a..5ac6e22 100644 --- a/package.json +++ b/package.json @@ -61,5 +61,8 @@ "style-loader": "0.13.x", "webpack": "2.x", "webpack-dev-server": "2.x" + }, + "optionalDependencies": { + "react-icons": "3.x" } -} \ No newline at end of file +} diff --git a/src/alert/icon.jsx b/src/alert/icon.jsx index f1e5b64..d519fbf 100644 --- a/src/alert/icon.jsx +++ b/src/alert/icon.jsx @@ -1,15 +1,46 @@ import React from "react"; + +// Import optional react-icons library +import("react-icons/fa").then(fa => { + const { FaCheck, FaExclamationCircle, FaExclamationTriangle, FaInfo } = fa; +}).catch(err => { + const FaCheck = null; +}); + const Icon = ({ type, className = "" }) => { const faType = iconType(type); if (faType) { - return