Buttons
import React from 'react';
import { Button } from 'reactstrap';
const Example = (props) => {
return (
<div>
<Button color="primary">primary</Button>{' '}
<Button color="secondary">secondary</Button>{' '}
<Button color="success">success</Button>{' '}
<Button color="info">info</Button>{' '}
<Button color="warning">warning</Button>{' '}
<Button color="danger">danger</Button>{' '}
<Button color="link">link</Button>
</div>
);
}
export default Example;
Properties
Button.propTypes = {
active: PropTypes.bool,
'aria-label': PropTypes.string,
block: PropTypes.bool,
color: PropTypes.string, // default: 'secondary'
disabled: PropTypes.bool,
outline: PropTypes.bool,
// Pass in a Component to override default button element
// example: react-router Link
// default: 'button'
tag: PropTypes.oneOfType([
PropTypes.func,
PropTypes.string,
PropTypes.shape({ $$typeof: PropTypes.symbol, render: PropTypes.func }),
PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.func,
PropTypes.string,
PropTypes.shape({ $$typeof: PropTypes.symbol, render: PropTypes.func }),
]))
]),
// ref will only get you a reference to the Button component, use innerRef to get a reference to the DOM element (for things like focus management).
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
onClick: PropTypes.func,
size: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
cssModule: PropTypes.object,
// use close prop for BS4 close icon utility
close: PropTypes.bool,
}
Button.defaultProps = {
color: 'secondary',
tag: 'button',
}
import React from 'react';
import { Button } from 'reactstrap';
const Example = (props) => {
return (
<div>
<Button outline color="primary">primary</Button>{' '}
<Button outline color="secondary">secondary</Button>{' '}
<Button outline color="success">success</Button>{' '}
<Button outline color="info">info</Button>{' '}
<Button outline color="warning">warning</Button>{' '}
<Button outline color="danger">danger</Button>
</div>
);
}
export default Example;
Sizes
<Button color="primary" size="lg">Large Button</Button>{' '}
<Button color="secondary" size="lg">Large Button</Button>
<Button color="primary" size="sm">Small Button</Button>{' '}
<Button color="secondary" size="sm">Small Button</Button>
<Button color="primary" size="lg" block>Block level button</Button>
<Button color="secondary" size="lg" block>Block level button</Button>
Active State
<Button color="primary" size="lg" active>Primary link</Button>{' '}
<Button color="secondary" size="lg" active>Link</Button>
Disabled State
<Button color="primary" size="lg" disabled>Primary button</Button>{' '}
<Button color="secondary" size="lg" disabled>Button</Button>
In order to have checkbox and radio buttons, your component needs to manage the state of which button(s) are active/select. It is not in the opinion of this library to manage state within it's components so it is left up to you. Below is a simple example showcasing how this could be done using the components which already exist in this library.
Radio Buttons
Selected:
Checkbox Buttons
Selected: []
import React, { useState } from 'react';
import { Button, ButtonGroup } from 'reactstrap';
const Example = (props) => {
const [cSelected, setCSelected] = useState([]);
const [rSelected, setRSelected] = useState(null);
const onCheckboxBtnClick = (selected) => {
const index = cSelected.indexOf(selected);
if (index < 0) {
cSelected.push(selected);
} else {
cSelected.splice(index, 1);
}
setCSelected([...cSelected]);
}
return (
<div>
<h5>Radio Buttons</h5>
<ButtonGroup>
<Button color="primary" onClick={() => setRSelected(1)} active={rSelected === 1}>One</Button>
<Button color="primary" onClick={() => setRSelected(2)} active={rSelected === 2}>Two</Button>
<Button color="primary" onClick={() => setRSelected(3)} active={rSelected === 3}>Three</Button>
</ButtonGroup>
<p>Selected: {rSelected}</p>
<h5>Checkbox Buttons</h5>
<ButtonGroup>
<Button color="primary" onClick={() => onCheckboxBtnClick(1)} active={cSelected.includes(1)}>One</Button>
<Button color="primary" onClick={() => onCheckboxBtnClick(2)} active={cSelected.includes(2)}>Two</Button>
<Button color="primary" onClick={() => onCheckboxBtnClick(3)} active={cSelected.includes(3)}>Three</Button>
</ButtonGroup>
<p>Selected: {JSON.stringify(cSelected)}</p>
</div>
);
}
export default Example;
Close icon
Use a generic close icon to dismiss content. Use <Button close />
for the default icon. Otherwise, custom content for the button may be defined. (e.g. JSX: <Button close><span aria-hidden="true">–</span></Button>
) The default aria-label is "Close".
Custom content and aria-label
import React, { Component } from 'react';
import { Button, Card, CardBody, CardText, CardGroup, CardTitle } from 'reactstrap';
const Example = () => (
<div>
<CardGroup>
<Card>
<CardBody>
<CardTitle>
<Button close />
</CardTitle>
<CardText>Default close icon</CardText>
</CardBody>
</Card>
<Card>
<CardBody>
<CardTitle>
<Button close aria-label="Cancel">
<span aria-hidden>–</span>
</Button>
</CardTitle>
<CardText>
Custom content and aria-label
</CardText>
</CardBody>
</Card>
</CardGroup>
</div>
);
export default Example;
Button toggle state
import React from "react";
import { ButtonToggle } from "reactstrap";
class Example extends React.Component {
render() {
return (
<div>
<ButtonToggle color="primary">primary</ButtonToggle>{' '}
<ButtonToggle color="secondary">secondary</ButtonToggle>{' '}
<ButtonToggle color="success">success</ButtonToggle>{' '}
<ButtonToggle color="info">info</ButtonToggle>{' '}
<ButtonToggle color="warning">warning</ButtonToggle>{' '}
<ButtonToggle color="danger">danger</ButtonToggle>{' '}
</div>
);
}
}
export default Example;