Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change colors for a button in react-bootstrap?

I know that changing colors is very difficult in react-bootstrap, but I would like to have my button with a color that isn't a primary color. How can I do this in JS/SCSS?

like image 250
qazwsxedcrfvtgbyhn Avatar asked Jun 13 '18 16:06

qazwsxedcrfvtgbyhn


People also ask

How do I change the color of a button in React?

To change background color on click in React:Set the onClick prop on the element. When the element is clicked, set the active state. Use a ternary operator to conditionally set the background color based on the state variable.

How do I customize Bootstrap in React?

To customize Bootstrap, create a file called src/custom. scss (or similar) and import the Bootstrap source stylesheet. Add any overrides before the imported file(s). You can reference Bootstrap's documentation for the names of the available variables.

How do you change the component on a button click in React?

We have to set initial state value inside constructor function and set click event handler of the element upon which click, results in changing state. Then pass the function to the click handler and change the state of the component inside the function using setState.

How do I give a button a color in HTML?

Type background-color: in the quotation marks after "style=". This element is used to change the background color of the button. Type a color name or hexadecimal code after "background-color:". You can type name of a color (i.e, blue) or a hexadecimal color.


3 Answers

const App = () => (
  <div className="content">
    <ReactBootstrap.Button bsStyle="primary">Default Button</ReactBootstrap.Button>
    <ReactBootstrap.Button bsClass="custom-btn">Custom Button</ReactBootstrap.Button>
  </div>
);

ReactDOM.render(
  <App />,
  document.getElementById("react")
);
.content {
  padding: 10px;
}

.custom-btn {
  background: #fff;
  color: red;
  border: 2px solid red;
  border-radius: 3px;
  padding: 5px 10px;
  text-transform: uppercase;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.32.1/react-bootstrap.min.js"></script>


<div id="react"></div>

To add the specific styling to react-bootstrap <Button /> component, simply use bsClass property

Taken from the official docs

like image 180
inaumov17 Avatar answered Oct 17 '22 19:10

inaumov17


In a pinch, I was able to use inline-style for some simple styling of buttons in ReactStrap.

import React from 'react';
import { Button } from 'reactstrap';

const PageButtons = (props) => {

return (

        <div>
        {!props.data.previous ? null : <Button style={{color:"#00005c", margin: "5%", boxShadow: "5px 5px 3px rgba(46, 46, 46, 0.62)"}} outline onClick={props.handlePrevious}>Previous</Button>}
        {!props.data.next ? null : <Button style={{ color:"#00005c", margin: "5%", boxShadow: "5px 5px 3px rgba(46, 46, 46, 0.62)"}} outline onClick={props.handleNext}>Next</Button>}
        </div>

      );
    }

    export default PageButtons;
like image 41
Imriven Avatar answered Oct 17 '22 20:10

Imriven


Try this:

https://react-bootstrap.github.io/getting-started/theming/

for buttons specifically, you can add variant='custom' attribute in Button component and in css file, you can customize your button like this:

.btn-custom {
    ...
}
like image 4
Deep Parekh Avatar answered Oct 17 '22 19:10

Deep Parekh