diff --git a/README.md b/README.md index d237cdb..a7ff7cb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,72 @@ -# react-alert-template-basic +# react-alert-template-basic-with-icons -> Basic alert template for [react-alert](https://github.com/schiehll/react-alert) +> Basic alert template with icons for [react-alert](https://github.com/schiehll/react-alert) -[![version](https://img.shields.io/npm/v/react-alert-template-basic.svg?style=flat-square)](http://npm.im/react-alert-template-basic) +[![version](https://img.shields.io/npm/v/react-alert-template-basic-with-icons.svg?style=flat-square)](http://npm.im/react-alert-template-basic-with-icons) ## Installation ```bash -$ npm install --save react-alert-template-basic +$ npm install --save react-alert-template-basic-with-icons ``` + +## Usage + +You can use this package with `react-alert` by importing AlertTemplate from this package and giving it to the AlertProvider from `react-alert`. Alternatively, you can create a styled alert component, and then give the styled component to the AlertProvider as the template. You can override the default template style, and change the icon colors like so: + +```js +// StyledAlertTemplate.js +import React from 'react'; +import AlertTemplate from 'react-alert-template-basic-with-icons' + +// Template style overrides +const styleOverrides = { + backgroundColor: 'white', + color: 'black', + width: '450px' +} + +export default (props) => ( + +) +``` + +You can also create your own custom alert template and use the exposed icons. You can import the icons like so: + +```js +//MyAlertTemplate.js + +import React from 'react'; +import { InfoIcon, SuccessIcon, ErrorIcon, CloseIcon } from 'react-alert-template-basic-with-icons' + +const MyAlertTemplate = () => {} //Create your template with the icon components here + +export default MyAlertTemplate +``` + +## Options + +You can provide an `iconColors` prop to AlertTemplate in order to change the color of the icons. It takes an object of the following type: + +```js +iconColors?: { + info?: string, + success?: string, + error?: string, + close?: string +} +``` + +The default colors are: + +```js +info: '#2E9AFE' +success: '#31B404' +error: '#FF0040' +close: '#FFFFFF' +``` + diff --git a/package.json b/package.json index 4bba433..0d59c3a 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { - "name": "react-alert-template-basic", - "version": "1.0.0", + "name": "react-alert-template-basic-with-icons", + "version": "1.2.4", "author": "Reinaldo Schiehll ", - "main": "dist/cjs/react-alert-template-basic.js", - "module": "dist/esm/react-alert-template-basic.js", + "main": "dist/cjs/react-alert-template-basic-with-icons.js", + "module": "dist/esm/react-alert-template-basic-with-icons.js", "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/schiehll/react-alert-template-basic.git" + "url": "https://github.com/jeronimomora/react-alert-template-basic.git" }, "keywords": [ "react", @@ -16,7 +16,9 @@ "toaster", "react-toaster", "react-component", - "react-alert-template" + "react-alert-template", + "react-alert-template-basic", + "react-alert-template-basc-with-icons" ], "scripts": { "build": "node ./scripts/build.js", diff --git a/src/AlertTemplate.js b/src/AlertTemplate.js new file mode 100644 index 0000000..0c7718f --- /dev/null +++ b/src/AlertTemplate.js @@ -0,0 +1,48 @@ +import React from 'react' +import { InfoIcon, SuccessIcon, ErrorIcon, CloseIcon } from './icons' + +const defaultAlertStyle = { + backgroundColor: '#151515', + color: 'white', + padding: '10px', + textTransform: 'uppercase', + borderRadius: '3px', + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center', + boxShadow: '0px 2px 2px 2px rgba(0, 0, 0, 0.03)', + fontFamily: 'Arial', + width: '300px', + boxSizing: 'border-box' +} + +const defaultButtonStyle = { + marginLeft: '20px', + border: 'none', + backgroundColor: 'transparent', + cursor: 'pointer', + color: '#FFFFFF' +} + +const AlertTemplate = ({ + message, + options, + style, + buttonStyle = defaultButtonStyle, + iconColors = {}, + close +}) => { + return ( +
+ {options.type === 'info' && } + {options.type === 'success' && } + {options.type === 'error' && } + {message} + +
+ ) +} + +export default AlertTemplate \ No newline at end of file diff --git a/src/icons/CloseIcon.js b/src/icons/CloseIcon.js index 101020c..a18a335 100644 --- a/src/icons/CloseIcon.js +++ b/src/icons/CloseIcon.js @@ -1,8 +1,8 @@ import React from 'react' import BaseIcon from './BaseIcon' -const CloseIcon = () => ( - +const CloseIcon = ({ color = '#FFFFFF' }) => ( + diff --git a/src/icons/ErrorIcon.js b/src/icons/ErrorIcon.js index 00f2e4a..2551401 100644 --- a/src/icons/ErrorIcon.js +++ b/src/icons/ErrorIcon.js @@ -1,8 +1,8 @@ import React from 'react' import BaseIcon from './BaseIcon' -const ErrorIcon = () => ( - +const ErrorIcon = ({ color = '#FF0040' }) => ( + diff --git a/src/icons/InfoIcon.js b/src/icons/InfoIcon.js index b1fb0d6..3da21f6 100644 --- a/src/icons/InfoIcon.js +++ b/src/icons/InfoIcon.js @@ -1,8 +1,8 @@ import React from 'react' import BaseIcon from './BaseIcon' -const InfoIcon = () => ( - +const InfoIcon = ({ color = '#2E9AFE' }) => ( + diff --git a/src/icons/SuccessIcon.js b/src/icons/SuccessIcon.js index a210adb..f4901a9 100644 --- a/src/icons/SuccessIcon.js +++ b/src/icons/SuccessIcon.js @@ -1,8 +1,8 @@ import React from 'react' import BaseIcon from './BaseIcon' -const SuccessIcon = () => ( - +const SuccessIcon = ({ color = '#31B404' }) => ( + diff --git a/src/icons/index.js b/src/icons/index.js new file mode 100644 index 0000000..6497f5e --- /dev/null +++ b/src/icons/index.js @@ -0,0 +1,7 @@ +import BaseIcon from './BaseIcon' +import InfoIcon from './InfoIcon' +import SuccessIcon from './SuccessIcon' +import ErrorIcon from './ErrorIcon' +import CloseIcon from './CloseIcon' + +export { BaseIcon, InfoIcon, SuccessIcon, ErrorIcon, CloseIcon } \ No newline at end of file diff --git a/src/index.js b/src/index.js index bf5066d..d134e51 100644 --- a/src/index.js +++ b/src/index.js @@ -1,44 +1,2 @@ -import React from 'react' -import InfoIcon from './icons/InfoIcon' -import SuccessIcon from './icons/SuccessIcon' -import ErrorIcon from './icons/ErrorIcon' -import CloseIcon from './icons/CloseIcon' - -const alertStyle = { - backgroundColor: '#151515', - color: 'white', - padding: '10px', - textTransform: 'uppercase', - borderRadius: '3px', - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center', - boxShadow: '0px 2px 2px 2px rgba(0, 0, 0, 0.03)', - fontFamily: 'Arial', - width: '300px', - boxSizing: 'border-box' -} - -const buttonStyle = { - marginLeft: '20px', - border: 'none', - backgroundColor: 'transparent', - cursor: 'pointer', - color: '#FFFFFF' -} - -const AlertTemplate = ({ message, options, style, close }) => { - return ( -
- {options.type === 'info' && } - {options.type === 'success' && } - {options.type === 'error' && } - {message} - -
- ) -} - -export default AlertTemplate +export * from './icons' +export { default } from './AlertTemplate' \ No newline at end of file