Skip to content

Commit

Permalink
feat(select): virtualization (#4203)
Browse files Browse the repository at this point in the history
* fix: should not export list item internal variables type

* feat: changeset

* feat: integrate virtualized listbox to select component, add more props

* feat: update docs for select component

* feat: update docs to include API for virtualization

* fix: update docs to follow the newest format

* fix: update test for disable virtualization, add test for virtualized version

* fix: fix typo

* fix: type error

* fix: code block type error

* chore: update docs to use raw jsx instead of template literal

* fix: fix code-demo for typecheck

* chore: rollback for files

* fix: types

* chore: remove caret version on tanstack virtual pkg

* fix: pnpm lock file

* fix: virtualization examples

* fix: number of items

---------

Co-authored-by: winches <329487092@qq.com>
Co-authored-by: Junior Garcia <jrgarciadev@gmail.com>
  • Loading branch information
3 people authored Dec 1, 2024
1 parent 44958bf commit 2d6e577
Show file tree
Hide file tree
Showing 27 changed files with 921 additions and 265 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {Autocomplete, AutocompleteItem} 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">
<Autocomplete
isVirtualized
className="max-w-xs"
defaultItems={items}
itemHeight={40}
label="Search from 1000 items"
maxListboxHeight={400}
placeholder="Search..."
>
{(item) => <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>}
</Autocomplete>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,4 @@
const App = `import {Autocomplete, AutocompleteItem} 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">
<Autocomplete
isVirtualized
label="Search from 1000 items"
className="max-w-xs"
defaultItems={items}
placeholder="Search..."
maxListboxHeight={400}
itemHeight={40}
>
{(item) => (
<AutocompleteItem key={item.value}>
{item.label}
</AutocompleteItem>
)}
</Autocomplete>
</div>
);
}`;
import App from "./virtualization-custom-item-height.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {Autocomplete, AutocompleteItem} 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">
<Autocomplete
isVirtualized
className="max-w-xs"
defaultItems={items}
label="Search from 1000 items"
maxListboxHeight={400}
placeholder="Search..."
>
{(item) => <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>}
</Autocomplete>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,4 @@
const App = `import {Autocomplete, AutocompleteItem} 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">
<Autocomplete
isVirtualized
label="Search from 1000 items"
className="max-w-xs"
defaultItems={items}
placeholder="Search..."
maxListboxHeight={400}
>
{(item) => (
<AutocompleteItem key={item.value}>
{item.label}
</AutocompleteItem>
)}
</Autocomplete>
</div>
);
}`;
import App from "./virtualization-max-listbox-height.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {Autocomplete, AutocompleteItem} 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(10000);

return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<Autocomplete
isVirtualized
className="max-w-xs"
defaultItems={items}
label="Search from 10000 items"
placeholder="Search..."
>
{(item) => <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>}
</Autocomplete>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
const App = `import {Autocomplete, AutocompleteItem} 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(10000);
return (
<div className="flex w-full flex-wrap md:flex-nowrap gap-4">
<Autocomplete
isVirtualized
label="Search from 10000 items"
className="max-w-xs"
defaultItems={items}
placeholder="Search..."
>
{(item) => (
<AutocompleteItem key={item.value}>
{item.label}
</AutocompleteItem>
)}
</Autocomplete>
</div>
);
}`;
import App from "./virtualization-ten-thousand.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
51 changes: 51 additions & 0 deletions apps/docs/content/components/autocomplete/virtualization.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {Autocomplete, AutocompleteItem} 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">
<Autocomplete
isVirtualized
className="max-w-xs"
defaultItems={items}
label="Search from 1000 items"
placeholder="Search..."
>
{(item) => <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>}
</Autocomplete>
</div>
);
}
Loading

0 comments on commit 2d6e577

Please sign in to comment.