Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/code-components/Combobox/Combobox.register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export function registerCombobox(
leftIcon: { type: "slot" },
rightIcon: { type: "slot" },
footer: { type: "slot" },
optionLeftIcon: {
type: "slot",
},
inputWrapperClassName: {
type: "class",
selectors: [
Expand Down Expand Up @@ -96,6 +99,8 @@ export function registerCombobox(
type: "class",
},
optionsClassName: { type: "class" },
optionLeftIconClassName: { type: "class" },
optionContentClassName: { type: "class" },
optionClassName: {
type: "class",
selectors: [
Expand Down Expand Up @@ -175,5 +180,6 @@ export function registerCombobox(
onChangeProp: "onChange",
},
},
providesData: true,
});
}
50 changes: 35 additions & 15 deletions src/code-components/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Combobox as HeadlessCombobox, Transition } from "@headlessui/react";
import { useState, useRef, Fragment, ReactNode } from "react";

import { MemoDataProvider } from "../MemoDataProvider/MemoDataProvider";
import styles from "./Combobox.module.css";
import { HighlightQueryValue } from "./HighlightQueryValue";
import { groupOptions } from "./utils";
Expand All @@ -19,6 +20,7 @@ interface ComboboxProps {
rightIcon: ReactNode;
footer?: ReactNode;
options?: ComboboxOption[];
optionLeftIcon?: ReactNode;
disabled?: boolean;
"aria-label"?: string;
"aria-labelledby"?: string;
Expand All @@ -31,6 +33,8 @@ interface ComboboxProps {
emptyOptionClassName?: string;
optionsClassName?: string;
optionClassName?: string;
optionLeftIconClassName?: string;
optionContentClassName?: string;
groupClassName?: string;
labelClassName?: string;
searchValueClassName?: string;
Expand Down Expand Up @@ -62,6 +66,7 @@ export function Combobox({
rightIcon,
footer,
options,
optionLeftIcon,
disabled,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy,
Expand All @@ -75,6 +80,8 @@ export function Combobox({
emptyOptionClassName,
optionsClassName,
optionClassName,
optionLeftIconClassName,
optionContentClassName,
groupClassName,
labelClassName,
searchValueClassName,
Expand Down Expand Up @@ -211,27 +218,40 @@ export function Combobox({
data-disabled={option.disabled ? "true" : undefined}
className={optionClassName}
>
<p className={labelClassName}>
<HighlightQueryValue
text={option.label ?? String(option.value)}
query={query}
queryClassName={searchValueClassName}
/>
</p>
{option.description ? (
<p
data-highlight={
option.highlight ? "true" : undefined
}
className={descriptionClassName}
{optionLeftIcon ? (
<MemoDataProvider
name="option"
data={option}
deps={[option]}
>
<div className={optionLeftIconClassName}>
{optionLeftIcon}
</div>
</MemoDataProvider>
) : null}
<div className={optionContentClassName}>
<p className={labelClassName}>
<HighlightQueryValue
text={option.description}
text={option.label ?? String(option.value)}
query={query}
queryClassName={searchValueClassName}
/>
</p>
) : null}
{option.description ? (
<p
data-highlight={
option.highlight ? "true" : undefined
}
className={descriptionClassName}
>
<HighlightQueryValue
text={option.description}
query={query}
queryClassName={searchValueClassName}
/>
</p>
) : null}
</div>
</HeadlessCombobox.Option>
))}
</Fragment>
Expand Down
Loading