1- import { FC , useState , forwardRef , ComponentType } from 'react' ;
1+ import { useState , forwardRef , ComponentType , PropsWithChildren } from 'react' ;
22import styled from 'styled-components' ;
33import moment from 'moment' ;
44import DateInputComponent from 'react-day-picker/DayPickerInput' ;
@@ -35,12 +35,12 @@ export type DatePickerProps = {
3535 dayPickerProps ?: Partial < DayPickerProps > ;
3636} ;
3737
38- export type OverlayComponentProps = {
38+ export type OverlayComponentProps = PropsWithChildren < {
3939 noExpiryOption : boolean ;
4040 noExpiryCopy : string ;
4141 handleNoExpiry : ( ) => void ;
4242 variant : BoxVariant ;
43- } ;
43+ } > ;
4444
4545const Overlay = styled ( Box ) ( ( { theme } ) => ( {
4646 ...( theme . DATEPICKER || { } ) ,
@@ -51,38 +51,39 @@ const Overlay = styled(Box)(({ theme }) => ({
5151const formatDate = ( date : Date | string , dateFormat : string ) =>
5252 moment ( date ) . format ( dateFormat ) ;
5353
54- const OverlayComponent : FC < OverlayComponentProps > = ( {
55- children,
56- noExpiryOption,
57- noExpiryCopy,
58- handleNoExpiry,
59- ...overlayProps
60- } ) => (
61- < Overlay { ...overlayProps } >
62- < Flex variant = "raw" dir = "column" align = "center" >
63- { children }
64- { noExpiryOption && (
65- < Button variant = "tertiary" margin = "s 0 0 0" onClick = { handleNoExpiry } >
66- { noExpiryCopy }
67- </ Button >
68- ) }
69- </ Flex >
70- </ Overlay >
71- ) ;
54+ export function OverlayComponent ( overlayProps : OverlayComponentProps ) {
55+ const { children, noExpiryOption, noExpiryCopy, handleNoExpiry, ...props } =
56+ overlayProps ;
57+
58+ return (
59+ < Overlay { ...props } >
60+ < Flex variant = "raw" dir = "column" align = "center" >
61+ { children }
62+ { noExpiryOption && (
63+ < Button variant = "tertiary" margin = "s 0 0 0" onClick = { handleNoExpiry } >
64+ { noExpiryCopy }
65+ </ Button >
66+ ) }
67+ </ Flex >
68+ </ Overlay >
69+ ) ;
70+ }
71+
72+ export function DatePicker ( datePickerProps : DatePickerProps ) {
73+ const {
74+ value,
75+ onChange,
76+ minDate,
77+ maxDate,
78+ hasIcon,
79+ noExpiryOption,
80+ noExpiryCopy = 'No expiry' ,
81+ dateFormat = 'MM/DD/YYYY' ,
82+ placeholder = 'mm/dd/yyyy' ,
83+ dayPickerProps = { } ,
84+ ...inputProps
85+ } = datePickerProps ;
7286
73- export const DatePicker : FC < DatePickerProps > = ( {
74- value,
75- onChange,
76- minDate,
77- maxDate,
78- hasIcon,
79- noExpiryOption,
80- noExpiryCopy = 'No expiry' ,
81- dateFormat = 'MM/DD/YYYY' ,
82- placeholder = 'mm/dd/yyyy' ,
83- dayPickerProps = { } ,
84- ...inputProps
85- } ) => {
8687 const isNoExpiry =
8788 noExpiryOption &&
8889 ( value === undefined || value === null || value === noExpiryCopy ) ;
@@ -153,4 +154,4 @@ export const DatePicker: FC<DatePickerProps> = ({
153154 ) }
154155 />
155156 ) ;
156- } ;
157+ }
0 commit comments