diff options
Diffstat (limited to 'toolkit/content/widgets/calendar.js')
-rw-r--r-- | toolkit/content/widgets/calendar.js | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/toolkit/content/widgets/calendar.js b/toolkit/content/widgets/calendar.js index 80c2976e0..44ba67501 100644 --- a/toolkit/content/widgets/calendar.js +++ b/toolkit/content/widgets/calendar.js @@ -11,6 +11,9 @@ * @param {Object} options * { * {Number} calViewSize: Number of days to appear on a calendar view + * {Function} getDayString: Transform day number to string + * {Function} getWeekHeaderString: Transform day of week number to string + * {Function} setSelection: Set selection for dateKeeper * } * @param {Object} context * { @@ -24,9 +27,11 @@ function Calendar(options, context) { this.context = context; this.state = { days: [], - weekHeaders: [] + weekHeaders: [], + setSelection: options.setSelection, + getDayString: options.getDayString, + getWeekHeaderString: options.getWeekHeaderString }; - this.props = {}; this.elements = { weekHeaders: this._generateNodes(DAYS_IN_A_WEEK, context.weekHeader), daysView: this._generateNodes(options.calViewSize, context.daysView) @@ -46,34 +51,32 @@ function Calendar(options, context) { * {Boolean} isVisible: Whether or not the calendar is in view * {Array<Object>} days: Data for days * { - * {Number} dateValue: Date in milliseconds - * {Number} textContent + * {Date} dateObj + * {Number} content * {Array<String>} classNames + * {Boolean} enabled * } * {Array<Object>} weekHeaders: Data for weekHeaders * { - * {Number} textContent + * {Number} content * {Array<String>} classNames - * {Boolean} enabled * } - * {Function} getDayString: Transform day number to string - * {Function} getWeekHeaderString: Transform day of week number to string - * {Function} setSelection: Set selection for dateKeeper * } */ setProps(props) { if (props.isVisible) { // Transform the days and weekHeaders array for rendering - const days = props.days.map(({ dateObj, classNames, enabled }) => { + const days = props.days.map(({ dateObj, content, classNames, enabled }) => { return { - textContent: props.getDayString(dateObj.getUTCDate()), + dateObj, + textContent: this.state.getDayString(content), className: classNames.join(" "), enabled }; }); - const weekHeaders = props.weekHeaders.map(({ textContent, classNames }) => { + const weekHeaders = props.weekHeaders.map(({ content, classNames }) => { return { - textContent: props.getWeekHeaderString(textContent), + textContent: this.state.getWeekHeaderString(content), className: classNames.join(" ") }; }); @@ -92,8 +95,6 @@ function Calendar(options, context) { this.state.days = days; this.state.weekHeaders = weekHeaders; } - - this.props = Object.assign(this.props, props); }, /** @@ -150,9 +151,9 @@ function Calendar(options, context) { case "click": { if (event.target.parentNode == this.context.daysView) { let targetId = event.target.dataset.id; - let targetObj = this.props.days[targetId]; + let targetObj = this.state.days[targetId]; if (targetObj.enabled) { - this.props.setSelection(targetObj.dateObj); + this.state.setSelection(targetObj.dateObj); } } break; |