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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                #app
              
            
!

CSS

              
                $line-color: #fff;
$font-color: $line-color;
$font-color-emphasis: #F8CA00;
$highlight-color-background: lighten(#8A9B0F, 5%);
$app-color-background: darken(#490A3D, 7%);
$calendar-color-background: #BD1550;
$calendar-color-alt-background: #E97F02;
$calendar-padding: 10px;

html, body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  
  background: linear-gradient(darken($app-color-background, 20%), $app-color-background),
    linear-gradient(90deg, lighten($app-color-background, 2%), transparent),
    linear-gradient(-90deg, darken($app-color-background, 2%), transparent);

  background-blend-mode: screen;
  background-size: cover;
}

#app {
  margin-top: 30vh;
  height: 100%;
}

.date-picker {
  position: relative;
  color: $font-color;
  width: 240px;
  box-sizing: border-box;
  font-family: 'Nunito Sans', sans-serif;
}

.date-picker__date-selection {
  padding: 10px;
  font-size: 24px;
  display: flex;
  cursor: pointer;
}

.date-picker__input {
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  margin-left: 1em;
  border: none;
  border-bottom: 2px solid $line-color;
  cursor: inherit;
  background: inherit;
  color: inherit;
  
  &:focus {
    outline: none;
  }
  
  &::placeholder {
    color: inherit;
    opacity: 0.7;
  }
}

.date-picker__calendar {
  position: absolute;
}

.calendar {
  box-sizing: border-box;
  width: inherit;
  min-height: 17em;
  padding: $calendar-padding;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: $font-color;
  font-size: 14px;
  border: 1px solid $line-color;
  border-radius: 5px;
  user-select: none;
  background: $calendar-color-background;
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
  font-family: 'Nunito Sans', sans-serif;
}

.calendar__controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding-bottom: 0.5em;
  font-weight: bold;
  
  .fas {
    cursor: pointer;
  }
}

.calendar__controls {
  align-self: stretch;
  display: flex;
  
  .fas {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.calendar__week,
.calendar__days-of-week {
  display: flex;
  justify-content: space-between;
}

.calendar__days-of-week {
  font-weight: bold;
  border-bottom: 1px solid $line-color;
  border-top: 1px solid $line-color;
  margin-bottom: 0.5em;
  margin-left: -$calendar-padding;
  margin-right: -$calendar-padding;
  padding: 0 $calendar-padding;
  background: $calendar-color-alt-background;
}

.calendar__day,
.calendar__day-of-week,
.calendar__month-with-year,
.calendar__controls .fas {
  text-align: center;
  min-width: 1.2em;
  padding: 0.2em;
}

.calendar__day,
.calendar__month-with-year,
.calendar__controls .fas {
  cursor: pointer;
  border-radius: 5px;
  transition: all 0.3s;
  
  &:hover {
    background: $highlight-color-background;
  }
}

.calendar__day--pale {
  color: rgba($font-color, 0.5);
}

.calendar__day--emphasize {
  font-weight: bold;
  color: $font-color-emphasis;
}
              
            
!

JS

              
                console.clear();

// Helpers
const getDaysForCalendar = (date = new Date(), calendarSize = 42) => {
  const visibleCalendarDays = [];
  const monthStartDate = dateFns.startOfMonth(date);
  const monthEndDate = dateFns.endOfMonth(date);
  const monthStartDayOfWeek = monthStartDate.getDay();
  const daysInMonth = dateFns.getDaysInMonth(date);
  const numOfDaysToAddBefore = monthStartDayOfWeek - 1;
  const calendarStartDate = dateFns.subDays(
    monthStartDate,
    numOfDaysToAddBefore
  );
  const calendarEndDate = dateFns.addDays(
    monthEndDate,
    calendarSize - daysInMonth - numOfDaysToAddBefore
  );

  dateFns
    .eachDay(calendarStartDate, calendarEndDate)
    .forEach(date => visibleCalendarDays.push(date));

  return visibleCalendarDays;
};

const getDaysByWeek = (days = []) => {
  const DAYS_IN_WEEK = 7;
  const result = [];
  let weekOfDays = [];

  days.forEach(day => {
    if (weekOfDays.length === DAYS_IN_WEEK) {
      result.push(weekOfDays);
      weekOfDays = [];
    }

    weekOfDays.push(day);
  });

  result.push(weekOfDays);
  return result;
};

const getMonthAsWord = date => date.toString().split(' ')[1];



// View
class Calendar extends React.Component {
  constructor(props) {
    super(props);
    this.state = { date: props.date };
  }
  
  addMonth = () => this.setState({ date: dateFns.addMonths(this.state.date, 1) });
  subMonth = () => this.setState({ date: dateFns.subMonths(this.state.date, 1) });
  addYear = () => this.setState({ date: dateFns.addYears(this.state.date, 1 ) });
  subYear = () => this.setState({ date: dateFns.subYears(this.state.date, 1 ) });
  showCurrentDate = () => this.setState({ date: new Date() });
  
  renderControls() {
    const { date } = this.state;
    return (
      <div className="calendar__controls-row">
        <div className="calendar__controls">
          <i className="fas fa-angle-left" onClick={this.subMonth}></i>
          <i className="fas fa-angle-double-left" onClick={this.subYear}></i>
        </div>
        <div
          className="calendar__month-with-year"
          onClick={this.showCurrentDate}
        >
          {getMonthAsWord(date)}{' '}{date.getFullYear()}
        </div>
        <div className="calendar__controls">
          <i className="fas fa-angle-double-right" onClick={this.addYear}></i>
          <i className="fas fa-angle-right" onClick={this.addMonth}></i>
        </div>
      </div>
    );
  }
  
  renderDaysOfWeek() {
    return (
      <div className="calendar__days-of-week">
        {['M', 'T', 'W', 'T', 'F', 'S', 'S'].map((letter, i) => (
          <div className="calendar__day-of-week" key={i}>{letter}</div>
        ))}
      </div>
    );
  }
  
  renderDate(date) {
    return (
      <div
        className={classNames(
          'calendar__day',
          {
            'calendar__day--pale': !dateFns.isSameMonth(date, this.state.date),
            'calendar__day--emphasize': dateFns.isToday(date)
          }
        )}
        onClick={() => this.props.onDatePick(date)}
        key={date}
      >
        {date.getDate()}
      </div>
    );
  }
  
  render() {
    const weeksWithDaysInside = getDaysByWeek(getDaysForCalendar(this.state.date));
    
    return (
      <div className={classNames('calendar', this.props.className)}>
        {this.renderControls()}
        {this.renderDaysOfWeek()}
        {weeksWithDaysInside.map((week, i) => (
          <div className="calendar__week" key={i}>
            {week.map(this.renderDate, this)}
          </div>
        ))}
      </div>
    );
  }
}

class DatePicker extends React.Component {
  static defaultProps = {
    dateFormat: 'DD.MM.YYYY'
  };

  constructor() {
    super();
    
    this.state = {
      isCalendarOpen: false,
      selectedDate: null
    };
  }
  
  handleClick = event => {
    event.preventDefault();
    event.target.blur();
    this.setState({ isCalendarOpen: !this.state.isCalendarOpen });
  };

  handleDatePick = date => {
    this.setState({
      isCalendarOpen: false,
      selectedDate: date
    });
    this.props.onDatePick(date);
  };
  
  render() {
    const { onDatePick, dateFormat } = this.props;
    const { isCalendarOpen, selectedDate } = this.state;
    
    return (
      <div className="date-picker">
        <div className="date-picker__date-selection" onClick={this.handleClick}>
          <i className="far fa-calendar-alt"></i>
          <input
            className="date-picker__input"
            type="text"
            placeholder="Select Date"
            value={selectedDate && dateFns.format(selectedDate, dateFormat)}
          />
        </div>
        {isCalendarOpen &&
          <Calendar
            className="date-picker__calendar"
            date={selectedDate || new Date()}
            onDatePick={this.handleDatePick}
          />
        }
      </div>
    );
  }
}

ReactDOM.render(
  <DatePicker onDatePick={date => console.log(date.toString())} />,
  document.getElementById('app')
);





new Footer().appendToDocument().stylize({
  footer: {
    background: 'rgba(11, 11, 11, 0.2)',
    color: '#666'
  }
});
              
            
!
999px

Console