Skip to content

Commit

Permalink
feat: added dateFormat and placeholder props
Browse files Browse the repository at this point in the history
  • Loading branch information
tewarig committed Jan 14, 2025
1 parent 368807a commit 90f8c7f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
15 changes: 8 additions & 7 deletions packages/blade/src/components/DatePicker/DateInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ const _DatePickerInput = (
successText,
errorText,
helpText,
dateFormat,
placeholder,
...props
}: DatePickerInputProps,
ref: React.ForwardedRef<any>,
): React.ReactElement => {
const isMobile = useIsMobile();
const format = 'DD/MM/YYYY';
const isLarge = size === 'large';
const hasLabel = typeof label === 'string' ? Boolean(label) : Boolean(label?.start || label?.end);
const isLabelPositionLeft = labelPosition === 'left';
Expand All @@ -109,7 +110,7 @@ const _DatePickerInput = (
if (selectionType == 'single') {
const dateValue = getFormattedDate({
date,
format,
format: dateFormat,
labelSeparator: '-',
locale,
type: 'default',
Expand All @@ -127,7 +128,7 @@ const _DatePickerInput = (
id="start-date"
labelPosition={labelPosition}
label={label}
placeholder={format}
placeholder={placeholder || dateFormat}
popupId={referenceProps['aria-controls']}
isPopupExpanded={referenceProps['aria-expanded']}
size={size}
Expand Down Expand Up @@ -164,14 +165,14 @@ const _DatePickerInput = (
const startValue = getFormattedDate({
type: 'default',
date: date[0],
format,
format: dateFormat,
labelSeparator: '-',
locale,
});
const endValue = getFormattedDate({
type: 'default',
date: date[1],
format,
format: dateFormat,
labelSeparator: '-',
locale,
});
Expand All @@ -197,7 +198,7 @@ const _DatePickerInput = (
leadingIcon={CalendarIcon}
label={label?.start}
labelPosition={labelPosition}
placeholder={format}
placeholder={placeholder || dateFormat}
popupId={referenceProps['aria-controls']}
isPopupExpanded={referenceProps['aria-expanded']}
size={size}
Expand Down Expand Up @@ -235,7 +236,7 @@ const _DatePickerInput = (
/>
<DateInput
id="end-date"
placeholder={format}
placeholder={placeholder || dateFormat}
leadingIcon={CalendarIcon}
label={shouldRenderEndLabel()}
labelPosition={isLabelPositionLeft ? undefined : labelPosition}
Expand Down
4 changes: 4 additions & 0 deletions packages/blade/src/components/DatePicker/DatePicker.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const DatePicker = <Type extends DateSelectionType = 'single'>({
picker,
onPickerChange,
zIndex = componentZIndices.popover,
dateFormat = 'DD/MM/YYYY',
inputPlaceHolder,
...props
}: DatePickerProps<Type> & StyledPropsBlade & DataAnalyticsAttribute): React.ReactElement => {
const { i18nState } = useI18nContext();
Expand Down Expand Up @@ -304,6 +306,8 @@ const DatePicker = <Type extends DateSelectionType = 'single'>({
validationState={validationState}
autoFocus={autoFocus}
necessityIndicator={necessityIndicator}
dateFormat={dateFormat}
placeholder={inputPlaceHolder}
{...makeAnalyticsAttribute(props)}
/>
{isMobile ? (
Expand Down
13 changes: 12 additions & 1 deletion packages/blade/src/components/DatePicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ type DatePickerProps<Type extends DateSelectionType> = Omit<
*/
onApply?: Type extends 'single' ? (value: DateValue) => void : (value: DatesRangeValue) => void;
labelPosition?: BaseInputProps['labelPosition'];
/**
* Sets the date format to be displayed in the input field.
*/
dateFormat?: string;
/**
* Placeholder text for the datepicker input , when no date is selected. Default value is formatType.
*/
inputPlaceHolder?: string;
};

type DatePickerRangeInputProps = {
Expand Down Expand Up @@ -195,7 +203,10 @@ type DatePickerCommonInputProps = {
FormInputValidationProps;

type DatePickerInputProps = DatePickerCommonInputProps &
(DatePickerRangeInputProps | DatePickerSingleInputProps);
(DatePickerRangeInputProps | DatePickerSingleInputProps) & {
dateFormat: string;
placeholder?: string;
};

export type {
CalendarProps,
Expand Down

0 comments on commit 90f8c7f

Please sign in to comment.