Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/common/DatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface DatePickerProps extends Pick<DatePickerBaseProps, 'yearsLength'
defaultValue?: Date | null;
disabledDate?: Matcher;
className?: string;
withClear?: boolean;
leftIconElement?: ReactNode;
}

Expand All @@ -28,6 +29,7 @@ export const DatePicker: React.FC<DatePickerProps> = props => {
disabledDate,
defaultValue,
yearsLength,
withClear,
} = useCombinedPropsWithKit({
name: 'DatePicker',
props,
Expand All @@ -45,6 +47,11 @@ export const DatePicker: React.FC<DatePickerProps> = props => {
return format(value, 'd MMM yyyy');
}, [value]);

const clearDate = () => {
setValue(null);
onChange?.(null);
};

useUpdateEffect(() => {
onChange?.(value);
}, [value]);
Expand All @@ -55,8 +62,15 @@ export const DatePicker: React.FC<DatePickerProps> = props => {
{leftIconElement !== undefined && leftIconElement}
{leftIconElement === undefined && <Icon name="calendar" size={16} />}
{displayDate || placeholder}
<Icon name="down-arrow" size={18} />

{withClear && displayDate ? null : <Icon name="down-arrow" size={18} />}
</button>
{withClear && displayDate && (
<button type="button" onClick={clearDate}>
<Icon name="close" size={16} />
</button>
)}

{isOpen && (
<DatePickerPopup
callableElement={buttonRef.current}
Expand Down
3 changes: 3 additions & 0 deletions src/components/common/DatePicker/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.date-picker {
display: flex;
gap: 0.43rem;
align-items: center;
&__btn {
display: flex;
align-items: center;
Expand Down