diff --git a/packages/core/src/components/Calendar/Calendar.styled.tsx b/packages/core/src/components/Calendar/Calendar.styled.tsx index c6a6bde3d..3291d068e 100644 --- a/packages/core/src/components/Calendar/Calendar.styled.tsx +++ b/packages/core/src/components/Calendar/Calendar.styled.tsx @@ -33,6 +33,8 @@ export const MonthNavigation = styled.button.attrs({ type: 'button' })<{ disable } `; export const Header = styled.div` + padding: 0 0.8rem; + box-sizing: border-box; width: 100%; display: flex; align-items: center; diff --git a/packages/core/src/components/Calendar/Calendar.test.tsx b/packages/core/src/components/Calendar/Calendar.test.tsx index f4068eff9..3a825a6aa 100644 --- a/packages/core/src/components/Calendar/Calendar.test.tsx +++ b/packages/core/src/components/Calendar/Calendar.test.tsx @@ -203,4 +203,20 @@ describe('Calendar Component', () => { expect(month).toEqual('Dec'); expect(year).toEqual('2021'); }); + + it('should call onClose on click on close icon', () => { + const onClose = jest.fn(); + render( + + ); + fireEvent.click(screen.getByTitle('test-calendar-close-icon')); + expect(onClose).toHaveBeenCalled(); + }); }); diff --git a/packages/core/src/components/Calendar/Calendar.tsx b/packages/core/src/components/Calendar/Calendar.tsx index b0cc351b8..c4bb763c9 100644 --- a/packages/core/src/components/Calendar/Calendar.tsx +++ b/packages/core/src/components/Calendar/Calendar.tsx @@ -1,4 +1,4 @@ -import { KeyboardArrowLeftIcon, KeyboardArrowRightIcon } from '@medly-components/icons'; +import { CloseIcon, KeyboardArrowLeftIcon, KeyboardArrowRightIcon } from '@medly-components/icons'; import { WithStyle } from '@medly-components/utils'; import { endOfDay } from 'date-fns'; import type { FC } from 'react'; @@ -12,7 +12,7 @@ import { getCalendarDates, getMonthAndYearFromDate, getNextMonthAndYear, getPrev import { CalendarProps } from './types'; const Component: FC = memo( - ({ date, onChange, minSelectableDate, maxSelectableDate, isErrorPresent, defaultMonth = 0, defaultYear, ...restProps }) => { + ({ date, onChange, onClose, minSelectableDate, maxSelectableDate, isErrorPresent, defaultMonth = 0, defaultYear, ...restProps }) => { const today = new Date(), ref = useRef(null), defaultDate = defaultYear ? new Date(defaultYear, defaultMonth, 1) : null, @@ -78,6 +78,13 @@ const Component: FC = memo( > + { + onClose?.(); + setCalenderVisibility(false); + }} + /> diff --git a/packages/core/src/components/Calendar/__snapshots__/Calendar.test.tsx.snap b/packages/core/src/components/Calendar/__snapshots__/Calendar.test.tsx.snap index e88aa5f91..26a8a5095 100644 --- a/packages/core/src/components/Calendar/__snapshots__/Calendar.test.tsx.snap +++ b/packages/core/src/components/Calendar/__snapshots__/Calendar.test.tsx.snap @@ -31,6 +31,21 @@ exports[`Calendar Component should render given date 1`] = ` fill: #607890; } +.c11 { + overflow: visible; + font-size: 2.4rem; + -webkit-transition: all 100ms linear; + transition: all 100ms linear; + cursor: pointer; +} + +.c11 * { + fill-opacity: 1; + -webkit-transition: all 100ms linear; + transition: all 100ms linear; + fill: #607890; +} + .c6 { margin: 0; color: inherit; @@ -45,7 +60,7 @@ exports[`Calendar Component should render given date 1`] = ` display: inline-block; } -.c12 { +.c13 { margin: 0; color: inherit; font-size: 1.4rem; @@ -59,7 +74,7 @@ exports[`Calendar Component should render given date 1`] = ` display: inline-block; } -.c15 { +.c16 { margin: 0; color: inherit; font-size: 1.4rem; @@ -123,6 +138,8 @@ exports[`Calendar Component should render given date 1`] = ` } .c1 { + padding: 0 0.8rem; + box-sizing: border-box; width: 100%; display: -webkit-box; display: -webkit-flex; @@ -138,13 +155,13 @@ exports[`Calendar Component should render given date 1`] = ` justify-content: space-between; } -.c11 { +.c12 { display: grid; grid-template-columns: repeat(7,4rem); grid-auto-rows: auto; } -.c14 { +.c15 { background-color: transparent; border: 0.2rem solid transparent; -webkit-text-decoration: none; @@ -175,20 +192,20 @@ exports[`Calendar Component should render given date 1`] = ` align-items: center; } -.c14:focus { +.c15:focus { outline: none; } -.c14:disabled { +.c15:disabled { cursor: not-allowed; color: #b0bcc8; } -.c14:hover { +.c15:hover { background-color: #eff2f4; } -.c16 { +.c17 { background-color: transparent; border: 0.2rem solid transparent; -webkit-text-decoration: none; @@ -218,29 +235,29 @@ exports[`Calendar Component should render given date 1`] = ` align-items: center; } -.c16:focus { +.c17:focus { outline: none; } -.c16:disabled { +.c17:disabled { cursor: not-allowed; } -.c16:hover { +.c17:hover { background-color: #eff2f4; } -.c16 span { +.c17 span { font-weight: bold; } -.c16, -.c16:hover { +.c17, +.c17:hover { background-color: #3872D2; color: #ffffff; } -.c17 { +.c18 { background-color: transparent; border: 0.2rem solid transparent; -webkit-text-decoration: none; @@ -270,16 +287,16 @@ exports[`Calendar Component should render given date 1`] = ` align-items: center; } -.c17:focus { +.c18:focus { outline: none; } -.c17:disabled { +.c18:disabled { cursor: not-allowed; color: #b0bcc8; } -.c17:hover { +.c18:hover { background-color: #eff2f4; } @@ -473,7 +490,7 @@ exports[`Calendar Component should render given date 1`] = ` padding: 0 0 0 1rem; } -.c13 { +.c14 { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; @@ -605,426 +622,441 @@ exports[`Calendar Component should render given date 1`] = ` /> + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
S M T W T F S + + +
+ + +