-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
604 additions
and
142 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect, useMemo, useState } from "react"; | ||
import DatePicker from "react-datepicker"; | ||
import { createPortal } from "react-dom"; | ||
|
||
const datePortal = document.getElementById('date-portal'); | ||
|
||
export default function DateCell({ getValue, row: { original }, column: { id }, table }) { | ||
const initialValue = getValue() || ""; | ||
// We need to keep and update the state of the cell normally | ||
const initialDate = useMemo(() => new Date(initialValue), [initialValue]); | ||
const [value, setValue] = useState(initialDate); | ||
|
||
// When the input is blurred, we'll call our table meta's updateData function | ||
const onBlur = () => { | ||
if (value !== initialValue) { | ||
table.options.meta?.updateData({ id: original.id, [id]: value.toLocaleDateString("en-US") }); | ||
} | ||
}; | ||
|
||
// If the initialValue is changed external, sync it up with our state | ||
useEffect(() => { | ||
setValue(initialValue || ""); | ||
}, [initialValue]); | ||
|
||
return ( | ||
<DatePicker | ||
selected={value} | ||
onChange={(e) => setValue(e)} | ||
onBlur={onBlur} | ||
dateFormat="dd/MM/YYYY" | ||
popperContainer={({children}) => createPortal(children, datePortal)} | ||
/> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/frontend/src/samples/components/Cell/SimpleCellInput.jsx
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,29 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
|
||
export default function SimpleCellInput({ getValue, row: { original }, column: { id }, table }) { | ||
const initialValue = getValue() || ""; | ||
// We need to keep and update the state of the cell normally | ||
const [value, setValue] = useState(initialValue); | ||
|
||
// When the input is blurred, we'll call our table meta's updateData function | ||
const onBlur = () => { | ||
if (value !== initialValue) { | ||
table.options.meta?.updateData({ id: original.id, [id]: value }); | ||
} | ||
}; | ||
|
||
// If the initialValue is changed external, sync it up with our state | ||
useEffect(() => { | ||
setValue(initialValue || ""); | ||
}, [initialValue]); | ||
|
||
return ( | ||
<input | ||
className="border-0 w-full" | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
onBlur={onBlur} | ||
/> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
table .react-datepicker-popper, form .react-datepicker-popper { | ||
z-index: 999; | ||
} | ||
|
||
.react-datepicker__input-container { | ||
height: 100%; | ||
} | ||
|
||
.react-datepicker__input-container input { | ||
width: 100%; | ||
height: 100%; | ||
border: 0px; | ||
} |
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
Oops, something went wrong.