UNPKG

10.6 kBMarkdownView Raw
1[![reactstrap](https://cloud.githubusercontent.com/assets/399776/13906899/1de62f0c-ee9f-11e5-95c0-c515fee8e918.png)](https://reactstrap.github.io)
2
3[![CDNJS](https://img.shields.io/cdnjs/v/reactstrap.svg)](https://cdnjs.com/libraries/reactstrap) [![NPM Version](https://img.shields.io/npm/v/reactstrap.svg?branch=master)](https://www.npmjs.com/package/reactstrap) [![Build Status](https://travis-ci.org/reactstrap/reactstrap.svg?branch=master)](https://travis-ci.org/reactstrap/reactstrap) [![Coverage Status](https://coveralls.io/repos/github/reactstrap/reactstrap/badge.svg?branch=master)](https://coveralls.io/github/reactstrap/reactstrap?branch=master) [![License](https://img.shields.io/npm/l/reactstrap.svg)](https://github.com/reactstrap/reactstrap/blob/master/LICENSE)
4
5# reactstrap
6
7Stateless React Components for Bootstrap 4.
8
9## Getting Started
10
11Follow the [create-react-app instructions](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md) **up to** the `Adding Bootstrap` section and instead follow the reactstrap version of [adding bootstrap](#adding-bootstrap).
12
13### tl;dr
14
15 ```
16npx create-react-app my-app
17cd my-app/
18npm start
19```
20or, if npx (Node >= 6 and npm >= 5.2 ) not available
21
22```
23npm install -g create-react-app
24
25create-react-app my-app
26cd my-app/
27npm start
28```
29
30Then open [http://localhost:3000/](http://localhost:3000/) to see your app. The initial structure of your app is setup. Next, let's [add reactstrap and bootstrap](#adding-bootstrap).
31
32### Adding Bootstrap
33
34Install reactstrap and Bootstrap from NPM. Reactstrap does not include Bootstrap CSS so this needs to be installed as well:
35
36```
37npm install --save bootstrap
38npm install --save reactstrap react react-dom
39```
40
41Import Bootstrap CSS in the ```src/index.js``` file:
42
43```js
44import 'bootstrap/dist/css/bootstrap.css';
45```
46
47Import required reactstrap components within ```src/App.js``` file or your custom component files:
48
49```js
50import { Button } from 'reactstrap';
51```
52
53Now you are ready to use the imported reactstrap components within your component hierarchy defined in the render
54method. Here is an example [`App.js`](https://gist.github.com/Thomas-Smyth/006fd507a7295f17a8473451938f9935) redone
55using reactstrap.
56
57### Dependencies
58
59##### Required Peer Dependencies
60
61These libraries are not bundled with Reactstrap and required at runtime:
62
63 * [**react**](https://www.npmjs.com/package/react)
64 * [**react-dom**](https://www.npmjs.com/package/react-dom)
65
66##### Optional Dependencies
67
68These libraries are not included in the main distribution file `reactstrap.min.js` and need to be manually
69included when using components that require transitions or popover effects (e.g. Tooltip, Modal, etc).
70
71 * [**react-transition-group**](https://www.npmjs.com/package/react-transition-group)
72 * [**react-popper**](https://www.npmjs.com/package/react-popper)
73
74
75### CDN
76
77If you prefer to include Reactstrap globally by marking `reactstrap` as external in your application, the
78`reactstrap` library provides various single-file distributions, which are hosted on the following CDNs:
79
80* [**cdnjs**](https://cdnjs.com/libraries/reactstrap)
81```html
82<!-- Main version -->
83<script src="https://cdnjs.cloudflare.com/ajax/libs/reactstrap/6.0.1/reactstrap.min.js"></script>
84
85<!-- All optional dependencies version -->
86<script src="https://cdnjs.cloudflare.com/ajax/libs/reactstrap/6.0.1/reactstrap.full.min.js"></script>
87```
88
89* [**unpkg**](https://unpkg.com/reactstrap/)
90```html
91<!-- Main version -->
92<script src="https://unpkg.com/reactstrap@6.0.1/dist/reactstrap.min.js"></script>
93
94<!-- All optional dependencies version -->
95<script src="https://unpkg.com/reactstrap@6.0.1/dist/reactstrap.full.min.js"></script>
96```
97
98> **Note**: To load a specific version of Reactstrap replace `6.0.1` with the version number.
99
100#### Versions
101
102Reactstrap has two primary distribution versions:
103
1041) `reactstrap.min.js`
105
106 This file **excludes** the optional dependencies – `react-popper` and `react-transition-group`.
107 This is the recommended approach (similar approach in Bootstrap's JavaScript components) for including
108 Reactstrap as it reduces the filesize and gives more flexibility in configuring needed dependencies.
109
110 **Recommended use cases:**
111
112 * Small, medium, or large applications
113 * Applications that do not use any transitions or popper components
114 * Applications that directly use `react-popper` or `react-transition-group` – Reactstrap and your application
115 will use the single global version included
116
117 2) `reactstrap.full.min.js`
118
119 This file **includes** the optional dependencies – `react-popper` and `react-transition-group`
120
121 **Recommended use cases:**
122
123 * Small applications
124
125
126#### Example
127
128```html
129<!doctype html>
130<html lang="en">
131 <head>
132 <!-- Required dependencies -->
133 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.1/prop-types.min.js"></script>
134 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/16.3.2/umd/react.production.min.js"></script>
135 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react-dom/16.3.2/umd/react-dom.production.min.js"></script>
136 <!-- Optional dependencies -->
137 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react-transition-group/2.2.1/react-transition-group.min.js"></script>
138 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
139 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react-popper/0.10.4/umd/react-popper.min.js"></script>
140 <!-- Reactstrap -->
141 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/reactstrap/6.0.1/reactstrap.min.js"></script>
142 <!-- Lastly, include your app's bundle -->
143 <script type="text/javascript" src="/assets/bundle.js"></script>
144 </head>
145 <body>
146 <div id="my-app" />
147 </body>
148</html>
149```
150
151## About the Project
152
153This library contains React Bootstrap 4 components that favor composition and control. The library does not depend on jQuery or Bootstrap javascript. However, [Poppers.js](https://popper.js.org/) via [react-popper](https://github.com/souporserious/react-popper) is relied upon for advanced positioning of content like Tooltips, Popovers, and auto-flipping Dropdowns.
154
155There are a few core concepts to understand in order to make the most out of this library.
156
1571. Your content is expected to be composed via props.children rather than using named props to pass in Components.
158
159 ```js
160 // Content passed in via props
161 const Example = (props) => {
162 return (
163 <p>This is a tooltip <TooltipTrigger tooltip={TooltipContent}>example</TooltipTrigger>!</p>
164 );
165 }
166
167 // Content passed in as children (Preferred)
168 const PreferredExample = (props) => {
169 return (
170 <p>
171 This is a <a href="#" id="TooltipExample">tooltip</a> example.
172 <Tooltip target="TooltipExample">
173 <TooltipContent/>
174 </Tooltip>
175 </p>
176 );
177 }
178 ```
179
1802. 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.
181
182 Examples:
183
184 - `isOpen` - current state for items like dropdown, popover, tooltip
185 - `toggle` - callback for toggling `isOpen` in the controlling component
186 - `color` - applies color classes, ex: `<Button color="danger"/>`
187 - `size` - for controlling size classes. ex: `<Button size="sm"/>`
188 - `tag` - customize component output by passing in an element name or Component
189 - boolean based props (attributes) when possible for alternative style classes or `sr-only` content
190
191
192## [Documentation](https://reactstrap.github.io)
193
194https://reactstrap.github.io
195
196Documentation search is powered by [Algolia's DocSearch](https://community.algolia.com/docsearch/).
197
198## [Contributing](CONTRIBUTING.md)
199
200## Development
201
202Install dependencies:
203
204```sh
205npm install
206```
207
208Run examples at [http://localhost:8080/](http://localhost:8080/) with webpack dev server:
209
210```sh
211npm start
212```
213
214Run tests & coverage report:
215
216```sh
217npm test
218```
219
220Watch tests:
221
222```sh
223npm run test-watch
224```
225
226## Releasing
227
228#### Create Release Branch
229
230Note: you must have the `GITHUB_TOKEN` environment variable set to a valid GitHub token with write access to your repo.
231
232To create a release branch and changelog, run the following command, optionally with a semantic release type (major, minor, patch) (if not provided, it will default to semver (it's best to let it default)):
233
234```bash
235./scripts/release <release-type>
236```
237
238Verify changelog in branch. Create a PR if everything looks good. Merge when tests are green.
239
240#### Tagging and Publishing
241
242Note: you must have write permission to this repo do perform this action
243
244Once the release branch is merged, checkout master and run:
245
246```bash
247./scripts/publish
248```
249
250This will build the current state of master, tag it based on the release version and push the tag up to GitHub. Travis will detect the new tag and publish to npm.
251
252_OR_
253
254You can create a new tag via the GitHub user interface. If you do it this way, make sure to use the correct version as the tag name (eg. `6.2.0`).
255
256## In the wild
257
258Organizations and projects using `reactstrap`
259
260- [availity-reactstrap-validation](https://availity.github.io/availity-reactstrap-validation/)
261- [component-template](https://reactstrap.github.io/component-template/)
262- [video-react](https://video-react.github.io/)
263- [CoreUI-Free-Bootstrap-Admin-Template](https://github.com/mrholek/CoreUI-Free-Bootstrap-Admin-Template) - [demo](http://coreui.io/demo/React_Demo/#/)
264- [Admin dashboard example app built with reactstrap](https://github.com/reduction-admin/react-reduction) - [demo](https://reduction-admin.firebaseapp.com/)
265- [DevExtreme React Grid](https://devexpress.github.io/devextreme-reactive/react/grid/) - It's a stateless data grid built on top of `reactstrap` with paging, sorting, filtering, grouping, selection, editing and virtual scrolling features.
266- [DevExtreme React Chart](https://devexpress.github.io/devextreme-reactive/react/chart/) - A chart built on top of `reactstrap` that visualizes data using a variety of series types, including bar, line, area, scatter, pie, and more.
267
268Submit a PR to add to this list!
269
270Looking to build, document and publish reusable components built on top of `reactstrap`? Consider forking https://github.com/reactstrap/component-template to kickstart your project!