Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                $height = 49px
$cellWidth = 65px
$selectedColor = #349AEF
@import url(https://fonts.googleapis.com/css?family=Roboto:500,500italic,400,400italic,300,300italic);
html
body
  margin 0
  padding 0
  font-family 'Roboto', serif
  height 100%
*
  box-sizing border-box
#app
  display flex
  height 100%
.calendar
  width 455px
  margin auto
  .calendar__range
    color #5d5d5d
    margin-bottom 10px
    .calendar__from-date
      min-width 180px
      vertical-align top
      min-height 60px
    .calendar__from-date
    .calendar__image-arrow
      display inline-block
    .calendar__image-arrow
      font-size 2.5rem
      color #dbd7db
      margin-right 30px
      vertical-align middle
    .calendar__range-h
      font-size 0.75rem
      text-transform uppercase
    .calendar__range-month
      font-size 1.1rem
    .calendar__range-date
      font-size 2.3rem
      line-height @font-size
      font-weight 100
      margin 0 5px 0 -5px
    .calendar__range-day
      font-size 0.9rem
      color #a2a2a2
      font-weight 100
    td
      padding 0
      line-height 1rem
  .calendar__chooser
    background #FFFDFF
    text-align center
  .calendar__header
    text-align center
    width @width
    padding-top 13px
    border-top 1px solid #efefef
    margin-bottom 4px
    .calendar__month-chooser
      color #5d5d5d
      font-size 1.1rem
      margin-bottom 16px
      width 455px
      padding 0 30px
      .calendar__prev-month
        float left
      .calendar__next-month
        float right
      .calendar__prev-month
      .calendar__next-month
        cursor pointer
        color #a2a2a2
        font-size 1.4rem
        line-height @font-size
  .calendar__days-names
    color #a2a2a2
    font-size 0.8rem
    .calendar__day-name
      min-width $cellWidth
  .calendar__wrap
    max-height 301px
    overflow hidden
    border-top 1px solid #efefef
    border-bottom 1px solid #efefef
  .calendar__table
    transform translate3d(0px, -(($height+1) * 4), 0px)
    transition all .3s ease-in
    cursor pointer
    will-change transform
    &.animate--forward
      animation list-forward .3s forwards
    &.animate--backward
      animation list-backward .3s forwards
    .calendar__day
      z-index -2
      min-width $cellWidth
      padding 0
      text-align center
      color #5D5D5D
      border-bottom 1px solid white
      &:hover
        .calendar__inner-day
          border-radius @height
          border 2px solid $selectedColor
      &.dis
        background #fcf9fc
        border-bottom 1px solid #fcf9fc
      &.selected
        background $selectedColor
        color white
        position relative
      &.sel--start
        position relative
        color white
        &:after
          content ''
          display block
          position absolute
          background $selectedColor
          width 20px
          height $height
          top 0
          right 0
        .calendar__inner-day
          border-radius $height
          border 2px solid $selectedColor
          border-top-right-radius 0
          border-bottom-right-radius 0
          background $selectedColor
      &.sel--end
        position relative
        &:before
          content ''
          display block
          position absolute
          background $selectedColor
          width 30px
          height $height
          top 0
          left 0
          z-index -1
        .calendar__inner-day
          border-radius @height
          border 2px solid $selectedColor
          background white
      &.out--range
        color #E3E3E3
      .calendar__inner-day
        height $height
        width $height
        line-height $height - 4
        border-radius 100%
        border 2px solid transparent
        margin auto
@keyframes list-forward {
  0%{
    transform translate3d(0px,0px,0px)
  }
  100%{
    transform translate3d(0px,-(($height+1) * 4), 0px)
  }
}
@keyframes list-backward {
  0%{
    transform translate3d(0px,-(($height+1) * 4),0px)
  }
  100%{
    transform translate3d(0px,0px,0px)
  }
}

              
            
!

JS

              
                /*Selector Range*/
class Range extends React.Component {
    constructor(props) {
        super(props);
        this.monthNames = ["January", "February", "March", "April", "May", "June",
            "July", "August", "September", "October", "November", "December"];
        this.daysNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    }
    dateInfo(date){
        let dateRow;
        let rangeMonthText = 'Choose a date';
        if(date){
            dateRow = <td rowSpan="2"><span className="calendar__range-date">{date.getDate()}</span></td>;
            rangeMonthText = this.monthNames[date.getMonth()]+' '+ date.getFullYear();
        }
        return (<tr>
            {dateRow}
            <td>
                <span className="calendar__range-month">
                    {rangeMonthText}
                </span>
            </td>
        </tr>);
    }
    dumbDate(date, title){
       let day = (date)?(<tr>
               <td>
                   <span className="calendar__range-day">{this.daysNames[date.getDay()]}</span>
               </td>
           </tr>)
           :null;
       return (<div className="calendar__from-date">
            <table>
                <tbody>
                    <tr>
                        <td colSpan="2"><span className="calendar__range-h">{title}</span></td>
                    </tr>
                    {this.dateInfo(date)}
                    {day}
                </tbody>
            </table>
        </div>)
    }
    render() {
        let {dateFrom, dateTo} = this.props;
        dateTo = dateTo ? new Date(dateTo) : dateTo;
        dateFrom = dateFrom ? new Date(dateFrom) : dateFrom;
        return (<div className="calendar__range">
            {this.dumbDate(dateFrom,'check-in')}
            <div className="calendar__image-arrow">
                <span>&#8594;</span>
            </div>
            {this.dumbDate(dateTo,'check-out')}
        </div>)
    }
}
/*Header Table*/
class Header extends React.Component {
    constructor(props) {
        super(props);
        this.monthNames = ["January", "February", "March", "April", "May", "June",
            "July", "August", "September", "October", "November", "December"];
        this.dayNames = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'];
    }
    shouldComponentUpdate(nextProps){
        return nextProps.date != this.props.date;
    }
    render() {
        let date  = new Date(this.props.date);
        return (<div className="calendar__header">
            <div className="calendar__month-chooser">
                <span className="calendar__prev-month" onClick={this.props.prevMonth}>❮</span>
                <span>{this.monthNames[date.getMonth()]}</span>
                <span className="calendar__next-month" onClick={this.props.nextMonth}>❯</span>
            </div>
            <table className="calendar__days-names" cellSpacing="0">
                <tbody>
                    <tr>
                        {this.dayNames.map((i, key)=> <td className="calendar__day-name" key={key}>{i}</td>)}
                    </tr>
                </tbody>
            </table>
        </div>)
    }
}

/*Calendar Table*/
class Calendar extends React.Component{
    constructor(props){
        super(props);
        this.selectionEnaled = false;
        this.animationDirection = "forward";
        this.shortMonthNames = ['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec']
        this.currentDate = new Date();
    }
    handleClick(index){
        let {setRange, indexStart, indexEnd} = this.props;
        if(this.selectionEnabled ){
            if((index == indexStart)){
                this.selectionEnabled = false;
                setRange();
            }else{
                this.selectionEnabled = false;
                setRange(this.props.indexStart, index);
            }
        }else{
            if(index == indexEnd){
                this.selectionEnabled = true;
            }else{
                this.selectionEnabled = true;
                setRange(index);
            }
        }
    }
    mouseOver(index){
        if(this.selectionEnabled){
            this.props.setRange(this.props.indexStart, index);
        }
    }
    componentWillUpdate(nextProps){
        if(nextProps.date != this.props.date){
            this.animationDirection = (nextProps.date - this.props.date > 0) ? "forward" : "backward"
        }
    }
    componentDidUpdate(prevProps){
        if(prevProps.date != this.props.date){
            this.refs.calendar.classList.add(`animate--${this.animationDirection}`);
        }
    }
    getDay(date, key, month){
        let time = date.getTime();
        let currentDate = this.currentDate;
        let {indexEnd, indexStart} = this.props;
        let dayClass = (time > indexStart && time < indexEnd) ? 'selected' : '';
        dayClass += ( date < currentDate.setHours(0)) ?' out--range':'';
        dayClass += (time == indexStart && indexEnd > indexStart) ? ' sel--start' : '';
        dayClass += (time == indexEnd && time > indexStart) ? ' sel--end' : '';
        dayClass += (date.getMonth() == month)?' calendar__day':' calendar__day dis';
        return(<td className={dayClass}
                   onClick={this.handleClick.bind(this, time)}
                   onMouseOver={this.mouseOver.bind(this,time)}
                   key={key}>
                       <div className="calendar__inner-day">
                           {date.getDate()}
                       </div>
              </td>)
    }
    render(){
        let date  = new Date(this.props.date);
        let month = date.getMonth();
        date.setDate(1);
        if(this.animationDirection == "forward"){
            date.setMonth(date.getMonth() - 1);
        }
        let firstDay = date.getDay();
        if(firstDay !== 1){
            (firstDay == 0)?
                date.setDate(date.getDate() - 6)
                :date.setDate(date.getDate() - (firstDay - 1));
        }
        date.setDate(date.getDate() - 1);
        return(<div className="calendar__wrap">
            <table className="calendar__table" ref="calendar" key={this.props.date} cellSpacing="0">
                <tbody>
                {Array(12).fill(0).map((i, key)=> {
                    return <tr key={key}>
                        {Array(7).fill(0).map((_i, _key)=> {
                            date.setDate(date.getDate() + 1);
                            return this.getDay(date, _key, month);
                        })}
                    </tr>
                })}
                </tbody>
            </table>
        </div>)
    }
}


/*Smart Component*/
class APP extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            date:Date.now(),
            selectionStart: 0,
            selectionEnd: 0
        }
    }
    prevMonth(){
        let date = new Date(this.state.date);
        date.setMonth(date.getMonth() - 1);
        this.setState({date:date.getTime()});
    }
    nextMonth(){
        let date = new Date(this.state.date);
        date.setMonth(date.getMonth() + 1);
        this.setState({date:date.getTime()});
    }
    setRange(selectionStart = 0, selectionEnd = 0){
        this.setState({selectionStart, selectionEnd});
    }
    render(){
       let {date, selectionStart, selectionEnd} = this.state;
       return (<div className="calendar">
           <Range dateFrom={selectionStart} dateTo={selectionEnd}/>
           <Header date={date} prevMonth={::this.prevMonth} nextMonth={::this.nextMonth}/>
           <Calendar date={date}
                     indexStart = {selectionStart}
                     indexEnd = {selectionEnd}
                     setRange = {::this.setRange}
                     />
       </div>)
    }
}

ReactDOM.render(<APP />, document.querySelector('#app'));
              
            
!
999px

Console