-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: virtualization feature, docs for listbox
- Loading branch information
Showing
8 changed files
with
269 additions
and
1 deletion.
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
57 changes: 57 additions & 0 deletions
57
apps/docs/content/components/listbox/virtualization-ten-thousand.raw.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,57 @@ | ||
import {Listbox, ListboxItem} from "@nextui-org/react"; | ||
|
||
const generateItems = (n) => { | ||
const items = [ | ||
"Cat", | ||
"Dog", | ||
"Elephant", | ||
"Lion", | ||
"Tiger", | ||
"Giraffe", | ||
"Dolphin", | ||
"Penguin", | ||
"Zebra", | ||
"Shark", | ||
"Whale", | ||
"Otter", | ||
"Crocodile", | ||
]; | ||
|
||
const dataset = []; | ||
|
||
for (let i = 0; i < n; i++) { | ||
const item = items[i % items.length]; | ||
|
||
dataset.push({ | ||
label: `${item}${i}`, | ||
value: `${item.toLowerCase()}${i}`, | ||
description: "Sample description", | ||
}); | ||
} | ||
|
||
return dataset; | ||
}; | ||
|
||
export default function App() { | ||
const items = generateItems(1000); | ||
|
||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<Listbox | ||
isVirtualized | ||
label={"Select from 10000 items"} | ||
placeholder="Select..." | ||
virtualization={{ | ||
maxListboxHeight: 400, | ||
itemHeight: 40, | ||
}} | ||
> | ||
{items.map((item, index) => ( | ||
<ListboxItem key={index} value={item.value}> | ||
{item.label} | ||
</ListboxItem> | ||
))} | ||
</Listbox> | ||
</div> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
apps/docs/content/components/listbox/virtualization-ten-thousand.ts
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,9 @@ | ||
import App from "./virtualization-ten-thousand.raw.jsx?raw"; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
export default { | ||
...react, | ||
}; |
56 changes: 56 additions & 0 deletions
56
apps/docs/content/components/listbox/virtualization.raw.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,56 @@ | ||
import {Listbox, ListboxItem} from "@nextui-org/react"; | ||
const generateItems = (n) => { | ||
const items = [ | ||
"Cat", | ||
"Dog", | ||
"Elephant", | ||
"Lion", | ||
"Tiger", | ||
"Giraffe", | ||
"Dolphin", | ||
"Penguin", | ||
"Zebra", | ||
"Shark", | ||
"Whale", | ||
"Otter", | ||
"Crocodile", | ||
]; | ||
|
||
const dataset = []; | ||
|
||
for (let i = 0; i < n; i++) { | ||
const item = items[i % items.length]; | ||
|
||
dataset.push({ | ||
label: `${item}${i}`, | ||
value: `${item.toLowerCase()}${i}`, | ||
description: "Sample description", | ||
}); | ||
} | ||
|
||
return dataset; | ||
}; | ||
|
||
export default function App() { | ||
const items = generateItems(1000); | ||
|
||
return ( | ||
<div className="flex w-full flex-wrap md:flex-nowrap gap-4"> | ||
<Listbox | ||
isVirtualized | ||
label={"Select from 1000 items"} | ||
placeholder="Select..." | ||
virtualization={{ | ||
maxListboxHeight: 400, | ||
itemHeight: 40, | ||
}} | ||
> | ||
{items.map((item, index) => ( | ||
<ListboxItem key={index} value={item.value}> | ||
{item.label} | ||
</ListboxItem> | ||
))} | ||
</Listbox> | ||
</div> | ||
); | ||
} |
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,9 @@ | ||
import App from "./virtualization.raw.jsx?raw"; | ||
|
||
const react = { | ||
"/App.jsx": App, | ||
}; | ||
|
||
export default { | ||
...react, | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.