The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Use Combobox for targeting dropdown
Tim Wilson0b8dfa3749e3
diff --git a/apps/web/ui/modals/link-builder/tag-select.tsx b/apps/web/ui/modals/link-builder/tag-select.tsxindex e50b445dc7..26c0123fd8 100644--- a/apps/web/ui/modals/link-builder/tag-select.tsx+++ b/apps/web/ui/modals/link-builder/tag-select.tsx@@ -79,8 +79,10 @@ export function TagSelect() {}}options={options}icon={<TagIcon tags={selectedTags.map(({ meta }) => meta)} />}+ side="top"placeholder="Tags"searchPlaceholder="Search or add tags..."+ shortcutHint="T"buttonProps={{className:"h-9 px-2.5 w-fit font-medium text-gray-700 max-w-48 min-w-0",diff --git a/apps/web/ui/modals/link-builder/targeting-modal.tsx b/apps/web/ui/modals/link-builder/targeting-modal.tsxindex fd7091e2cd..cdc088f0a5 100644--- a/apps/web/ui/modals/link-builder/targeting-modal.tsx+++ b/apps/web/ui/modals/link-builder/targeting-modal.tsx@@ -1,6 +1,7 @@import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";import {Button,+ Combobox,Modal,SimpleTooltipContent,Tooltip,@@ -133,27 +134,46 @@ function TargetingModal({<div className="mb-2 grid grid-cols-[min-content_1fr] gap-y-2">{Object.entries(geo).map(([key, value]) => (<Fragment key={key}>- <select- id={`geo-selector-${key}`}- value={key}- onChange={(e) => {+ <Combobox+ selected={{ value: key, label: COUNTRIES[key] }}+ setSelected={(option) => {+ if (!option) return;const newGeo = {};delete Object.assign(newGeo, geo, {- [e.target.value]: value,+ [option.value]: value,})[key];setValue("geo", newGeo, { shouldDirty: true });}}- className="flex w-32 items-center justify-center rounded-l-md border border-r-0 border-gray-300 bg-white pl-3 pr-7 text-left text-sm text-gray-500 focus:border-gray-300 focus:outline-none focus:ring-0"- >- <option value="" disabled selected={!key}>- Country- </option>- {Object.entries(COUNTRIES).map(([key, value]) => (- <option key={key} value={key}>- {value}- </option>- ))}- </select>+ options={Object.entries(COUNTRIES).map(+ ([key, value]) => ({+ icon: (+ <img+ alt={value}+ src={`https://flag.vercel.app/m/${key}.svg`}+ className="mr-1 h-2.5 w-4"+ />+ ),+ value: key,+ label: value,+ }),+ )}+ icon={+ key ? (+ <img+ alt={COUNTRIES[key]}+ src={`https://flag.vercel.app/m/${key}.svg`}+ className="h-2.5 w-4"+ />+ ) : undefined+ }+ caret={true}+ placeholder="Country"+ searchPlaceholder="Search countries..."+ buttonProps={{+ className:+ "w-32 sm:w-40 rounded-r-none border-r-0 justify-start px-2.5",+ }}+ /><inputtype="text"id={`${id}-${key}`}diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsxindex 3375f214e7..349b1f2447 100644--- a/packages/ui/src/combobox/index.tsx+++ b/packages/ui/src/combobox/index.tsx@@ -1,5 +1,6 @@import { cn, truncate } from "@dub/utils";import { Command, CommandEmpty, CommandInput, CommandItem } from "cmdk";+import { ChevronDown } from "lucide-react";import {isValidElement,PropsWithChildren,@@ -13,13 +14,14 @@ import { AnimatedSizeContainer } from "../animated-size-container";import { Button, ButtonProps } from "../button";import { useMediaQuery, useScrollProgress } from "../hooks";import {+ Check2,CheckboxCheckedFill,CheckboxUnchecked,Icon,LoadingSpinner,Plus,} from "../icons";-import { Popover } from "../popover";+import { Popover, PopoverProps } from "../popover";export type ComboboxOption<TMeta = any> = {label: string;@@ -47,6 +49,9 @@ export type ComboboxProps<createLabel?: (search: string) => ReactNode;onCreate?: (search: string) => Promise<boolean>;buttonProps?: ButtonProps;+ shortcutHint?: string;+ caret?: boolean;+ side?: PopoverProps["side"];open?: boolean;onOpenChange?: (open: boolean) => void;}>;@@ -70,6 +75,9 @@ export function Combobox({createLabel,onCreate,buttonProps,+ shortcutHint,+ caret,+ side,open,onOpenChange,children,@@ -151,7 +159,7 @@ export function Combobox({openPopover={isOpen}setOpenPopover={setIsOpen}align="start"- side="top"+ side={side}onWheel={(e) => {// Allows scrolling to work when the popover's in a modale.stopPropagation();@@ -182,9 +190,11 @@ export function Combobox({}}}/>- <kbd className="mr-2 hidden shrink-0 rounded bg-gray-200 px-2 py-0.5 text-xs font-light text-gray-500 md:block">- T- </kbd>+ {shortcutHint && (+ <kbd className="mr-2 hidden shrink-0 rounded bg-gray-200 px-2 py-0.5 text-xs font-light text-gray-500 md:block">+ {shortcutHint}+ </kbd>+ )}</div><Scroll><Command.List@@ -251,10 +261,23 @@ export function Combobox({variant="secondary"{...buttonProps}className={cn(buttonProps?.className, "flex items-center gap-2")}+ textWrapperClassName={cn(+ buttonProps?.textWrapperClassName,+ "w-full flex items-center justify-start",+ )}text={- children ||- selected.map((option) => option.label).join(", ") ||- placeholder+ <>+ <div className="min-w-0 grow truncate text-left">+ {children ||+ selected.map((option) => option.label).join(", ") ||+ placeholder}+ </div>+ {caret && (+ <ChevronDown+ className={`size-4 shrink-0 text-gray-400 transition-transform duration-75 group-data-[state=open]:rotate-180`}+ />+ )}+ </>}icon={Icon ? (@@ -322,7 +345,7 @@ function Option({)}</div>)}- <div className="flex items-center gap-1">+ <div className="flex grow items-center gap-1">{option.icon && (<span className="shrink-0 text-gray-600">{isReactNode(option.icon) ? (@@ -334,6 +357,9 @@ function Option({)}{truncate(option.label, 48)}</div>+ {!multiple && selected && (+ <Check2 className="size-4 shrink-0 text-gray-600" />+ )}</Command.Item>);}