1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | 370× 370× 370× 3× 370× 37× 370× 1× 370× 7× 370× 314× 314× 314× 314× 426× 426× 314× 314× 314× 314× 314× 314× 314× 314× 314× 314× 314× 314× 314× 426× 426× 370× 370× 314× 56× 56× 56× | import Component from '@ember/component'; import { computed } from '@ember/object'; import layout from '../../templates/components/polaris-date-picker/day'; import { monthsArray, isSameDay, dateIsInRange, dateIsSelected, isDateBefore, isDateAfter } from '../../utils/dates'; export default Component.extend({ tagName: '', layout, /** * @property focusedDate * @public * @type {Date} * @default null */ focusedDate: null, /** * @property day * @public * @type {Date} * @default null */ day: null, /** * @property selectedDates * @public * @type {Object} * @default null */ selectedDates: null, /** * @property disableDatesBefore * @public * @type {Date} * @default null */ disableDatesBefore: null, /** * @property disableDatesAfter * @public * @type {Date} * @default null */ disableDatesAfter: null, /** * @property allowRange * @public * @type {Boolean} * @default false */ allowRange: false, /** * @property onClick * @public * @type {Function} * @default noop */ onClick(/* day */) {}, /** * @property onHover * @public * @type {Function} * @default noop */ onHover(/* day */) {}, /** * @property onFocus * @public * @type {Function} * @default noop */ onFocus(/* day */) {}, dayButtonClasses: computed('selected', 'disabled', 'isDateToday', 'inHoveringRange', 'inRange', function() { let classNames = ['Polaris-DatePicker__Day']; let { selected, disabled, isDateToday, inHoveringRange, inRange } = this.getProperties( 'selected', 'disabled', 'isDateToday', 'inHoveringRange', 'inRange' ); if (selected) { classNames.push('Polaris-DatePicker__Day--selected'); } if (disabled) { classNames.push('Polaris-DatePicker__Day--disabled'); } if (isDateToday) { classNames.push('Polaris-DatePicker__Day--today'); } if (inHoveringRange || inRange) { classNames.push('Polaris-DatePicker__Day--inRange'); } return classNames.join(' '); }).readOnly(), date: computed('day', function() { let day = this.get('day'); return day.getDate(); }).readOnly(), isDateToday: computed('day', function() { let day = this.get('day'); return isSameDay(new Date(), day); }).readOnly(), focused: computed('focusedDate', 'day', function() { let { focusedDate, day } = this.getProperties('focusedDate', 'day'); return focusedDate !== null && isSameDay(day, focusedDate); }).readOnly(), selected: computed('selectedDates', 'day', function() { let { selectedDates, day } = this.getProperties('selectedDates', 'day'); return selectedDates !== null && dateIsSelected(day, selectedDates); }).readOnly(), inRange: computed('selectedDates', 'day', function() { let selectedDates = this.get('selectedDates'); let day = this.get('day'); return selectedDates !== null && dateIsInRange(day, selectedDates); }).readOnly(), disabled: computed('day', 'disableDatesBefore', 'disableDatesAfter', function() { let { day, disableDatesBefore, disableDatesAfter } = this.getProperties('day', 'disableDatesBefore', 'disableDatesAfter'); return (disableDatesBefore && isDateBefore(day, disableDatesBefore)) || (disableDatesAfter && isDateAfter(day, disableDatesAfter)) }).readOnly(), ariaLabel: computed('day', 'isDateToday', 'date', function() { let isDateToday = this.get('isDateToday'); let day = this.get('day'); let month = monthsArray[ day.getMonth() ]; let date = this.get('date'); let year = day.getFullYear(); return `${ isDateToday ? 'Today ' : '' }${ month } ${ date } ${ year }`; }).readOnly(), tabIndex: computed('focused', 'selected', 'disabled', 'date', 'isDateToday', function() { let { focused, selected, disabled, date, isDateToday } = this.getProperties('focused', 'selected', 'disabled', 'date', 'isDateToday'); return (focused || selected || isDateToday || date === 1) && !disabled ? 0 : -1; }).readOnly(), inHoveringRange: computed('day', 'selectedDates', 'hoverDate', 'allowRange', function() { let { day, allowRange } = this.getProperties('day', 'allowRange'); if (!allowRange || day === null) { return false; } let { selectedDates, hoverDate } = this.getProperties('selectedDates', 'hoverDate'); const { start, end } = selectedDates; return start === end && day > start && day <= hoverDate; }).readOnly() }); |