Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: streamline tag creation and layout
Marc Seitz3cfbe7b3342d
diff --git a/components/tags/add-tag-modal.tsx b/components/tags/add-tag-modal.tsxnew file mode 100644index 00000000..5ffd3dee--- /dev/null+++ b/components/tags/add-tag-modal.tsx@@ -0,0 +1,184 @@+import { ChangeEvent, FormEventHandler, useMemo, useRef } from "react";++import { PlanEnum } from "@/ee/stripe/constants";++import { usePlan } from "@/lib/swr/use-billing";+import { TagColorProps } from "@/lib/types";+import { cn } from "@/lib/utils";++import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";+import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/components/ui/dialog";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import { Textarea } from "@/components/ui/textarea";+import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";++import { COLORS_LIST } from "../links/link-sheet/tags/tag-badge";++export function AddTagsModal({+ open,+ setMenuOpen,+ children,+ tagForm,+ setTagForm,+ handleSubmit,+ tagCount = 0,+}: {+ tagCount: number | undefined;+ open: boolean;+ setMenuOpen: (open: boolean) => void;+ children?: React.ReactNode;+ tagForm: {+ color: TagColorProps;+ name: string;+ description: string | null;+ loading: boolean;+ id?: string;+ };+ setTagForm: React.Dispatch<+ React.SetStateAction<{+ color: TagColorProps;+ name: string;+ description: string | null;+ loading: boolean;+ }>+ >;+ handleSubmit: FormEventHandler<HTMLFormElement> | undefined;+}) {+ const { isFree } = usePlan();+ const initialValues = useRef(tagForm);++ useMemo(() => {+ if (tagForm.id && tagForm.id !== initialValues.current.id) {+ initialValues.current = tagForm;+ }+ }, [tagForm.id]);++ const hasChanged =+ tagForm.name !== initialValues.current.name ||+ tagForm.color !== initialValues.current.color ||+ tagForm.description !== initialValues.current.description;++ const isFormValid =+ tagForm.name.length >= 3 && !!tagForm.color && (!tagForm.id || hasChanged);++ // If the team is on a free plan and has reached the max limit of 5 tags+ if (isFree && tagCount >= 5) {+ if (children) {+ return (+ <UpgradePlanModal clickedPlan={PlanEnum.Pro} trigger={"create_tag"}>+ <Button>Upgrade to Create Tags</Button>+ </UpgradePlanModal>+ );+ }+ }++ function handleValueChange(+ e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,+ ): void {+ setTagForm((prev) => ({+ ...prev,+ [e.target.name]: e.target.value,+ }));+ }++ return (+ <Dialog open={open} onOpenChange={setMenuOpen}>+ <DialogTrigger asChild>{children}</DialogTrigger>+ <DialogContent className="sm:max-w-[425px]">+ <DialogHeader className="text-start">+ <DialogTitle>{tagForm.id ? "Create Tag" : "Edit Tag"}</DialogTitle>+ <DialogDescription>+ Organize your links with tags for easy categorization and search.+ </DialogDescription>+ </DialogHeader>+ <form onSubmit={handleSubmit}>+ <Label htmlFor="name" className="opacity-80">+ Tag name+ </Label>+ <Input+ name="name"+ id="name"+ value={tagForm.name}+ placeholder="documentation"+ className="mb-3 mt-1 w-full"+ onChange={(e) => handleValueChange(e)}+ />++ <Label htmlFor="color" className="opacity-80">+ Tag Color+ </Label>+ <ToggleGroup+ id="color"+ type="single"+ value={tagForm.color}+ onValueChange={(value: TagColorProps) => {+ if (value) {+ setTagForm((prev) => ({+ ...prev,+ color: value,+ }));+ }+ }}+ className="my-2 flex-shrink-0 flex-wrap !justify-start gap-3"+ >+ {COLORS_LIST.map((li) => (+ <ToggleGroupItem+ key={li.color}+ value={li.color}+ aria-label={`Select ${li.color}`}+ className={cn(+ "h-8 rounded-full border-0 px-3 text-sm transition-all",+ li.css,+ tagForm.color === li.color+ ? `ring-${li.color}-500 ring-2 text-${li.color}-500`+ : "border-transparent",+ )}+ >+ {li.color}+ </ToggleGroupItem>+ ))}+ </ToggleGroup>++ <div>+ <Label htmlFor="description" className="opacity-80">+ Description+ </Label>+ <Textarea+ value={tagForm.description || ""}+ onChange={(e) => handleValueChange(e)}+ rows={5}+ name="description"+ id="description"+ placeholder="Add a description to understand the purpose of this tag..."+ className="mt-1 flex-1 bg-muted"+ autoComplete="off"+ />+ </div>+ <DialogFooter>+ <Button+ type="submit"+ className="mt-3 h-9 w-full"+ disabled={!isFormValid || tagForm.loading}+ >+ {tagForm.loading+ ? "Saving..."+ : tagForm.id+ ? "Save Changes"+ : "Create Tag"}+ </Button>+ </DialogFooter>+ </form>+ </DialogContent>+ </Dialog>+ );+}diff --git a/components/ui/command.tsx b/components/ui/command.tsxindex 4d1faad0..a2a07a75 100644--- a/components/ui/command.tsx+++ b/components/ui/command.tsx@@ -2,12 +2,12 @@ import * as React from "react";import { type DialogProps } from "@radix-ui/react-dialog";import { Command as CommandPrimitive } from "cmdk";-import { Search } from "lucide-react";--import { Dialog, DialogContent } from "@/components/ui/dialog";+import { LucideIcon, Search } from "lucide-react";import { cn } from "@/lib/utils";+import { Dialog, DialogContent } from "@/components/ui/dialog";+const Command = React.forwardRef<React.ElementRef<typeof CommandPrimitive>,React.ComponentPropsWithoutRef<typeof CommandPrimitive>@@ -39,10 +39,16 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {const CommandInput = React.forwardRef<React.ElementRef<typeof CommandPrimitive.Input>,- React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>->(({ className, ...props }, ref) => (- <div className="flex items-center border-b px-3" cmdk-input-wrapper="">- <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {+ wrapperClassName?: string;+ noIcon?: boolean;+ }+>(({ className, wrapperClassName, noIcon, ...props }, ref) => (+ <div+ className={cn("flex items-center border-b px-3", wrapperClassName)}+ cmdk-input-wrapper=""+ >+ {!noIcon && <Search className="h-4 w-4 shrink-0 opacity-50" />}<CommandPrimitive.Inputref={ref}className={cn(@@ -118,7 +124,7 @@ const CommandItem = React.forwardRef<ref={ref}className={cn(// NOTE: removed these classNames because it broke the UI "data-[disabled]:pointer-events-none data-[disabled]:opacity-50"- "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground ",+ "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground",className,)}{...props}diff --git a/components/ui/multi-select-v2.tsx b/components/ui/multi-select-v2.tsxindex 3ee4a56b..2d42e2fc 100644--- a/components/ui/multi-select-v2.tsx+++ b/components/ui/multi-select-v2.tsx@@ -1,39 +1,28 @@import * as React from "react";import { type VariantProps, cva } from "class-variance-authority";-import {- CheckIcon,- ChevronDownIcon,- CircleHelpIcon,- PlusIcon,- WandSparkles,- XCircle,- XIcon,-} from "lucide-react";+import { CheckIcon, PlusIcon, TagIcon, WandSparkles } from "lucide-react";++import { TagColorProps } from "@/lib/types";+import { cn } from "@/lib/utils";-import { Badge } from "@/components/ui/badge";import { Button } from "@/components/ui/button";import {Command,- CommandEmpty,CommandGroup,CommandInput,CommandItem,CommandList,- CommandSeparator,} from "@/components/ui/command";import {Popover,PopoverContent,PopoverTrigger,} from "@/components/ui/popover";-import { Separator } from "@/components/ui/separator";--import { cn } from "@/lib/utils";+import TagBadge from "../links/link-sheet/tags/tag-badge";import { Icon } from "../shared/icons";import LoadingSpinner from "./loading-spinner";-import { BadgeTooltip } from "./tooltip";/*** Variants for the multi-select component to handle different styles.@@ -207,21 +196,21 @@ export const MultiSelect = React.forwardRef<setIsPopoverOpen((prev) => !prev);};- const clearExtraOptions = () => {- const newSelectedValues = value.slice(0, maxCount);- // setSelectedValues(newSelectedValues);- onValueChange(newSelectedValues);- };+ // const clearExtraOptions = () => {+ // const newSelectedValues = value.slice(0, maxCount);+ // // setSelectedValues(newSelectedValues);+ // onValueChange(newSelectedValues);+ // };- const toggleAll = () => {- if (value.length === options.length) {- handleClear();- } else {- const allValues = options.map((option) => option.value);- // setSelectedValues(allValues);- onValueChange(allValues);- }- };+ // const toggleAll = () => {+ // if (value.length === options.length) {+ // handleClear();+ // } else {+ // const allValues = options.map((option) => option.value);+ // // setSelectedValues(allValues);+ // onValueChange(allValues);+ // }+ // };// flex w-full rounded-none rounded-l-md border border-input bg-white text-foreground placeholder-muted-foreground focus:border-muted-foreground focus:outline-none focus:ring-inset focus:ring-muted-foreground dark:border-gray-500 dark:bg-gray-800 focus:dark:bg-transparent sm:text-smreturn (<Popover@@ -235,80 +224,43 @@ export const MultiSelect = React.forwardRef<{...props}onClick={handleTogglePopover}className={cn(- "flex h-auto w-full items-center justify-between rounded-md border border-input bg-inherit px-3 py-2 hover:bg-inherit focus:border-muted-foreground focus:outline-none focus:ring-1 focus:ring-inset focus:ring-muted-foreground dark:border-gray-500 dark:bg-gray-800 focus:dark:bg-transparent [&_svg]:pointer-events-auto",+ "flex h-auto w-full items-center justify-between rounded-md border border-input bg-inherit px-3 py-1.5 hover:bg-inherit focus:border-muted-foreground focus:outline-none focus:ring-1 focus:ring-inset focus:ring-muted-foreground dark:border-gray-500 dark:bg-gray-800 focus:dark:bg-transparent [&_svg]:pointer-events-auto",className,)}>+ <TagIcon className="!size-4 shrink-0 text-muted-foreground" />{loading ? (<div className="mx-auto flex w-full items-center justify-between"><LoadingSpinner className="size-4 shrink-0" /></div>) : value.length > 0 ? (<div className="flex w-full items-center justify-between">- <div className="flex flex-wrap items-center">+ <div className="flex flex-wrap items-center gap-2">{value.slice(0, maxCount).map((value) => {const option = options.find((o) => o.value === value);return (- <Badge+ <TagBadgekey={value}- className={cn(- isAnimating ? "animate-bounce" : "",- multiSelectVariants({ variant }),- )}- style={{ animationDuration: `${animation}s` }}- >- {option?.label}- <XCircle- className="ml-2 h-4 w-4 cursor-pointer"- onClick={(event) => {- event.stopPropagation();- toggleOption(value);- }}- />- </Badge>+ name={option?.label as string}+ color={option?.meta?.color as TagColorProps}+ />);})}{value.length > maxCount && (- <Badge- className={cn(- "border-foreground/1 bg-transparent text-foreground hover:bg-transparent",- isAnimating ? "animate-bounce" : "",- multiSelectVariants({ variant }),- )}+ <span+ className="my-auto block whitespace-nowrap rounded-md border px-2 py-0.5 text-sm text-foreground"style={{ animationDuration: `${animation}s` }}>{`+ ${value.length - maxCount} more`}- <XCircle- className="ml-2 h-4 w-4 cursor-pointer"- onClick={(event) => {- event.stopPropagation();- clearExtraOptions();- }}- />- </Badge>+ </span>)}</div>- <div className="flex items-center justify-between">- <XIcon- className="mx-2 h-4 cursor-pointer text-muted-foreground"- onClick={(event) => {- event.stopPropagation();- handleClear();- }}- />- <Separator- orientation="vertical"- className="flex h-full min-h-6"- />- <ChevronDownIcon className="ml-2 h-4 w-4 cursor-pointer text-muted-foreground opacity-50" />- </div></div>) : (<div className="mx-auto flex w-full items-center justify-between">- <span className="text-sm font-normal text-muted-foreground">+ <span className="py-[3px] text-sm font-normal text-muted-foreground">{placeholder}</span>- <ChevronDownIcon className="h-4 w-4 cursor-pointer text-muted-foreground opacity-50" /></div>)}</Button>@@ -323,33 +275,15 @@ export const MultiSelect = React.forwardRef<placeholder={searchPlaceholder}value={search}onValueChange={setSearch}+ noIcon+ wrapperClassName="px-0"className={cn(- "grow border-0 py-3 pl-4 pr-2 outline-none placeholder:text-neutral-400 focus:ring-0 sm:text-sm",+ "grow border-0 py-3 outline-none placeholder:text-neutral-400 focus:ring-0 sm:text-sm",inputClassName,)}onKeyDown={handleInputKeyDown}/><CommandList>- <CommandGroup>- <CommandItem- key="all"- onSelect={toggleAll}- className="cursor-pointer"- >- <div- className={cn(- "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",- value.length === options?.length- ? "bg-primary text-primary-foreground"- : "opacity-50 [&_svg]:invisible",- )}- >- <CheckIcon className="h-4 w-4" />- </div>- <span>(Select All)</span>- </CommandItem>- </CommandGroup>- <CommandSeparator /><CommandGroup>{loading ? (<CommandItem className="justify-center">@@ -363,7 +297,7 @@ export const MultiSelect = React.forwardRef<<CommandItemkey={option.value}onSelect={() => toggleOption(option.value)}- className="cursor-pointer gap-2"+ className="cursor-pointer gap-2 py-2"data-Value={option.value}><div@@ -382,11 +316,6 @@ export const MultiSelect = React.forwardRef<<IconComponent className="h-5 w-4" />) : null}<span>{option.label}</span>- {option.meta?.description && (- <BadgeTooltip content={option.meta?.description}>- <CircleHelpIcon className="h-4 w-4 shrink-0 text-muted-foreground hover:text-foreground" />- </BadgeTooltip>- )}</CommandItem>);})@@ -397,61 +326,33 @@ export const MultiSelect = React.forwardRef<)}</CommandGroup>{search.length > 0 && onCreate && (- <>- <CommandSeparator />- <CommandGroup>- <CommandItem- className={cn(- "flex cursor-pointer items-center gap-2 whitespace-nowrap",- optionClassName,- )}- onSelect={async () => {- setIsCreating(true);- const success = await onCreate?.(search);- if (success) {- setSearch("");- setIsPopoverOpen(false);- }- setIsCreating(false);- }}- >- {isCreating ? (- <LoadingSpinner className="size-4 shrink-0" />- ) : (- <PlusIcon className="size-4 shrink-0" />- )}- <p className="grow truncate">- {createLabel?.(search) || `Create "${search}"`}- </p>- </CommandItem>- </CommandGroup>- </>- )}- <CommandSeparator />- <CommandGroup>- <div className="flex items-center justify-between">- {value.length > 0 && (- <>- <CommandItem- onSelect={handleClear}- className="flex-1 cursor-pointer justify-center"- >- Clear- </CommandItem>- <Separator- orientation="vertical"- className="flex h-full min-h-6"- />- </>- )}+ <CommandGroup><CommandItem- onSelect={() => setIsPopoverOpen(false)}- className="max-w-full flex-1 cursor-pointer justify-center"+ className={cn(+ "flex cursor-pointer items-center gap-2 whitespace-nowrap",+ optionClassName,+ )}+ onSelect={async () => {+ setIsCreating(true);+ const success = await onCreate?.(search);+ if (success) {+ setSearch("");+ setIsPopoverOpen(false);+ }+ setIsCreating(false);+ }}>- Close+ {isCreating ? (+ <LoadingSpinner className="size-4 shrink-0" />+ ) : (+ <PlusIcon className="size-4 shrink-0" />+ )}+ <p className="grow truncate">+ {createLabel?.(search) || `Create "${search}"`}+ </p></CommandItem>- </div>- </CommandGroup>+ </CommandGroup>+ )}</CommandList></Command></PopoverContent>