-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
179 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
packages/twenty-front/src/modules/ui/field/input/components/DateInputStandalone.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import styled from '@emotion/styled'; | ||
import { Nullable } from 'twenty-ui'; | ||
|
||
import { dateInputStandaloneInternalValueFamilyState } from '@/ui/field/input/states/dateInputStandaloneInternalValueState'; | ||
import { | ||
InternalDatePicker, | ||
MONTH_AND_YEAR_DROPDOWN_ID, | ||
MONTH_AND_YEAR_DROPDOWN_MONTH_SELECT_ID, | ||
MONTH_AND_YEAR_DROPDOWN_YEAR_SELECT_ID, | ||
} from '@/ui/input/components/internal/date/components/InternalDatePicker'; | ||
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown'; | ||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside'; | ||
import { useRef } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
const StyledCalendarContainer = styled.div` | ||
background: ${({ theme }) => theme.background.transparent.secondary}; | ||
backdrop-filter: ${({ theme }) => theme.blur.medium}; | ||
border: 1px solid ${({ theme }) => theme.border.color.light}; | ||
border-radius: ${({ theme }) => theme.border.radius.md}; | ||
box-shadow: ${({ theme }) => theme.boxShadow.strong}; | ||
`; | ||
|
||
export type DateInputStandaloneProps = { | ||
inputId: string; | ||
defaultValue: Nullable<Date>; | ||
onEnter: (newDate: Nullable<Date>) => void; | ||
onEscape: (newDate: Nullable<Date>) => void; | ||
onClickOutside: ( | ||
event: MouseEvent | TouchEvent, | ||
newDate: Nullable<Date>, | ||
) => void; | ||
clearable?: boolean; | ||
onChange?: (newDate: Nullable<Date>) => void; | ||
isDateTimeInput?: boolean; | ||
onClear?: () => void; | ||
onSubmit?: (newDate: Nullable<Date>) => void; | ||
hideHeaderInput?: boolean; | ||
}; | ||
|
||
export const DateInputStandalone = ({ | ||
inputId, | ||
defaultValue, | ||
onEnter, | ||
onEscape, | ||
onClickOutside, | ||
clearable, | ||
onChange, | ||
isDateTimeInput, | ||
onClear, | ||
onSubmit, | ||
hideHeaderInput, | ||
}: DateInputStandaloneProps) => { | ||
const [internalValue, setInternalValue] = useRecoilState( | ||
dateInputStandaloneInternalValueFamilyState({ | ||
inputId, | ||
defaultDate: defaultValue, | ||
}), | ||
); | ||
|
||
const wrapperRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleChange = (newDate: Date | null) => { | ||
setInternalValue(newDate); | ||
onChange?.(newDate); | ||
}; | ||
|
||
const handleClear = () => { | ||
setInternalValue(null); | ||
onClear?.(); | ||
}; | ||
|
||
const handleMouseSelect = (newDate: Date | null) => { | ||
setInternalValue(newDate); | ||
onSubmit?.(newDate); | ||
}; | ||
|
||
const { closeDropdown } = useDropdown(MONTH_AND_YEAR_DROPDOWN_ID); | ||
const { closeDropdown: closeDropdownMonthSelect } = useDropdown( | ||
MONTH_AND_YEAR_DROPDOWN_MONTH_SELECT_ID, | ||
); | ||
const { closeDropdown: closeDropdownYearSelect } = useDropdown( | ||
MONTH_AND_YEAR_DROPDOWN_YEAR_SELECT_ID, | ||
); | ||
|
||
useListenClickOutside({ | ||
refs: [wrapperRef], | ||
listenerId: 'DateInput', | ||
callback: (event) => { | ||
event.stopImmediatePropagation(); | ||
|
||
closeDropdownYearSelect(); | ||
closeDropdownMonthSelect(); | ||
closeDropdown(); | ||
onClickOutside(event, internalValue); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div ref={wrapperRef}> | ||
<StyledCalendarContainer> | ||
<InternalDatePicker | ||
date={internalValue ?? new Date()} | ||
onChange={handleChange} | ||
onMouseSelect={handleMouseSelect} | ||
clearable={clearable ? clearable : false} | ||
isDateTimeInput={isDateTimeInput} | ||
onEnter={onEnter} | ||
onEscape={onEscape} | ||
onClear={handleClear} | ||
hideHeaderInput={hideHeaderInput} | ||
/> | ||
</StyledCalendarContainer> | ||
</div> | ||
); | ||
}; |
15 changes: 15 additions & 0 deletions
15
...s/twenty-front/src/modules/ui/field/input/states/dateInputStandaloneInternalValueState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { atomFamily } from 'recoil'; | ||
import { Nullable } from 'twenty-ui'; | ||
|
||
type DateInputStandaloneInternalValueFamilyStateKey = { | ||
inputId: string; | ||
defaultDate: Nullable<Date>; | ||
}; | ||
|
||
export const dateInputStandaloneInternalValueFamilyState = atomFamily< | ||
Nullable<Date>, | ||
DateInputStandaloneInternalValueFamilyStateKey | ||
>({ | ||
key: 'dateInputStandaloneInternalValueFamilyState', | ||
default: (param) => param.defaultDate, | ||
}); |