Skip to content

Commit c78c88a

Browse files
committed
add documentation for custom item component
1 parent 4a35e71 commit c78c88a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { useMemo } from 'react';
2+
import type { LinksFunction } from 'remix';
3+
import { Item } from '../combobox';
4+
import { DatalistInput, useComboboxControls } from '../combobox';
5+
6+
import comboboxStyles from '../combobox.css';
7+
8+
export const links: LinksFunction = () => {
9+
return [{ rel: 'stylesheet', href: comboboxStyles }];
10+
};
11+
12+
type CustomItem = Item & {
13+
description: string;
14+
};
15+
16+
const items: Array<CustomItem> = [
17+
{ id: 'Chocolate', value: 'Chocolate', description: 'Chocolate is delicious' },
18+
{ id: 'Coconut', value: 'Coconut', description: 'Coconut is tasty but watch your head!' },
19+
{ id: 'Mint', value: 'Mint', description: 'Mint is a herb?' },
20+
{ id: 'Strawberry', value: 'Strawberry', description: 'Strawberries are red' },
21+
{ id: 'Vanilla', value: 'Vanilla', description: 'Vanilla is a flavor' },
22+
];
23+
24+
const CustomItem = ({ item }: { item: CustomItem }) => {
25+
// already wrapped in <li></li>, so we don't have to do that here
26+
return (
27+
<div style={{ display: 'flex', gap: '5px', flexDirection: 'column' }}>
28+
<b>{item.value}</b>
29+
<span>{item.description}</span>
30+
</div>
31+
);
32+
};
33+
34+
export default function Index() {
35+
const customItems = useMemo(
36+
() =>
37+
items.map((item) => ({
38+
...item,
39+
node: <CustomItem item={item} />,
40+
})),
41+
[],
42+
);
43+
44+
return (
45+
<div
46+
style={{
47+
fontFamily: 'system-ui, sans-serif',
48+
lineHeight: '1.4',
49+
width: '100%',
50+
marginTop: '10vh',
51+
display: 'flex',
52+
justifyContent: 'center',
53+
}}
54+
>
55+
<div style={{ width: '500px' }}>
56+
<DatalistInput
57+
label={<div>Custom Label</div>}
58+
placeholder="Chocolate"
59+
items={customItems}
60+
onSelect={(i) => console.log(i)}
61+
/>
62+
</div>
63+
</div>
64+
);
65+
}

0 commit comments

Comments
 (0)