Skip to content

Commit 490ea88

Browse files
committed
[@types/react-big-calendar] Add dayLayoutAlgorithm property added in jquense/react-big-calendar#1473 , add slotGroupPropGetter added in jquense/react-big-calendar#1510 , constrain Culture type to string instead of string | string[]
1 parent f2db20e commit 490ea88

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

types/react-big-calendar/index.d.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Type definitions for react-big-calendar 0.22
2-
// Project: https://github.com/intljusticemission/react-big-calendar
2+
// Project: https://github.com/jquense/react-big-calendar
33
// Definitions by: Piotr Witek <https://github.com/piotrwitek>
44
// Austin Turner <https://github.com/paustint>
55
// Krzysztof Bezrąk <https://github.com/pikpok>
@@ -15,14 +15,16 @@
1515
// Eric Kenney <https://github.com/KenneyE>
1616
// Paito Anderson <https://github.com/PaitoAnderson>
1717
// Jan Michalak <https://github.com/michalak111>
18+
// Felix Hessenberger <https://github.com/fhessenberger>
1819
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
1920
// TypeScript Version: 2.8
2021
import { Validator } from 'prop-types';
2122
import * as React from 'react';
2223

23-
export type DayPropGetter = (date: Date) => { className?: string, style?: React.CSSProperties };
24-
export type EventPropGetter<T> = (event: T, start: stringOrDate, end: stringOrDate, isSelected: boolean) => { className?: string, style?: React.CSSProperties };
25-
export type SlotPropGetter = (date: Date) => { className?: string, style?: React.CSSProperties };
24+
export type DayPropGetter = (date: Date, resourceId?: number | string) => React.HTMLAttributes<HTMLDivElement>;
25+
export type EventPropGetter<T> = (event: T, start: stringOrDate, end: stringOrDate, isSelected: boolean) => React.HTMLAttributes<HTMLDivElement>;
26+
export type SlotPropGetter = (date: Date, resourceId?: number | string) => React.HTMLAttributes<HTMLDivElement>;
27+
export type SlotGroupPropGetter = () => React.HTMLAttributes<HTMLDivElement>;
2628
export type stringOrDate = string | Date;
2729
export type ViewKey = 'MONTH' | 'WEEK' | 'WORK_WEEK' | 'DAY' | 'AGENDA';
2830
export type View = 'month' | 'week' | 'work_week' | 'day' | 'agenda';
@@ -33,6 +35,7 @@ export type ViewsProps = View[] | {
3335
month?: boolean | React.ComponentType<any> & ViewStatic,
3436
week?: boolean | React.ComponentType<any> & ViewStatic
3537
};
38+
export type DayLayoutAlgorithm = 'overlap' | 'no-overlap';
3639
export type NavigateAction = 'PREV' | 'NEXT' | 'TODAY' | 'DATE';
3740
export interface Event {
3841
allDay?: boolean;
@@ -46,8 +49,8 @@ export interface DateRange {
4649
end: Date;
4750
}
4851

49-
export type DateFormatFunction = (date: Date, culture?: string, localizer?: object) => string;
50-
export type DateRangeFormatFunction = (range: DateRange, culture?: string, localizer?: object) => string;
52+
export type DateFormatFunction = (date: Date, culture?: Culture, localizer?: DateLocalizer) => string;
53+
export type DateRangeFormatFunction = (range: DateRange, culture?: Culture, localizer?: DateLocalizer) => string;
5154
export type DateFormat = string | DateFormatFunction;
5255

5356
export interface Formats {
@@ -228,7 +231,7 @@ export interface Messages {
228231
noEventsInRange?: string;
229232
}
230233

231-
export type Culture = string | string[];
234+
export type Culture = string;
232235
export type FormatInput = number | string | Date;
233236

234237
export interface DateLocalizerSpec {
@@ -284,6 +287,7 @@ export interface CalendarProps<TEvent extends object = Event, TResource extends
284287
rtl?: boolean;
285288
eventPropGetter?: EventPropGetter<TEvent>;
286289
slotPropGetter?: SlotPropGetter;
290+
slotGroupPropGetter?: SlotGroupPropGetter;
287291
dayPropGetter?: DayPropGetter;
288292
showMultiDayTimes?: boolean;
289293
min?: stringOrDate;
@@ -293,6 +297,7 @@ export interface CalendarProps<TEvent extends object = Event, TResource extends
293297
formats?: Formats;
294298
components?: Components<TEvent>;
295299
messages?: Messages;
300+
dayLayoutAlgorithm?: DayLayoutAlgorithm;
296301
titleAccessor?: keyof TEvent | ((event: TEvent) => string);
297302
tooltipAccessor?: keyof TEvent | ((event: TEvent) => string);
298303
allDayAccessor?: keyof TEvent | ((event: TEvent) => boolean);

types/react-big-calendar/react-big-calendar-tests.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
ToolbarProps,
1717
EventProps,
1818
EventWrapperProps,
19-
NavigateAction
19+
NavigateAction,
20+
Culture
2021
} from "react-big-calendar";
2122
import withDragAndDrop from "react-big-calendar/lib/addons/dragAndDrop";
2223

@@ -197,6 +198,7 @@ class CalendarResource {
197198
const end = slotInfo.end;
198199
return true;
199200
}}
201+
dayLayoutAlgorithm="overlap"
200202
views={['day']}
201203
toolbar={true}
202204
popup={true}
@@ -218,8 +220,8 @@ class CalendarResource {
218220
scrollToTime={new Date()}
219221
formats={{
220222
dateFormat: 'h a',
221-
agendaDateFormat: (date: Date, culture?: string, localizer?: object) => 'some-format',
222-
dayRangeHeaderFormat: (range: DateRange, culture?: string, localizer?: object) => 'some-format',
223+
agendaDateFormat: (date: Date, culture?: Culture, localizer?: DateLocalizer) => 'some-format',
224+
dayRangeHeaderFormat: (range: DateRange, culture?: Culture, localizer?: DateLocalizer) => 'some-format',
223225
}}
224226
messages={{
225227
date: 'Date',
@@ -253,6 +255,7 @@ class CalendarResource {
253255
}}
254256
dayPropGetter={customDayPropGetter}
255257
slotPropGetter={customSlotPropGetter}
258+
slotGroupPropGetter={customGroupSlotPropGetter}
256259
defaultDate={new Date()}
257260
resources={getResources()}
258261
resourceAccessor={event => event.resourceId}
@@ -325,6 +328,12 @@ const customSlotPropGetter = (date: Date) => {
325328
else return {};
326329
};
327330

331+
const customGroupSlotPropGetter = () => {
332+
return {
333+
className: 'slot-group'
334+
};
335+
};
336+
328337
function Event(props: EventProps<CalendarEvent>) {
329338
return (
330339
<span>

0 commit comments

Comments
 (0)