Easy to use React Bootstrap 4 components compatible with React 0.14.x and 15.x.
Install reactstrap and peer dependencies via NPM
npm install --save reactstrap react-addons-transition-group react-addons-css-transition-group react react-domImport the components you need, example:
import { Button, Popover, Tooltip } from 'reactstrap';You don’t have to use Reactstrap together with React but it is a popular library for integrating Bootstrap with React apps. If you need it, you can integrate it with Create React App by following these steps:
Install Reactstrap and Bootstrap from NPM. Reactstrap does not include Bootstrap CSS so this needs to be installed as well:
npm install reactstrap --save
npm install bootstrap@4.0.0-alpha.5 --save
Import Bootstrap CSS in the src/index.js file:
import 'bootstrap/dist/css/bootstrap.css';Import required Reactstrap components within src/App.js file or your custom component files:
import { Navbar, Jumbotron, Button } from 'reactstrap';Now you are ready to use the imported Reactstrap components within your component hierarchy defined in the render method. Here is an example App.js redone using Reactstrap:
import React, { Component } from 'react';
import { Grid, Navbar, Jumbotron, Button } from 'reactstrap';
class App extends Component {
render() {
return (
<div>
<Navbar color="faded" light>
<NavbarBrand href="/">reactstrap</NavbarBrand>
<Nav className="pull-xs-right" navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">Github</NavLink>
</NavItem>
</Nav>
</Navbar>
<Jumbotron>
<Grid>
<h1>Welcome to Reactstrap</h1>
<p>
<Button
color="success"
size="lg">
View Reactstrap Docs
</Button>{'http://reactstrap.github.io/components/buttons/'}
</p>
</Grid>
</Jumbotron>
</div>
);
}
}
export default App;This library contains React Bootstrap 4 components that favor composition and control. The library does not depend on jQuery or Bootstrap javascript. However, Tether is relied upon for advanced positioning of content like Tooltips, Popovers, and auto-flipping Dropdowns.
There are a few core concepts to understand in order to make the most out of this library.
-
Your content is expected to be composed via props.children rather than using named props to pass in Components.
// Content passed in via props const Example = (props) => { return ( <p>This is a tooltip <TooltipTrigger tooltip={TooltipContent}>example</TooltipTrigger>!</p> ); } // Content passed in as children (Preferred) const PreferredExample = (props) => { return ( <p> This is a <a href="#" id="TooltipExample">tooltip</a> example. <Tooltip target="TooltipExample"> <TooltipContent/> </Tooltip> </p> ); }
-
Attributes in this library are used to pass in state, conveniently apply modifier classes, enable advanced functionality (like tether), or automatically include non-content based elements.
Examples:
isOpen- current state for items like dropdown, popover, tooltiptoggle- callback for togglingisOpenin the controlling componentcolor- applies color classes, ex:<Button color="danger"/>size- for controlling size classes. ex:<Button size="sm"/>tag- customize component output by passing in an element name or Component- boolean based props (attributes) when possible for alternative style classes or
sr-onlycontent
Install dependencies:
npm installRun examples at http://localhost:8080/ with webpack dev server:
npm startRun tests & coverage report:
npm testWatch tests:
npm run test-watchOrganizations and projects using reactstrap
Submit a PR to add to this list!
Looking to build, document and publish reusable components built on top of reactstrap? Consider forking https://github.com/reactstrap/component-template to kickstart your project!
