How can I rotate the arrows onclick
This is my code below for my react collapse and I would like to rotate the arrows of my collapse accordion when it clicked.
I'm using reactstrap to build it and react fontawsome for my Icons
I've also attached a .GIF Link to demonstrate how my accordion is currently functioning.
import React, { Component } from "react";
import { Collapse, CardBody, Card, CardHeader } from "reactstrap";
import { faChevronDown } from "#fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
const nested = [
{
id: 10,
title:"Customer Queries"
},
];
const Icon = <FontAwesomeIcon icon={faChevronDown} color={"#EB8C00" } />;
class Colapse extends Component {
constructor(props) {
super(props);
this.tog = this.tog.bind(this);
this.state = {
col: 0,
cards: [
{
id:1,
title:"General information requests",
sub_title:"Fault reports",
body:"Something to display for body 1",
},
{
id:2,
title:"Account queries",
sub_title:"Communication protocols",
body:"Something to display for body 2",
}
] };
}
tog(e) {
let event = e.target.dataset.event;
this.setState({
col: this.state.col === Number(event) ? 0 : Number(event),
});
}
render() {
const { col, cards } = this.state;
return (
<div className="container collapse-container">
{nested.map((element, index) => {
return (
<Card key={index} className="card rounded ">
<CardHeader
className="card-header"
onClick={this.tog}
data-event={(index = element.id)}
>
<p className="collapse d-flex">
<div className=" p-2 mr-auto font-weight-bold">
<p className="">{element.title}</p>
</div>
<a
class="click-layer"
onClick={this.tog}
data-event={index}
></a>
</p>
</CardHeader>
<Collapse isOpen={col !== index}>
<CardBody className="card-body">
<p className="card-text">Customer Queries relate to information, account or meter related faults reported by the customer.</p>
{/**HERE NESTED */}
{cards.map((index) => {
return (
<Card key={index} className="card-sub rounded ">
<p className="card-header-sub" >{index.title}</p>
<CardHeader
className="card-header-sub"
onClick={this.tog}
data-event={index.id}
>
<p className="colle d-flex">
<div className="p-2 rotate">{Icon}</div>
<div className=" p-2 mr-auto font-weight-bold">
<p className="card-header-sub">{index.sub_title}</p>
</div>
<a
class="click-layer"
onClick={this.tog}
data-event={index.id}
></a>
</p>
</CardHeader>
<Collapse isOpen={col === index.id}>
<CardBody className="card-body-sub">
<p className="card-text-body">{index.body}</p>
</CardBody>
</Collapse>
</Card>
);
})}
{/**End Of Nested */}
</CardBody>
</Collapse>
</Card>
);
})}
</div>
);
}
}
export default Colapse;
Rotate the svg according to some condition e.g. col === element.id
<div className={`p-2 rotate ${col === element.id ? "isRotated" : ""}`}>{Icon}</div>
on your stylesheet:
.isRotated svg {
transform: rotate(-90deg);
}
Related
I'm trying to create header component for next.js/tailwindcss app. The nav active class only shows active when clicked on a second time. I'd like for it to be active upon the first click. Where am I going wrong? What element should I target with tailwindcss to reflect active state?
navlink.js file:
import Link from 'next/link';
const NavItem = ({ text, href, active }) => {
return (
<Link href={href}>
<a
className={`nav__item ${
active ? 'active underline underline-offset-8' : ''
}`}
>
{text}
</a>
</Link>
);
};
export default NavItem;
header.js :
import Image from 'next/image';
import React, { useState } from 'react';
import NavItem from './NavItem';
const MENU_LIST = [
{ text: 'About', href: '/about' },
{ text: 'My Work', href: '/MyWork' },
{ text: 'Blog', href: '/blog' },
{ text: 'Contact', href: '/contact' },
];
const Header = () => {
const [navActive, setNavActive] = useState(null);
const [activeIdx, setActiveIdx] = useState(-1);
return (
<header className="bg-white">
<nav className="max-w-5xl mx-auto border border-top-gray">
{/*containment div*/}
<div className="flex justify-between">
{/*Logo Container*/}
<div className="cursor-pointer">
<a href="/">
<Image
src="/../public/images/soulLogo.webp"
alt="site logo"
width={233}
height={144}
/>
</a>
</div>
{/*Link Container*/}
<div className="hidden md:flex">
<div
onClick={() => setNavActive(!navActive)}
className={`nav__menu-bar md:underline underline-offset-8 decoration-black `}
></div>
<div
className={`${
navActive
? 'active underline underline-offset-8 decoration-black'
: ''
} nav__menu-list flex items-center space-x-8 text-gray-700 tracking-wider `}
>
{MENU_LIST.map((menu, idx) => (
<div
onClick={() => {
setActiveIdx(idx);
setNavActive(false);
}}
key={menu.text}
>
<NavItem active={activeIdx === idx} {...menu} />
</div>
))}
</div>
</div>
{/*Mobile Menu button*/}
<div className="flex relative flex-col gap-y-2 cursor-pointer pt-14 pr-3 md:hidden">
<div className="w-24 h-1 bg-black shadow-gray-700 rounded"></div>
<div className="w-24 h-1 bg-black shadow-gray-700 rounded"></div>
<div className="w-24 h-1 bg-black shadow-gray-700 rounded"></div>
</div>
{/*Mobile Menu*/}
<
</div>
</nav>
</header>
);
};
export default Header;
I think we used the same code and I ran into the same problem.
I fixed it with with using next/router and comparing the paths inside the NavItem.js component.
navitem.js
import Link from "next/link";
import { useRouter } from 'next/router';
const NavItem = ({ href, text }) => {
const router = useRouter();
const currentRoute = router.pathname;
return (
<Link href={href} className={currentRoute === `${href}` ? 'active' : ''}> {text} </Link>
);
};
export default NavItem;
navbar.js
{PRIMARY_NAVIGATION_LIST.map((menu) => (
<div key={menu.text} >
<NavItem
href={menu.href}
text={menu.text}
/>
</div>
))}
I recently started doing React JS but facing one Problem. I use
bootstrap flat icons in my component. I have two APIs one for the
product list and the second for the wish list I have to compare both
API results. if the product is present in the wishlist then I have to
show the heart icon filled if not then unfilled. But I am facing an
issue in that I create the logic for comparing them and then push in
the state but it renders the product list first but does not show the
icons filled. But if I make any changes in the component & save them
crtl+s then show the icons filled. means it updates the state early.
I did not find any solution to this.
import React, { useEffect, useState } from 'react';
import { product } from '../../../_services';
import "../../../_UI/slick-carousel/slick/slick.css";
import "../../../_UI/slick-carousel/slick/slick-theme.css";
import { Link } from 'react-router-dom';
import { useHistory } from 'react-router-dom'
import Slider from "react-slick";
import { useDispatch,useSelector} from 'react-redux';
import { CartActions,wishlistActions } from '../../../_actions';
function NewArrival() {
const selector = useSelector((state)=>state);
const dispatch = useDispatch();
const [value, setvalue] = useState([]);
const [value2, setvalue2] = useState([]);
const settingSlider = {
dots: true,
slidesToShow: 4,
slidesToScroll: 4,
autoplay: true,
autoplaySpeed: 5000,
Speed:10,
pauseOnHover:true,
arrows: false,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
}
},
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
infinite: true,
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
infinite: true,
}
}
]
}
const AddToWishList = (sku_name)=>{
dispatch(wishlistActions.AddToWishListRequested(sku_name))
}
const AddToCart = async (sku,index) => {
const user_id = localStorage.getItem('card_id');
let product_details = {
sku_name: sku,
qty: 1,
quote_id: user_id
}
dispatch(CartActions.ADDCARTREQUEST(product_details,index));
}
useEffect(() => {
newArrivalApi()
}, [])
async function newArrivalApi(){
if(localStorage.getItem('user')){
const result = await product.ProductsNewarrival(39);
const result2 = await product.ProductsNewarrival(71)
console.log(selector.WishListProcess.wishlist);
//compare logic
result2.data.items?.map((items,index)=>{
selector?.WishListProcess?.wishlist?.map((item)=>{
if(items.id==item.product_id){
result2.data.items.push({...items,wishlist:true})
result2.data.items.splice(index,1);
}
})
})
//compare logic second slider
result.data.items?.map((items,index)=>{
selector?.WishListProcess?.wishlist?.map((item)=>{
if(items.id==item.product_id){
result.data.items.push({...items,wishlist:true})
result.data.items.splice(index,1);
}
})
})
// console.log(result.data.items);
// console.log(result2.data.items);
setvalue(result?.data?.items);
setvalue2(result2?.data?.items)
}
else{
const result = await product.ProductsNewarrival(39);
const result2 = await product.ProductsNewarrival(71)
console.log(result)
console.log(result2);
setvalue2(result2.data.items)
setvalue(result.data.items)
}
}
return (
<>
<section className="collection-section">
{value?.length > 0 ?
<div className="container-fluid">
<div className="text-center my-5">
<h3 className="heading-text">
New Arrival
</h3>
<h4 className="sub-heading-text">
"Fashion Fade. Style is eternal."
</h4>
</div>
<div className="row align-items-lg-center">
<div className="col-lg-9 col-md-9">
<div className="row justify-content-lg-between justify-content-center" >
<div className="col-lg-12">
<Slider {...settingSlider}>
{value.map((item, index) => {
return (
<div key={index} >
<div className="product-info">
<div className="product-image">
<Link to={"/product_details/" + item.sku} > <img src={item?.custom_attributes[0].attribute_code ==="image" ? item.custom_attributes[0].value : item.custom_attributes[1].value } alt='' className="img-fluid" /></Link>
</div>
<div className="product-title"><a href={"/product_details/" + item.sku}>{item.name}</a></div>
<div className="product-price">${item.price}</div>
<div className="add-wishlist-out">
<div className="add-to-cart-outer">
<button onClick={()=>{AddToCart(item.sku,item.id)}} className="add-to-cart-btn"><i className="fa fa-solid fa-cart-shopping"></i>{selector?.CartProcess?.loading === true && selector?.CartProcess?.index === item.id ? "LOADING..." : "Add to cart"}</button>
</div>
<div className="wishlist-out">
<a onClick={()=>{AddToWishList(item.sku)}} className="wishlist-icon"><i className={item.wishlist===true ? "fa fa-solid fa-heart" :"far fa-heart"}></i></a>
<i className="fa fa-solid fa-signal"></i>
</div>
</div>
</div>
</div>
)})}
</Slider>
</div>
</div>
</div>
<div className="col-lg-3 col-md-3">
<div className="long-img">
<img src="./assets/images/1608b80571524e822b386e9da05f02f2.jpg" className="img-fluid" />
</div>
</div>
</div>
<div className="row align-items-lg-center">
<div className="col-lg-3 col-md-3">
<div className="long-img">
<img src="./assets/images/ww8.jpg" className="img-fluid" />
</div>
</div>
<div className="col-lg-9 col-md-9">
<div className="row justify-content-lg-between justify-content-center" >
<div className="col-lg-12" >
<Slider {...settingSlider} >
{value2.map((item, index) => {
return (
<div key={index} >
<div className="product-info">
<div className="product-image">
<a href={'/product_details/' + item.sku} ><img src={item?.custom_attributes[0].attribute_code ==="image" ? item.custom_attributes[0].value : item.custom_attributes[1].value } alt='' className="img-fluid" /></a>
</div>
<div className="product-title"><a href={"/product_details/" + item.sku}>{item.name}</a></div>
<div className="product-price">${item.price}</div>
<div className="add-wishlist-out">
<div className="add-to-cart-outer">
<button onClick={()=>{AddToCart(item.sku,item.id)}} className="add-to-cart-btn"><i className="fa fa-solid fa-cart-shopping"></i>{selector?.CartProcess?.loading === true && selector?.CartProcess?.index === item.id ? "LOADING..." : "Add to cart"}</button>
</div>
<div className="wishlist-out">
<a onClick={()=>{AddToWishList(item.sku)}} className="wishlist-icon"><i className={item.wishlist===true ? "fa fa-solid fa-heart" :"far fa-heart"}></i></a>
<i className="fa fa-solid fa-signal"></i>
</div>
</div>
</div>
</div>
)})}
</Slider>
</div>
</div>
</div>
</div>
</div>
: " "}
</section>
</>
)
}
export { NewArrival };
That is the normal behavior of useState because useState is async function so it takes a little bit of time to set the state before use it so you have to find a way around to use it, I suggest why are you setting two set one state and inside its object like this:
const [valueState, setValueState] = React.useState({ result: [], result2: [] });
setValueState({ result: result?.data?.items, result2: result2?.data?.items });
and use it like this
valueState?.result
valueState?.result2
I have some problem with a function I set up to change the background color of a button when it is clicked.
I setup the function in a parent component below:
import React, { useRef, useState } from 'react';
import Aside from './Aside';
import Content from './Content';
const Dashboard = () => {
let asideRef = useRef(null);
const handleColor = color => {
asideRef.current.style.backgroundColor = color;
};
return (
<div className="d-flex flex-row" id="main_wrapper">
<Aside handleColor={handleColor} postedRef={asideRef} />
<Content />
</div>
);
};
export default Dashboard;
in the child component it is called in this manner:
import { Link } from 'react-router-dom';
import React, { createRef } from 'react';
class Aside extends React.Component {
constructor(props) {
super(props);
this.state = {
btn: true,
btnEn: true,
background: '#fff',
};
this.handleClick = this.handleClick.bind(this);
}
handleClick = () => {
const { btn } = this.state;
this.setState({
btn: !btn,
});
};
render() {
const { btn, btnEn, background } = this.state;
const { handleColor, postedRef } = this.props;
console.log(this.props);
return (
<div className="d-flex flex-column asidebar" id="aside_wrapper" style={{ width: '20%', height: '100vh' }}>
<div className="d-flex flex-row justify-content-center nav-header">
<a href="/dashboard" className="brand-logo">
<picture>
<img src="https://user-images.githubusercontent.com/25479050/99581983-c1c18e00-29e1-11eb-9bd3-4a53585456cb.png" className="img-fluid img-thumbnail" alt="plaschema logo" />
<source media="(min-width:650px)" srcSet="https://user-images.githubusercontent.com/25479050/99581983-c1c18e00-29e1-11eb-9bd3-4a53585456cb.png" type="image/svg+xml" />
<source media="(min-width:465px)" srcSet="https://user-images.githubusercontent.com/25479050/99582047-d736b800-29e1-11eb-92f3-83dce3912e39.png" type="image/svg+xml" />
</picture>
</a>
</div>
<div className="link_container d-flex flex-column">
<button type="button" className="buttonTrue" ref={postedRef} onClick={() => { handleColor('#f4f2f6'); }}>
<Link to="/">
<i className="lni lni-dashboard" />
<span className="link_name">Dashboard</span>
</Link>
</button>
<button type="button" className={btnEn ? 'buttonTrue' : 'buttonFalse'}>
<Link to="/enroll">
<i className="lni lni-tab" />
<span className="link_name">Enrollment</span>
</Link>
</button>
<Link className=" icons accreditation-wrapper" to="/accreditation">
<i className="lni lni-checkbox" />
<span className="link_name">Accreditation</span>
</Link>
<Link className=" icons subscription-wrapper" to="/subscription">
<i className="lni lni-tab" />
<span className="link_name">Subscription</span>
</Link>
<Link className=" icons service-wrapper" to="/service">
<i className="lni lni-control-panel" />
<span className="link_name">Service Usage</span>
</Link>
<Link className=" icons report-wrapper" to="/report">
<i className="lni lni-library" />
<span className="link_name">Reports</span>
</Link>
</div>
</div>
);
}
}
export default Aside;
After setup, anytime I click on the only button I set it up on as a test, I keep getting this error page handleColor is not a function. Right now I can't think of what the issue maybe because I have tried several approaches to get it to work but the error is still there. Below is the code of the component I am trying to apply it on:
Looking forward to helpful responses. Thanks.
The question has been updated for more insight. Sorry for the earlier issues with the first iteration.
you can try with
const handleClick = () => {
or
function handleClick () {
You're wrongly referring the handleColor. handleColor is not a prop, it is a component method, you can use like this.handleColor
const { handleColor } = this.props // this is wrong, it's not a prop method
<button type="button" className="buttonTrue" ref={this.colorSwitch} onClick={() => { this.handleColor('#f4f2f6'); // this is right }}>
<Link to="/">
<i className="lni lni-dashboard" />
<span className="link_name">Dashboard</span>
</Link>
</button>
I have created sample example here with some of your code. Check out this link
This is the error I am trying to render the createCardHotels function;however, whenever I run it, nothing shows up. Any help will be appreciated.
I used map function to loop through the data and whenever I run it I can see on the console that there is the data. The problem is just the rendering part.
import React, {Component} from 'react';
import {Container, Button, DropdownMenu, DropdownItem, Dropdown, DropdownToggle} from 'reactstrap';
import {Carousel} from 'react-responsive-carousel';
import styles from 'react-responsive-carousel/lib/styles/carousel.min.css';
import './selectHotel.css'
import Scroll from '../ScrollUp';
import {search} from '../../actions/search';
import {connect} from 'react-redux';
class SelectHotel extends Component{
constructor(props){
super(props);
this.state={
dropdownOpen: false,
hotels: []
};
this.toggleDropdown = this.toggleDropdown.bind(this);
}
static getDerivedStateFromProps(state, props){
if(props.hotels !== state.hotels)
return{
...state,
hotels: props.hotels
}
return null;
}
createCardHotels = () => {
return this.state.hotels.map((hotel) => {
return(
<div key={hotel._id} className="card">
<div className="row ">
<div className="col-md-4">
<Carousel autoPlay infiniteLoop>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
</Carousel>
</div>
<div className="col-md-5 px-3">
<div className="card-block px-3">
<h3 className="card-title">{hotel.name}</h3>
<p className="card-text">description</p>
</div>
</div>
<div className="col-md-3 price">
<h1 className="reservation-price">$Price</h1>
<Button style={cssStyles.buttonRoom} bsStyle="primary">Choose Hotel</Button>
</div>
</div>
</div>
)}
)
}
toggleDropdown() {
this.setState(prevState => ({
dropdownOpen: !prevState.dropdownOpen
}));
}
render(){
console.log(this.state)
console.log(this.props)
return(
<div>
<Container>
<Scroll/>
<div>
<Dropdown className = 'sortbutton' size="lg" isOpen={this.state.dropdownOpen} toggle={this.toggleDropdown}>
<DropdownToggle style={{backgroundColor: "white", borderColor: "grey" , color: "black"}} caret>
Sort By:
</DropdownToggle>
<DropdownMenu>
<DropdownItem onClick={()=>{this.setSort("low");}}>
Price: Low to High
</DropdownItem>
<DropdownItem divider />
<DropdownItem onClick={()=>{this.setSort("high");}}>
Price: High to Low
</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>
{this.createCardHotels()}
<br></br>
</Container>
</div>
);
}
}
const cssStyles = {
buttonRoom:{
backgroundColor: '#156bc1',
border: '1px solid #156bc1',
alignItems: 'left',
boxShadow: 'inset 0 -2px 0 #063665',
paddingLeft: '2rem',
paddingRight: '2rem',
fontSize: '0.8rem'
}
}
const mapStatetoProps = state => {
return {
hotels: state.search.hotels
};
}
export default connect(mapStatetoProps, {search})(SelectHotel);
EDIT:
This is the image from console after I put console.log(this.state), console.log(this.props), it seems like there is data in this.props and not in this.state
The issue is with add class names to JSX elements. You are using class to apply css styles with class names but class is reserved for creating class components in React so you need to use className
Wherever you see class on jsx elements change it to className
Also never forget to add key to the top parent jsx element when you render them in loop. If you have unique from data then set id from data as a key like I did below else use index as key
Change
return this.state.hotels.map((hotel) => {
return(
<div class="card">
........
To
return this.state.hotels.map((hotel) => {
return(
<div key={hotel.id} className="card">
.......
Also
Change
<h1 className="reservation-price">$Price</h1>
To
<h1 className="reservation-price">{"$Price"}</h1>
For images you need to use require or import
Change
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
To
<img src={require("https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400")} className="w-100"/>
Do the same for other images as well
Or import it like
import text from "https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400";
<img src={text} className="w-100"/>
Сould you please show your building file. May be a problem with file-loader.
import React, { Component } from 'react';
import { Link } from 'react-router'
import { Dropdown, DropdownMenu, DropdownItem, Progress } from 'reactstrap';
class Notifications extends Component {
constructor(){
super();
this.state = {
data:[
{title:"Nikko Laus1" , text:"abcd" , type:"Big text" },
{title:"Sam Collins", text:"" ,type:"Inbox style"},
{title:"Sam ", text:"" ,type:"Image style"}
]
};
}
render() {
let rows = this.state.data.map(person =>
{
return <TableRow key={person.id} data={person}/>
});
return (<div><div>
<div className="animated fadeIn">
<div className="px-2 mb-1">
<Link to={'/Components/BasicNotification'} style= {{ width:20 + '%' }} className="nav-link btn btn-block btn-success" activeClassName="active">Add Notification</Link>
</div>
<br /><div className="card" style={{ width: 57 + '%' }}>
<div className="card-header">
Manage Notifications
</div>
<div className="card-block">
<table className="table table-hover table-outline mb-0 hidden-sm-down">
<tbody>
{this.props.type.Bigtext ? <Link to={'/Components/BigText'} className="nav-link" activeClassName="active" />:
this.props.type.ImageStyle ? <Link to={'/Components/ImageStyle'} className="nav-link" activeClassName="active" />:
<Link to={'/Components/InboxStyle'} className="nav-link" activeClassName="active" />}
{rows}</tbody>
</table></div>
<br />
</div>
</div><div className="px-2 mb-1"><Link to={'/components/tabs'} style={{ width:20 + '%' }} className="px-1 nav-link btn btn-block btn-success" activeClassName="active">Filter Notifications</Link>
</div>
</div></div>
)
}
}
class TableRow extends React.Component
{
constructor()
{
super();
}
render()
{
return (<tr>
<td className="text-center">{this.props.data.title}<br />
{this.props.data.text}<br /></td></tr>
);
}
}
export default Notifications;
I want to give condition and if else condition and using that condition I want to open an particular page as seen in the code snippet.
But when I run no output comes at all.
I just wanted to do like on the basis of notification type relevant page is to be opened on clicking that table row
You can make use of this.context.router.push to dynamically change the route onClick of the table row. See the below snippet.
import React, { Component } from 'react';
import { Link } from 'react-router'
import { Dropdown, DropdownMenu, DropdownItem, Progress } from 'reactstrap';
class Notifications extends Component {
constructor(){
super();
this.state = {
data:[
{title:"Nikko Laus1" , text:"abcd" , type:"Big text" },
{title:"Sam Collins", text:"" ,type:"Inbox style"},
{title:"Sam ", text:"" ,type:"Image style"}
]
};
}
static contextTypes = {
router: React.PropTypes.object
}
handleClick = (index) => {
if(this.state.data[index].type === "Big text") {
this.context.router.push('/Components/BigText');
} else if(this.state.data[index].type === "Image style") {
this.context.router.push('/Components/ImageStyle');
} else {
this.context.router.push('/Components/InboxStyle');
}
}
render() {
let rows = this.state.data.map((person, index) =>
{
return <TableRow key={person.id} data={person} onClick={this.handleClick.bind(this, index)}/>
});
return (<div><div>
<div className="animated fadeIn">
<div className="px-2 mb-1">
<Link to={'/Components/BasicNotification'} style= {{ width:20 + '%' }} className="nav-link btn btn-block btn-success" activeClassName="active">Add Notification</Link>
</div>
<br /><div className="card" style={{ width: 57 + '%' }}>
<div className="card-header">
Manage Notifications
</div>
<div className="card-block">
<table className="table table-hover table-outline mb-0 hidden-sm-down">
<tbody>
{rows}</tbody>
</table></div>
<br />
</div>
</div><div className="px-2 mb-1"><Link to={'/components/tabs'} style={{ width:20 + '%' }} className="px-1 nav-link btn btn-block btn-success" activeClassName="active">Filter Notifications</Link>
</div>
</div></div>
)
}
}
class TableRow extends React.Component
{
constructor(props)
{
super(props);
}
render()
{
return (<tr onClick={this.props.onClick}>
<td className="text-center">{this.props.data.title}<br />
{this.props.data.text}<br /></td></tr>
);
}
}
export default Notifications;