From 07d1c452220f883686c039adb995d0ff2ab4fe5e Mon Sep 17 00:00:00 2001 From: David Avsajanishvili Date: Tue, 21 Mar 2023 19:57:34 +0000 Subject: [PATCH 1/2] 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; From 3171461863f3b9a7a7c4259c68f0c521a6278a7b Mon Sep 17 00:00:00 2001 From: David Avsajanishvili Date: Tue, 21 Mar 2023 20:04:25 +0000 Subject: [PATCH 2/2] Linting fixes --- src/components/calendar/calendar.tsx | 270 ++++++++++++++------------- stories/data.ts | 2 +- 2 files changed, 138 insertions(+), 134 deletions(-) diff --git a/src/components/calendar/calendar.tsx b/src/components/calendar/calendar.tsx index a7262d05..ba2e89f6 100644 --- a/src/components/calendar/calendar.tsx +++ b/src/components/calendar/calendar.tsx @@ -79,149 +79,153 @@ const Calendar: React.FC = ({ }); const calendarInstance = ( - -
- {calendars.map((calendar, calendarIdx) => ( -
-
-
- {calendarIdx === 0 && ( - -
+
+ {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) => ( - - {weekday.slice(0, 2)} - - ))} - {calendar.weeks.map((week) => - week.map((dateObj, weekIdx) => { - const key = `${calendar.year}-${calendar.month}-${weekIdx}`; +
+ {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; + + {calendarInstance} + + ) : ( + calendarInstance + ); }; export default Calendar; diff --git a/stories/data.ts b/stories/data.ts index 889835bc..bc9f2e7d 100644 --- a/stories/data.ts +++ b/stories/data.ts @@ -33,7 +33,7 @@ const locale = [ function arrayToMap( arr: readonly T[] -): { [key in typeof arr[number]]: typeof arr[number] } { +): { [key in (typeof arr)[number]]: (typeof arr)[number] } { return arr.reduce( (acc, cur) => ({ ...acc, [cur]: cur }), {} as { [key in T]: T }