generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: start box selection when the area exceeds 1 (#6)
- Loading branch information
Showing
10 changed files
with
104 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { useState } from 'react'; | ||
import Selectable, { useSelectable } from 'react-selectable-box'; | ||
|
||
const list: string[] = []; | ||
for (let i = 0; i < 200; i++) { | ||
list.push(String(i)); | ||
} | ||
|
||
const Item = ({ value }: { value: string }) => { | ||
const { setNodeRef, isSelected, isAdding, isRemoving } = useSelectable({ | ||
value, | ||
}); | ||
|
||
return ( | ||
<div | ||
ref={setNodeRef} | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
width: 50, | ||
height: 50, | ||
border: isAdding ? '1px solid #1677ff' : undefined, | ||
background: isRemoving ? 'red' : isSelected ? '#1677ff' : '#ccc', | ||
}} | ||
> | ||
{value} | ||
</div> | ||
); | ||
}; | ||
|
||
export default () => { | ||
const [value, setValue] = useState<React.Key[]>([]); | ||
|
||
return ( | ||
<Selectable | ||
value={value} | ||
onStart={() => { | ||
setValue([]); | ||
}} | ||
onEnd={(newValue) => { | ||
setValue(newValue); | ||
}} | ||
> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
gap: 20, | ||
padding: 20, | ||
border: '1px solid #ccc', | ||
}} | ||
> | ||
{list.map((i) => ( | ||
<Item key={i} value={i} /> | ||
))} | ||
</div> | ||
</Selectable> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ title: click to select | |
group: | ||
title: examples | ||
order: 1 | ||
order: 4 | ||
order: 5 | ||
--- | ||
|
||
### click to select | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ title: reset at end | |
group: | ||
title: examples | ||
order: 1 | ||
order: 1 | ||
order: 2 | ||
--- | ||
|
||
### reset at end | ||
|
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,11 @@ | ||
--- | ||
title: reset at start | ||
group: | ||
title: examples | ||
order: 1 | ||
order: 1 | ||
--- | ||
|
||
### reset at start | ||
|
||
<code src="../examples/reset-at-start.tsx"></code> |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ title: virtual-list | |
group: | ||
title: examples | ||
order: 1 | ||
order: 5 | ||
order: 6 | ||
--- | ||
|
||
### virtual list | ||
|
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