From 07d1c452220f883686c039adb995d0ff2ab4fe5e Mon Sep 17 00:00:00 2001 From: David Avsajanishvili Date: Tue, 21 Mar 2023 19:57:34 +0000 Subject: [PATCH] Make it work with Semantic-UI-React v3. See the roadmap: https://github.com/Semantic-Org/Semantic-UI-React/issues/4409 See the breaking change: https://github.com/Semantic-Org/Semantic-UI-React/pull/4286 --- src/components/calendar/calendar.tsx | 272 ++++++++++++++------------- 1 file changed, 137 insertions(+), 135 deletions(-) diff --git a/src/components/calendar/calendar.tsx b/src/components/calendar/calendar.tsx index 65aa6587..a7262d05 100644 --- a/src/components/calendar/calendar.tsx +++ b/src/components/calendar/calendar.tsx @@ -1,6 +1,6 @@ import cn from 'classnames'; import React, { Fragment, SyntheticEvent, useEffect, useRef } from 'react'; -import { Ref, Segment } from 'semantic-ui-react'; +import * as SemanticUiReact from 'semantic-ui-react'; import { Locale, RenderProps, SemanticDatepickerProps } from 'types'; import { getShortDate, getToday } from '../../utils'; import Button from '../button'; @@ -78,148 +78,150 @@ const Calendar: React.FC = ({ } }); - return ( - - -
- {calendars.map((calendar, calendarIdx) => ( -
-
-
- {calendarIdx === 0 && ( - -
+ const calendarInstance = ( + +
+ {calendars.map((calendar, calendarIdx) => ( +
+
+
+ {calendarIdx === 0 && ( + +
- - {months[calendar.month].slice(0, 3)} {calendar.year} - + + {months[calendar.month].slice(0, 3)} {calendar.year} + -
- {calendarIdx === calendars.length - 1 && ( - -
-
-
- {weekdays.map((weekday) => ( - + {calendarIdx === calendars.length - 1 && ( + +
+
+
+ {weekdays.map((weekday) => ( + + {weekday.slice(0, 2)} + + ))} + {calendar.weeks.map((week) => + week.map((dateObj, weekIdx) => { + const key = `${calendar.year}-${calendar.month}-${weekIdx}`; - if (!dateObj) { - return ; - } + if (!dateObj) { + return ; + } - const selectable = - dateObj.selectable && filterDate(dateObj.date); - const shortDate = getShortDate(dateObj.date); + const selectable = + dateObj.selectable && filterDate(dateObj.date); + const shortDate = getShortDate(dateObj.date); - return ( - - {dateObj.date.getDate()} - - ); - }) - )} -
-
- ))} + return ( + + {dateObj.date.getDate()} + + ); + }) + )} +
- {showToday ? ( - - {todayButton} - - ) : null} - - + ))} +
+ {showToday ? ( + + {todayButton} + + ) : null} + ); + return SemanticUiReact.Ref ? ( + {calendarInstance} + ) : calendarInstance; }; export default Calendar;