List Box
A listbox displays a list of options and allows a user to select one or more of them.
Matt
Sarah
James
Kim
Installation
Install via VScode or copy and paste the code below into a new file, preferably in a folder at components/base.
BaseLayer
Examples
Default
import { ListBox, ListBoxItem } from "@/components/base/listBox";
export const ListBoxExample = () => {
return (
<ListBox aria-label="Member" selectionMode="multiple">
<ListBoxItem>Matt</ListBoxItem>
<ListBoxItem>Sarah</ListBoxItem>
<ListBoxItem>James</ListBoxItem>
<ListBoxItem>Kim</ListBoxItem>
</ListBox>
);
};
bl-list-box
Reorderable
Adobe Photoshop
Adobe XD
Adobe Dreamweaver
Adobe InDesign
Adobe Connect
bl-list-box-reorderable
import { ListBox, ListBoxItem } from "@/components/base/listBox";
import { useDragAndDrop } from "react-aria-components";
import { useListData } from "react-stately";
export const ListBoxReorderable = () => {
let list = useListData({
initialItems: [
{ id: 1, name: "Adobe Photoshop" },
{ id: 2, name: "Adobe XD" },
{ id: 3, name: "Adobe Dreamweaver" },
{ id: 4, name: "Adobe InDesign" },
{ id: 5, name: "Adobe Connect" },
],
});
let { dragAndDropHooks } = useDragAndDrop({
getItems: (keys) =>
[...keys].map((key) => ({ "text/plain": list.getItem(key).name })),
onReorder(e) {
if (e.target.dropPosition === "before") {
list.moveBefore(e.target.key, e.keys);
} else if (e.target.dropPosition === "after") {
list.moveAfter(e.target.key, e.keys);
}
},
});
return (
<ListBox
aria-label="Reorderable list"
selectionMode="multiple"
items={list.items}
dragAndDropHooks={dragAndDropHooks}
>
{(item: any) => <ListBoxItem>{item.name}</ListBoxItem>}
</ListBox>
);
};