Reputation: 261
I have created a button component in react. Functionality is working but I'm unable to change the button colors and style
parent.js
import React, { Component } from "react";
import {Button, TYPES} from '../../../Global/button';
class ProductDisplay extends Component{
render(){
return(
<Button buttonType={TYPES.DANGER} label="Add To Cart" onClick={() =>
this.addItemToCart(pdpList.uniqueID)}></Button>
)
}
}
export default ProductDisplay;
button.js
import React from 'react';
import classnames from 'classnames';
export const TYPES = {
PRIMARY: 'btn-primary',
WARNING: 'btn-warning',
DANGER: 'btn-danger',
SUCCESS: 'btn-success',
}
export const Button = (props) => (
<button buttonType={props.TYPES} onClick={props.onClick} classnames={
[props.buttonType || TYPES.PRIMARY]
}>
{props.label}
</button>
);
I'm not able to change the color. Can anybody help me
Upvotes: 1
Views: 211
Reputation: 292
In button.js
:
export const Button = (props) => (
<button
onClick={props.onClick}
className={styles[props.buttonType || TYPES.PRIMARY]}
>
{props.label}
</button>
);
Bear in mind that the prop name for classes is singular and camelcase, i.e. className
rather than classnames
.
Upvotes: 1