Skip to content

Commit a379c6c

Browse files
committed
feat: add new props to datepicker
1 parent 2fedc04 commit a379c6c

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

packages/styled/src/components/DateRangeInputModern/DateRangeInputModern.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ export interface DateRangeInputModernProps extends UseDatepickerProps {
108108
initialVisibleMonth?: Date
109109
startDateLabel?: string
110110
endDateLabel?: string
111+
datepickerSelectDateGridTemplateColumns?: string
112+
datepickerBorderRadiusCustom?: string
113+
datepickerWidthCustom?: string
114+
datepickerHeightCustom?: string
115+
datepickerLeftCustom?: string
116+
datepickerTopCustom?: string
111117
}
112118

113119
function DateRangeInputModern({
@@ -144,6 +150,12 @@ function DateRangeInputModern({
144150
unavailableDates = [],
145151
startDateLabel = 'From',
146152
endDateLabel = 'To',
153+
datepickerSelectDateGridTemplateColumns,
154+
datepickerBorderRadiusCustom,
155+
datepickerWidthCustom,
156+
datepickerHeightCustom,
157+
datepickerLeftCustom,
158+
datepickerTopCustom,
147159
}: DateRangeInputModernProps) {
148160
const ref = useRef(null)
149161
const datepickerWrapperRef = useRef<HTMLDivElement>(null)
@@ -162,6 +174,9 @@ function DateRangeInputModern({
162174
dateRangeStartDateInputPadding: vertical ? (rtl ? '0 32px 0 8px' : '0 8px 0 32px') : '0 0x',
163175
dateRangeEndDateInputPadding: vertical ? (rtl ? '0 32px 0 8px' : '0 8px 0 32px') : '0 0px',
164176
dateRangeDatepickerWrapperPosition: 'absolute',
177+
datepickerHeight: 'unset',
178+
datepickerLeft: '0px',
179+
datepickerTop: '0px',
165180
...getPlacement(placement, rtl),
166181
})
167182

@@ -253,8 +268,8 @@ function DateRangeInputModern({
253268
<Box
254269
position={theme.dateRangeDatepickerWrapperPosition}
255270
bottom={theme.dateRangeDatepickerWrapperBottom}
256-
left={theme.dateRangeDatepickerWrapperLeft}
257-
top={theme.dateRangeDatepickerWrapperTop}
271+
left={datepickerLeftCustom || theme.dateRangeDatepickerWrapperLeft}
272+
top={datepickerTopCustom || theme.dateRangeDatepickerWrapperTop}
258273
right={theme.dateRangeDatepickerWrapperRight}
259274
>
260275
{focusedInput !== null && (
@@ -285,6 +300,10 @@ function DateRangeInputModern({
285300
unavailableDates={unavailableDates}
286301
ref={ref}
287302
initialVisibleMonth={initialVisibleMonth}
303+
datepickerSelectDateGridTemplateColumns={datepickerSelectDateGridTemplateColumns}
304+
datepickerBorderRadius={datepickerBorderRadiusCustom}
305+
datepickerWidth={datepickerWidthCustom}
306+
datepickerHeight={datepickerHeightCustom}
288307
/>
289308
)}
290309
</Box>

packages/styled/src/components/Datepicker/Datepicker.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ interface StyledDatepicker
7373
ZIndexProps,
7474
BoxShadowProps {
7575
rtl: boolean
76+
height: string
77+
left: string
78+
top: string
7679
}
7780
const composeStyledDatepickerStyles = compose(
7881
background,
@@ -85,7 +88,10 @@ const composeStyledDatepickerStyles = compose(
8588
)
8689

8790
const StyledDatepicker = styled('div')<StyledDatepicker>`
88-
${composeStyledDatepickerStyles}
91+
${composeStyledDatepickerStyles};
92+
height: ${({height}) => height || 'unset'};
93+
left: ${({left}) => left || 'unset'};
94+
top: ${({top}) => top || 'unset'};
8995
${({rtl}) =>
9096
rtl &&
9197
css`
@@ -141,6 +147,12 @@ export interface DatepickerProps extends UseDatepickerProps {
141147
monthLabelFormat?(date: Date): string
142148
onDayRender?(date: Date): React.ReactNode
143149
unavailableDates?: Date[]
150+
datepickerSelectDateGridTemplateColumns?: string
151+
datepickerWidth?: string
152+
datepickerBorderRadius?: string
153+
datepickerHeight?: string
154+
datepickerLeft?: string
155+
datepickerTop?: string
144156
}
145157

146158
function Datepicker(
@@ -170,6 +182,12 @@ function Datepicker(
170182
displayFormat = 'MM/dd/yyyy',
171183
phrases = datepickerPhrases,
172184
unavailableDates = [],
185+
datepickerSelectDateGridTemplateColumns = '',
186+
datepickerWidth = '',
187+
datepickerBorderRadius = '',
188+
datepickerHeight = 'unset',
189+
datepickerLeft = '0px',
190+
datepickerTop = '0px',
173191
}: DatepickerProps,
174192
ref?: React.Ref<unknown>,
175193
) {
@@ -214,11 +232,11 @@ function Datepicker(
214232
const themeContext = useContext(ThemeContext)
215233
const theme: DatepickerTheme = useThemeProps({
216234
datepickerZIndex: null,
217-
datepickerBackground: '#ffffff',
235+
datepickerBackground: '#ffffff !important',
218236
datepickerPadding: vertical ? '16px 16px 0' : '32px',
219237
datepickerBorderRadius: '2px',
220238
datepickerPosition: 'relative',
221-
datepickerWidth: 'fit-content',
239+
datepickerWidth: datepickerWidth || 'fit-content',
222240
datepickerCloseWrapperPosition: vertical ? 'relative' : 'absolute',
223241
datepickerCloseWrapperDisplay: vertical ? 'flex' : 'block',
224242
datepickerCloseWrapperJustifyContent: vertical ? 'flex-end' : 'initial',
@@ -292,12 +310,15 @@ function Datepicker(
292310
<StyledDatepicker
293311
background={theme.datepickerBackground}
294312
p={theme.datepickerPadding}
295-
borderRadius={theme.datepickerBorderRadius}
313+
borderRadius={datepickerBorderRadius || theme.datepickerBorderRadius}
296314
position={theme.datepickerPosition}
297315
boxShadow={theme.datepickerBoxShadow}
298316
width={theme.datepickerWidth}
317+
height={datepickerHeight}
299318
zIndex={theme.datepickerZIndex}
300319
rtl={rtl}
320+
left={datepickerLeft}
321+
top={datepickerTop}
301322
>
302323
{showClose && (
303324
<CloseWrapper
@@ -319,7 +340,10 @@ function Datepicker(
319340
<DateWrapper>
320341
<Grid
321342
data-testid="SelectedDatesGrid"
322-
gridTemplateColumns={theme.datepickerSelectDateGridTemplateColumns}
343+
gridTemplateColumns={
344+
datepickerSelectDateGridTemplateColumns ||
345+
theme.datepickerSelectDateGridTemplateColumns
346+
}
323347
gridTemplateRows={theme.datepickerSelectDateGridTemplateRows}
324348
>
325349
<SelectedDate

0 commit comments

Comments
 (0)