Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update tags control

Tim Wilson16fd0fceab4b
diff --git a/apps/web/ui/links/short-link-input-new.tsx b/apps/web/ui/links/short-link-input-new.tsx
index fe4fba6982..828f1a3d8c 100644
--- a/apps/web/ui/links/short-link-input-new.tsx
+++ b/apps/web/ui/links/short-link-input-new.tsx
@@ -277,6 +277,7 @@ export const ShortLinkInputNew = forwardRef<
!key && "text-gray-600",
),
}}
+ optionClassName="sm:max-w-[225px]"
open={isOpen}
onOpenChange={setIsOpen}
/>
diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx
index 46a690daca..8a8d84a003 100644
--- a/apps/web/ui/modals/link-builder/index.tsx
+++ b/apps/web/ui/modals/link-builder/index.tsx
@@ -53,6 +53,7 @@ import { MoreDropdown } from "./more-dropdown";
import { OptionsList } from "./options-list";
import { usePasswordModal } from "./password-modal";
import { QRCodePreview } from "./qr-code-preview";
+import { TagSelect } from "./tag-select";
import { useTargetingModal } from "./targeting-modal";
import { useMetatags } from "./use-metatags";
import { useUTMModal } from "./utm-modal";
@@ -412,6 +413,8 @@ function LinkBuilderInner({
/>
)}
+ <TagSelect />
+
<div>
<div className="flex items-center gap-2">
<label
diff --git a/apps/web/ui/modals/link-builder/tag-select.tsx b/apps/web/ui/modals/link-builder/tag-select.tsx
index 0251b9ce4f..a0abd25b65 100644
--- a/apps/web/ui/modals/link-builder/tag-select.tsx
+++ b/apps/web/ui/modals/link-builder/tag-select.tsx
@@ -1,5 +1,13 @@
import useTags from "@/lib/swr/use-tags";
-import { Combobox, useKeyboardShortcut } from "@dub/ui";
+import TagBadge from "@/ui/links/tag-badge";
+import {
+ Combobox,
+ InfoTooltip,
+ SimpleTooltipContent,
+ useKeyboardShortcut,
+} from "@dub/ui";
+import { Tag } from "@dub/ui/src";
+import { cn } from "@dub/utils";
import { useContext, useMemo, useState } from "react";
import { useFormContext } from "react-hook-form";
import { toast } from "sonner";
@@ -64,36 +72,64 @@ export function TagSelect() {
useKeyboardShortcut("t", () => setIsOpen(true), { modal: true });
return (
- <Combobox
- multiple
- selected={selectedTags}
- setSelected={(tags) => {
- const selectedIds = tags.map(({ value }) => value);
- setValue(
- "tags",
- selectedIds.map((id) => availableTags?.find((t) => t.id === id)),
- { shouldDirty: true },
- );
- }}
- options={options}
- icon={<MultiTagsIcon 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",
- }}
- onCreate={(search) => createTag(search)}
- open={isOpen}
- onOpenChange={setIsOpen}
- >
- {selectedTags.length > 0
- ? selectedTags.length === 1
- ? selectedTags[0].label
- : `${selectedTags.length} Tags`
- : "Tags"}
- </Combobox>
+ <div>
+ <div className="mb-1 flex items-center gap-2">
+ <label
+ htmlFor="comments"
+ className="block text-sm font-medium text-gray-700"
+ >
+ Tags
+ </label>
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title={`Tags are used to organize your links in your ${process.env.NEXT_PUBLIC_APP_NAME} dashboard.`}
+ cta="Learn more."
+ href="https://dub.co/help/article/how-to-use-tags"
+ />
+ }
+ />
+ </div>
+ <Combobox
+ multiple
+ selected={selectedTags}
+ setSelected={(tags) => {
+ const selectedIds = tags.map(({ value }) => value);
+ setValue(
+ "tags",
+ selectedIds.map((id) => availableTags?.find((t) => t.id === id)),
+ { shouldDirty: true },
+ );
+ }}
+ options={options}
+ icon={<Tag className="mt-[5px] size-4 text-gray-500" />}
+ searchPlaceholder="Search or add tags..."
+ shortcutHint="T"
+ buttonProps={{
+ className: cn(
+ "h-auto py-1.5 px-2.5 w-full text-gray-700 border-gray-300 items-start",
+ selectedTags.length === 0 && "text-gray-400",
+ ),
+ }}
+ onCreate={(search) => createTag(search)}
+ open={isOpen}
+ onOpenChange={setIsOpen}
+ matchTriggerWidth
+ >
+ {selectedTags.length > 0 ? (
+ <div className="flex flex-wrap gap-2">
+ {selectedTags.slice(0, 10).map((tag) => (
+ <TagBadge
+ key={tag.value}
+ name={tag.label}
+ color={tag.meta.color}
+ />
+ ))}
+ </div>
+ ) : (
+ <span className="my-px block py-0.5">Select tags...</span>
+ )}
+ </Combobox>
+ </div>
);
}
diff --git a/apps/web/ui/modals/link-builder/targeting-modal.tsx b/apps/web/ui/modals/link-builder/targeting-modal.tsx
index 3a337a37d4..bc637f2680 100644
--- a/apps/web/ui/modals/link-builder/targeting-modal.tsx
+++ b/apps/web/ui/modals/link-builder/targeting-modal.tsx
@@ -181,6 +181,7 @@ function TargetingModal({
!key && "text-gray-600",
),
}}
+ optionClassName="sm:max-w-[200px]"
/>
</div>
<input
diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsx
index 9c444353ed..3acc06c549 100644
--- a/packages/ui/src/combobox/index.tsx
+++ b/packages/ui/src/combobox/index.tsx
@@ -1,4 +1,4 @@
-import { cn, truncate } from "@dub/utils";
+import { cn } from "@dub/utils";
import { Command, CommandEmpty, CommandInput, CommandItem } from "cmdk";
import { ChevronDown } from "lucide-react";
import {
@@ -54,6 +54,8 @@ export type ComboboxProps<
side?: PopoverProps["side"];
open?: boolean;
onOpenChange?: (open: boolean) => void;
+ optionClassName?: string;
+ matchTriggerWidth?: boolean;
}>;
function isMultipleSelection(
@@ -80,6 +82,8 @@ export function Combobox({
side,
open,
onOpenChange,
+ optionClassName,
+ matchTriggerWidth,
children,
}: ComboboxProps<boolean | undefined, any>) {
const isMultiple = isMultipleSelection(multiple, setSelected);
@@ -166,11 +170,13 @@ export function Combobox({
// Allows scrolling to work when the popover's in a modal
e.stopPropagation();
}}
+ popoverContentClassName={cn(
+ matchTriggerWidth && "sm:w-[var(--radix-popover-trigger-width)]",
+ )}
content={
<AnimatedSizeContainer
- width={!isMobile}
+ width={!isMobile && !matchTriggerWidth}
height
- className="rounded-[inherit]"
style={{ transform: "translateZ(0)" }} // Fixes overflow on some browsers
transition={{ ease: "easeInOut", duration: 0.1 }}
>
@@ -213,6 +219,7 @@ export function Combobox({
({ value }) => value === option.value,
)}
onSelect={() => handleSelect(option)}
+ className={optionClassName}
/>
))}
{search.length > 0 && onCreate && (
@@ -220,6 +227,7 @@ export function Combobox({
className={cn(
"flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm text-gray-700",
"data-[selected=true]:bg-gray-100",
+ optionClassName,
)}
onSelect={async () => {
setIsCreating(true);
@@ -236,7 +244,7 @@ export function Combobox({
) : (
<Plus className="size-4 shrink-0" />
)}
- <div className="grow">
+ <div className="grow truncate">
{createLabel?.(search) || `Create "${search}"`}
</div>
</CommandItem>
@@ -262,7 +270,7 @@ export function Combobox({
<Button
variant="secondary"
{...buttonProps}
- className={cn(buttonProps?.className, "flex items-center gap-2")}
+ className={cn(buttonProps?.className, "flex gap-2")}
textWrapperClassName={cn(
buttonProps?.textWrapperClassName,
"w-full flex items-center justify-start",
@@ -303,7 +311,7 @@ const Scroll = ({ children }: PropsWithChildren) => {
return (
<>
<div
- className="scrollbar-hide max-h-[min(50vh,190px)] w-screen overflow-y-scroll sm:w-auto"
+ className="scrollbar-hide max-h-[min(50vh,250px)] w-screen overflow-y-scroll sm:w-auto"
ref={ref}
onScroll={updateScrollProgress}
>
@@ -323,17 +331,20 @@ function Option({
onSelect,
multiple,
selected,
+ className,
}: {
option: ComboboxOption;
onSelect: () => void;
multiple: boolean;
selected: boolean;
+ className?: string;
}) {
return (
<Command.Item
className={cn(
"flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm",
"data-[selected=true]:bg-gray-100",
+ className,
)}
onSelect={onSelect}
value={option.label + option?.value}
@@ -347,7 +358,7 @@ function Option({
)}
</div>
)}
- <div className="flex grow items-center gap-1">
+ <div className="flex min-w-0 grow items-center gap-1">
{option.icon && (
<span className="shrink-0 text-gray-600">
{isReactNode(option.icon) ? (
@@ -357,7 +368,7 @@ function Option({
)}
</span>
)}
- {truncate(option.label, 48)}
+ <span className="grow truncate">{option.label}</span>
</div>
{!multiple && selected && (
<Check2 className="size-4 shrink-0 text-gray-600" />