react-day-picker 8.6.0 → 8.7.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.
@@ -1,5 +1,6 @@
1
1
  .root {
2
2
  --rdp-cell-size: 40px;
3
+ --rdp-caption-font-size: 18px;
3
4
  --rdp-accent-color: #0000ff;
4
5
  --rdp-background-color: #e7edff;
5
6
  --rdp-accent-color-dark: #3003e1;
@@ -130,7 +131,7 @@
130
131
  border: 0;
131
132
  border: 2px solid transparent;
132
133
  font-family: inherit;
133
- font-size: 140%;
134
+ font-size: var(--rdp-caption-font-size);
134
135
  font-weight: bold;
135
136
  }
136
137
 
@@ -224,6 +225,7 @@
224
225
  height: 100%;
225
226
  height: var(--rdp-cell-size);
226
227
  padding: 0;
228
+ text-transform: uppercase;
227
229
  }
228
230
 
229
231
  .tbody {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-day-picker",
3
- "version": "8.6.0",
3
+ "version": "8.7.0",
4
4
  "description": "Customizable Date Picker for React",
5
5
  "author": "Giampaolo Bellavite <io@gpbl.dev>",
6
6
  "homepage": "http://react-day-picker.js.org",
@@ -39,24 +39,24 @@
39
39
  "@rollup/plugin-typescript": "^11.0.0",
40
40
  "@testing-library/dom": "^8.20.0",
41
41
  "@testing-library/jest-dom": "^5.16.5",
42
- "@testing-library/react": "^13.4.0",
42
+ "@testing-library/react": "^14.0.0",
43
43
  "@testing-library/user-event": "^14.4.3",
44
44
  "@types/jest": "^29.4.0",
45
- "@types/node": "^18.11.19",
46
- "@types/react": "^18.0.27",
47
- "@typescript-eslint/eslint-plugin": "^5.51.0",
48
- "@typescript-eslint/parser": "^5.50.0",
45
+ "@types/node": "^18.15.11",
46
+ "@types/react": "^18.0.28",
47
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
48
+ "@typescript-eslint/parser": "^5.55.0",
49
49
  "date-fns": "^2.29.3",
50
- "eslint": "^8.34.0",
51
- "eslint-config-prettier": "^8.6.0",
50
+ "eslint": "^8.35.0",
51
+ "eslint-config-prettier": "^8.7.0",
52
52
  "eslint-config-rdp": "workspace:^",
53
53
  "eslint-import-resolver-typescript": "^3.5.3",
54
54
  "eslint-plugin-import": "^2.27.5",
55
55
  "eslint-plugin-jest": "^27.2.1",
56
56
  "eslint-plugin-prettier": "^4.2.1",
57
57
  "eslint-plugin-react-hooks": "^4.6.0",
58
- "jest": "^29.4.1",
59
- "jest-environment-jsdom": "^29.4.1",
58
+ "jest": "^29.4.3",
59
+ "jest-environment-jsdom": "^29.5.0",
60
60
  "postcss": "^8.4.21",
61
61
  "postcss-d-ts": "^1.2.0",
62
62
  "postcss-typescript-d-ts": "^1.0.0",
@@ -64,10 +64,10 @@
64
64
  "react": "^18.2.0",
65
65
  "react-classnaming": "^0.16.4",
66
66
  "react-dom": "^18.2.0",
67
- "rimraf": "^4.1.2",
68
- "rollup": "^3.15.0",
67
+ "rimraf": "^4.4.1",
68
+ "rollup": "^3.19.1",
69
69
  "rollup-plugin-copy": "^3.4.0",
70
- "rollup-plugin-dts": "^5.1.1",
70
+ "rollup-plugin-dts": "^5.2.0",
71
71
  "rollup-plugin-postcss": "^4.0.2",
72
72
  "rollup-plugin-terser": "^7.0.2",
73
73
  "timekeeper": "^2.2.0",
@@ -0,0 +1 @@
1
+ style.css.d.ts
@@ -11,7 +11,7 @@ import { useNavigation } from 'contexts/Navigation';
11
11
  * Render a caption with a button-based navigation.
12
12
  */
13
13
  export function CaptionNavigation(props: CaptionProps): JSX.Element {
14
- const { numberOfMonths, dir } = useDayPicker();
14
+ const { numberOfMonths } = useDayPicker();
15
15
  const { previousMonth, nextMonth, goToMonth, displayMonths } =
16
16
  useNavigation();
17
17
 
@@ -19,11 +19,8 @@ export function CaptionNavigation(props: CaptionProps): JSX.Element {
19
19
  isSameMonth(props.displayMonth, month)
20
20
  );
21
21
 
22
- let isFirst = displayIndex === 0;
23
- let isLast = displayIndex === displayMonths.length - 1;
24
- if (dir === 'rtl') {
25
- [isLast, isFirst] = [isFirst, isLast];
26
- }
22
+ const isFirst = displayIndex === 0;
23
+ const isLast = displayIndex === displayMonths.length - 1;
27
24
 
28
25
  const hideNext = numberOfMonths > 1 && (isFirst || !isLast);
29
26
  const hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
@@ -67,10 +67,7 @@ describe('when showing the week numbers', () => {
67
67
  setup({ ...dayPickerProps, showWeekNumber: true });
68
68
  });
69
69
  test('should render 8 head elements', () => {
70
- expect(thElements).toHaveLength(8);
71
- });
72
- test('the first head element should be empty', () => {
73
- expect(thElements[0]).toHaveTextContent('');
70
+ expect(thElements).toHaveLength(7);
74
71
  });
75
72
  test('should render the head elements with the "head_cell" class name', () => {
76
73
  thElements.forEach((el) => {
@@ -24,11 +24,7 @@ export function HeadRow(): JSX.Element {
24
24
  return (
25
25
  <tr style={styles.head_row} className={classNames.head_row}>
26
26
  {showWeekNumber && (
27
- <th
28
- scope="col"
29
- style={styles.head_cell}
30
- className={classNames.head_cell}
31
- ></th>
27
+ <td style={styles.head_cell} className={classNames.head_cell}></td>
32
28
  )}
33
29
  {weekdays.map((weekday, i) => (
34
30
  <th
@@ -56,6 +56,30 @@ describe('when using the "classNames" prop', () => {
56
56
  });
57
57
  });
58
58
 
59
+ describe('when using the "id" prop', () => {
60
+ const testId = 'foo';
61
+ beforeEach(() => setup({ id: testId }));
62
+ test('should display the specified number of month grids', () => {
63
+ expect(container.firstChild).toHaveAttribute('id', testId);
64
+ });
65
+ });
66
+
67
+ describe('when using a "data-" attribute', () => {
68
+ const testId = 'foo';
69
+ beforeEach(() => setup({ 'data-test': testId }));
70
+ test('should have the "data-" attribute', () => {
71
+ expect(container.firstChild).toHaveAttribute('data-test', testId);
72
+ });
73
+ });
74
+
75
+ describe('when using a "aria-" attribute', () => {
76
+ const testValue = 'foo';
77
+ beforeEach(() => setup({ 'aria-label': testValue }));
78
+ test('should have the "aria-" attribute', () => {
79
+ expect(container.firstChild).toHaveAttribute('aria-label', testValue);
80
+ });
81
+ });
82
+
59
83
  describe('when using the "className" prop', () => {
60
84
  const props: DayPickerProps = { className: 'foo' };
61
85
  beforeEach(() => {
@@ -1,9 +1,10 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { AriaAttributes, useEffect, useState } from 'react';
2
2
 
3
3
  import { Month } from 'components/Month';
4
4
  import { useDayPicker } from 'contexts/DayPicker';
5
5
  import { useFocusContext } from 'contexts/Focus';
6
6
  import { useNavigation } from 'contexts/Navigation';
7
+ import { DataAttributes } from 'types/DayPickerBase';
7
8
 
8
9
  /** Render the container with the months according to the number of months to display. */
9
10
  export function Root(): JSX.Element {
@@ -43,8 +44,29 @@ export function Root(): JSX.Element {
43
44
  ...dayPicker.style
44
45
  };
45
46
 
47
+ const dataAttributes = (Object.keys(dayPicker) as Array<keyof DataAttributes>)
48
+ .filter((key) => key.startsWith('data-'))
49
+ .reduce(
50
+ (attrs, key) => ({ ...attrs, [key]: dayPicker[key] }),
51
+ {} as DataAttributes
52
+ );
53
+
54
+ const ariaAttributes = (Object.keys(dayPicker) as Array<keyof AriaAttributes>)
55
+ .filter((key) => key.startsWith('aria-'))
56
+ .reduce(
57
+ (attrs, key) => ({ ...attrs, [key]: dayPicker[key] }),
58
+ {} as AriaAttributes
59
+ );
60
+
46
61
  return (
47
- <div className={classNames.join(' ')} style={style} dir={dayPicker.dir}>
62
+ <div
63
+ className={classNames.join(' ')}
64
+ style={style}
65
+ dir={dayPicker.dir}
66
+ id={dayPicker.id}
67
+ {...dataAttributes}
68
+ {...ariaAttributes}
69
+ >
48
70
  <div
49
71
  className={dayPicker.classNames.months}
50
72
  style={dayPicker.styles.months}
@@ -16,49 +16,49 @@ exports[`should render correctly 1`] = `
16
16
  class="rdp-head_cell"
17
17
  scope="col"
18
18
  >
19
- SU
19
+ Su
20
20
  </th>
21
21
  <th
22
22
  aria-label="Monday"
23
23
  class="rdp-head_cell"
24
24
  scope="col"
25
25
  >
26
- MO
26
+ Mo
27
27
  </th>
28
28
  <th
29
29
  aria-label="Tuesday"
30
30
  class="rdp-head_cell"
31
31
  scope="col"
32
32
  >
33
- TU
33
+ Tu
34
34
  </th>
35
35
  <th
36
36
  aria-label="Wednesday"
37
37
  class="rdp-head_cell"
38
38
  scope="col"
39
39
  >
40
- WE
40
+ We
41
41
  </th>
42
42
  <th
43
43
  aria-label="Thursday"
44
44
  class="rdp-head_cell"
45
45
  scope="col"
46
46
  >
47
- TH
47
+ Th
48
48
  </th>
49
49
  <th
50
50
  aria-label="Friday"
51
51
  class="rdp-head_cell"
52
52
  scope="col"
53
53
  >
54
- FR
54
+ Fr
55
55
  </th>
56
56
  <th
57
57
  aria-label="Saturday"
58
58
  class="rdp-head_cell"
59
59
  scope="col"
60
60
  >
61
- SA
61
+ Sa
62
62
  </th>
63
63
  </tr>
64
64
  </thead>
@@ -468,58 +468,57 @@ exports[`when showing the week numbers should render correctly 1`] = `
468
468
  <tr
469
469
  class="rdp-head_row"
470
470
  >
471
- <th
471
+ <td
472
472
  class="rdp-head_cell"
473
- scope="col"
474
473
  />
475
474
  <th
476
475
  aria-label="Sunday"
477
476
  class="rdp-head_cell"
478
477
  scope="col"
479
478
  >
480
- SU
479
+ Su
481
480
  </th>
482
481
  <th
483
482
  aria-label="Monday"
484
483
  class="rdp-head_cell"
485
484
  scope="col"
486
485
  >
487
- MO
486
+ Mo
488
487
  </th>
489
488
  <th
490
489
  aria-label="Tuesday"
491
490
  class="rdp-head_cell"
492
491
  scope="col"
493
492
  >
494
- TU
493
+ Tu
495
494
  </th>
496
495
  <th
497
496
  aria-label="Wednesday"
498
497
  class="rdp-head_cell"
499
498
  scope="col"
500
499
  >
501
- WE
500
+ We
502
501
  </th>
503
502
  <th
504
503
  aria-label="Thursday"
505
504
  class="rdp-head_cell"
506
505
  scope="col"
507
506
  >
508
- TH
507
+ Th
509
508
  </th>
510
509
  <th
511
510
  aria-label="Friday"
512
511
  class="rdp-head_cell"
513
512
  scope="col"
514
513
  >
515
- FR
514
+ Fr
516
515
  </th>
517
516
  <th
518
517
  aria-label="Saturday"
519
518
  class="rdp-head_cell"
520
519
  scope="col"
521
520
  >
522
- SA
521
+ Sa
523
522
  </th>
524
523
  </tr>
525
524
  </thead>
@@ -5,11 +5,11 @@ import { formatWeekdayName } from './formatWeekdayName';
5
5
  const date = new Date(2022, 10, 21);
6
6
 
7
7
  test('should return the formatted weekday name', () => {
8
- expect(formatWeekdayName(date)).toEqual('MO');
8
+ expect(formatWeekdayName(date)).toEqual('Mo');
9
9
  });
10
10
 
11
11
  describe('when a locale is passed in', () => {
12
12
  test('should format using the locale', () => {
13
- expect(formatWeekdayName(date, { locale: es })).toEqual('LU');
13
+ expect(formatWeekdayName(date, { locale: es })).toEqual('lu');
14
14
  });
15
15
  });
@@ -8,5 +8,5 @@ export function formatWeekdayName(
8
8
  weekday: Date,
9
9
  options?: { locale?: Locale }
10
10
  ): string {
11
- return format(weekday, 'cccccc', options).toUpperCase();
11
+ return format(weekday, 'cccccc', options);
12
12
  }
@@ -43,7 +43,19 @@ const tests: [EventName, DayEventName][] = [
43
43
  describe.each(tests)('when calling "%s"', (eventName, dayEventName) => {
44
44
  const activeModifiers: ActiveModifiers = {};
45
45
  const dayPickerProps = {
46
- [dayEventName]: jest.fn()
46
+ onDayClick: jest.fn(),
47
+ onDayFocus: jest.fn(),
48
+ onDayBlur: jest.fn(),
49
+ onDayMouseEnter: jest.fn(),
50
+ onDayMouseLeave: jest.fn(),
51
+ onDayPointerEnter: jest.fn(),
52
+ onDayPointerLeave: jest.fn(),
53
+ onDayTouchEnd: jest.fn(),
54
+ onDayTouchCancel: jest.fn(),
55
+ onDayTouchMove: jest.fn(),
56
+ onDayTouchStart: jest.fn(),
57
+ onDayKeyUp: jest.fn(),
58
+ onDayKeyDown: jest.fn()
47
59
  };
48
60
  const mouseEvent = {} as React.MouseEvent<HTMLButtonElement, MouseEvent>;
49
61
  const date = today;
package/src/style.css CHANGED
@@ -1,5 +1,6 @@
1
1
  .rdp {
2
2
  --rdp-cell-size: 40px;
3
+ --rdp-caption-font-size: 18px;
3
4
  --rdp-accent-color: #0000ff;
4
5
  --rdp-background-color: #e7edff;
5
6
  --rdp-accent-color-dark: #3003e1;
@@ -130,7 +131,7 @@
130
131
  border: 0;
131
132
  border: 2px solid transparent;
132
133
  font-family: inherit;
133
- font-size: 140%;
134
+ font-size: var(--rdp-caption-font-size);
134
135
  font-weight: bold;
135
136
  }
136
137
 
@@ -224,6 +225,7 @@
224
225
  height: 100%;
225
226
  height: var(--rdp-cell-size);
226
227
  padding: 0;
228
+ text-transform: uppercase;
227
229
  }
228
230
 
229
231
  .rdp-tbody {
@@ -1,39 +1,39 @@
1
1
  declare const styles: {
2
- rdp: string;
3
- 'rdp-vhidden': string;
4
- 'rdp-button_reset': string;
5
- 'rdp-button': string;
6
- 'rdp-day_selected': string;
7
- 'rdp-months': string;
8
- 'rdp-month': string;
9
- 'rdp-table': string;
10
- 'rdp-with_weeknumber': string;
11
- 'rdp-caption': string;
12
- 'rdp-multiple_months': string;
13
- 'rdp-caption_dropdowns': string;
14
- 'rdp-caption_label': string;
15
- 'rdp-nav': string;
16
- 'rdp-caption_start': string;
17
- 'rdp-caption_end': string;
18
- 'rdp-nav_button': string;
19
- 'rdp-dropdown_year': string;
20
- 'rdp-dropdown_month': string;
21
- 'rdp-dropdown': string;
22
- 'rdp-dropdown_icon': string;
23
- 'rdp-head': string;
24
- 'rdp-head_row': string;
25
- 'rdp-row': string;
26
- 'rdp-head_cell': string;
27
- 'rdp-tbody': string;
28
- 'rdp-tfoot': string;
29
- 'rdp-cell': string;
30
- 'rdp-weeknumber': string;
31
- 'rdp-day': string;
32
- 'rdp-day_today': string;
33
- 'rdp-day_outside': string;
34
- 'rdp-day_range_start': string;
35
- 'rdp-day_range_end': string;
36
- 'rdp-day_range_middle': string;
37
- };
2
+ 'rdp': string
3
+ 'rdp-vhidden': string
4
+ 'rdp-button_reset': string
5
+ 'rdp-button': string
6
+ 'rdp-day_selected': string
7
+ 'rdp-months': string
8
+ 'rdp-month': string
9
+ 'rdp-table': string
10
+ 'rdp-with_weeknumber': string
11
+ 'rdp-caption': string
12
+ 'rdp-multiple_months': string
13
+ 'rdp-caption_dropdowns': string
14
+ 'rdp-caption_label': string
15
+ 'rdp-nav': string
16
+ 'rdp-caption_start': string
17
+ 'rdp-caption_end': string
18
+ 'rdp-nav_button': string
19
+ 'rdp-dropdown_year': string
20
+ 'rdp-dropdown_month': string
21
+ 'rdp-dropdown': string
22
+ 'rdp-dropdown_icon': string
23
+ 'rdp-head': string
24
+ 'rdp-head_row': string
25
+ 'rdp-row': string
26
+ 'rdp-head_cell': string
27
+ 'rdp-tbody': string
28
+ 'rdp-tfoot': string
29
+ 'rdp-cell': string
30
+ 'rdp-weeknumber': string
31
+ 'rdp-day': string
32
+ 'rdp-day_today': string
33
+ 'rdp-day_outside': string
34
+ 'rdp-day_range_start': string
35
+ 'rdp-day_range_end': string
36
+ 'rdp-day_range_middle': string
37
+ }
38
38
 
39
- export default styles;
39
+ export default styles
@@ -1,5 +1,7 @@
1
1
  import type { Locale } from 'date-fns';
2
2
 
3
+ import { AriaAttributes } from 'react';
4
+
3
5
  import { CaptionLayout, CaptionProps } from 'components/Caption';
4
6
  import { CaptionLabelProps } from 'components/CaptionLabel';
5
7
  import { DayProps } from 'components/Day';
@@ -29,6 +31,11 @@ import {
29
31
  } from './Modifiers';
30
32
  import { ClassNames, StyledComponent, Styles } from './Styles';
31
33
 
34
+ /** A type with all the attributes starting with data- */
35
+ export type DataAttributes = {
36
+ [key: `data-${string}`]: string | boolean | number | undefined;
37
+ };
38
+
32
39
  /**
33
40
  * Selection modes supported by DayPicker.
34
41
  *
@@ -43,7 +50,7 @@ export type DaySelectionMode = 'single' | 'multiple' | 'range' | 'default';
43
50
  /**
44
51
  * The base props for the {@link DayPicker} component and the {@link DayPickerContext}.
45
52
  */
46
- export interface DayPickerBase {
53
+ export interface DayPickerBase extends DataAttributes, AriaAttributes {
47
54
  /**
48
55
  * The CSS class to add to the container element. To change the name of the
49
56
  * class instead, use `classNames.root`.