Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="outer">
  <div id="root"></div>
</div>

              
            
!

CSS

              
                $primary-color: #eeeeee;
$secondary-color: #195499;
@mixin flexbox-col {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
@mixin flexbox-row {
	width: 100%;
	display: flex;
	align-items: center;
	flex-direction: row;
	justify-content: space-around;
}
@mixin font-arial {
	font-family: arial;
	font-weight: normal;
}
body {
	background-color: #444444;
}
button:focus,
select:focus,
input {
	outline: 0;
}
.outer {
	padding: 1vw 0 1vw 0;
	margin-left: 50%;
	transform: translateX(-50%);
	.wrapper {
		margin: auto;
		position: static;
		display: flex;
		.flip-container-left,
		.flip-container-right {
			.flipper {
				transform-style: preserve-3d;
				position: relative;
				height: inherit;
				.btn {
					width: 4vw;
					height: 4vw;
					cursor: pointer;
					border-radius: 50%;
					&:hover {
						opacity: 0.5;
					}
				}
				.btn-prev,
				.btn-next {
					border: 0.25vw $secondary-color solid;
					font-weight: bold;
					font-size: 1vw;
				}
				.select-month {
					height: 2vw;
					cursor: pointer;
					font-size: 1.5vw;
					border: none;
					border-left: 0.25vw solid $secondary-color;
					border-right: 0.25vw solid $secondary-color;
				}
				.input-year {
					width: 4vw;
					height: 2vw;
					font-size: 1.5vw;
					text-align: center;
					border: none;
					border-bottom: 0.25vw solid $secondary-color;
				}
				.container-event {
					@include flexbox-row;
					.input-time {
						width: 4vw;
						height: 2vw;
						font-size: 1.5vw;
						text-align: center;
						border: none;
						border-bottom: 0.25vw solid $secondary-color;
					}
					.btn-submit {
						border: 0.25vw $secondary-color solid;
					}
				}
				.input-event {
					margin-top: 1vw;
					width: 16vw;
					height: 2vw;
					font-size: 1.5vw;
					text-align: center;
					border: none;
					border-bottom: 0.25vw solid $secondary-color;
				}
				.option-month {
					color: $primary-color;
					background-color: $secondary-color;
				}
				.front-left,
				.back-left {
					border-bottom-left-radius: 3vw;
					border-top-left-radius: 3vw;
					.btn-flip {
						font-size: 1vw;
					}
				}
			}
			.front-right,
			.back-right {
				border-bottom-right-radius: 3vw;
				border-top-right-radius: 3vw;
			}
			.back {
				transform: rotateX(180deg);
			}
			.front,
			.back {
				backface-visibility: hidden;
				position: absolute;
			}
		}
	}
	.flip-container-left {
		.toggle {
			transform: rotateX(180deg);
		}
		.flipper {
			transition: 1s ease-out;

			.front {
				background-color: $secondary-color;
				@include flexbox-col;
				* {
					background-color: $secondary-color;

					color: $primary-color;
				}
				.btn-flip {
					border: 0.25vw $primary-color solid;
					margin-top: 3vw;
				}
				h1 {
					margin: 0;
					font-size: 9vw;
					@include font-arial;
				}
				h2 {
					margin: 0;
					font-size: 1.5vw;
					@include font-arial;
				}
			}
			.back {
				background-color: $primary-color;
				@include flexbox-col;
				* {
					background-color: $primary-color;
					color: $secondary-color;
				}
				.btn-flip {
					border: 0.25vw $secondary-color solid;
					margin-top: 6vw;
				}

				background-color: $primary-color;
				color: $secondary-color;
			}
		}
	}
	.flip-container-right {
		.toggle {
			transform: rotateX(180deg);
		}
		.flipper {
			transition: 1s ease-in;
			.front {
				background-color: $primary-color;
				* {
					background-color: $primary-color;
					color: $secondary-color;
				}
				@include flexbox-col;
				justify-content: space-around;
				overflow: hidden;
				* {
					overflow: hidden;
				}
				.container-date-picker {
					@include flexbox-row;
				}
				.container-day {
					display: grid;
					text-align: center;
					width: 100%;
					justify-content: center;
					align-items: center;
					grid-template-columns: repeat(7, 3.4vw);
					.weekday,
					.day-block {
						height: 2vw;
						@include font-arial;
						font-weight: bold;
						font-size: 1.2vw;
					}
					.day-block {
						cursor: pointer;
						border: 0.7vw solid $primary-color;
						border-radius: 50%;
						transition: 1s;
						.inner {
							transition: background-color 1s;
							position: relative;
							top: 50%;
							transform: translateY(-50%);
						}
					}
					.active {
						* {
							background-color: $secondary-color;
							color: $primary-color;
						}
						background-color: $secondary-color;
						border: 0.7vw solid $secondary-color;
						border-radius: 50%;
					}
				}
			}
			.back {
				background-color: $secondary-color;				
				overflow: hidden;

				* {
					background-color: $secondary-color;
					color: $primary-color;
					@include font-arial;
				}
				.event{
					@include flexbox-row;
					border-bottom: 0.1vw $primary-color solid;
					.event-time{
						padding-left: 1vw;
						min-width: 4vw;
						flex-grow: 0;
					}
					.event-name{
						flex-grow: 2;
					}
				}
			}
		}
	}
	.flip-container-left,
	.front-left,
	.back-left {
		width: 19vw;
		height: 28vw;
	}
	.flip-container-right,
	.front-right,
	.back-right {
		width: 30vw;
		height: 28vw;
	}
}

              
            
!

JS

              
                const arrMonth = {
	January: 31,
	February: 28,
	March: 31,
	April: 30,
	May: 31,
	June: 30,
	July: 31,
	August: 31,
	September: 30,
	October: 31,
	November: 30,
	December: 31
};
const arrDays = [
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
];

class LeftBlock extends React.Component {
	constructor(props) {
		super(props);
		this.state = { toggle: true, time:"", event:"" };
	}
	handleClick = () => {
		this.handleToUpdate(!this.state.toggle);
		this.setState(prevState => ({
			toggle: !prevState.toggle
		}));
	};
	handleSubmit= () => {
		this.handleToUpdateSubmit(this.state.time, this.state.event);
    event.preventDefault();

	};
handleTimeChange= event =>{
	    this.setState({time: event.target.value});
}
handleEventChange= event =>{
		    this.setState({event: event.target.value});

}
	render() {
		this.handleToUpdate = this.props.handleToUpdate;
		this.handleToUpdateSubmit = this.props.handleToUpdateSubmit;
		let h =
			(this.props.date.getHours() < 10 ? "0" : "") + this.props.date.getHours();
		let m =
			(this.props.date.getMinutes() < 10 ? "0" : "") +
			this.props.date.getMinutes();
		return (
			<div className="flip-container-left">
				<div className={`flipper ${this.state.toggle ? "" : "toggle"}`}>
					<div className="front front-left">
						<h2>Today</h2>
						<h1>{this.props.date.getDate()}</h1>
						<h2>{arrDays[this.props.date.getDay()]}</h2>
						<button className="btn btn-flip" onClick={this.handleClick}>
							+
						</button>
					</div>
					<div className="back back-left">
						<form onSubmit={this.handleSubmit}>
							<div className="container-event">
								<input
									type="text"
									className="input-time"
									maxlength="5"
									placeholder="12:00"
									onChange={this.handleTimeChange}
								/>
								<button className="btn btn-submit">→</button>
							</div>
							<input
								type="text"
								className="input-event"
								placeholder="Event"
								onChange={this.handleEventChange}
							/>
						</form>
						<button className="btn btn-flip" onClick={this.handleClick}>
							-
						</button>
					</div>
				</div>
			</div>
		);
	}
}

class RightBlock extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			firstDay: new Date(
				this.props.date.getFullYear() +
					"-" +
					(this.props.date.getMonth() + 1) +
					"-01"
			).getDay(),
			selectedYear: this.props.date.getFullYear(),
			selectedMonth: this.props.date.getMonth(),
			selectedDay: this.props.date.getDate()
		};
	}
	updateMonth = event => {
		let newMonth = Object.keys(arrMonth).indexOf(event.target.value);
		this.handleToUpdateDate(this.state.selectedDay + "/" + newMonth + "/" + this.state.selectedYear);
		this.setState({
			selectedMonth: newMonth,
			firstDay: new Date(
				this.state.selectedYear + "-" + (newMonth + 1) + "-01"
			).getDay()
		});
	};
	prevMonth = () => {
		if (this.state.selectedMonth - 1 < 0) {
			this.handleToUpdateDate(this.state.selectedDay + "/" + 11 + "/" + this.state.selectedYear -1);
			this.setState(prevState => ({
				selectedMonth: 11,
				selectedYear: prevState.selectedYear - 1,
				firstDay: new Date(prevState.selectedYear - 1 + "-" + "12-01").getDay()
			}));
		} else {
			this.handleToUpdateDate(this.state.selectedDay + "/" + this.state.selectedMonth -1 + "/" + this.state.selectedYear);
			this.setState(prevState => ({
				selectedMonth: prevState.selectedMonth - 1,
				firstDay: new Date(
					this.state.selectedYear + "-" + prevState.selectedMonth + "-01"
				).getDay()
			}));
		}
	};
	nextMonth = () => {
		if (this.state.selectedMonth + 1 > 11) {
			this.handleToUpdateDate(this.state.selectedDay + "/" +0 + "/" + this.state.selectedYear+1);
			this.setState(prevState => ({
				selectedMonth: 0,
				selectedYear: prevState.selectedYear + 1,
				firstDay: new Date(prevState.selectedYear + 1 + "-" + "01-01").getDay()
			}));
		} else {
			this.handleToUpdateDate(this.state.selectedDay + "/" + this.state.selectedMonth + 1+ "/" + this.state.selectedYear);
			this.setState(prevState => ({
				selectedMonth: prevState.selectedMonth + 1,
				firstDay: new Date(
					this.state.selectedYear + "-" + (prevState.selectedMonth + 2) + "-01"
				).getDay()
			}));
		}
	};
	updateYear = event => {
		if (event.target.value.length == 4) {
			this.handleToUpdateDate(this.state.selectedDay + "/" + this.state.selectedMonth + "/" + event.target.value);
			this.setState({
				selectedYear: parseInt(event.target.value),
				firstDay: new Date(
					parseInt(event.target.value) + "-" + (this.state.selectedMonth + 1) + "-01"
				).getDay()
			});
		} else if (event.target.value.length > 0) {
			this.setState({
				selectedYear: parseInt(event.target.value)
			});
		}
	};
	handleClick = event => {
		this.handleToUpdateDate(event.currentTarget.dataset.id + "/" + this.state.selectedMonth + "/" + this.state.selectedYear);
			this.setState({
			selectedDay: parseInt(event.currentTarget.dataset.id)
		});
	};

	getDayBlocks() {
		let arrNo = [];
		for (let n = 0; n < this.state.firstDay; n++) {
			arrNo.push(<div className="day-block" />);
		}
		for (
			let i = 1;
			i < Object.values(arrMonth)[this.state.selectedMonth] + 1;
			i++
		) {
			arrNo.push(
				<div
					data-id={i}
					onClick={this.handleClick}
					className={`day-block ${i == this.state.selectedDay ? "active" : ""}`}
				>
					<div className="inner">{i}</div>
				</div>
			);
		}
		return arrNo;
	}
	getEvents(){
		let events = [];
		let eventsToday = this.props.eventList.filter(event => {
			let dateArr = event[0].split('/');
			if (dateArr[0] == this.state.selectedDay && dateArr[1] == this.state.selectedMonth && dateArr[2] == this.state.selectedYear){
				events.push(<div className="event"><p className="event-time">{event[1]}</p><p className="event-name">{event[2]}</p></div>)
			}
		})
		return events;
	}
	render() {
		this.handleToUpdateDate = this.props.handleToUpdateDate;

		const monthOptions = Object.keys(arrMonth).map(month => (
			<option
				className="option-month"
				selected={
					month == Object.keys(arrMonth)[this.state.selectedMonth] ? "selected" : ""
				}
			>
				{month}
			</option>
		));

		return (
			<div className="flip-container-right">
				<div className={`flipper ${this.props.toggle ? "" : "toggle"}`}>
					<div className="front front-right">
						<div className="container-date-picker">
							<button className="btn btn-prev" onClick={this.prevMonth}>
								&lt;
							</button>
							<select className="select-month" onChange={this.updateMonth}>
								{monthOptions}
							</select>
							<input
								type="text"
								className="input-year"
								onChange={this.updateYear}
								value={this.state.selectedYear}
								maxlength="4"
							/>
							<button className="btn btn-next" onClick={this.nextMonth}>
								&gt;
							</button>
						</div>
						<div className="container-day">
							{arrDays.map(day => (
								<div className="weekday">{day.substring(0, 3)}</div>
							))}
							{this.getDayBlocks()}
						</div>
					</div>
					<div className="back back-right">
						<div className="container-events">{this.getEvents()} </div>
					</div>
				</div>
			</div>
		);
	}
}

class Calendar extends React.Component {
	constructor(props) {
		super(props);
		let date = new Date();
		this.state = {
			date: date,
			toggle: true,
			eventList: [],
			selectedDate: date.getDate() + "/" + date.getMonth() + "/" + date.getFullYear()
		};
	}

	handleToUpdate = isToggle => {
		this.setState({ toggle: isToggle });
	};
	handleToUpdateSubmit = (time, event) => {
		this.setState(prevState => {
			const list = [...prevState.eventList, [this.state.selectedDate, time, event]];
			return {
			eventList: list
			}
		});
	};
handleToUpdateDate = (date) =>{
	this.setState({
		selectedDate: date
	});
}
	componentDidMount() {
		this.timerID = setInterval(this.tick, 1000); //refresh each second
	}

	componentWillUnmount() {
		clearInterval(this.timerID);
	}

	tick = () => {
		this.setState({
			date: new Date()
		});
	};

	render() {
		return (
			<div className="wrapper">
				<LeftBlock date={this.state.date} handleToUpdate={this.handleToUpdate} handleToUpdateSubmit= {this.handleToUpdateSubmit}/>
				<RightBlock date={this.state.date} toggle={this.state.toggle} handleToUpdateDate={this.handleToUpdateDate} eventList={this.state.eventList}/>
			</div>
		);
	}
}
ReactDOM.render(<Calendar />, document.getElementById("root"));

              
            
!
999px

Console