Code Monkey home page Code Monkey logo

react-yearly-calendar's Introduction

React-yearly-calendar

React calendar component with yearly view.

npm version Alt text

$ npm install react-yearly-calendar

Demo

http://belkalab.github.io/react-yearly-calendar/

http://belkalab.github.io/react-yearly-calendar/

Or taste an example usage below:

var ReactDOM = require('react-dom');
var {Calendar, CalendarControls} = require('react-yearly-calendar');

function onDatePicked(date) {
  alert(date);
}

ReactDOM.render(
  <Calendar
    year={2018}
    onPickDate={onDatePicked}
  />,
  document.getElementById('calendar')
);

Options

Calendar

Prop Type Description Default
year React.PropTypes.number.isRequired year to be displayed current year
selectedDay moment.js object selected day today
forceFullWeeks React.PropTypes.bool match calendar row end with row start false
showDaysOfWeek React.PropTypes.bool show table header with days of week true
showWeekSeparators React.PropTypes.bool shows a blank column between one week and another true
firstDayOfWeek React.PropTypes.number select first day of week 0 (Sunday)
selectRange React.PropTypes.bool enable selecting ranges false
selectedRange [moment.js obj, moment.js obj] selected range of dates in the form [start, end]
customClasses React.PropTypes.object, React.PropTypes.func custom days/periods coloring (see section below)
titles React.PropTypes.func function mapping dates to html titles

CalendarControls

Prop Type Description Default
year React.PropTypes.number.isRequired current year number current year
showTodayButton React.PropTypes.bool show Today button on top left true

Callbacks

Calendar

Prop Type Syntax Description
onPickDate React.PropTypes.func function(selectedDay, dayClasses) {} called when user clicks on a day. dayClasses is a string representing the classes applied to that day
onPickRange React.PropTypes.func function(rangeStart, rangeEnd) {} called when user selects a range of dates (only in selectRange mode)

CalendarControls

Prop Type Syntax Description
onPrevYear React.PropTypes.func function() {} called on user clicking « (previous year button)
onNextYear React.PropTypes.func function() {} called on user clicking » (next year button)
goToToday React.PropTypes.func function() {} called on user clicking the today button

Styling guide

The calendar is rendered as an html table element, to ensure proper displaying even in case the style isn't being loaded.

Take a look at the css file in examples/basic/src/style.css. Here are some head-ups if you want to style it yourself.

  • table.calendar: the main element that renders the calendar
  • table.calendar thead: renders the week day names
  • table.calendar thead th.bolder: adds bolder class to Sundays
  • table.calendar td.month-name: first column in table body, showing month names
  • table.calendar td.prev-month, table.calendar td.next-month: classes applied to the days of the previous and next month showed in a month's row to fill it up. Day numbers and callbacks are present even in these cells, so we suggest to play with text color to make days less intrusive and add pointer-events: none to prevent clicking.
  • table.calendar td.week-separator: class applied to table cells used to separate one week from another. As above, pointer-events: none is suggested
  • table.calendar td.selected: the currently selected day
  • table.calendar td.bolder: the days which are Sundays
  • table.calendar td.range: the days in the selected range
  • table.calendar td.range-left, table.calendar td.range-right: the left and right boundaries of the selected range

  • div.calendar-controls: the main CalendarControls container
  • div.calendar-controls .current-year: the current year
  • div.calendar-controls .controls: applies to next and previous arrows and to today button
  • div.calendar-controls .today: the today button

Responsive

A first attempt at making this design responsive can be seen here (window width < 1200px triggers mobile layout). Suggestions and feedback on this are welcome on issue #10

Custom days/periods colors

By passing the customClasses prop, you can have a fine control on which CSS classes are assigned to each day.

  • customClasses can be a function accepting a moment object as a parameter, giving back the css class to be applied to the given day.
const customClasses = day => ( day.isBefore( moment([day.year(),2,21]) ) || day.isAfter( moment([day.year(),11,21]) ) ) ? 'cheap low-season': 'expensive high-season'
  • If customClasses is an object, the Calendar will use the keys as css classes and the values as rules to apply them.
    • if the value is an array of strings in the form YYYY-MM-DD, those days will be given the css class. Useful for single days, like holidays!
    • if the value is an object with a start and an end value (still in the YYYY-MM-DD form), the days in that period will be given the css class. Nice for seasons!
    • if the value is a string of comma-separated, three-letter weekdays names in the form "ddd,ddd", the class will be given to the days of the week appearing on the string. Great for closing days during the week!
    • if the value is a function returning a boolean value, the class will be assigned using the function itself as a test. A must have for the finest tuning!

Confused? see the snippet below or try it yourself with this interactive example!

const customCSSclasses = {
  holidays: [
    '2018-04-25',
    '2018-05-01',
    '2018-06-02',
    '2018-08-15',
    '2018-11-01'
  ],
  spring: {
    start: '2018-03-21',
    end: '2018-6-20'
  },
  summer: {
    start: '2018-06-21',
    end: '2018-09-22'
  },
  autumn: {
    start: '2018-09-23',
    end: '2018-12-21'
  },
  weekend: 'Sat,Sun',
  winter: day => day.isBefore( moment([2018,2,21]) ) || day.isAfter( moment([2018,11,21]))
}

Build it yourself

Clone and run

$ npm install

License

react-yearly-calendar is Copyright (c) 2016-2020 Belka s.r.l.

It is free software, and may be redistributed under the terms specified in the LICENSE file (TL;DR: MIT license).

About Belka

Belka is a Digital Agency focused on design, mobile applications development and custom solutions. We love open source software! You can see our projects or look at our case studies.

Interested? Hire us to help you build your next amazing project.

www.belkadigital.com

react-yearly-calendar's People

Contributors

furious-luke avatar giovannifrigo avatar hanse avatar lcfd avatar stecb avatar trejgun avatar valgaze avatar victorpinheiro avatar whamtet avatar woodenconsulting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-yearly-calendar's Issues

style is disappear

react is not has a hash,but less has hash,I use umi,how can I resolve?

Highlight particular days

Hi,

It's possible to bind a list of dates (moment) to be highlighted on the calendar like event, for example officials holidays or birthdays? A limitation fo 1 event per days should work for my use case.

Best Regards,
Fábio Correia

componentWillReceiveProps has been renamed

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: Month

seems quite clear !!!

Missing Key Properties

Howdy,

Awesome job with this calendar, it's fantastic!

I noticed some missing key props (using React 0.14.7 which throws errors in the console).

https://github.com/BelkaLab/react-yearly-calendar/blob/master/src/Calendar.js#L88
https://github.com/BelkaLab/react-yearly-calendar/blob/master/src/Month.js#L208

screen shot 2016-03-21 at 4 35 52 pm

I'm about to fix the issue in a fork as I need it cleaned up for what I'm working on. I will open a pull request afterwords if you would like to merge it.

Thanks again for this awesome calendar!

Component is not accessible

The component is not accessible: it is not possible to click on controls (<< and >>) . It is not possible navigate between table cell using tab or arrows

Wrong td bolder styles

Behaviour
The "bolder" styles applied to table td elements, are always applied to sunday independently.
This is, ignoring props like: firstDayOfWeek or weekend in customClasses.

Expected
Maybe both or one of these options:
The "bolder" styles applied to firstDayOfWeek when showing days at top.
The "bolder" styles applied to weekend days when using customClasses.

Anyway, really nice work
: )

Uncaught TypeError: Cannot read property '0' of undefined

I'm trying to set up methods, according to the example, to select a range between dates, but no matter what I do, this error pops up at line 229 of Month.js file:

var start = (selectingRange || selectedRange)[0];

This is my attempt. A modal that pops up the Calendar, receiving via props a method from the parent to then store in the state the selected range:

The modal:

class AvailabilityOfPostModal extends BaseModal {
  onPickRange = (s, e) => {
    const { onPickRange } = this.props;
    onPickRange(s, e);
  };

  renderHeader = () => {
    return (
      <h4 className="title">
        Choose a starting and ending date.
      </h4>
    )
  };

  renderBody = () => {
    return (
      <Calendar
        year={moment().format('Y')}
        selectRange={true}
        onPickRange={(s, e) => this.onPickRange(s, e)}
      />
    )
  }
}

export default AvailabilityOfPostModal;

Parent:

...
onChangeRange = (start, end) => {
  this.setState({
    selectedRange: [start, end],
    selectedDay: start
  });
};
...
render() {
  ...
  <AvailabilityOfPostModal ref="availabilityOfPostModal" onPickRange={this.onChangeRange} />
  ...  
}

What am I missing?

Uncaught TypeError: Cannot read property '0' of undefined

I love the Calendar, is it still maintained?

´Found an Issue while selecting a Range the selectingRange prop is not defined. Is it even needed?
var newRangeStart = nextProps.selectingRange[0].month();

Uncaught TypeError: Cannot read property '0' of undefined
    at Month.shouldComponentUpdate (Month.js:89)
    at eval (ReactCompositeComponent.js:622)
    at measureLifeCyclePerf (ReactCompositeComponent.js:73)
    at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:621)
    at ReactCompositeComponentWrapper.receiveComponent (ReactCompositeComponent.js:544)
    at Object.receiveComponent (ReactReconciler.js:122)
    at Object.updateChildren (ReactChildReconciler.js:107)
    at ReactDOMComponent._reconcilerUpdateChildren (ReactMultiChild.js:204)
    at ReactDOMComponent._updateChildren (ReactMultiChild.js:308)
    at ReactDOMComponent.updateChildren (ReactMultiChild.js:295)

Thank you.

Date hover

Hi

Is there anyway to show tooltip when hover selected date or date range?

Thanks

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended

Hello

I get this warning since I upgraded React to v17 :

Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended 
and may indicate bugs in your code. See https://reactjs.org/link/unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques 
* or move it to static getDerivedStateFromProps. Learn more at: https://reactjs.org/link/derived-state

Please update the following components: Month

Here is the code to reproduce it :

https://codesandbox.io/s/bug-yearly-izs2q

Is there any plan to remove this warning ?

Fix weekdays name in Portuguese

Moment.js has some weird behavior with Portuguese dates.
I have sent a PR to fix the function to display the names correctly.

Functionality question

Does this library support text overlay on day/days and multiple events (custom class Event1, Event2 etc.) on single day or multiple day span.

Determine which custom Class was set on the clickedDate

Hey,

first of all thank you very much for sharing this awesome project.
I would love to have the option to determine which custom Class/Classes are set on the selected Day. If this would be enabled by default, it would help to make this Calendar much more attractive for non static use-cases.

Currently I´m searching for the class selected

var select = document.getElementsByClassName('selected');
console.log(select[0].classList)

and do my stuff. But a cleaner, more usable way would be awesome.

Thanks

select Date/ Daterange pro programmatically

Hey,

in addition to my previous feature request, the next step for non-static use-cases would be to have an option to select a date/ date range programmatically.

It could be a simple method that takes a date or a daterange and returns all classes for that are set on the date/ date range.

If you have some time, could you probably implement that too? Would be awesome.

Thanks

Select range of dates

How do I highlight/select/add class to a range of dates?
I would like to have a button, after clicking range of dates should be selected/highlighted. Is this possible?

2 months only ?

Hi, is there option to reduce number of months to two, for the example ?

Responsive example

Hi. I was wondering if you had any ideas on how one would make the 'basic demo' responsive. For example, in a narrower viewport, it would switch to a more traditional calendar, or maybe have the days of the month laid out as a column (instead of a row)

Pass the Day instance as parameter of the onPickDate callback

Hello, thanks for sharing this great calendar !

I would like to know if it was possible to pass the clicked Day instance as param of the onPickDate callback.
I need to show a popup above the clicked day and so I need a ref to the Day instance which was clicked for positioning.

Thanks a lot !

(I'm forking your project to see if I can implement something useful )

Install react-yearly-calendar in next-js

I can't find a way to install this in next js, since you can't import css globally outside of _app.js. The css file throw me lot of error like :
`Syntax error: Unclosed block

175 | }
176 |

177 | div.options select {
| ^
178 | margin-left: 10px;`

Any help on this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.