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 id="app"></div>
              
            
!

CSS

              
                $dark-background: #444;
$dark-backgorund-hover: #333;
$dark-font-color: #ccc;

@import url('https://fonts.googleapis.com/css?family=Lato');

$dark-background: #444;
$dark-backgorund-hover: #333;
$dark-header-background: #555;
$dark-font-color: #ccc;
$arrow-color: #888;
$button-background-hover: #666;
$button-background-focus: #595959;
$button-padding: 15px;
$button-border-size: 8px;
$day-soft-color: #565656;

body {
  margin: 0;
  background-color: #777;
}

.calendar {
  color: $dark-font-color;
  float: left;
  font-family: 'Lato', sans-serif;
  height: 430px;
  margin-left: 50%;
  margin-top: 25px;
  position: relative;
  transform: translateX(-50%);
  width: 400px;
  max-width: 100%;
}

.calendar-header {
  background-color: $dark-header-background;
  float: left;
  font-size: 18px;
  height: 50px;
  line-height: 2.78;
  position: relative;
  text-align: center;
  width: 100%;
}

.button-container {
  height: 100%;
  position: relative;

  &--left {
    float: left;
  }

  &--right {
    float: right;
  }
}

.button-content {
  background-color: transparent;
  border: 0;
  cursor: pointer;
  float: left;
  height: 100%;
  padding-left: $button-padding;
  position: relative;
  transition: background .3s ease;

  &:hover {
    background-color: $button-background-hover;
  }

  &:focus {
    outline: 0;
  }

  &--left {
    &::before {
      border-bottom: $button-border-size solid transparent;
      border-right: $button-border-size solid $arrow-color;
      border-top: $button-border-size solid transparent;
      content: '';
      display: inline-block;
      height: 0;
      margin-right: 10px;
      vertical-align: middle;
      width: 0;

    }
  }

  &--right {
    &::before {
      border-bottom: $button-border-size solid transparent;
      border-left: $button-border-size solid $arrow-color;
      border-top: $button-border-size solid transparent;
      content: '';
      display: inline-block;
      height: 0;
      margin-right: 10px;
      vertical-align: middle;
      width: 0;
    }
  }
}

.week {
  float: left;
  width: 100%;
}

.weekday {
  background-color: $dark-background;
  float: left;
  height: 40px;
  line-height: 2.5;
  text-align: center;
  width: 14.28%;
}

.day {
  background-color: $dark-background;
  box-sizing: border-box;
  float: left;
  font-weight: 300;
  height: 50px;
  padding: 10px 0;
  position: relative;
  text-align: center;
  transition: background .2s ease;
  width: 14.28%;
  z-index: 999;

  &--soft {
    color: $day-soft-color;
  }
}
              
            
!

JS

              
                class Calendar extends React.Component {
  constructor() {
    super();
    this.state = {
      days: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
      months: [
        'January', 'February', 'March', 'April', 'May', 'June',
        'July', 'August', 'September', 'October', 'November', 'December',
      ],
      weekDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
      lastMonth: 11,
      month: 0,
      nextMonth: 1,
      year: 0,
      currentMonth: 0,
      currentYear: 0,
      calendar: [
        { id: 'week-1', data: [0, 0, 0, 0, 0, 0, 0] },
        { id: 'week-2', data: [0, 0, 0, 0, 0, 0, 0] },
        { id: 'week-3', data: [0, 0, 0, 0, 0, 0, 0] },
        { id: 'week-4', data: [0, 0, 0, 0, 0, 0, 0] },
        { id: 'week-5', data: [0, 0, 0, 0, 0, 0, 0] },
        { id: 'week-6', data: [0, 0, 0, 0, 0, 0, 0] },
      ],
      holidays: [],
      holiday: '',
    };

    this.previousCalendar = this.previousCalendar.bind(this);
    this.nextCalendar = this.nextCalendar.bind(this);
  }

  componentWillMount() {
    const now = new Date();
    const currentMonth = now.getMonth();
    const currentYear = now.getFullYear();

    this.setState({
      currentMonth,
      currentYear,
      month: currentMonth,
      year: currentYear,
    });

    this.setCalendar(new Date(currentYear, currentMonth, 1));
  }

  setMonth(date) {
    const month = date.getMonth();
    const lastMonth = month === 0 ? 11 : month - 1;
    const nextMonth = month === 11 ? 0 : month + 1;

    this.setState({
      lastMonth,
      month,
      nextMonth,
    });

    return { lastMonth, month, nextMonth };
  }

  setCalendar(date) {
    const { lastMonth, month, nextMonth } = this.setMonth(date);
    const year = date.getFullYear();
    const weekday = date.getDay();
    const days = this.checkLeapYear(year);
    let nextMonthDay = 0;

    const firstWeek = this.state.calendar[0].data.map((day, index) => {
      let holiday = '';
      if (index < weekday) {
        const value = (days[lastMonth] - (weekday - index)) + 1;
        return {
          value,
          class: 'day--soft',
          month: lastMonth,
        };
      }
      const value = (index - weekday) + 1;
      return {
        value: (index - weekday) + 1,
        class: '',
        month,
      };
    });
    const secondWeek = this.state.calendar[0].data.map((day, index) => {
      const value = firstWeek[6].value + index + 1;
      return {
        value,
        class: '',
        month,
      };
    });
    const thirdWeek = this.state.calendar[0].data.map((day, index) => {
      const value = secondWeek[6].value + index + 1;
      return {
        value,
        class: '',
        month,
      };
    });
    const forthWeek = this.state.calendar[0].data.map((day, index) => {
      const value = thirdWeek[6].value + index + 1;
      return {
        value,
        class: '',
        month,
      };
    });
    const fifthWeek = this.state.calendar[0].data.map((day, index) => {
      if (forthWeek[6].value + index + 1 > days[month]) {
        nextMonthDay += 1;
        return {
          value: nextMonthDay,
          class: 'day--soft',
          month: nextMonth,
        };
      }
      const value = forthWeek[6].value + index + 1;
      return {
        value,
        class: '',
        month,
      };
    });
    const sixthWeek = this.state.calendar[0].data.map((day, index) => {
      if (fifthWeek[6].value + index + 1 > days[month] || fifthWeek[6].value < 10) {
        nextMonthDay += 1;
        return {
          value: nextMonthDay,
          class: 'day--soft',
          month: nextMonth,
        };
      }

      const value = fifthWeek[6].value + index + 1;
      return {
        value,
        class: '',
        month,
      };
    });

    this.setState({
      month,
      year,
      calendar: [
        { id: 'week-1', data: firstWeek },
        { id: 'week-2', data: secondWeek },
        { id: 'week-3', data: thirdWeek },
        { id: 'week-4', data: forthWeek },
        { id: 'week-5', data: fifthWeek },
        { id: 'week-6', data: sixthWeek },
      ],
    });
  }

  checkLeapYear(year) {
    let days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
      days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    }
    this.setState({
      days,
    });
    return days;
  }

  previousCalendar() {
    const month = this.state.month !== 0 ? this.state.month - 1 : 11;
    const year = this.state.month !== 0 ? this.state.year : this.state.year - 1;
    this.setCalendar(new Date(year, month, 1));
  }

  nextCalendar() {
    const month = this.state.month !== 11 ? this.state.month + 1 : 0;
    const year = this.state.month !== 11 ? this.state.year : this.state.year + 1;
    this.setCalendar(new Date(year, month, 1));
  }

  render() {
    return (
      <div className="calendar">
        <div className="calendar-header">
          <span className="button-container button-container--left">
            <button onClick={this.previousCalendar} className="button-content button-content--left" />
          </span>
          <span className="calendar-header-date">{`${this.state.year} ${this.state.months[this.state.month]}`}</span>
          <span className="button-container button-container--right">
            <button onClick={this.nextCalendar} className="button-content button-content--right" />
          </span>
        </div>
        <div className="week">
          {this.state.weekDays.map(weekDay => <div key={weekDay} className="weekday">{weekDay}</div>)}
        </div>
        {this.state.calendar.map(week =>
          <div key={week.id} className="week">
            {week.data.map(day =>
              <div
                key={`${day.month}${day.value}`}
                className={`day ${day.class}`}
              >
                {day.value < 10 && day.value !== ' ' ? `0${day.value}` : day.value}
              </div>,
            )}
          </div>,
        )}
      </div>
    );
  }
}


/*
 * Render the above component into the div#app
 */
ReactDOM.render(<Calendar />, document.getElementById('app'));
              
            
!
999px

Console