From b0e98a7d8bb95d0862b58075911837dfd5f24684 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 22 Aug 2024 09:53:22 +0200 Subject: [PATCH 1/2] refactor(sanity): move base components from form/inputs/DateInputs to ui-components --- .../src/core/form/inputs/DateInputs/CommonDateTimeInput.tsx | 4 ++-- packages/sanity/src/core/form/inputs/DateInputs/DateInput.tsx | 2 +- .../sanity/src/core/form/inputs/DateInputs/DateTimeInput.tsx | 2 +- packages/sanity/src/core/form/inputs/DateInputs/utils.ts | 2 +- .../base => ui-components/inputs/DateInputs}/DatePicker.tsx | 0 .../inputs/DateInputs}/DateTimeInput.tsx | 3 ++- .../inputs/DateInputs}/LazyTextInput.tsx | 0 .../inputs/DateInputs}/calendar/Calendar.tsx | 2 +- .../inputs/DateInputs}/calendar/CalendarDay.tsx | 0 .../inputs/DateInputs}/calendar/CalendarMonth.tsx | 2 +- .../inputs/DateInputs}/calendar/YearInput.tsx | 0 .../inputs/DateInputs}/calendar/constants.ts | 0 .../inputs/DateInputs}/calendar/features.ts | 0 .../inputs/DateInputs}/calendar/types.ts | 0 .../inputs/DateInputs}/calendar/utils.ts | 2 +- 15 files changed, 10 insertions(+), 9 deletions(-) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/DatePicker.tsx (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/DateTimeInput.tsx (97%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/LazyTextInput.tsx (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/Calendar.tsx (99%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/CalendarDay.tsx (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/CalendarMonth.tsx (96%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/YearInput.tsx (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/constants.ts (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/features.ts (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/types.ts (100%) rename packages/sanity/src/{core/form/inputs/DateInputs/base => ui-components/inputs/DateInputs}/calendar/utils.ts (94%) diff --git a/packages/sanity/src/core/form/inputs/DateInputs/CommonDateTimeInput.tsx b/packages/sanity/src/core/form/inputs/DateInputs/CommonDateTimeInput.tsx index c1e9bf9a3ac..d2178604d06 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/CommonDateTimeInput.tsx +++ b/packages/sanity/src/core/form/inputs/DateInputs/CommonDateTimeInput.tsx @@ -12,9 +12,9 @@ import { useState, } from 'react' +import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/calendar/types' +import {DateTimeInput} from '../../../../ui-components/inputs/DateInputs/DateTimeInput' import {useTranslation} from '../../../i18n/hooks/useTranslation' -import {type CalendarLabels} from './base/calendar/types' -import {DateTimeInput} from './base/DateTimeInput' import {type ParseResult} from './types' export interface CommonDateTimeInputProps { diff --git a/packages/sanity/src/core/form/inputs/DateInputs/DateInput.tsx b/packages/sanity/src/core/form/inputs/DateInputs/DateInput.tsx index db7a54c9ebc..535effa670a 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/DateInput.tsx +++ b/packages/sanity/src/core/form/inputs/DateInputs/DateInput.tsx @@ -1,10 +1,10 @@ import {DEFAULT_DATE_FORMAT, format, parse} from '@sanity/util/legacyDateFormat' import {useCallback, useMemo} from 'react' +import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/calendar/types' import {useTranslation} from '../../../i18n' import {set, unset} from '../../patch' import {type StringInputProps} from '../../types' -import {type CalendarLabels} from './base/calendar/types' import {CommonDateTimeInput} from './CommonDateTimeInput' import {getCalendarLabels} from './utils' diff --git a/packages/sanity/src/core/form/inputs/DateInputs/DateTimeInput.tsx b/packages/sanity/src/core/form/inputs/DateInputs/DateTimeInput.tsx index 4f85eb676c5..03d5cdb1d46 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/DateTimeInput.tsx +++ b/packages/sanity/src/core/form/inputs/DateInputs/DateTimeInput.tsx @@ -7,10 +7,10 @@ import { import {getMinutes, parseISO, setMinutes} from 'date-fns' import {useCallback, useMemo} from 'react' +import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/calendar/types' import {useTranslation} from '../../../i18n' import {set, unset} from '../../patch' import {type StringInputProps} from '../../types' -import {type CalendarLabels} from './base/calendar/types' import {CommonDateTimeInput} from './CommonDateTimeInput' import {type ParseResult} from './types' import {getCalendarLabels, isValidDate} from './utils' diff --git a/packages/sanity/src/core/form/inputs/DateInputs/utils.ts b/packages/sanity/src/core/form/inputs/DateInputs/utils.ts index 462166ab364..82f7fca7309 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/utils.ts +++ b/packages/sanity/src/core/form/inputs/DateInputs/utils.ts @@ -1,4 +1,4 @@ -import {type CalendarLabels} from './base/calendar/types' +import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/calendar/types' export function isValidDate(date: Date): boolean { return date instanceof Date && !isNaN(date.valueOf()) diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/DatePicker.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/DatePicker.tsx similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/DatePicker.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/DatePicker.tsx diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/DateTimeInput.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/DateTimeInput.tsx similarity index 97% rename from packages/sanity/src/core/form/inputs/DateInputs/base/DateTimeInput.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/DateTimeInput.tsx index 3e7eccd63da..c726ae00e20 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/base/DateTimeInput.tsx +++ b/packages/sanity/src/ui-components/inputs/DateInputs/DateTimeInput.tsx @@ -12,7 +12,8 @@ import { } from 'react' import FocusLock from 'react-focus-lock' -import {Button, Popover} from '../../../../../ui-components' +import {Button} from '../../button' +import {Popover} from '../../popover' import {type CalendarLabels} from './calendar/types' import {DatePicker} from './DatePicker' import {LazyTextInput} from './LazyTextInput' diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/LazyTextInput.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/LazyTextInput.tsx similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/LazyTextInput.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/LazyTextInput.tsx diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/Calendar.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/Calendar.tsx similarity index 99% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/Calendar.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/Calendar.tsx index fb4b1695029..4ec38cf15ff 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/Calendar.tsx +++ b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/Calendar.tsx @@ -14,7 +14,7 @@ import { useRef, } from 'react' -import {Button} from '../../../../../../ui-components' +import {Button} from '../../../button' import {CalendarMonth} from './CalendarMonth' import {ARROW_KEYS, DEFAULT_TIME_PRESETS, HOURS_24} from './constants' import {features} from './features' diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/CalendarDay.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/CalendarDay.tsx similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/CalendarDay.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/CalendarDay.tsx diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/CalendarMonth.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/CalendarMonth.tsx similarity index 96% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/CalendarMonth.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/CalendarMonth.tsx index 26b87dc26fc..25464874c93 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/CalendarMonth.tsx +++ b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/CalendarMonth.tsx @@ -1,7 +1,7 @@ import {Box, Grid, Text} from '@sanity/ui' import {isSameDay, isSameMonth} from 'date-fns' -import {useCurrentLocale} from '../../../../../i18n/hooks/useLocale' +import {useCurrentLocale} from '../../../../core/i18n/hooks/useLocale' import {CalendarDay} from './CalendarDay' import {useWeeksOfMonth} from './utils' diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/YearInput.tsx b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/YearInput.tsx similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/YearInput.tsx rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/YearInput.tsx diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/constants.ts b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/constants.ts similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/constants.ts rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/constants.ts diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/features.ts b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/features.ts similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/features.ts rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/features.ts diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/types.ts b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/types.ts similarity index 100% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/types.ts rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/types.ts diff --git a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/utils.ts b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/utils.ts similarity index 94% rename from packages/sanity/src/core/form/inputs/DateInputs/base/calendar/utils.ts rename to packages/sanity/src/ui-components/inputs/DateInputs/calendar/utils.ts index 0888302d271..49f3cf86cb5 100644 --- a/packages/sanity/src/core/form/inputs/DateInputs/base/calendar/utils.ts +++ b/packages/sanity/src/ui-components/inputs/DateInputs/calendar/utils.ts @@ -1,6 +1,6 @@ import {addDays, eachWeekOfInterval, getWeek, lastDayOfMonth, startOfMonth} from 'date-fns' -import {useCurrentLocale} from '../../../../../i18n/hooks/useLocale' +import {useCurrentLocale} from '../../../../core/i18n/hooks/useLocale' import {TAIL_WEEKDAYS} from './constants' /** From 2ece26ad68536c51b70b7a16098f67bd78e550b0 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Thu, 22 Aug 2024 09:57:10 +0200 Subject: [PATCH 2/2] refactor(sanity): update the imports --- .../components/dateInputs/base/DateTimeInput.tsx | 2 +- .../components/dateInputs/base/calendar/YearInput.tsx | 2 +- .../core/tasks/components/form/fields/DateEditFormField.tsx | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/DateTimeInput.tsx b/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/DateTimeInput.tsx index c47d5fe5d1a..5819de19d24 100644 --- a/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/DateTimeInput.tsx +++ b/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/DateTimeInput.tsx @@ -20,7 +20,7 @@ import { import FocusLock from 'react-focus-lock' import {Popover} from '../../../../../ui-components' -import {LazyTextInput} from '../../../../form/inputs/DateInputs/base/LazyTextInput' +import {LazyTextInput} from '../../../../../ui-components/inputs/DateInputs/LazyTextInput' import {DatePicker} from './DatePicker' type Props = { diff --git a/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/calendar/YearInput.tsx b/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/calendar/YearInput.tsx index 19c99c113ba..4659dd14368 100644 --- a/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/calendar/YearInput.tsx +++ b/packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/calendar/YearInput.tsx @@ -1,6 +1,6 @@ import {type ChangeEvent, type ComponentProps, type FocusEvent, useCallback} from 'react' -import {LazyTextInput} from '../../../../../form/inputs/DateInputs/base/LazyTextInput' +import {LazyTextInput} from '../../../../../../ui-components/inputs/DateInputs/LazyTextInput' type Props = Omit, 'onChange' | 'value'> & { value?: number diff --git a/packages/sanity/src/core/tasks/components/form/fields/DateEditFormField.tsx b/packages/sanity/src/core/tasks/components/form/fields/DateEditFormField.tsx index 9714b5eb45e..a47efa77911 100644 --- a/packages/sanity/src/core/tasks/components/form/fields/DateEditFormField.tsx +++ b/packages/sanity/src/core/tasks/components/form/fields/DateEditFormField.tsx @@ -6,9 +6,9 @@ import {type KeyboardEvent, useCallback, useMemo, useRef, useState} from 'react' import ReactFocusLock from 'react-focus-lock' import {Button, Popover} from '../../../../../ui-components' +import {type CalendarLabels} from '../../../../../ui-components/inputs/DateInputs/calendar/types' +import {DatePicker} from '../../../../../ui-components/inputs/DateInputs/DatePicker' import {type FormPatch, type PatchEvent, set, unset} from '../../../../form' -import {type CalendarLabels} from '../../../../form/inputs/DateInputs/base/calendar/types' -import {DatePicker} from '../../../../form/inputs/DateInputs/base/DatePicker' import {getCalendarLabels} from '../../../../form/inputs/DateInputs/utils' import {useDateTimeFormat} from '../../../../hooks' import {useTranslation} from '../../../../i18n'