bs4react v0.1.9
bs4react
A Collection of React components for Bootstrap 4. Use props to customize the bootstrap classes applied to elements.
Bootstrap
The classes assigned to the components correlate to Bootstrap v4.0.0-alpha.6 and using a different version will result in unexpected behavior. At this point in time, Bootstrap is not required or included in this package. Please use one of the methods outlined in their docs to access Bootstrap in your project.
Get Started
Make sure you have also installed Bootstrap, React, ReactDom, and classNames
npm i -D bs4react
or yarn add -D bs4react
import { Container, Row, Col } from 'bs4react'
//...
return (
<Container bg="primary" textColor="white" fluid>
<Row>
<Col>
Produce a div with a class of "col"
<Col>
<Col gridWidth="4">
Produce a div with a class of "col-4"
</Col>
<Col gridWidth={['4', 'md-6']}>
Produce a div with classes of "col-4" and "col-md-6"
</Col>
<Col className="foo">
Produce a div with classes of "col" and "foo" - Props that are not explicitly consumed by the component are passed through.
</Col>
</Row>
</Container>
)
Components Included
Utility
Utility
is a High Order Component that every other component uses as a wrapper via the withUtility
function. Composing the components in this way allows the following props to be used on any of the components provided:
Prop | Type | Class Produced |
---|---|---|
alignContent | string or array | align-content-* |
alignItems | string or array | align-items-* |
alignSelf | string or array | align-self-* |
bg | string | bg-* |
border | string | border-* |
clearfix | boolean | clearfix |
display | string or array | d-* |
embed | boolean or string | embed-responsive + embed-responsive-* |
flexDirection | string or array | flex-* |
flexOrder | string or array | flex-* |
flexWrap | string or array | flex-* |
float | string or array | float-* |
fontWeight | string | font-weight-* |
height | string or number | h-* |
hidden | string | hidden-* |
invisible | boolean | invisible |
italic | boolean | font-italic |
justifyContent | string or array | justify-content-* |
margin | string or array | m-* |
marginBot | string or array | mb-* |
marginLeft | string or array | ml-* |
marginRight | string or array | mr-* |
marginTop | string or array | mt-* |
marginX | string or array | mx-* |
marginY | string or array | my-* |
maxHeight | boolean | mh-100 |
maxWidth | boolean | mw-100 |
padding | string or array | p-* |
paddingBot | string or array | pb-* |
paddingLeft | string or array | pl-* |
paddingRight | string or array | pr-* |
paddingTop | string or array | pt-* |
paddingX | string or array | px-* |
paddingY | string or array | py-* |
position | string | * |
print | string | visible-print-* or hidden-print |
rounded | boolean or string | rounded or rounded-* |
srOnly | boolean or string | sr-only + sr-only-* |
textAlign | string or array | text-* |
textColor | string | text-* |
textTransform | string | text-* |
vertAlign | string | align-* |
width | string | w-* |
It is important to note that more advanced PropType validation based on the classes provided by bootstrap is done within each component. For example, supplying a component with bg="foo"
will produce an invalid PropType error. However, that component would still receive a class of bg-foo
.
Utility props on custom components
To make the utility props available in a custom component, simply supply that component as an argument to withUtilities()
.
import { withUtilities } from 'bs4react'
//...
const CustomComponentWithUtilities = withUtilities(
CustomComponent,
)
export default CustomComponentWithUtilities
Make sure you do not use the withUtilities function from within a render method
Btn
btn
class is always applied
If a value for href
is passed in, the Btn
component will return an <a>
element. Otherwise, it will default to a button
Prop | Type | Class Produced |
---|---|---|
active | boolean | active |
block | boolean | btn-block |
disabled | boolean | disabled - as an attribute if it's a <button> |
outline | boolean | btn-outline-{theme} - theme required |
size | string | btn-* |
theme | string | btn-* |
Col
col
is applied if no gridWidth is defined. The col
class can also be applied by passing undefined
or null
to the gridWidth
prop.
Produces a <div
element.
Prop | Type | Class Produced |
---|---|---|
gridOffset | string or array | offset-* |
gridWidth | string or array | col-* |
Container
container
class is always applied to a <div>
element.
Prop | Type | Class Produced |
---|---|---|
fluid | bool | container-fluid |
Jumbotron
jumbotron
class is always applied to a <section>
element
Prop | Type | Class Produced |
---|---|---|
fluid | bool | jumbotron-fluid |
Nav
NavLink
nav-link
is always applied. NavLink
always produces an <li>
element that wraps an <a>
element.
Prop | Type | Class Produced |
---|---|---|
active | boolean | active |
disabled | boolean | disabled |
Navbar
navbar
class is always applied to a <nav>
element.
Prop | Type | Class Produced |
---|---|---|
theme | string | light or inverse |
toggleable | string | navbar-toggleable-* |
NavbarBrand
navbar-brand
class is always applied to an <a>
element.
NavbarCollapse
collapse
and navbar-collapse
are alway applied to a <div>
element with id="navbarToggleTarget"
.
NavbarNav
navbar-nav
is always applied to an <ul>
element.
NavbarToggler
navbar-toggler
is always applied to a <button>
element with data-target="#navbarToggleTarget"
as well as other accessibility-based roles.
Prop | Type | Class Produced |
---|---|---|
align | string | navbar-toggler-* |
Row
row
is always applied to a <div>
element.
Prop | Type | Class Produced |
---|---|---|
gutters | boolean | no-gutters if false |
TODOS
- Create React wrapper components for the remaining Bootstrap components
- Rewrite Bootstrap's javascript functionality to utilize React (Probably via additional HOCs)
- Find a way to include styles from Bootstrap
- Sass? CSS-Modules? Something Else?
- Should provide an easy way to use custom variables
- Components should have access to the custom variables
- Would a configuration
.bootstraprc
make sense?
- Create a best-practice for customizing/modifying the standard components
- For example: if theme developers would like to make
primaryGradient
pass the prop validation forbg
, where should they put that change?
- For example: if theme developers would like to make
- Add tests