From c71f1d4db2f74f75a5c773ca2b80c85b5ad05507 Mon Sep 17 00:00:00 2001 From: Pankaj Phartiyal Date: Mon, 25 Jun 2018 19:51:24 +0530 Subject: [PATCH] feat(alert): add ability to disable fade (#1078) Closes #824 --- docs/lib/Components/AlertsPage.js | 17 +++++++++++++ docs/lib/examples/AlertFadeless.js | 40 ++++++++++++++++++++++++++++++ src/Alert.js | 12 ++++++++- src/UncontrolledAlert.js | 4 ++- 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 docs/lib/examples/AlertFadeless.js diff --git a/docs/lib/Components/AlertsPage.js b/docs/lib/Components/AlertsPage.js index e67aa106a..9c7097e34 100644 --- a/docs/lib/Components/AlertsPage.js +++ b/docs/lib/Components/AlertsPage.js @@ -20,6 +20,9 @@ const AlertDismissExampleSource = require('!!raw!../examples/AlertDismiss'); import AlertUncontrolledDismissExample from '../examples/AlertUncontrolledDismiss'; const AlertUncontrolledDismissExampleSource = require('!!raw!../examples/AlertUncontrolledDismiss'); +import {AlertFadelessExample, UncontrolledAlertFadelessExample} from '../examples/AlertFadeless'; +const AlertFadelessExampleSource = require('!!raw!../examples/AlertFadeless'); + export default class AlertsPage extends React.Component { render() { return ( @@ -93,6 +96,20 @@ export default class AlertsPage extends React.Component { {AlertUncontrolledDismissExampleSource} + + Alerts without fade +

+ Fade can be disbaled using fade=false. +

+
+ + +
+
+          
+            {AlertFadelessExampleSource}
+          
+        
); } diff --git a/docs/lib/examples/AlertFadeless.js b/docs/lib/examples/AlertFadeless.js new file mode 100644 index 000000000..2f62be19b --- /dev/null +++ b/docs/lib/examples/AlertFadeless.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { UncontrolledAlert } from 'reactstrap'; +import Alert from '../../../src/Alert'; + +export class AlertFadelessExample extends React.Component { + + constructor(props) { + super(props); + + this.state = { + visible: true + }; + + this.onDismiss = this.onDismiss.bind(this); + } + + onDismiss() { + this.setState({ visible: false }); + } + + render() { + return ( +
+ + I am a primary alert and I can be dismissed without animating! + +
+ ); + } +} + +export function UncontrolledAlertFadelessExample() { + return ( +
+ + I am an alert and I can be dismissed without animating! + +
+ ); +} diff --git a/src/Alert.js b/src/Alert.js index 56a99aa17..04b33e54a 100644 --- a/src/Alert.js +++ b/src/Alert.js @@ -11,6 +11,7 @@ const propTypes = { closeAriaLabel: PropTypes.string, cssModule: PropTypes.object, color: PropTypes.string, + fade: PropTypes.bool, isOpen: PropTypes.bool, toggle: PropTypes.func, tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), @@ -22,6 +23,7 @@ const defaultProps = { isOpen: true, tag: 'div', closeAriaLabel: 'Close', + fade: true, transition: { ...Fade.defaultProps, unmountOnExit: true, @@ -40,6 +42,7 @@ function Alert(props) { toggle, children, transition, + fade, ...attributes } = props; @@ -52,8 +55,15 @@ function Alert(props) { const closeClasses = mapToCssModules(classNames('close', closeClassName), cssModule); + const alertTransition = { + ...Fade.defaultProps, + ...transition, + baseClass: fade ? transition.baseClass : '', + timeout: fade ? transition.timeout : 0, + }; + return ( - + {toggle ?