Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Research - Bootstrap Integration with React #19

Closed
jamescd18 opened this issue Jan 27, 2021 · 5 comments
Closed

Research - Bootstrap Integration with React #19

jamescd18 opened this issue Jan 27, 2021 · 5 comments
Assignees
Labels
approved Reviewed by admins and ready for development front-end Visual layout, styling, or view-specific issues

Comments

@jamescd18
Copy link
Member

Research various options for integrating bootstrap with React to cut down development time. Potentially react-bootstrap (main site) or reactstrap.

Also possibly look into Awesome React Bootstrap Components and react-router-bootstrap.

@jamescd18 jamescd18 added the front-end Visual layout, styling, or view-specific issues label Jan 27, 2021
@jamescd18 jamescd18 added this to the 0.1.4 - Front-End Setup milestone Jan 29, 2021
@aschimmichanga aschimmichanga self-assigned this Jan 31, 2021
@albeartoz
Copy link

albeartoz commented Feb 2, 2021

Bootstrap

A responsive CSS framework.
Current release (Bootstrap 4) uses jQuery, but latest release (Bootstrap 5 beta) drops this for vanilla JS.

List of options for bootstrapping our React app

The three most common ways to add Bootstrap to a React app is BootstrapCDN, import Bootstrap as a dependency,
and using a React Bootstrap package such as bootstrap-react or reactstrap. We'll look at all 3 options.

BootstrapCDN

Just put this code block into the <head> section of index.html:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" 
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" 
crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" 
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" 
integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" 
crossorigin="anonymous"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" 
integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" 
crossorigin="anonymous"></script>

Seems like we need jQuery and Popper.js to use Bootstrap's JS components,
but afterwards we can start using Bootstrap classes/JS components in our React components.

Importing Bootstrap as a dependency

npm install bootstrap

We also need jQuery and Popper to make use of Bootstrap's JS components and not just Bootstrap's classes.

npm install jquery popper.js

Add this to index.js:

import 'bootstrap/dist/css/bootstrap.min.css';
import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<Dropdown />, document.getElementById('root'));
registerServiceWorker();

And done!

Reactstrap

  • Both Reactstrap and React-bootstrap use Bootstrap 4
  • Does not depend on jQuery or Bootstrap JS components. However, Popper is required for mor advanced control.
  • Content should be composed via props.children rather that using named props to pass in React components.
  • Attributes in this library are used to pass state, apply modifiers, and more. Ex) isOpen refers to the state of a dropdown menu
  • Seems to prefer class components
  • According to a guy on stackoverflow, this seems to be closer to web dev, while react-bootstrap is closer to using React Native? I've never used react native though

Example code:

import React from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';

class ModalExample extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      modal: false
    };

    this.toggle = this.toggle.bind(this);
  }

  toggle() {
    this.setState(prevState => ({
      modal: !prevState.modal
    }));
  }

  render() {
    return (
      <div>
        <Button color="danger" onClick={this.toggle}>{this.props.buttonLabel}</Button>
        <Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className}>
          <ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
          <ModalBody>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          </ModalBody>
          <ModalFooter>
            <Button color="primary" onClick={this.toggle}>Do Something</Button>{' '}
            <Button color="secondary" onClick={this.toggle}>Cancel</Button>
          </ModalFooter>
        </Modal>
      </div>
    );
  }
}

export default ModalExample; 

React-bootstrap

  • Very similar to Reactstrap in that it does not depend on jQuery or Bootstrap JS components.
  • Instead of using Bootstrap js, react-strap lets you use Bootstrap within React-styled components
  • State passed within react-bootstrap components as a prop
  • Seems to prefer functions and hooks
  • Uses a grid system and Flexbox to layout content

Example code:

function AlertDismissible() {
  const [show, setShow] = useState(true);

  return (
    <>
      <Alert show={show} variant="success">
        <Alert.Heading>How's it going?!</Alert.Heading>
        <p>
          Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget
          lacinia odio sem nec elit. Cras mattis consectetur purus sit amet
          fermentum.
        </p>
        <hr />
        <div className="d-flex justify-content-end">
          <Button onClick={() => setShow(false)} variant="outline-success">
            Close me y'all!
          </Button>
        </div>
      </Alert>

      {!show && <Button onClick={() => setShow(true)}>Show Alert</Button>}
    </>
  );
}

render(<AlertDismissible />);

My thoughts

It looks like react-bootstrap and reactstrap are similar enough that it's hard to go wrong choosing either one.
If we want to go with jQuery and Bootstrap.js components, I'd go with the other two options, but I think we can drop these.
Here's a couple articles on the difference between the two libraries, and they all kind of say the same thing: use your preference.
[1] [2]

Alternatives to Bootstrap?

Should I do research on these as well, or are we sticking to Bootstrap?

  • Bootstrap 5 - currently in beta, but it should just work alongside React
  • TailwindCSS - another CSS framework
  • Foundation - another CSS framework
  • Bulma - another CSS framework based on Flexbox
  • PrimeReact - Just a large collection of React components and styles
  • Material UI - Another collection of React components, already styled

@albeartoz
Copy link

I'll look into Awesome React Bootstrap Components and react-router-bootstrap tomorrow!

@jamescd18
Copy link
Member Author

Thank you! This is super thorough! I think we'll probably stick with some form of bootstrap for now. That said, looking through the various other options it seems like we theoretically could end up running into situations where we might want more customization like that of TailwindCSS or more different component selection, but we'll cross that bridge when we get there. Bootstrap-based styling should be more than enough to get us off the ground.

When it comes to our particular application and deciding what styling to use, there's a few important things to consider. We're building a data-first web application primarily for desktop only. Beautification and responsiveness to work on other platforms is sorta incidental. While Material UI and PrimeReact are perhaps a little more "modern" looking, they have a variety of design decisions and animations that make them much better suited for crowded screens on mobile. As such, I think Boostrap's simplistic philosophy fits better for our app.

When it comes to React, everything I know seems to suggest that hooks with functional components are basically equal if not better than class components with constructor local state. This is really great research, and I'm looking forward to hearing your thoughts on the two supplemental packages. Unless something else comes up, it looks to me like we'll go ahead and choose react-bootstrap given about 2x popularity and its reference of the two supplemental packages. As always, let me know your thoughts too! And feel free to open PR linked to this issue that updates the README to reflect this decision. Thank you Albert!

@jamescd18
Copy link
Member Author

As is implemented in #74, we'll be using Bootstrap 4 in combination with react-bootstrap-table-next (aka react-bootstrap-table2).

jamescd18 added a commit that referenced this issue Feb 8, 2021
@jamescd18 jamescd18 added the approved Reviewed by admins and ready for development label Feb 11, 2021
@jamescd18
Copy link
Member Author

Marking this as closed and decided.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Reviewed by admins and ready for development front-end Visual layout, styling, or view-specific issues
Projects
None yet
Development

No branches or pull requests

4 participants