From ba0b657a798c8f538ee025144d579d862bbd583a Mon Sep 17 00:00:00 2001 From: Alaa Yahia <6881345+alaa-yahia@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:45:27 +0300 Subject: [PATCH] fix: clear button and arrow alignment issues (#1609) * fix: clear button alignment in calendar input component * fix: prev and next arrow alignment in calendar navigation container * fix: remove tests dependent on calendarDate --- collections/ui/API.md | 3 +- components/calendar/API.md | 3 +- .../src/calendar-input/calendar-input.js | 29 ++++++- .../src/calendar/navigation-container.js | 79 ++++++++----------- .../supports_ethiopic_calendar.js | 4 - .../supports_gregorian_calendar.js | 4 - .../supports_nepali_calendar.js | 4 - .../stories/calendar-input.prod.stories.js | 9 +-- .../src/stories/calendar-story-wrapper.js | 10 --- 9 files changed, 68 insertions(+), 77 deletions(-) diff --git a/collections/ui/API.md b/collections/ui/API.md index b73858e5dc..96e07654de 100644 --- a/collections/ui/API.md +++ b/collections/ui/API.md @@ -255,13 +255,14 @@ import { CalendarInput } from '@dhis2/ui' |date|string|||the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601)| |dir|'ltr' │ 'rtl'|||the direction of the library - internally the library will use rtl for rtl-languages but this can be overridden here for more control| |format|'YYYY-MM-DD' │ 'DD-MM-YYYY'|||The date format to use either `YYYY-MM-DD` or `DD-MM-YYYY`| +|inputWidth|string|||the width of input field| |locale|string|||any valid locale - if none provided, the internal library will fallback to the user locale (more info here: https://github.com/dhis2/multi-calendar-dates/blob/main/src/hooks/internal/useResolvedLocaleOptions.ts#L15)| |maxDate|string|||The maximum selectable date| |minDate|string|||The minimum selectable date| |numberingSystem|string|||numbering system to use - full list here https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/numberingSystems.ts| |strictValidation|boolean|||Whether to use strict validation by showing errors for out-of-range dates when enabled (default), and warnings when disabled| |weekDayFormat|'narrow' │ 'short' │ 'long'|`'narrow'`||the format to display for the week day, i.e. Monday (long), Mon (short), M (narrow)| -|width|string|`'240px'`||the width of the calendar component| +|width|string|`'300px'`||the width of the calendar component| ### Card diff --git a/components/calendar/API.md b/components/calendar/API.md index b17b48051e..7ff62fe3f4 100644 --- a/components/calendar/API.md +++ b/components/calendar/API.md @@ -49,10 +49,11 @@ import { CalendarInput } from '@dhis2/ui' |date|string|||the currently selected date using an iso-like format YYYY-MM-DD, in the calendar system provided (not iso8601)| |dir|'ltr' │ 'rtl'|||the direction of the library - internally the library will use rtl for rtl-languages but this can be overridden here for more control| |format|'YYYY-MM-DD' │ 'DD-MM-YYYY'|||The date format to use either `YYYY-MM-DD` or `DD-MM-YYYY`| +|inputWidth|string|||the width of input field| |locale|string|||any valid locale - if none provided, the internal library will fallback to the user locale (more info here: https://github.com/dhis2/multi-calendar-dates/blob/main/src/hooks/internal/useResolvedLocaleOptions.ts#L15)| |maxDate|string|||The maximum selectable date| |minDate|string|||The minimum selectable date| |numberingSystem|string|||numbering system to use - full list here https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/numberingSystems.ts| |strictValidation|boolean|||Whether to use strict validation by showing errors for out-of-range dates when enabled (default), and warnings when disabled| |weekDayFormat|'narrow' │ 'short' │ 'long'|`'narrow'`||the format to display for the week day, i.e. Monday (long), Mon (short), M (narrow)| -|width|string|`'240px'`||the width of the calendar component| +|width|string|`'300px'`||the width of the calendar component| diff --git a/components/calendar/src/calendar-input/calendar-input.js b/components/calendar/src/calendar-input/calendar-input.js index 7824d25539..d8d25d7558 100644 --- a/components/calendar/src/calendar-input/calendar-input.js +++ b/components/calendar/src/calendar-input/calendar-input.js @@ -34,13 +34,15 @@ export const CalendarInput = ({ clearable, minDate, maxDate, - format, // todo: props and types for format and validation + format, strictValidation, + inputWidth, ...rest } = {}) => { const ref = useRef() const [open, setOpen] = useState(false) const [partialDate, setPartialDate] = useState(date) + const [isIconDisplayed, setIsIconDisplayed] = useState(false) const excludeRef = useRef(null) @@ -58,8 +60,21 @@ export const CalendarInput = ({ const pickerResults = useDatePicker({ onDateSelect: (result) => { + const validated = validateDateString(result.calendarDateString, { + calendar, + format, + minDateString: minDate, + maxDateString: maxDate, + strictValidation, + }) + setIsIconDisplayed( + validated.errorMessage || validated.warningMessage + ) setOpen(false) - parentOnDateSelect?.(result) + parentOnDateSelect?.({ + calendarDateString: result.calendarDateString, + ...validated, + }) }, date, minDate: minDate, @@ -82,6 +97,7 @@ export const CalendarInput = ({ maxDateString: maxDate, strictValidation, }) + setIsIconDisplayed(validated.errorMessage || validated.warningMessage) parentOnDateSelect?.({ calendarDateString: partialDate, ...validated }) if ( @@ -133,6 +149,7 @@ export const CalendarInput = ({ } error={!!pickerResults.errorMessage} warning={!!pickerResults.warningMessage} + inputWidth={inputWidth} /> {clearable && (