Skip to content

Commit

Permalink
add documentation for custom item component
Browse files Browse the repository at this point in the history
  • Loading branch information
andrelandgraf committed Jul 22, 2022
1 parent 4a35e71 commit c78c88a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/remix-demo/app/routes/custom-options.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useMemo } from 'react';
import type { LinksFunction } from 'remix';
import { Item } from '../combobox';
import { DatalistInput, useComboboxControls } from '../combobox';

import comboboxStyles from '../combobox.css';

export const links: LinksFunction = () => {
return [{ rel: 'stylesheet', href: comboboxStyles }];
};

type CustomItem = Item & {
description: string;
};

const items: Array<CustomItem> = [
{ id: 'Chocolate', value: 'Chocolate', description: 'Chocolate is delicious' },
{ id: 'Coconut', value: 'Coconut', description: 'Coconut is tasty but watch your head!' },
{ id: 'Mint', value: 'Mint', description: 'Mint is a herb?' },
{ id: 'Strawberry', value: 'Strawberry', description: 'Strawberries are red' },
{ id: 'Vanilla', value: 'Vanilla', description: 'Vanilla is a flavor' },
];

const CustomItem = ({ item }: { item: CustomItem }) => {
// already wrapped in <li></li>, so we don't have to do that here
return (
<div style={{ display: 'flex', gap: '5px', flexDirection: 'column' }}>
<b>{item.value}</b>
<span>{item.description}</span>
</div>
);
};

export default function Index() {
const customItems = useMemo(
() =>
items.map((item) => ({
...item,
node: <CustomItem item={item} />,
})),
[],
);

return (
<div
style={{
fontFamily: 'system-ui, sans-serif',
lineHeight: '1.4',
width: '100%',
marginTop: '10vh',
display: 'flex',
justifyContent: 'center',
}}
>
<div style={{ width: '500px' }}>
<DatalistInput
label={<div>Custom Label</div>}
placeholder="Chocolate"
items={customItems}
onSelect={(i) => console.log(i)}
/>
</div>
</div>
);
}

0 comments on commit c78c88a

Please sign in to comment.