@soul-refiner/design-system 1.7.4 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,5 +2,6 @@ import React from 'react';
|
|
|
2
2
|
export interface CalendarInputProps {
|
|
3
3
|
selectedDate: Date | null;
|
|
4
4
|
onSelect: (value: Date) => void;
|
|
5
|
+
disablePastDates?: true;
|
|
5
6
|
}
|
|
6
|
-
export declare const CalendarInput: ({ selectedDate, onSelect: parentOnSelect, }: CalendarInputProps) => React.JSX.Element;
|
|
7
|
+
export declare const CalendarInput: ({ selectedDate, onSelect: parentOnSelect, disablePastDates, }: CalendarInputProps) => React.JSX.Element;
|
|
@@ -5,7 +5,7 @@ import { MONTHS, WEEKDAYS } from '../../../common';
|
|
|
5
5
|
import { Button, P } from '../..';
|
|
6
6
|
import { ChevronLeft, ChevronRight, Calendar as CalendarIcon, } from '../../../icons';
|
|
7
7
|
import { buildCalendar, zeroPad } from '../../../utils';
|
|
8
|
-
export const CalendarInput = ({ selectedDate, onSelect: parentOnSelect, }) => {
|
|
8
|
+
export const CalendarInput = ({ selectedDate, onSelect: parentOnSelect, disablePastDates, }) => {
|
|
9
9
|
const today = new Date();
|
|
10
10
|
today.setHours(0);
|
|
11
11
|
today.setMinutes(0);
|
|
@@ -83,13 +83,17 @@ export const CalendarInput = ({ selectedDate, onSelect: parentOnSelect, }) => {
|
|
|
83
83
|
React.createElement(WeekdayWrapper, null, Object.values(WEEKDAYS).map((day) => (React.createElement(P, { key: day }, day)))),
|
|
84
84
|
React.createElement(Calendar, null, calendar.map((week, index) => {
|
|
85
85
|
return (React.createElement(Week, { key: 'week-' + index.toString(36) }, week.map((day, dayIndex) => {
|
|
86
|
+
const dateObj = new Date(`${day[1]}-${day[2]}-${day[0]}`);
|
|
87
|
+
const isPastDate = today.getTime() - dateObj.getTime() > 0;
|
|
86
88
|
const isCurrMonth = day[1] !==
|
|
87
89
|
zeroPad(new Date(displayDate).getMonth() + 1, 2);
|
|
88
|
-
const
|
|
90
|
+
const isNotCurrent = disablePastDates
|
|
91
|
+
? isPastDate
|
|
92
|
+
: isCurrMonth;
|
|
89
93
|
const isToday = Math.abs(dateObj.getTime() - today.getTime()) < 0.5;
|
|
90
94
|
const isSelected = new Date(componentSelectedDate).getTime() ===
|
|
91
95
|
dateObj.getTime();
|
|
92
|
-
return (React.createElement(Day, { className: `${isToday ? 'today' : ''}${
|
|
96
|
+
return (React.createElement(Day, { className: `${isToday ? 'today' : ''}${isNotCurrent ? ' not-current' : ''}${isSelected ? ' selected' : ''}`.trim(), "data-day": day[2], "data-month": day[1], "data-year": day[0], key: 'day-' + dayIndex.toString(36), onClick: handleClick }, `${day[2]}`.startsWith('0')
|
|
93
97
|
? `${day[2]}`[1]
|
|
94
98
|
: day[2]));
|
|
95
99
|
})));
|