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

              
                //variables & mixins
@white: #FFFFFF;
@ltGrey: #EFEFEF;
@mdGrey: #C0C0C0;
@dkGrey: #CCCCCC;
@secondary:#2875C7;
@dkSecondary: darken(@secondary,10%);
@ltSecondary: lighten(@secondary,45%);
@borderColor: @dkGrey;
@background: @white;

.vertical-center {
  display: flex;
  justify-content:center;
  align-items: center;
}

// meat of the matter
html {
    font-size: 62.5%;
}

body {
    background: @ltGrey;
}

.row {
    display: flex;
    width: 100%;
}

.calendar {
    display: block;
    background:@white;
    width: 300px;
    border: solid 1px @borderColor;
    margin: 10px auto;
    box-shadow: 0 0 15px 0 @mdGrey;
    font-size: 1.3rem;
    text-align: center;

    header {
        .vertical-center;
        color: @white;
        cursor: default;
        font-size:1.4rem;
        display: block;
        font-weight: bold;
        text-transform: uppercase;
        user-select: none;
        
        .month-display {
            align-items: center;
            height: 40px;
            background: @secondary;
        }

        .month-label { 
           flex: 1;
        }
      
        .arrow {
            text-align: center;
            flex-basis: 15%;
            font-weight: bold;
            cursor: pointer;
            transition: background .2s;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
          
            &:hover {
                background: @dkSecondary;
            }
        }
    }
  
    .week {
        border-top: solid 1px @borderColor;

        &:first-child {
            border-top: none;
        }
    }
  
    .day-names {
        color: @secondary;
        font-weight: bold;
        cursor: default;
        font-size: 1.2rem;
        
        .day {
            cursor: default;
            
            &:hover {
                background: inherit;

            }
        }
    }
  
    .day {
        .vertical-center;
        flex: 1;
        height: 35px;
        border-left: solid 1px @borderColor;
        cursor: pointer;
        transition: all .2s;

        &:hover {
            background: @ltGrey;
        }

        &:first-child {
            border-left:none;
        }

        &.today {
            background: @ltSecondary;
        }

        &.different-month {
            color: @mdGrey;
        }

        &.selected {
            background: @secondary;
            color: @white;
        }
    }
}
              
            
!

JS

              
                //based on https://www.codementor.io/reactjs/tutorial/building-a-calendar-using-react-js--less-css-and-font-awesome


class Calendar extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      month: moment(),
      selected: moment().startOf('day')
    };
    
    this.previous = this.previous.bind(this);
    this.next = this.next.bind(this);
  }
  
  previous() {
    const {
      month,
    } = this.state;

    this.setState({
      month: month.subtract(1, 'month'),
    });
  }

  next() {
    const {
      month,
    } = this.state;

    this.setState({
      month: month.add(1,'month'),
    });
  }
  
  select(day) {
    this.setState({
      selected: day.date,
      month: day.date.clone(),
    });
  }

  renderWeeks() {
    let weeks = [];
    let done = false;
    let date = this.state.month.clone().startOf("month").add("w" -1).day("Sunday");
    let count = 0;
    let monthIndex = date.month();

    const {
      selected,
      month,
    } = this.state;

    while (!done) {
      weeks.push(
        <Week key={date} 
          date={date.clone()} 
          month={month} 
          select={(day)=>this.select(day)} 
          selected={selected} />
      );

      date.add(1, "w");
      
      done = count++ > 2 && monthIndex !== date.month();
      monthIndex = date.month();
    }

    return weeks;
  };

  renderMonthLabel() {
    const {
      month,
    } = this.state;

    return <span className="month-label">{month.format("MMMM YYYY")}</span>;
  }

  render() {
    return (
      <section className="calendar">
        <header className="header">
          <div className="month-display row">
            <i className="arrow fa fa-angle-left" onClick={this.previous}/>
            {this.renderMonthLabel()}
            <i className="arrow fa fa-angle-right" onClick={this.next}/>
          </div>
          <DayNames />
        </header>
        {this.renderWeeks()}
      </section>
    );
  }
}

class DayNames extends React.Component {
    render() {
        return (
          <div className="row day-names">
            <span className="day">Sun</span>
            <span className="day">Mon</span>
            <span className="day">Tue</span>
            <span className="day">Wed</span>
            <span className="day">Thu</span>
            <span className="day">Fri</span>
            <span className="day">Sat</span>
          </div>
        );
    }
}

class Week extends React.Component {
  render() {
    let days = [];
    let {
      date,
    } = this.props;
    
    const {
      month,
      selected,
      select,
    } = this.props;

    for (var i = 0; i < 7; i++) {
      let day = {
          name: date.format("dd").substring(0, 1),
          number: date.date(),
          isCurrentMonth: date.month() === month.month(),
          isToday: date.isSame(new Date(), "day"),
          date: date
      };
      days.push(
        <Day day={day}
          selected={selected}
          select={select}/>
      );

      date = date.clone();
      date.add(1, "day");
    }

    return (
      <div className="row week" key={days[0]}>
        {days}
      </div>
    );
  }

}

class Day extends React.Component {
  render() {
    const {
      day,
      day: {
        date,
        isCurrentMonth,
        isToday,
        number
      },
      select,
      selected
    } = this.props;

    return (
      <span 
        key={date.toString()} 
        className={"day" + (isToday ? " today" : "") + (isCurrentMonth ? "" : " different-month") + (date.isSame(selected) ? " selected" : "")} 
        onClick={()=>select(day)}>{number}</span>
    );
  }
}

ReactDOM.render(<Calendar/>, document.getElementById('app'));
              
            
!
999px

Console