Skip to content

Commit 7304d3f

Browse files
authored
chore: proofread and update jsdocs for consistency (#2760)
* chore: proofread and update jsdocs for consistency Signed-off-by: Giampaolo Bellavite <[email protected]> * Add jsdocs to components Signed-off-by: Giampaolo Bellavite <[email protected]> --------- Signed-off-by: Giampaolo Bellavite <[email protected]>
1 parent f91ac90 commit 7304d3f

File tree

97 files changed

+679
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+679
-288
lines changed

react-day-picker.code-workspace

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"orta.vscode-jest",
66
"andys8.jest-snippets",
77
"esbenp.prettier-vscode",
8-
"streetsidesoftware.code-spell-checker",
8+
"streetsidesoftware.code-spell-checker"
99
]
1010
},
1111
"folders": [
@@ -42,6 +42,9 @@
4242
"activityBar.inactiveForeground": "#d8d8d877",
4343
"activityBarBadge.background": "#dd006f",
4444
"activityBarBadge.foreground": "#e7e7e7"
45+
},
46+
"[typescript]": {
47+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4548
}
4649
}
4750
}

src/DayPicker.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ import { rangeIncludesDate } from "./utils/rangeIncludesDate.js";
3434
import { isDateRange } from "./utils/typeguards.js";
3535

3636
/**
37-
* Render the date picker calendar.
37+
* Renders the DayPicker calendar component.
3838
*
39+
* @param initialProps - The props for the DayPicker component.
40+
* @returns The rendered DayPicker component.
3941
* @group DayPicker
4042
* @see https://daypicker.dev
4143
*/

src/UI.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { CSSProperties } from "react";
33
import type { CustomComponents, ClassNames, Styles } from "./types/index.js";
44

55
/**
6-
* The UI elements composing DayPicker. These elements are mapped to
7-
* {@link CustomComponents}, the {@link ClassNames} and the {@link Styles} used by
8-
* DayPicker.
6+
* Enum representing the UI elements composing DayPicker. These elements are
7+
* mapped to {@link CustomComponents}, {@link ClassNames}, and {@link Styles}.
98
*
10-
* Some of these elements are extended by flags and modifiers.
9+
* Some elements are extended by flags and modifiers.
1110
*/
1211
export enum UI {
1312
/** The root component displaying the months and the navigation bar. */
@@ -71,7 +70,7 @@ export enum UI {
7170
YearsDropdown = "years_dropdown"
7271
}
7372

74-
/** The flags for the {@link UI.Day}. */
73+
/** Enum representing flags for the {@link UI.Day} element. */
7574
export enum DayFlag {
7675
/** The day is disabled. */
7776
disabled = "disabled",
@@ -86,8 +85,8 @@ export enum DayFlag {
8685
}
8786

8887
/**
89-
* The state that can be applied to the {@link UI.Day} element when in selection
90-
* mode.
88+
* Enum representing selection states that can be applied to the {@link UI.Day}
89+
* element in selection mode.
9190
*/
9291
export enum SelectionState {
9392
/** The day is at the end of a selected range. */
@@ -100,7 +99,6 @@ export enum SelectionState {
10099
selected = "selected"
101100
}
102101

103-
/** CSS classes used for animating months and captions. */
104102
/**
105103
* Enum representing different animation states for transitioning between
106104
* months.
@@ -125,25 +123,15 @@ export enum Animation {
125123
}
126124

127125
/**
128-
* Deprecated UI elements and flags.
126+
* Deprecated UI elements and flags from previous versions of DayPicker.
129127
*
130-
* These elements were used in previous version of DayPicker and are kept here
131-
* to help the transition to the new {@link UI | UI elements}.
132-
*
133-
* ```diff
134-
* <DayPicker classNames={{
135-
* - cell: "my-cell",
136-
* + day: "my-cell",
137-
* - day: "my-day",
138-
* + day_button: "my-day",
139-
* - day_disabled: "my-day_disabled",
140-
* + disabled: "my-day_disabled",
141-
* // etc.
142-
* }}/>
143-
* ```
128+
* These elements are kept for backward compatibility and to assist in
129+
* transitioning to the new {@link UI} elements.
144130
*
145131
* @deprecated
146132
* @since 9.0.1
133+
* @template T - The type of the deprecated UI element (e.g., CSS class or
134+
* style).
147135
* @see https://daypicker.dev/upgrading
148136
* @see https://daypicker.dev/docs/styling
149137
*/

src/classes/CalendarDay.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { type DateLib, defaultDateLib } from "./DateLib.js";
22

33
/**
4-
* Represent the day displayed in the calendar.
4+
* Represents a day displayed in the calendar.
55
*
6-
* In DayPicker, a `Day` is a `Date` that can be displayed in the calendar. It
7-
* is used as extension of the native `Date` object to provide additional
8-
* information about the day.
6+
* In DayPicker, a `CalendarDay` is a wrapper around a `Date` object that
7+
* provides additional information about the day, such as whether it belongs to
8+
* the displayed month.
99
*/
1010
export class CalendarDay {
1111
constructor(
@@ -22,35 +22,38 @@ export class CalendarDay {
2222
}
2323

2424
/**
25-
* The utility functions to manipulate dates.
25+
* Utility functions for manipulating dates.
2626
*
2727
* @private
2828
*/
2929
readonly dateLib: DateLib;
3030

3131
/**
32-
* Whether the day is not belonging to the displayed month.
32+
* Indicates whether the day does not belong to the displayed month.
3333
*
34-
* When `outside` is `true`, use `displayMonth` to know to which month the day
35-
* belongs.
34+
* If `outside` is `true`, use `displayMonth` to determine the month to which
35+
* the day belongs.
3636
*/
3737
readonly outside: boolean;
3838

3939
/**
40-
* The months where the day is displayed.
40+
* The month that is currently displayed in the calendar.
4141
*
42-
* In DayPicker, days can fall out the displayed months (e.g. when
43-
* `showOutsideDays` is `true`). This property is useful to know if the day is
44-
* in the same month of the displayed month.
42+
* This property is useful for determining if the day belongs to the same
43+
* month as the displayed month, especially when `showOutsideDays` is
44+
* enabled.
4545
*/
4646
readonly displayMonth: Date;
4747

4848
/** The date represented by this day. */
4949
readonly date: Date;
5050

5151
/**
52-
* Check if the day is the same as the given day: considering if it is in the
53-
* same display month.
52+
* Checks if this day is equal to another `CalendarDay`, considering both the
53+
* date and the displayed month.
54+
*
55+
* @param day The `CalendarDay` to compare with.
56+
* @returns `true` if the days are equal, otherwise `false`.
5457
*/
5558
isEqualTo(day: CalendarDay) {
5659
return (

src/classes/CalendarMonth.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { CalendarWeek } from "./CalendarWeek.js";
22

3-
/** Represent a month in a calendar year. Contains the weeks within the month. */
3+
/**
4+
* Represents a month in a calendar year.
5+
*
6+
* A `CalendarMonth` contains the weeks within the month and the date of the
7+
* month.
8+
*/
49
export class CalendarMonth {
510
constructor(month: Date, weeks: CalendarWeek[]) {
611
this.date = month;
712
this.weeks = weeks;
813
}
914

10-
/** The date of the month. */
15+
/** The date representing the first day of the month. */
1116
date: Date;
1217

13-
/** The weeks within the month. */
18+
/** The weeks that belong to this month. */
1419
weeks: CalendarWeek[];
1520
}

src/classes/CalendarWeek.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { CalendarDay } from "./CalendarDay.js";
22

3-
/** Represent a week in a calendar month. */
3+
/**
4+
* Represents a week in a calendar month.
5+
*
6+
* A `CalendarWeek` contains the days within the week and the week number.
7+
*/
48
export class CalendarWeek {
59
constructor(weekNumber: number, days: CalendarDay[]) {
610
this.days = days;
711
this.weekNumber = weekNumber;
812
}
13+
914
/** The number of the week within the year. */
1015
weekNumber: number;
11-
/** The days within the week. */
16+
17+
/** The days that belong to this week. */
1218
days: CalendarDay[];
1319
}

src/classes/DateLib.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,26 @@ export interface DateLibOptions
9494
}
9595

9696
/**
97-
* A wrapper class around [date-fns](http://date-fns.org) sharing the same
98-
* options.
97+
* A wrapper class around [date-fns](http://date-fns.org) that provides utility
98+
* methods for date manipulation and formatting.
9999
*
100100
* @since 9.2.0
101101
* @example
102102
* const dateLib = new DateLib({ locale: es });
103103
* const newDate = dateLib.addDays(new Date(), 5);
104104
*/
105105
export class DateLib {
106-
/** The options for the date library. */
106+
/** The options for configuring the date library. */
107107
readonly options: DateLibOptions;
108108

109-
/** Overrides for the date library functions. */
109+
/** Overrides for the default date library functions. */
110110
readonly overrides?: Partial<typeof DateLib.prototype>;
111111

112112
/**
113-
* Creates an instance of DateLib.
113+
* Creates an instance of `DateLib`.
114114
*
115-
* @param options The options for the date library.
116-
* @param overrides Overrides for the date library functions.
115+
* @param options Configuration options for the date library.
116+
* @param overrides Custom overrides for the date library functions.
117117
*/
118118
constructor(
119119
options?: DateLibOptions,
@@ -124,9 +124,11 @@ export class DateLib {
124124
}
125125

126126
/**
127-
* Generate digit map dynamically using Intl.NumberFormat.
127+
* Generates a mapping of Arabic digits (0-9) to the target numbering system
128+
* digits.
128129
*
129130
* @since 9.5.0
131+
* @returns A record mapping Arabic digits to the target numerals.
130132
*/
131133
private getDigitMap(): Record<string, string> {
132134
const { numerals = "latn" } = this.options;
@@ -146,21 +148,23 @@ export class DateLib {
146148
}
147149

148150
/**
149-
* Replace Arabic digits with the target numbering system digits.
151+
* Replaces Arabic digits in a string with the target numbering system digits.
150152
*
151153
* @since 9.5.0
154+
* @param input The string containing Arabic digits.
155+
* @returns The string with digits replaced.
152156
*/
153157
private replaceDigits(input: string): string {
154158
const digitMap = this.getDigitMap();
155159
return input.replace(/\d/g, (digit) => digitMap[digit] || digit);
156160
}
157161

158162
/**
159-
* Format number using the custom numbering system.
163+
* Formats a number using the configured numbering system.
160164
*
161165
* @since 9.5.0
162166
* @param value The number to format.
163-
* @returns The formatted number.
167+
* @returns The formatted number as a string.
164168
*/
165169
formatNumber(value: number | string): string {
166170
return this.replaceDigits(value.toString());
@@ -174,10 +178,10 @@ export class DateLib {
174178
Date: typeof Date = Date;
175179

176180
/**
177-
* Creates a new date object to the today's date.
181+
* Creates a new `Date` object representing today's date.
178182
*
179183
* @since 9.5.0
180-
* @returns The new date object.
184+
* @returns A `Date` object for today's date.
181185
*/
182186
today = (): Date => {
183187
if (this.overrides?.today) {
@@ -190,13 +194,13 @@ export class DateLib {
190194
};
191195

192196
/**
193-
* Creates a new date object with the specified year, month and date.
197+
* Creates a new `Date` object with the specified year, month, and day.
194198
*
195199
* @since 9.5.0
196200
* @param year The year.
197201
* @param monthIndex The month (0-11).
198202
* @param date The day of the month.
199-
* @returns The new date object.
203+
* @returns A new `Date` object.
200204
*/
201205
newDate = (year: number, monthIndex: number, date: number): Date => {
202206
if (this.overrides?.newDate) {

src/components/Day.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import type { CalendarDay } from "../classes/index.js";
44
import type { Modifiers } from "../types/index.js";
55

66
/**
7-
* Render the gridcell of a day in the calendar and handle the interaction and
8-
* the focus with they day.
7+
* Render a grid cell for a specific day in the calendar.
98
*
10-
* If you need to just change the content of the day cell, consider swapping the
11-
* `DayButton` component instead.
9+
* Handles interaction and focus for the day. If you only need to change the
10+
* content of the day cell, consider swapping the `DayButton` component
11+
* instead.
1212
*
1313
* @group Components
1414
* @see https://daypicker.dev/guides/custom-components

src/components/DayButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { CalendarDay } from "../classes/index.js";
44
import type { Modifiers } from "../types/index.js";
55

66
/**
7-
* Render the button for a day in the calendar.
7+
* Render a button for a specific day in the calendar.
88
*
99
* @group Components
1010
* @see https://daypicker.dev/guides/custom-components
@@ -13,7 +13,7 @@ export function DayButton(
1313
props: {
1414
/** The day to render. */
1515
day: CalendarDay;
16-
/** The modifiers for the day. */
16+
/** The modifiers to apply to the day. */
1717
modifiers: Modifiers;
1818
} & ButtonHTMLAttributes<HTMLButtonElement>
1919
) {

src/components/Dropdown.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ export type DropdownOption = {
99
value: number;
1010
/** The label of the option. */
1111
label: string;
12-
/**
13-
* The dropdown option is disabled when it cannot be selected because out of
14-
* the calendar range.
15-
*/
12+
/** Whether the dropdown option is disabled (e.g., out of the calendar range). */
1613
disabled: boolean;
1714
};
1815

1916
/**
20-
* Render a dropdown component to use in the navigation bar.
17+
* Render a dropdown component for navigation in the calendar.
2118
*
2219
* @group Components
2320
* @see https://daypicker.dev/guides/custom-components
2421
*/
2522
export function Dropdown(
2623
props: {
2724
/**
28-
* @deprecated Use{@link useDayPicker} hook to get the list of internal
25+
* @deprecated Use {@link useDayPicker} hook to get the list of internal
2926
* components.
3027
*/
3128
components: CustomComponents;
@@ -34,6 +31,7 @@ export function Dropdown(
3431
* class names.
3532
*/
3633
classNames: ClassNames;
34+
/** The options to display in the dropdown. */
3735
options?: DropdownOption[] | undefined;
3836
} & Omit<SelectHTMLAttributes<HTMLSelectElement>, "children">
3937
) {

0 commit comments

Comments
 (0)