@@ -18,10 +24,4 @@ const CalendarWidget = (props) => (
);
-CalendarWidget.propTypes = {
- maxDate: PropTypes.instanceOf(Date),
- minDate: PropTypes.instanceOf(Date),
- value: PropTypes.instanceOf(Date),
-};
-
export default CalendarWidget;
diff --git a/src/widgets/CalendarWidget/ui/CalendarWidgetContext.jsx b/src/widgets/CalendarWidget/ui/CalendarWidgetContext.jsx
deleted file mode 100644
index 92ae75c..0000000
--- a/src/widgets/CalendarWidget/ui/CalendarWidgetContext.jsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import PropTypes from 'prop-types';
-import { createContext, useMemo, useState } from 'react';
-
-export const CalendarWidgetContext = createContext({});
-
-export const CalendarWidgetProvider = (props) => {
- const {
- children,
- maxDate = new Date(2030, 0, 1),
- minDate = new Date(1990, 0, 1),
- locale = 'ru',
- ...restProps
- } = props;
-
- const [targetDate, setTargetDate] = useState(new Date());
-
- const contextValue = useMemo(() => ({
- targetYear: targetDate.getFullYear(),
- targetMonthIndex: targetDate.getMonth(),
- targetDate,
- setTargetDate,
- minDate,
- maxDate,
- locale,
- ...restProps,
- }), [maxDate, minDate, targetDate, locale, restProps]);
-
- return (
-
- {children}
-
- );
-};
-
-CalendarWidgetProvider.propTypes = {
- children: PropTypes.node.isRequired,
-
- maxDate: PropTypes.instanceOf(Date),
- minDate: PropTypes.instanceOf(Date),
- locale: PropTypes.oneOf(['ru', 'en']),
-};
diff --git a/src/widgets/CalendarWidget/ui/CalendarWidgetContext.tsx b/src/widgets/CalendarWidget/ui/CalendarWidgetContext.tsx
new file mode 100644
index 0000000..3d6e163
--- /dev/null
+++ b/src/widgets/CalendarWidget/ui/CalendarWidgetContext.tsx
@@ -0,0 +1,54 @@
+import PropTypes from 'prop-types';
+import React, { createContext, useMemo, useState } from 'react';
+
+import type { CalendarWidgetProps } from './CalendarWidget.ui';
+import type { FC, PropsWithChildren } from 'react';
+
+type CalendarWidgetContextValue = Required
& {
+ targetYear: number;
+ targetMonthIndex: number;
+ targetDate: Date;
+ setTargetDate: React.Dispatch>;
+};
+export const CalendarWidgetContext = createContext({} as CalendarWidgetContextValue);
+
+export type CalendarWidgetProviderProps = PropsWithChildren;
+
+export const CalendarWidgetProvider: FC = (props) => {
+ const {
+ children,
+ maxDate = new Date(2030, 0, 1),
+ minDate = new Date(1990, 0, 1),
+ locale = 'ru',
+ value = new Date(),
+ ...restProps
+ } = props;
+
+ const [targetDate, setTargetDate] = useState(value);
+
+ const contextValue = useMemo(() => ({
+ targetYear: targetDate.getFullYear(),
+ targetMonthIndex: targetDate.getMonth(),
+ targetDate,
+ setTargetDate,
+ minDate,
+ maxDate,
+ locale,
+ value,
+ ...restProps,
+ }), [maxDate, minDate, targetDate, locale, restProps, value]);
+
+ return (
+
+ {children}
+
+ );
+};
+
+CalendarWidgetProvider.propTypes = {
+ children: PropTypes.node.isRequired,
+
+ maxDate: PropTypes.instanceOf(Date),
+ minDate: PropTypes.instanceOf(Date),
+ locale: PropTypes.oneOf(['ru', 'en']),
+};
diff --git a/src/widgets/CalendarWidget/ui/components/DateCell/index.js b/src/widgets/CalendarWidget/ui/components/DateCell/index.ts
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DateCell/index.js
rename to src/widgets/CalendarWidget/ui/components/DateCell/index.ts
diff --git a/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.spec.jsx b/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.spec.tsx
similarity index 96%
rename from src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.spec.jsx
rename to src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.spec.tsx
index ac52c45..8819c30 100644
--- a/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.spec.jsx
+++ b/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.spec.tsx
@@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react';
import DateCell from './DateCell.ui';
describe('Base Render', () => {
- const setup = (date) => {
+ const setup = (date: Date) => {
render();
};
diff --git a/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.style.module.css b/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.style.module.css
index 33002eb..55246c4 100644
--- a/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.style.module.css
+++ b/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.style.module.css
@@ -16,13 +16,25 @@
border-right: 1px solid black;
}
- &.today {
+ .today {
color: red;
font-size: 1.2em;
font-weight: bold;
}
- &.outMothRange {
+ .outMothRange {
color: darkgrey;
}
+
+ .valueDate {
+ color: gold;
+ background: red;
+ border-radius: 50%;
+ padding: 5px;
+ height: 1.2em;
+ width: 1.2em;
+ display: inline-flex;
+ justify-content: center;
+ align-items: center;
+ }
}
diff --git a/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.ui.jsx b/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.ui.tsx
similarity index 51%
rename from src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.ui.jsx
rename to src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.ui.tsx
index 26d5b2a..3fd2048 100644
--- a/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.ui.jsx
+++ b/src/widgets/CalendarWidget/ui/components/DateCell/ui/DateCell.ui.tsx
@@ -1,44 +1,49 @@
import classnames from 'classnames';
-import PropTypes from 'prop-types';
import { useContext } from 'react';
import { CalendarWidgetContext } from '../../../CalendarWidgetContext';
import classes from './DateCell.style.module.css';
-const DateCell = (props) => {
+import type { FC } from 'react';
+
+type DateCellProps = {
+ date: Date;
+};
+const DateCell: FC = (props) => {
const {
date,
} = props;
const format = 'en-En';
- const { targetMonthIndex } = useContext(CalendarWidgetContext);
+ const { targetMonthIndex, value } = useContext(CalendarWidgetContext);
const todayDate = new Date();
const dataDate = new Intl.DateTimeFormat(format).format(date);
const dataToday = new Intl.DateTimeFormat(format).format(todayDate);
+ const dataValue = new Intl.DateTimeFormat(format).format(value);
const isOutMonthRange = date.getMonth() !== targetMonthIndex;
return (
- {date.getDate()}
+
+ {date.getDate()}
+
);
};
-DateCell.propTypes = {
- date: PropTypes.instanceOf(Date).isRequired,
-};
-
export default DateCell;
diff --git a/src/widgets/CalendarWidget/ui/components/DateRow/index.js b/src/widgets/CalendarWidget/ui/components/DateRow/index.ts
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DateRow/index.js
rename to src/widgets/CalendarWidget/ui/components/DateRow/index.ts
diff --git a/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.spec.jsx b/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.spec.tsx
similarity index 72%
rename from src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.spec.jsx
rename to src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.spec.tsx
index 7371937..ef8d83a 100644
--- a/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.spec.jsx
+++ b/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.spec.tsx
@@ -2,8 +2,10 @@ import { render, screen } from '@testing-library/react';
import DateRow from './DateRow.ui';
+import type { DateRowType } from './DateRow.ui';
+
describe('Test Date Row', () => {
- const setup = (cells) => {
+ const setup = (cells: DateRowType['cells']) => {
render();
};
@@ -53,13 +55,13 @@ describe('Test Date Row', () => {
setupWeek();
const dateCellElems = screen.getAllByTestId('date-cell');
- expect(dateCellElems[0]).toHaveTextContent(15);
- expect(dateCellElems[1]).toHaveTextContent(16);
- expect(dateCellElems[2]).toHaveTextContent(17);
- expect(dateCellElems[3]).toHaveTextContent(18);
- expect(dateCellElems[4]).toHaveTextContent(19);
- expect(dateCellElems[5]).toHaveTextContent(20);
- expect(dateCellElems[6]).toHaveTextContent(21);
+ expect(dateCellElems[0]).toHaveTextContent('15');
+ expect(dateCellElems[1]).toHaveTextContent('16');
+ expect(dateCellElems[2]).toHaveTextContent('17');
+ expect(dateCellElems[3]).toHaveTextContent('18');
+ expect(dateCellElems[4]).toHaveTextContent('19');
+ expect(dateCellElems[5]).toHaveTextContent('20');
+ expect(dateCellElems[6]).toHaveTextContent('21');
});
});
});
diff --git a/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.ui.jsx b/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.ui.tsx
similarity index 81%
rename from src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.ui.jsx
rename to src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.ui.tsx
index 7c6acc2..9f44e98 100644
--- a/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.ui.jsx
+++ b/src/widgets/CalendarWidget/ui/components/DateRow/ui/DateRow.ui.tsx
@@ -1,10 +1,13 @@
-import PropTypes from 'prop-types';
-
import { DateCell } from '../../DateCell';
import classes from './DateRow.style.module.css';
-const DateRow = (props) => {
+import type { FC } from 'react';
+
+export type DateRowType = {
+ cells: Date[];
+};
+const DateRow: FC = (props) => {
const {
cells,
} = props;
@@ -28,8 +31,4 @@ const DateRow = (props) => {
);
};
-DateRow.propTypes = {
- cells: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
-};
-
export default DateRow;
diff --git a/src/widgets/CalendarWidget/ui/components/DateWrapper/index.js b/src/widgets/CalendarWidget/ui/components/DateWrapper/index.ts
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DateWrapper/index.js
rename to src/widgets/CalendarWidget/ui/components/DateWrapper/index.ts
diff --git a/src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.spec.jsx b/src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.spec.tsx
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.spec.jsx
rename to src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.spec.tsx
diff --git a/src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.ui.jsx b/src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.ui.tsx
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.ui.jsx
rename to src/widgets/CalendarWidget/ui/components/DateWrapper/ui/DateWrapper.ui.tsx
diff --git a/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/index.js b/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/index.ts
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DayOfWeekCell/index.js
rename to src/widgets/CalendarWidget/ui/components/DayOfWeekCell/index.ts
diff --git a/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.spec.jsx b/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.spec.tsx
similarity index 91%
rename from src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.spec.jsx
rename to src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.spec.tsx
index 357d0df..00cb8d8 100644
--- a/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.spec.jsx
+++ b/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.spec.tsx
@@ -7,14 +7,17 @@ import { CalendarWidgetProvider } from '../../../CalendarWidgetContext';
import DayOfWeekCell from './DayOfWeekCell.ui';
+import type { DayOfWeekCellProps } from './DayOfWeekCell.ui';
+import type { CalendarWidgetProviderProps } from '../../../CalendarWidgetContext';
+
describe('Test DayOfWeekCell', () => {
- const setup = (day, locale) => {
+ const setup = (day: DayOfWeekCellProps['day'], locale: CalendarWidgetProviderProps['locale']) => {
const DayOfWeekCellComponent = () => (
);
- const Provider = (props) => (
-
+ const Provider = (props: CalendarWidgetProviderProps) => (
+
);
const DayOfWeekCellWithProvider = withProvider(Provider)(DayOfWeekCellComponent);
diff --git a/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.ui.jsx b/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.ui.tsx
similarity index 56%
rename from src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.ui.jsx
rename to src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.ui.tsx
index 0dd4836..220c38b 100644
--- a/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.ui.jsx
+++ b/src/widgets/CalendarWidget/ui/components/DayOfWeekCell/ui/DayOfWeekCell.ui.tsx
@@ -1,16 +1,21 @@
-import PropTypes from 'prop-types';
import { useContext } from 'react';
-import { WEEK_DAYS_LABEL, WEEK_DAYS } from 'shared/constants';
+import type { WeekDaysValues } from 'shared/constants';
+import { WEEK_DAYS_LABEL } from 'shared/constants';
import { CalendarWidgetContext } from '../../../CalendarWidgetContext';
import classes from './DayOfWeekCell.style.module.css';
-const DayOfWeekCell = (props) => {
+import type { FC } from 'react';
+
+export type DayOfWeekCellProps = {
+ day: WeekDaysValues;
+};
+const DayOfWeekCell: FC = (props) => {
const { day } = props;
const { locale } = useContext(CalendarWidgetContext);
- const content = WEEK_DAYS_LABEL[day][locale]?.short;
+ const content = WEEK_DAYS_LABEL[day]?.[locale].short;
return (
@@ -20,8 +25,4 @@ const DayOfWeekCell = (props) => {
);
};
-DayOfWeekCell.propTypes = {
- day: PropTypes.oneOf(Object.values(WEEK_DAYS)).isRequired,
-};
-
export default DayOfWeekCell;
diff --git a/src/widgets/CalendarWidget/ui/components/DayOfWeekRow/index.js b/src/widgets/CalendarWidget/ui/components/DayOfWeekRow/index.ts
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/DayOfWeekRow/index.js
rename to src/widgets/CalendarWidget/ui/components/DayOfWeekRow/index.ts
diff --git a/src/widgets/CalendarWidget/ui/components/MonthSelect/ui/MonthSelect.spec.jsx b/src/widgets/CalendarWidget/ui/components/MonthSelect/ui/MonthSelect.spec.jsx
index 238745c..e9bdaca 100644
--- a/src/widgets/CalendarWidget/ui/components/MonthSelect/ui/MonthSelect.spec.jsx
+++ b/src/widgets/CalendarWidget/ui/components/MonthSelect/ui/MonthSelect.spec.jsx
@@ -15,11 +15,15 @@ describe('Test MonthSelect', () => {
user = userEvent.setup();
});
- const setup = (props) => {
+ const setup = (props, providerProps) => {
const MonthSelectComponent = () => (
);
- const MonthSelectWithProvider = withProvider(CalendarWidgetProvider)(MonthSelectComponent);
+
+ const Provider = (params) => (
+
+ );
+ const MonthSelectWithProvider = withProvider(Provider)(MonthSelectComponent);
render();
};
@@ -40,13 +44,13 @@ describe('Test MonthSelect', () => {
test('onChange handler', async () => {
const onChange = jest.fn();
- setup({ onChange });
+ setup({ onChange }, { value: new Date(2020, 9, 15) });
const monthSelectElem = screen.getByTestId('month-select');
await user.selectOptions(monthSelectElem, String(MONTHS.JULY));
expect(onChange).toHaveBeenCalled();
- const newDate = new Date(2024, 6);
+ const newDate = new Date(2020, 6);
expect(onChange).toHaveBeenCalledWith(newDate);
});
});
diff --git a/src/widgets/CalendarWidget/ui/components/NextMonthButton/index.js b/src/widgets/CalendarWidget/ui/components/NextMonthButton/index.ts
similarity index 100%
rename from src/widgets/CalendarWidget/ui/components/NextMonthButton/index.js
rename to src/widgets/CalendarWidget/ui/components/NextMonthButton/index.ts
diff --git a/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.spec.jsx b/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.spec.tsx
similarity index 59%
rename from src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.spec.jsx
rename to src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.spec.tsx
index e8266d6..6e9ad7f 100644
--- a/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.spec.jsx
+++ b/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.spec.tsx
@@ -7,18 +7,25 @@ import { CalendarWidgetProvider } from '../../../CalendarWidgetContext';
import NextMonthButton from './NextMonthButton.ui';
+import type { NextMonthButtonProps } from './NextMonthButton.ui';
+import type { CalendarWidgetProviderProps } from '../../../CalendarWidgetContext';
+import type { UserEvent } from '@testing-library/user-event';
+
describe('Test NextMonthButton', () => {
- let user;
+ let user: UserEvent;
beforeEach(() => {
user = userEvent.setup();
});
- const setup = (props) => {
+ const setup = (props?: NextMonthButtonProps, providerProps?: CalendarWidgetProviderProps) => {
const NextMonthButtonComponent = () => (
);
- const NextMonthButtonWithProvider = withProvider(CalendarWidgetProvider)(NextMonthButtonComponent);
+ const Provider = (params: CalendarWidgetProviderProps) => (
+
+ );
+ const NextMonthButtonWithProvider = withProvider(Provider)(NextMonthButtonComponent);
render();
};
@@ -33,11 +40,12 @@ describe('Test NextMonthButton', () => {
test('onClick handler', async () => {
const onClick = jest.fn();
- setup({ onClick });
+ setup({ onClick }, { value: new Date(2020, 9, 15) });
const nextMontButtonElem = screen.getByTestId('next-month-button');
await user.click(nextMontButtonElem);
expect(onClick).toHaveBeenCalled();
+ expect(onClick).toHaveBeenCalledWith(new Date(2020, 10, 1));
});
});
diff --git a/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.ui.jsx b/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.ui.tsx
similarity index 71%
rename from src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.ui.jsx
rename to src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.ui.tsx
index b7001c7..b5d0c07 100644
--- a/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.ui.jsx
+++ b/src/widgets/CalendarWidget/ui/components/NextMonthButton/ui/NextMonthButton.ui.tsx
@@ -1,9 +1,15 @@
-import PropTypes from 'prop-types';
import { useContext } from 'react';
import { CalendarWidgetContext } from '../../../CalendarWidgetContext';
-const NextMonthButton = (props) => {
+import type { ReactNode, FC } from 'react';
+
+export type NextMonthButtonProps = {
+ children?: ReactNode;
+ onClick?: (newDate: Date) => void;
+ disabled?: boolean;
+};
+const NextMonthButton: FC = (props) => {
const {
children = 'next',
disabled,
@@ -27,7 +33,7 @@ const NextMonthButton = (props) => {
return (