List components #31
@ -1,4 +1,6 @@
|
||||
import ListItem from '../ListItem/ListItem';
|
||||
import type { HTMLAttributes } from "react";
|
||||
import clsx from "clsx";
|
||||
import ListItem from "../ListItem/ListItem";
|
||||
|
||||
export interface SearchResultOption {
|
||||
value: string;
|
||||
|
ansv7779 marked this conversation as resolved
|
||||
@ -6,7 +8,8 @@ export interface SearchResultOption {
|
||||
subtitle?: string;
|
||||
}
|
||||
|
||||
export interface SearchResultListProps {
|
||||
export interface SearchResultListProps
|
||||
extends Omit<HTMLAttributes<HTMLDivElement>, "onSelect"> {
|
||||
options: SearchResultOption[];
|
||||
selectedValues?: string[];
|
||||
focusedIndex?: number;
|
||||
@ -16,26 +19,39 @@ export interface SearchResultListProps {
|
||||
itemRefs?: React.RefObject<(HTMLDivElement | null)[]>;
|
||||
}
|
||||
|
||||
const containerClasses = [
|
||||
'w-full bg-base-canvas border border-base-ink-medium rounded-(--border-radius-md)',
|
||||
'overflow-y-auto',
|
||||
].join(' ');
|
||||
const baseClasses = clsx(
|
||||
"w-full bg-base-canvas",
|
||||
"border border-base-ink-medium rounded-(--border-radius-md)",
|
||||
"overflow-y-auto",
|
||||
);
|
||||
|
||||
const noResultsClasses = 'px-(--padding-md) py-(--padding-md) body-normal-md text-base-ink-placeholder text-center';
|
||||
const noResultsClasses =
|
||||
"px-(--padding-md) py-(--padding-md) body-normal-md text-base-ink-placeholder text-center";
|
||||
|
||||
const dividerClasses =
|
||||
"border-t border-base-ink-soft [border-top-width:var(--border-width-sm)]";
|
||||
|
||||
export default function SearchResultList({
|
||||
options,
|
||||
selectedValues = [],
|
||||
focusedIndex = -1,
|
||||
maxHeight = 300,
|
||||
noResultsText = 'No results found',
|
||||
noResultsText = "No results found",
|
||||
onSelect,
|
||||
itemRefs,
|
||||
className,
|
||||
style,
|
||||
...props
|
||||
}: SearchResultListProps) {
|
||||
const isSelected = (value: string) => selectedValues.includes(value);
|
||||
|
||||
return (
|
||||
<div className={containerClasses} style={{ maxHeight }} onMouseDown={(e) => e.preventDefault()}>
|
||||
<div
|
||||
className={clsx(baseClasses, className)}
|
||||
style={{ maxHeight, ...style }}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
{...props}
|
||||
>
|
||||
{options.length > 0 ? (
|
||||
options.map((option, index) => (
|
||||
<div
|
||||
@ -45,9 +61,7 @@ export default function SearchResultList({
|
||||
itemRefs.current[index] = el;
|
||||
}
|
||||
}}
|
||||
className={
|
||||
index > 0 ? 'border-t border-base-ink-soft [border-top-width:var(--border-width-sm)]' : ''
|
||||
}
|
||||
className={index > 0 ? dividerClasses : undefined}
|
||||
>
|
||||
<ListItem
|
||||
title={option.label}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user
This is limiting. Often times you want to select some more complex object as you do in your examples in
ComponentLibrary. Forcing all users of the component to do their own lookup when it should be handled by theCombobox/this component.