Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/prebuilds/configuration-input/ComboboxItem.tsx
2501 views
1
/**
2
* Copyright (c) 2024 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { FC } from "react";
8
import { cn } from "@podkit/lib/cn";
9
import { ComboboxElement } from "./Combobox";
10
11
type Props = {
12
element: ComboboxElement;
13
isActive: boolean;
14
className?: string;
15
onSelected: (id: string) => void;
16
onFocused: (id: string) => void;
17
};
18
export const ComboboxItem: FC<Props> = ({ element, isActive, className, onSelected, onFocused }) => {
19
let selectionClasses = `bg-pk-surface-secondary/25 font-normal focus:text-accent-foreground cursor-default select-none`;
20
if (isActive) {
21
selectionClasses = `bg-pk-content-secondary/10 cursor-pointer focus:outline-none focus:ring-0`;
22
}
23
if (!element.isSelectable) {
24
selectionClasses = ``;
25
}
26
27
return (
28
<li
29
id={element.id}
30
className={cn("h-min rounded-lg flex items-center px-2 py-1.5", selectionClasses, className)}
31
onMouseDown={() => {
32
if (element.isSelectable) {
33
onSelected(element.id);
34
}
35
}}
36
onMouseOver={() => onFocused(element.id)}
37
onFocus={() => onFocused(element.id)}
38
>
39
{element.element}
40
</li>
41
);
42
};
43
44