Skip to content

Commit 57d2d9f

Browse files
authored
feat(datepicker): exposing footer prop (#2927)
* feat(datepicker): exposing footer slot prop * Create cuddly-pigs-explode.md * chore: updated storybook example * fix: lint error * chore: resolved commets * chore: fix maxwidth value * Update cuddly-pigs-explode.md
1 parent c5003ac commit 57d2d9f

File tree

7 files changed

+97
-25
lines changed

7 files changed

+97
-25
lines changed

.changeset/cuddly-pigs-explode.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@razorpay/blade": patch
3+
"@razorpay/blade-mcp": patch
4+
---
5+
6+
feat(datepicker): exposing footer prop

packages/blade-mcp/knowledgebase/components/DatePicker.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ type DatePickerCommonProps<T extends DatePickerSelectionType> = {
119119
*/
120120
showFooterActions?: boolean;
121121

122+
/**
123+
* Custom React element to render in the footer above/side of action buttons
124+
* Can be used to add custom content like informational text, links, or other components
125+
*/
126+
footer?: React.ReactElement;
127+
122128
/**
123129
* Sets the date format to be displayed in the input field
124130
* @default 'DD/MM/YYYY'
@@ -414,6 +420,12 @@ const SizeVariantsExample = () => {
414420
isOpen={isSingleOpen}
415421
onOpenChange={({ isOpen }) => setIsSingleOpen(isOpen)}
416422
showFooterActions={false}
423+
footer={
424+
<Text size="small" color="surface.text.gray.muted">
425+
This section only displays records from the last 45 days. For earlier data, please
426+
download a report from the Reports section.
427+
</Text>
428+
}
417429
/>
418430

419431
<DatePicker

packages/blade/src/components/DatePicker/BaseDatePicker.web.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import { useFilterChipGroupContext } from '~components/Dropdown/FilterChipGroupC
4646
// Calendar dimensions for consistent layout
4747
const CALENDAR_HEIGHTS = {
4848
// Height includes: Calendar grid (6 weeks * ~44px) + header (~48px) + footer actions (~64px) + padding
49-
DAY_PICKER_WITH_FOOTER: '447px',
49+
// moved to auto since we are exposing footer slot
50+
DAY_PICKER_WITH_FOOTER: 'auto',
5051
} as const;
5152

5253
const BaseDatePicker = <Type extends DateSelectionType = 'single'>({
@@ -84,6 +85,7 @@ const BaseDatePicker = <Type extends DateSelectionType = 'single'>({
8485
labelSuffix,
8586
labelTrailing,
8687
showFooterActions = true,
88+
footer,
8789
...props
8890
}: DatePickerProps<Type> &
8991
StyledPropsBlade &
@@ -383,6 +385,8 @@ const BaseDatePicker = <Type extends DateSelectionType = 'single'>({
383385
isButtonDisabled={applyButtonDisabled}
384386
onApply={handleApply}
385387
onCancel={handleCancel}
388+
footer={footer}
389+
selectionType={_selectionType}
386390
/>
387391
))}
388392
</BaseBox>
@@ -516,7 +520,12 @@ const BaseDatePicker = <Type extends DateSelectionType = 'single'>({
516520
</BottomSheetBody>
517521
{showFooterActions && (
518522
<BottomSheetFooter>
519-
<CalendarFooter onCancel={handleCancel} onApply={handleApply} />
523+
<CalendarFooter
524+
onCancel={handleCancel}
525+
onApply={handleApply}
526+
footer={footer}
527+
selectionType={_selectionType}
528+
/>
520529
</BottomSheetFooter>
521530
)}
522531
</BottomSheet>

packages/blade/src/components/DatePicker/CalendarFooter.web.tsx

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { DateSelectionType } from './types';
23
import BaseBox from '~components/Box/BaseBox';
34
import { Button } from '~components/Button';
45
import { Divider } from '~components/Divider';
@@ -9,43 +10,58 @@ type CalendarFooterProps = {
910
onApply: () => void;
1011
onCancel: () => void;
1112
isButtonDisabled?: boolean;
13+
footer?: React.ReactElement;
14+
selectionType?: DateSelectionType;
1215
};
1316
const CalendarFooter = ({
1417
onApply,
1518
onCancel,
1619
isButtonDisabled,
20+
footer,
21+
selectionType,
1722
}: CalendarFooterProps): React.ReactElement => {
1823
const isMobile = useIsMobile();
1924

25+
const isSingleSelectionOrMobile = isMobile || selectionType === 'single';
26+
const footerMaxWidth = React.useMemo(() => {
27+
if (isMobile) return '100%';
28+
return selectionType === 'single' ? '280px' : '390px';
29+
}, [isMobile, selectionType]);
30+
2031
return (
2132
<BaseBox display="flex" flexDirection="column" gap="spacing.5">
2233
{isMobile ? null : <Divider />}
34+
2335
<BaseBox
24-
width={{ base: '100%', m: 'auto' }}
25-
marginLeft="auto"
2636
display="flex"
27-
flexDirection="row"
28-
gap={isMobile ? 'spacing.5' : 'spacing.3'}
37+
flexDirection={isSingleSelectionOrMobile ? 'column' : 'row'}
38+
gap={isSingleSelectionOrMobile ? 'spacing.5' : 'spacing.6'}
39+
justifyContent="space-between"
2940
>
30-
<Button
31-
isFullWidth={isMobile}
32-
variant="tertiary"
33-
size="medium"
34-
onClick={onCancel}
35-
data-analytics-name={MAKE_ANALYTICS_CONSTANTS.DATE_PICKER.CANCEL_BUTTON}
36-
>
37-
Cancel
38-
</Button>
39-
<Button
40-
isDisabled={isButtonDisabled}
41-
isFullWidth={isMobile}
42-
variant="primary"
43-
size="medium"
44-
onClick={onApply}
45-
data-analytics-name={MAKE_ANALYTICS_CONSTANTS.DATE_PICKER.APPLY_BUTTON}
46-
>
47-
Apply
48-
</Button>
41+
{footer ? <BaseBox maxWidth={footerMaxWidth}>{footer}</BaseBox> : null}
42+
<BaseBox width={{ base: '100%', m: 'auto' }} marginLeft="auto">
43+
<BaseBox display="flex" flexDirection="row" gap={isMobile ? 'spacing.5' : 'spacing.3'}>
44+
<Button
45+
isFullWidth={isMobile}
46+
variant="tertiary"
47+
size="medium"
48+
onClick={onCancel}
49+
data-analytics-name={MAKE_ANALYTICS_CONSTANTS.DATE_PICKER.CANCEL_BUTTON}
50+
>
51+
Cancel
52+
</Button>
53+
<Button
54+
isDisabled={isButtonDisabled}
55+
isFullWidth={isMobile}
56+
variant="primary"
57+
size="medium"
58+
onClick={onApply}
59+
data-analytics-name={MAKE_ANALYTICS_CONSTANTS.DATE_PICKER.APPLY_BUTTON}
60+
>
61+
Apply
62+
</Button>
63+
</BaseBox>
64+
</BaseBox>
4965
</BaseBox>
5066
</BaseBox>
5167
);

packages/blade/src/components/DatePicker/DatePicker.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default {
6363
onPreviousMonth: baseProp,
6464
onPreviousYear: baseProp,
6565
locale: baseProp,
66+
footer: baseProp,
6667
accessibilityLabel: inputProp,
6768
errorText: inputProp,
6869
helpText: inputProp,
@@ -632,6 +633,24 @@ export const DatePickerWithLabelSuffixTrailing: StoryFn<typeof DatePickerCompone
632633
);
633634
};
634635

636+
export const DatePickerWithFooter = DatePickerTemplate.bind({});
637+
DatePickerWithFooter.storyName = 'DatePicker with Footer';
638+
DatePickerWithFooter.args = {
639+
label: 'Select a date',
640+
selectionType: 'range',
641+
footer: (
642+
<Box display="flex" flexDirection="column" gap="spacing.2">
643+
<Text size="small" color="surface.text.gray.normal">
644+
This section only displays records from the last 45 days. This section only displays records
645+
from the last 45 days.
646+
</Text>
647+
<Link size="small" href="#">
648+
Link to report tab
649+
</Link>
650+
</Box>
651+
),
652+
};
653+
635654
export const WithoutActionButtons = DatePickerTemplate.bind({});
636655
WithoutActionButtons.storyName = 'Without Action Buttons';
637656
WithoutActionButtons.args = {

packages/blade/src/components/DatePicker/_decisions/decisions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ type DatePickerProps = InputProps &
7272
* @default true
7373
*/
7474
showFooterActions?: boolean;
75+
/**
76+
* Custom React element to render in the footer above/side of action buttons
77+
* Can be used to add custom content like informational text, links, or other components
78+
*/
79+
footer?: React.ReactElement;
7580
};
7681
```
7782

packages/blade/src/components/DatePicker/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ type CalendarProps<SelectionType extends DateSelectionType> = Pick<
132132
* @default true
133133
*/
134134
showFooterActions?: boolean;
135+
/**
136+
* Custom React element to render in the footer above/side of action buttons
137+
* Can be used to add custom content like informational text, links, or other components
138+
*/
139+
footer?: React.ReactElement;
135140
};
136141

137142
type DatePickerProps<Type extends DateSelectionType> = Omit<

0 commit comments

Comments
 (0)