-
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.
Merge branch 'infintescroll' into v2
- Loading branch information
Showing
13 changed files
with
2,385 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,89 @@ | ||
import React, { memo, useEffect } from "react"; | ||
|
||
const HeaderCheckboxComp = memo( | ||
({ | ||
value, | ||
onChange, | ||
}: { | ||
value: boolean | null; | ||
onChange: (value: boolean | null) => void; | ||
}) => { | ||
const checkboxRef = React.useRef(); | ||
|
||
useEffect(() => { | ||
const cbRef = checkboxRef.current as any; | ||
|
||
if (value === true) { | ||
cbRef.checked = true; | ||
cbRef.indeterminate = false; | ||
} else if (value === false) { | ||
cbRef.checked = false; | ||
cbRef.indeterminate = false; | ||
} else if (value === null) { | ||
cbRef.checked = false; | ||
cbRef.indeterminate = true; | ||
} | ||
}); | ||
|
||
return ( | ||
<input | ||
style={{ | ||
width: "13px", | ||
height: "13px", | ||
border: "1px solid grey", | ||
cursor: "pointer", | ||
margin: 0, | ||
}} | ||
onDoubleClick={(e) => { | ||
e.stopPropagation(); | ||
}} | ||
ref={checkboxRef as any} | ||
type="checkbox" | ||
onChange={onChange as any} | ||
tabIndex={-1} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
HeaderCheckboxComp.displayName = "HeaderCheckboxComp"; | ||
|
||
export const HeaderCheckbox = memo( | ||
({ | ||
selectedRowKeysLength, | ||
totalRows, | ||
allRowSelected, | ||
onHeaderCheckboxChange, | ||
allRowSelectedMode, | ||
}: { | ||
selectedRowKeysLength: number; | ||
totalRows: number; | ||
allRowSelected: boolean; | ||
onHeaderCheckboxChange: (value: boolean | null) => void; | ||
allRowSelectedMode: boolean; | ||
}) => { | ||
const noRowsSelected = selectedRowKeysLength === 0; | ||
const someRowsSelected = | ||
selectedRowKeysLength > 0 && totalRows !== selectedRowKeysLength; | ||
|
||
let value: boolean | null = false; | ||
|
||
if (allRowSelectedMode) { | ||
value = true; | ||
} else if (totalRows === selectedRowKeysLength && totalRows > 0) { | ||
value = true; | ||
} else if (allRowSelected) { | ||
value = true; | ||
} else if (noRowsSelected) { | ||
value = false; | ||
} else if (someRowsSelected) { | ||
value = null; | ||
} | ||
|
||
return ( | ||
<HeaderCheckboxComp value={value} onChange={onHeaderCheckboxChange} /> | ||
); | ||
}, | ||
); | ||
|
||
HeaderCheckbox.displayName = "HeaderCheckbox"; |
Oops, something went wrong.