React Base Fiddle (JSX)
Starting point for creating JSFiddles with React.
by keysl183
HTML
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
CSS
.month{
min-height: 20vh;
border:1px solid black;
margin-bottom:5px;
}
.month.calendar_active{
}
Babel + JSX
class Hello extends React.Component {
constructor(props){
super(props);
this.IsCurrentMonth = this.IsCurrentMonth.bind(this);
this.ScrollToCurrentMonth = this.ScrollToCurrentMonth.bind(this);
this.state = {
months: ['January', 'February','March', 'April', 'May', 'June', 'July', 'August','September', 'October', 'November', 'December'],
currentMonth : new Date().getMonth(),
}
}
componentDidMount(){
this.ScrollToCurrentMonth();
}
IsCurrentMonth(toCompare){
if(this.state.currentMonth === toCompare){
return 'calendar_active';
}
return;
}
ScrollToCurrentMonth(){
var myElement = document.getElementsByClassName('calendar_active')[0];
const y = myElement.getBoundingClientRect().top + window.scrollY;
window.scroll({
top: y,
behavior: 'smooth'
});
}
render() {
return (
<div className={this.state.currentMonth}>
{
this.state.months.map((month, index) =>{
return <div className={`month ${this.IsCurrentMonth(index)}` }>{month}</div>
})
}
</div>
);
}
}
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);