Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit c71f1d4

Browse files
electriccodeTheSharpieOne
authored andcommitted
feat(alert): add ability to disable fade (reactstrap#1078)
Closes reactstrap#824
1 parent e6a1313 commit c71f1d4

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

docs/lib/Components/AlertsPage.js

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const AlertDismissExampleSource = require('!!raw!../examples/AlertDismiss');
2020
import AlertUncontrolledDismissExample from '../examples/AlertUncontrolledDismiss';
2121
const AlertUncontrolledDismissExampleSource = require('!!raw!../examples/AlertUncontrolledDismiss');
2222

23+
import {AlertFadelessExample, UncontrolledAlertFadelessExample} from '../examples/AlertFadeless';
24+
const AlertFadelessExampleSource = require('!!raw!../examples/AlertFadeless');
25+
2326
export default class AlertsPage extends React.Component {
2427
render() {
2528
return (
@@ -93,6 +96,20 @@ export default class AlertsPage extends React.Component {
9396
{AlertUncontrolledDismissExampleSource}
9497
</PrismCode>
9598
</pre>
99+
100+
<SectionTitle>Alerts without fade</SectionTitle>
101+
<p>
102+
Fade can be disbaled using <code>fade=false</code>.
103+
</p>
104+
<div className="docs-example">
105+
<AlertFadelessExample />
106+
<UncontrolledAlertFadelessExample />
107+
</div>
108+
<pre>
109+
<PrismCode className="language-jsx">
110+
{AlertFadelessExampleSource}
111+
</PrismCode>
112+
</pre>
96113
</div>
97114
);
98115
}

docs/lib/examples/AlertFadeless.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { UncontrolledAlert } from 'reactstrap';
3+
import Alert from '../../../src/Alert';
4+
5+
export class AlertFadelessExample extends React.Component {
6+
7+
constructor(props) {
8+
super(props);
9+
10+
this.state = {
11+
visible: true
12+
};
13+
14+
this.onDismiss = this.onDismiss.bind(this);
15+
}
16+
17+
onDismiss() {
18+
this.setState({ visible: false });
19+
}
20+
21+
render() {
22+
return (
23+
<div>
24+
<Alert color="primary" isOpen={this.state.visible} toggle={this.onDismiss} fade={false}>
25+
I am a primary alert and I can be dismissed without animating!
26+
</Alert>
27+
</div>
28+
);
29+
}
30+
}
31+
32+
export function UncontrolledAlertFadelessExample() {
33+
return (
34+
<div>
35+
<UncontrolledAlert color="info" fade={false}>
36+
I am an alert and I can be dismissed without animating!
37+
</UncontrolledAlert>
38+
</div>
39+
);
40+
}

src/Alert.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const propTypes = {
1111
closeAriaLabel: PropTypes.string,
1212
cssModule: PropTypes.object,
1313
color: PropTypes.string,
14+
fade: PropTypes.bool,
1415
isOpen: PropTypes.bool,
1516
toggle: PropTypes.func,
1617
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
@@ -22,6 +23,7 @@ const defaultProps = {
2223
isOpen: true,
2324
tag: 'div',
2425
closeAriaLabel: 'Close',
26+
fade: true,
2527
transition: {
2628
...Fade.defaultProps,
2729
unmountOnExit: true,
@@ -40,6 +42,7 @@ function Alert(props) {
4042
toggle,
4143
children,
4244
transition,
45+
fade,
4346
...attributes
4447
} = props;
4548

@@ -52,8 +55,15 @@ function Alert(props) {
5255

5356
const closeClasses = mapToCssModules(classNames('close', closeClassName), cssModule);
5457

58+
const alertTransition = {
59+
...Fade.defaultProps,
60+
...transition,
61+
baseClass: fade ? transition.baseClass : '',
62+
timeout: fade ? transition.timeout : 0,
63+
};
64+
5565
return (
56-
<Fade {...attributes} {...transition} tag={Tag} className={classes} in={isOpen} role="alert">
66+
<Fade {...attributes} {...alertTransition} tag={Tag} className={classes} in={isOpen} role="alert">
5767
{toggle ?
5868
<button type="button" className={closeClasses} aria-label={closeAriaLabel} onClick={toggle}>
5969
<span aria-hidden="true">&times;</span>

src/UncontrolledAlert.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import Alert from './Alert';
33

4-
export default class UncontrolledAlert extends Component {
4+
class UncontrolledAlert extends Component {
55
constructor(props) {
66
super(props);
77

@@ -17,3 +17,5 @@ export default class UncontrolledAlert extends Component {
1717
return <Alert isOpen={this.state.isOpen} toggle={this.toggle} {...this.props} />;
1818
}
1919
}
20+
21+
export default UncontrolledAlert;

0 commit comments

Comments
 (0)