Alerts
import React from 'react';
import { Alert } from 'reactstrap';
const Example = (props) => {
return (
<div>
<Alert color="primary">
This is a primary alert — check it out!
</Alert>
<Alert color="secondary">
This is a secondary alert — check it out!
</Alert>
<Alert color="success">
This is a success alert — check it out!
</Alert>
<Alert color="danger">
This is a danger alert — check it out!
</Alert>
<Alert color="warning">
This is a warning alert — check it out!
</Alert>
<Alert color="info">
This is a info alert — check it out!
</Alert>
<Alert color="light">
This is a light alert — check it out!
</Alert>
<Alert color="dark">
This is a dark alert — check it out!
</Alert>
</div>
);
};
export default Example;
Properties
Alert.propTypes = {
className: PropTypes.string,
closeClassName: PropTypes.string,
color: PropTypes.string, // default: 'success'
isOpen: PropTypes.bool, // default: true
toggle: PropTypes.func,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
fade: PropTypes.bool, // default: true
// Controls the transition of the alert fading in and out
// See Fade for more details
transition: PropTypes.shape(Fade.propTypes),
}
Link color
import React from 'react';
import { Alert } from 'reactstrap';
const Example = (props) => {
return (
<div>
<Alert color="primary">
This is a primary alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="secondary">
This is a secondary alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="success">
This is a success alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="danger">
This is a danger alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="warning">
This is a warning alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="info">
This is a info alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="light">
This is a light alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
<Alert color="dark">
This is a dark alert with <a href="#" className="alert-link">an example link</a>. Give it a click if you like.
</Alert>
</div>
);
};
export default Example;
Additional content
import React from 'react';
import { Alert } from 'reactstrap';
const Example = (props) => {
return (
<div>
<Alert color="success">
<h4 className="alert-heading">Well done!</h4>
<p>
Aww yeah, you successfully read this important alert message. This example text is going
to run a bit longer so that you can see how spacing within an alert works with this kind
of content.
</p>
<hr />
<p className="mb-0">
Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
</p>
</Alert>
</div>
);
};
export default Example;
Dismissing
import React from 'react';
import { Alert } from 'reactstrap';
class AlertExample extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: true
};
this.onDismiss = this.onDismiss.bind(this);
}
onDismiss() {
this.setState({ visible: false });
}
render() {
return (
<Alert color="info" isOpen={this.state.visible} toggle={this.onDismiss}>
I am an alert and I can be dismissed!
</Alert>
);
}
}
export default AlertExample;
Uncontrolled [disable] Alerts
For the most basic use-case an uncontrolled component can provide the functionality wanted without the need to manage/control the state of the component. UncontrolledAlert
does not require isOpen
nor toggle
props to work.
import React from 'react';
import { UncontrolledAlert } from 'reactstrap';
function AlertExample() {
return (
<UncontrolledAlert color="info">
I am an alert and I can be dismissed!
</UncontrolledAlert>
);
}
export default AlertExample;
Alerts without fade
Fade can be disabled using fade=false
.
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 (
<div>
<Alert color="primary" isOpen={this.state.visible} toggle={this.onDismiss} fade={false}>
I am a primary alert and I can be dismissed without animating!
</Alert>
</div>
);
}
}
export function UncontrolledAlertFadelessExample() {
return (
<div>
<UncontrolledAlert color="info" fade={false}>
I am an alert and I can be dismissed without animating!
</UncontrolledAlert>
</div>
);
}
当前内容版权归 reactstrap 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 reactstrap .