|
|
@@ -1,94 +1,24 @@
|
|
|
-import Component, { ComponentContext } from '../component/Component'
|
|
|
-import { htmlToElement, removeElement } from '../util/dom-manip'
|
|
|
-import { DateMarker, DAY_IDS } from '../datelib/marker'
|
|
|
-import { DateProfile } from '../DateProfileGenerator'
|
|
|
import { rangeContainsMarker } from '../datelib/date-range'
|
|
|
import { htmlEscape } from '../util/html'
|
|
|
import { buildGotoAnchorHtml, getDayClasses } from '../component/date-rendering'
|
|
|
-import { createFormatter } from '../datelib/formatting'
|
|
|
-
|
|
|
-export interface DayTableHeaderProps {
|
|
|
- dates: DateMarker[]
|
|
|
- dateProfile: DateProfile
|
|
|
- datesRepDistinctDays: boolean
|
|
|
- renderIntroHtml?: () => string
|
|
|
-}
|
|
|
-
|
|
|
-export default class DayTableHeader extends Component<DayTableHeaderProps> {
|
|
|
-
|
|
|
- el: HTMLElement
|
|
|
- thead: HTMLElement
|
|
|
-
|
|
|
- constructor(context: ComponentContext, parentEl: HTMLElement) {
|
|
|
- super(context)
|
|
|
-
|
|
|
- parentEl.innerHTML = '' // because might be nbsp
|
|
|
- parentEl.appendChild(
|
|
|
- this.el = htmlToElement(
|
|
|
- '<div class="fc-row ' + this.theme.getClass('headerRow') + '">' +
|
|
|
- '<table class="' + this.theme.getClass('tableGrid') + '">' +
|
|
|
- '<thead></thead>' +
|
|
|
- '</table>' +
|
|
|
- '</div>'
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- this.thead = this.el.querySelector('thead')
|
|
|
- }
|
|
|
-
|
|
|
- destroy() {
|
|
|
- removeElement(this.el)
|
|
|
- }
|
|
|
-
|
|
|
- render(props: DayTableHeaderProps) {
|
|
|
- let { dates, datesRepDistinctDays } = props
|
|
|
- let parts = []
|
|
|
-
|
|
|
- if (props.renderIntroHtml) {
|
|
|
- parts.push(props.renderIntroHtml())
|
|
|
- }
|
|
|
-
|
|
|
- let colHeadFormat = createFormatter(
|
|
|
- this.opt('columnHeaderFormat') ||
|
|
|
- computeFallbackHeaderFormat(datesRepDistinctDays, dates.length)
|
|
|
- )
|
|
|
-
|
|
|
- for (let date of dates) {
|
|
|
- parts.push(
|
|
|
- renderDateCell(
|
|
|
- date,
|
|
|
- props.dateProfile,
|
|
|
- datesRepDistinctDays,
|
|
|
- dates.length,
|
|
|
- colHeadFormat,
|
|
|
- this.context
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- if (this.isRtl) {
|
|
|
- parts.reverse()
|
|
|
- }
|
|
|
-
|
|
|
- this.thead.innerHTML = '<tr>' + parts.join('') + '</tr>'
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+import { DateMarker, DAY_IDS } from '../datelib/marker'
|
|
|
+import { DateProfile } from '../DateProfileGenerator'
|
|
|
+import { ComponentContext } from '../component/Component'
|
|
|
|
|
|
// Computes a default column header formatting string if `colFormat` is not explicitly defined
|
|
|
-function computeFallbackHeaderFormat(datesRepDistinctDays: boolean, dayCnt: number) {
|
|
|
- // if more than one week row, or if there are a lot of columns with not much space,
|
|
|
- // put just the day numbers will be in each cell
|
|
|
- if (!datesRepDistinctDays || dayCnt > 10) {
|
|
|
- return { weekday: 'short' } // "Sat"
|
|
|
- } else if (dayCnt > 1) {
|
|
|
- return { weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true } // "Sat 11/12"
|
|
|
- } else {
|
|
|
- return { weekday: 'long' } // "Saturday"
|
|
|
- }
|
|
|
+export function computeFallbackHeaderFormat(datesRepDistinctDays: boolean, dayCnt: number) {
|
|
|
+ // if more than one week row, or if there are a lot of columns with not much space,
|
|
|
+ // put just the day numbers will be in each cell
|
|
|
+ if (!datesRepDistinctDays || dayCnt > 10) {
|
|
|
+ return { weekday: 'short' } // "Sat"
|
|
|
+ } else if (dayCnt > 1) {
|
|
|
+ return { weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true } // "Sat 11/12"
|
|
|
+ } else {
|
|
|
+ return { weekday: 'long' } // "Saturday"
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function renderDateCell(
|
|
|
+export function renderDateCell(
|
|
|
date: DateMarker,
|
|
|
dateProfile: DateProfile,
|
|
|
datesRepDistinctDays,
|