Skip to content

Commit

Permalink
docs: add example to md
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Jan 18, 2024
1 parent accc559 commit 29d362b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,56 @@ pnpm i react-selectable-box

[docs](https://linxianxi.github.io/react-selectable-box/)

### Example

```typescript
import Selectable, { useSelectable } from 'react-selectable-box';

const list: number[] = [];
for (let i = 0; i < 200; i++) {
list.push(i);
}

const App = () => {
return (
<Selectable>
<div
style={{
display: 'flex',
flexWrap: 'wrap',
gap: 20,
padding: 20,
border: '1px solid #ccc',
}}
>
{list.map((i) => (
<Item key={i} value={i} />
))}
</div>
</Selectable>
);
};

const Item = ({ value }: { value: number }) => {
const { setNodeRef, isSelected, isAdding } = useSelectable({
value,
});

return (
<div
ref={setNodeRef}
style={{
width: 50,
height: 50,
borderRadius: 4,
border: isAdding ? '1px solid #1677ff' : undefined,
background: isSelected ? '#1677ff' : '#ccc',
}}
/>
);
};
```

## Changelog

[CHANGELOG](https://linxianxi.github.io/react-selectable-box/changelog)
Expand Down

0 comments on commit 29d362b

Please sign in to comment.