Skip to content
Closed
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
160 changes: 81 additions & 79 deletions packages/ui/src/dropdowns/custom-search-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ export function CustomSearchSelect(props: ICustomSearchSelectProps) {
const [query, setQuery] = useState("");

const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
const [popperElement, setPopperElement] = useState<HTMLElement | null>(null);
const [isOpen, setIsOpen] = useState(defaultOpen);
// refs
const dropdownRef = useRef<HTMLDivElement | null>(null);

const { styles, attributes } = usePopper(referenceElement, popperElement, {
placement: placement ?? "bottom-start",
strategy: "fixed",
});

const filteredOptions =
Expand All @@ -73,7 +74,7 @@ export function CustomSearchSelect(props: ICustomSearchSelectProps) {

const closeDropdown = () => {
setIsOpen(false);
onClose && onClose();
onClose?.();
};

const handleKeyDown = useDropdownKeyDown(openDropdown, closeDropdown, isOpen);
Expand Down Expand Up @@ -104,7 +105,7 @@ export function CustomSearchSelect(props: ICustomSearchSelectProps) {
ref={setReferenceElement}
type="button"
className={cn(
"flex w-full items-center justify-between gap-1 text-11",
"flex w-full items-center justify-between gap-1 text-11 outline-none",
{
"cursor-not-allowed text-secondary": disabled,
"cursor-pointer hover:bg-layer-transparent-hover": !disabled,
Expand All @@ -122,7 +123,7 @@ export function CustomSearchSelect(props: ICustomSearchSelectProps) {
ref={setReferenceElement}
type="button"
className={cn(
"flex w-full items-center justify-between gap-1 rounded-sm border-[0.5px] border-strong",
"flex w-full items-center justify-between gap-1 rounded-sm border-[0.5px] border-strong outline-none",
{
"px-3 py-2 text-13": input,
"px-2 py-1 text-11": !input,
Expand All @@ -142,85 +143,86 @@ export function CustomSearchSelect(props: ICustomSearchSelectProps) {
)}
{isOpen &&
createPortal(
<Combobox.Options as="ul" data-prevent-outside-click static>
<Combobox.Options
as="ul"
data-prevent-outside-click
static
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
className={cn(
"z-30 my-1 min-w-48 overflow-y-scroll rounded-md border-[0.5px] border-subtle-1 bg-surface-1 py-2.5 text-11 whitespace-nowrap outline-none",
optionsClassName
)}
>
<div className="mx-2 flex items-center gap-1.5 rounded-sm border border-subtle px-2">
<SearchOutline className="h-3.5 w-3.5 text-placeholder" />
<Combobox.Input
className="w-full bg-transparent py-1 text-11 text-secondary placeholder:text-placeholder focus:outline-none"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search"
displayValue={(assigned: any) => assigned?.name}
/>
</div>
<div
className={cn(
"z-30 my-1 min-w-48 overflow-y-scroll rounded-md border-[0.5px] border-subtle-1 bg-surface-1 py-2.5 text-11 whitespace-nowrap focus:outline-none",
optionsClassName
)}
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
className={cn("vertical-scrollbar mt-2 scrollbar-xs space-y-1 overflow-y-scroll px-2", {
"max-h-96": maxHeight === "2xl",
"max-h-80": maxHeight === "xl",
"max-h-60": maxHeight === "lg",
"max-h-48": maxHeight === "md",
"max-h-36": maxHeight === "rg",
"max-h-28": maxHeight === "sm",
})}
>
<div className="mx-2 flex items-center gap-1.5 rounded-sm border border-subtle px-2">
<SearchOutline className="h-3.5 w-3.5 text-placeholder" />
<Combobox.Input
className="w-full bg-transparent py-1 text-11 text-secondary placeholder:text-placeholder focus:outline-none"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search"
displayValue={(assigned: any) => assigned?.name}
/>
</div>
<div
className={cn("vertical-scrollbar mt-2 scrollbar-xs space-y-1 overflow-y-scroll px-2", {
"max-h-96": maxHeight === "2xl",
"max-h-80": maxHeight === "xl",
"max-h-60": maxHeight === "lg",
"max-h-48": maxHeight === "md",
"max-h-36": maxHeight === "rg",
"max-h-28": maxHeight === "sm",
})}
>
{filteredOptions ? (
filteredOptions.length > 0 ? (
filteredOptions.map((option) => (
<Combobox.Option
as="li"
key={option.value}
value={option.value}
className={({ active }) =>
cn(
"flex w-full cursor-pointer items-center justify-between gap-2 truncate rounded-sm px-1 py-1.5 select-none",
{
"bg-layer-transparent-hover": active,
"cursor-not-allowed text-placeholder opacity-60": option.disabled,
}
)
}
onClick={() => {
if (!multiple) closeDropdown();
}}
disabled={option.disabled}
>
{({ selected }) => (
<>
<span className="flex-grow truncate">{option.content}</span>
{selected && <TickOutline className="h-3.5 w-3.5 flex-shrink-0" />}
{option.tooltip && (
<>
{typeof option.tooltip === "string" ? (
<Tooltip tooltipContent={option.tooltip}>
<InfoOutline className="h-3.5 w-3.5 flex-shrink-0 cursor-pointer text-secondary" />
</Tooltip>
) : (
option.tooltip
)}
</>
)}
</>
)}
</Combobox.Option>
))
) : (
<p className="px-1.5 py-1 text-placeholder italic">{noResultsMessage}</p>
)
{filteredOptions ? (
filteredOptions.length > 0 ? (
filteredOptions.map((option) => (
<Combobox.Option
as="li"
key={option.value}
value={option.value}
className={({ active }) =>
cn(
"flex w-full cursor-pointer items-center justify-between gap-2 truncate rounded-sm px-1 py-1.5 select-none",
{
"bg-layer-transparent-hover": active,
"cursor-not-allowed text-placeholder opacity-60": option.disabled,
}
)
}
onClick={() => {
if (!multiple) closeDropdown();
}}
disabled={option.disabled}
>
{({ selected }) => (
<>
<span className="flex-grow truncate">{option.content}</span>
{selected && <TickOutline className="h-3.5 w-3.5 flex-shrink-0" />}
{option.tooltip && (
<>
{typeof option.tooltip === "string" ? (
<Tooltip tooltipContent={option.tooltip}>
<InfoOutline className="h-3.5 w-3.5 flex-shrink-0 cursor-pointer text-secondary" />
</Tooltip>
) : (
option.tooltip
)}
</>
)}
</>
)}
</Combobox.Option>
))
) : (
<p className="px-1.5 py-1 text-placeholder italic">Loading...</p>
)}
</div>
{footerOption}
<p className="px-1.5 py-1 text-placeholder italic">{noResultsMessage}</p>
)
) : (
<p className="px-1.5 py-1 text-placeholder italic">Loading...</p>
)}
</div>
{footerOption}
</Combobox.Options>,
document.body
)}
Expand Down
44 changes: 23 additions & 21 deletions packages/ui/src/dropdowns/custom-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ function CustomSelect(props: ICustomSelectProps) {
} = props;
// states
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
const [popperElement, setPopperElement] = useState<HTMLElement | null>(null);
const [isOpen, setIsOpen] = useState(false);
// refs
const dropdownRef = useRef<HTMLDivElement | null>(null);

const { styles, attributes } = usePopper(referenceElement, popperElement, {
placement: placement ?? "bottom-start",
strategy: "fixed",
});

const openDropdown = useCallback(() => {
Expand Down Expand Up @@ -86,7 +87,7 @@ function CustomSelect(props: ICustomSelectProps) {
<button
ref={setReferenceElement}
type="button"
className={`flex items-center justify-between gap-1 rounded text-11 ${
className={`flex items-center justify-between gap-1 rounded text-11 outline-none ${
disabled ? "cursor-not-allowed text-secondary" : "cursor-pointer hover:bg-layer-transparent-hover"
} ${customButtonClassName}`}
onClick={toggleDropdown}
Expand All @@ -100,7 +101,7 @@ function CustomSelect(props: ICustomSelectProps) {
ref={setReferenceElement}
type="button"
className={cn(
"flex w-full items-center justify-between gap-1 rounded border border-strong",
"flex w-full items-center justify-between gap-1 rounded border border-strong outline-none",
{
"px-3 py-2 text-13": input,
"px-2 py-1 text-11": !input,
Expand All @@ -119,26 +120,27 @@ function CustomSelect(props: ICustomSelectProps) {
</>
{isOpen &&
createPortal(
<Combobox.Options as="ul" data-prevent-outside-click>
<Combobox.Options
as="ul"
data-prevent-outside-click
static
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
className={cn(
"z-30 my-1 min-w-48 overflow-y-scroll rounded-md border-[0.5px] border-subtle-1 bg-surface-1 px-2 py-2.5 text-11 whitespace-nowrap outline-none",
optionsClassName
)}
>
<div
className={cn(
"z-30 my-1 min-w-48 overflow-y-scroll rounded-md border-[0.5px] border-subtle-1 bg-surface-1 px-2 py-2.5 text-11 whitespace-nowrap focus:outline-none",
optionsClassName
)}
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
className={cn("space-y-1 overflow-y-scroll", {
"max-h-60": maxHeight === "lg",
"max-h-48": maxHeight === "md",
"max-h-36": maxHeight === "rg",
"max-h-28": maxHeight === "sm",
})}
>
<div
className={cn("space-y-1 overflow-y-scroll", {
"max-h-60": maxHeight === "lg",
"max-h-48": maxHeight === "md",
"max-h-36": maxHeight === "rg",
"max-h-28": maxHeight === "sm",
})}
>
{children}
</div>
{children}
</div>
</Combobox.Options>,
document.body
Expand Down