@utrecht/calendar-react 1.0.16 → 1.1.0
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.
- package/dist/CalendarButton.d.ts.map +1 -1
- package/dist/CalendarIcon.d.ts.map +1 -1
- package/dist/CalendarNavigation.d.ts.map +1 -1
- package/dist/CalendarNavigationButtons.d.ts.map +1 -1
- package/dist/CalendarNavigationLabel.d.ts.map +1 -1
- package/dist/CalendarTableDaysContainer.d.ts.map +1 -1
- package/dist/CalendarTableDaysItem.d.ts.map +1 -1
- package/dist/CalendarTableDaysItemDay.d.ts.map +1 -1
- package/dist/CalendarTableWeeksContainer.d.ts.map +1 -1
- package/dist/CalendarTableWeeksItem.d.ts.map +1 -1
- package/dist/IconArrowLeft.d.ts.map +1 -1
- package/dist/IconArrowLeftDouble.d.ts.map +1 -1
- package/dist/IconArrowRight.d.ts.map +1 -1
- package/dist/IconArrowRightDouble.d.ts.map +1 -1
- package/dist/css.mjs +31 -6
- package/dist/css.mjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +31 -6
- package/dist/index.mjs.map +1 -1
- package/dist/insert-style.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/index.test.tsx +40 -0
- package/src/index.tsx +31 -18
package/dist/index.d.ts
CHANGED
|
@@ -33,10 +33,12 @@ export interface CalendarProps {
|
|
|
33
33
|
nextMonthButtonTitle?: string;
|
|
34
34
|
minDate?: Date;
|
|
35
35
|
maxDate?: Date;
|
|
36
|
+
displayWeekend?: boolean;
|
|
37
|
+
displayYearNavigation?: boolean;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Calendar Component
|
|
39
41
|
* powered by date-fns, so that make it easy to use the `date-fns` date functions & locale
|
|
40
42
|
* */
|
|
41
|
-
export declare const Calendar: ({ onCalendarClick, events, currentDate, locale, previousYearButtonTitle, nextYearButtonTitle, previousMonthButtonTitle, nextMonthButtonTitle, minDate, maxDate, }: CalendarProps) => import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare const Calendar: ({ onCalendarClick, events, currentDate, locale, previousYearButtonTitle, nextYearButtonTitle, previousMonthButtonTitle, nextMonthButtonTitle, displayWeekend, displayYearNavigation, minDate, maxDate, }: CalendarProps) => import("react/jsx-runtime").JSX.Element;
|
|
42
44
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAeL,MAAM,EAOP,MAAM,UAAU,CAAC;AA2BlB,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B;;;SAGK;IACL,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC;;;;SAIK;IACL,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;SAGK;IACL,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB;;;SAGK;IACL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;KAGK;AAEL,eAAO,MAAM,QAAQ,GAAI,0MAatB,aAAa,4CAyGf,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -162,6 +162,30 @@ function addMonths(dirtyDate, dirtyAmount) {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @name isWeekend
|
|
167
|
+
* @category Weekday Helpers
|
|
168
|
+
* @summary Does the given date fall on a weekend?
|
|
169
|
+
*
|
|
170
|
+
* @description
|
|
171
|
+
* Does the given date fall on a weekend?
|
|
172
|
+
*
|
|
173
|
+
* @param {Date|Number} date - the date to check
|
|
174
|
+
* @returns {Boolean} the date falls on a weekend
|
|
175
|
+
* @throws {TypeError} 1 argument required
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* // Does 5 October 2014 fall on a weekend?
|
|
179
|
+
* const result = isWeekend(new Date(2014, 9, 5))
|
|
180
|
+
* //=> true
|
|
181
|
+
*/
|
|
182
|
+
function isWeekend(dirtyDate) {
|
|
183
|
+
requiredArgs(1, arguments);
|
|
184
|
+
var date = toDate(dirtyDate);
|
|
185
|
+
var day = date.getDay();
|
|
186
|
+
return day === 0 || day === 6;
|
|
187
|
+
}
|
|
188
|
+
|
|
165
189
|
/**
|
|
166
190
|
* @name addMilliseconds
|
|
167
191
|
* @category Millisecond Helpers
|
|
@@ -3593,26 +3617,26 @@ const IconArrowRight = ({ title, titleId, ...props }) => (jsxs("svg", { width: "
|
|
|
3593
3617
|
|
|
3594
3618
|
const IconArrowRightDouble = ({ title, titleId, ...props }) => (jsxs("svg", { fill: "none", width: "100%", height: "100%", xmlns: "http://www.w3.org/2000/svg", "aria-labelledby": titleId, ...props, children: [title ? jsx("title", { id: titleId, children: title }) : null, jsx("path", { d: "M6.41 6 5 7.41 9.58 12 5 16.59 6.41 18l6-6-6-6Z", fill: "currentColor" }), jsx("path", { d: "m13 6-1.41 1.41L16.17 12l-4.58 4.59L13 18l6-6-6-6Z", fill: "currentColor" })] }));
|
|
3595
3619
|
|
|
3596
|
-
function createCalendar(today) {
|
|
3620
|
+
function createCalendar(today, displayWeekend) {
|
|
3597
3621
|
const start = startOfWeek(startOfMonth(today), {
|
|
3598
3622
|
weekStartsOn: 1 /* Monday */,
|
|
3599
3623
|
});
|
|
3600
3624
|
const end = endOfWeek(addWeeks(start, 5), {
|
|
3601
3625
|
weekStartsOn: 1 /* Monday */,
|
|
3602
3626
|
});
|
|
3603
|
-
return eachDayOfInterval({ start, end });
|
|
3627
|
+
return eachDayOfInterval({ start, end }).filter((date) => displayWeekend || !isWeekend(date));
|
|
3604
3628
|
}
|
|
3605
3629
|
/**
|
|
3606
3630
|
* Calendar Component
|
|
3607
3631
|
* powered by date-fns, so that make it easy to use the `date-fns` date functions & locale
|
|
3608
3632
|
* */
|
|
3609
|
-
const Calendar = ({ onCalendarClick, events, currentDate, locale: locale$1 = locale, previousYearButtonTitle = 'Previous year', nextYearButtonTitle = 'Next year', previousMonthButtonTitle = 'Previous month', nextMonthButtonTitle = 'Next month', minDate, maxDate, }) => {
|
|
3633
|
+
const Calendar = ({ onCalendarClick, events, currentDate, locale: locale$1 = locale, previousYearButtonTitle = 'Previous year', nextYearButtonTitle = 'Next year', previousMonthButtonTitle = 'Previous month', nextMonthButtonTitle = 'Next month', displayWeekend = true, displayYearNavigation = true, minDate, maxDate, }) => {
|
|
3610
3634
|
const [visibleMonth, setVisibleMonth] = useState(currentDate || new Date());
|
|
3611
3635
|
const [selectedDate, setSelectedDate] = useState(currentDate);
|
|
3612
|
-
const calendar = createCalendar(visibleMonth);
|
|
3636
|
+
const calendar = createCalendar(visibleMonth, displayWeekend);
|
|
3613
3637
|
const start = startOfWeek(visibleMonth, { weekStartsOn: 1 });
|
|
3614
3638
|
const end = endOfWeek(visibleMonth, { weekStartsOn: 1 });
|
|
3615
|
-
const currentWeek = eachDayOfInterval({ start, end }).
|
|
3639
|
+
const currentWeek = eachDayOfInterval({ start, end }).filter((day) => displayWeekend || !isWeekend(day));
|
|
3616
3640
|
const chunksWeeks = chunk(calendar, calendar.length / 6);
|
|
3617
3641
|
const weeks = chunksWeeks.map((week) => week.map((date) => {
|
|
3618
3642
|
const currentEvent = events && events.length > 0 && events.find((e) => isSameDay(endOfDay(parseISO(e.date)), date));
|
|
@@ -3633,7 +3657,8 @@ const Calendar = ({ onCalendarClick, events, currentDate, locale: locale$1 = loc
|
|
|
3633
3657
|
};
|
|
3634
3658
|
}
|
|
3635
3659
|
}));
|
|
3636
|
-
|
|
3660
|
+
const monthNavigation = (jsx(CalendarNavigationButtons, { previousIcon: jsx(IconArrowLeft, { title: previousMonthButtonTitle }), nextIcon: jsx(IconArrowRight, { title: nextMonthButtonTitle }), onPreviousClick: () => setVisibleMonth(setMonth(visibleMonth, visibleMonth.getMonth() - 1)), onNextClick: () => setVisibleMonth(addMonths(visibleMonth, 1)), children: jsx(CalendarNavigationLabel, { dateTime: format(visibleMonth, 'yyyy-mm'), children: format(visibleMonth, 'LLLL y', { locale: locale$1 }) }) }));
|
|
3661
|
+
return (jsxs("div", { className: "utrecht-calendar", children: [jsx(CalendarNavigation, { children: !displayYearNavigation ? (monthNavigation) : (jsx(CalendarNavigationButtons, { previousIcon: jsx(IconArrowLeftDouble, { title: previousYearButtonTitle }), nextIcon: jsx(IconArrowRightDouble, { title: nextYearButtonTitle }), onPreviousClick: () => setVisibleMonth(setYear(visibleMonth, getYear(visibleMonth) - 1)), onNextClick: () => setVisibleMonth(addYears(visibleMonth, 1)), children: monthNavigation })) }), jsxs("table", { className: "utrecht-calendar__table", role: "grid", children: [jsx(CalendarTableWeeksContainer, { children: currentWeek &&
|
|
3637
3662
|
currentWeek.length > 0 &&
|
|
3638
3663
|
currentWeek.map((day, index) => (jsx(CalendarTableWeeksItem, { scope: "col", abbr: format(day, 'EEEE', { locale: locale$1 }), children: format(day, 'EEEEEE', { locale: locale$1 }) }, index))) }), jsx(CalendarTableDaysContainer, { children: weeks &&
|
|
3639
3664
|
weeks.length > 0 &&
|