-
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
1 parent
383399f
commit 45b741a
Showing
3 changed files
with
201 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { memo, useEffect } from "react"; | ||
|
||
type CheckboxState = "checked" | "unchecked" | "indeterminate"; | ||
export type { CheckboxState }; | ||
|
||
interface PaginatedHeaderCheckboxCompProps { | ||
state: CheckboxState; | ||
onClick: () => void; | ||
} | ||
|
||
const PaginatedHeaderCheckboxComp = memo( | ||
({ state, onClick }: PaginatedHeaderCheckboxCompProps) => { | ||
const checkboxRef = React.useRef<HTMLInputElement>(null); | ||
|
||
useEffect(() => { | ||
const cbRef = checkboxRef.current; | ||
if (cbRef) { | ||
if (state === "checked") { | ||
cbRef.checked = true; | ||
cbRef.indeterminate = false; | ||
} else if (state === "unchecked") { | ||
cbRef.checked = false; | ||
cbRef.indeterminate = false; | ||
} else if (state === "indeterminate") { | ||
cbRef.checked = false; | ||
cbRef.indeterminate = true; | ||
} | ||
} | ||
}, [state]); | ||
|
||
return ( | ||
<input | ||
style={{ | ||
width: "13px", | ||
height: "13px", | ||
border: "1px solid grey", | ||
cursor: "pointer", | ||
margin: 0, | ||
}} | ||
onDoubleClick={(e) => { | ||
e.stopPropagation(); | ||
}} | ||
ref={checkboxRef} | ||
type="checkbox" | ||
onChange={onClick} | ||
checked={state === "checked"} | ||
tabIndex={-1} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
PaginatedHeaderCheckboxComp.displayName = "PaginatedHeaderCheckboxComp"; | ||
|
||
interface PaginatedHeaderCheckboxProps { | ||
state: CheckboxState; | ||
onClick: () => void; | ||
} | ||
|
||
export const PaginatedHeaderCheckbox = memo( | ||
({ state, onClick }: PaginatedHeaderCheckboxProps) => { | ||
return <PaginatedHeaderCheckboxComp state={state} onClick={onClick} />; | ||
}, | ||
); | ||
|
||
PaginatedHeaderCheckbox.displayName = "PaginatedHeaderCheckbox"; |
Oops, something went wrong.