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.

fix: responsive drawer modal

flooorianfloa921ef0f7cd9
diff --git a/apps/web/ui/analytics/tag-selector.tsx b/apps/web/ui/analytics/tag-selector.tsx
index ddc94dbc74..c5216efd90 100644
--- a/apps/web/ui/analytics/tag-selector.tsx
+++ b/apps/web/ui/analytics/tag-selector.tsx
@@ -13,6 +13,7 @@ export default function TagSelector() {
return tags && tags.length > 0 ? (
<InputSelect
+ adjustForMobile
items={tags.map(({ id, name, color }) => ({
id,
color,
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index db12a55503..0c15b8a612 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -164,7 +164,7 @@ export default function Toggle() {
>
<button
onClick={() => setOpenDatePopover(!openDatePopover)}
- className="flex items-center justify-between space-x-2 truncate rounded-md bg-white px-3 py-2.5 shadow transition-all hover:shadow-md md:w-48"
+ className="flex w-full items-center justify-between space-x-2 truncate rounded-md bg-white px-3 py-2.5 shadow transition-all hover:shadow-md md:w-48"
>
<IconMenu
text={selectedInterval.display}
diff --git a/packages/ui/src/input-select.tsx b/packages/ui/src/input-select.tsx
index bc568a4ba7..45faaa4877 100644
--- a/packages/ui/src/input-select.tsx
+++ b/packages/ui/src/input-select.tsx
@@ -12,6 +12,8 @@ import {
} from "react";
import { Badge } from "./badge";
import { cn } from "@dub/utils";
+import { useMediaQuery } from "./hooks";
+import { Drawer } from "vaul";
export interface InputSelectItemProps {
id: string;
@@ -27,6 +29,7 @@ export function InputSelect({
selectedItem,
setSelectedItem,
className,
+ adjustForMobile,
icon,
inputAttrs,
}: {
@@ -34,6 +37,7 @@ export function InputSelect({
selectedItem: InputSelectItemProps | null;
setSelectedItem: Dispatch<SetStateAction<InputSelectItemProps | null>>;
className?: string;
+ adjustForMobile?: boolean;
icon?: ReactNode;
inputAttrs?: InputHTMLAttributes<HTMLInputElement>;
}) {
@@ -63,6 +67,8 @@ export function InputSelect({
}
}, [selectedItem?.value]);
+ const { isMobile } = useMediaQuery();
+
const CommandInput = () => {
const isEmpty = useCommandState((state: any) => state.filtered.count === 0);
return (
@@ -87,12 +93,155 @@ export function InputSelect({
setOpenCommandList(true);
}
}}
- className="block w-full rounded-md border-none px-0 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-0 sm:text-sm"
+ className="block w-full rounded-md border-none px-0 text-sm text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-0"
/>
</>
);
};
+ // when adjustForMobile is true, render the input as a drawer
+ if (isMobile && adjustForMobile) {
+ return (
+ <Drawer.Root open={openCommandList} onOpenChange={setOpenCommandList}>
+ <Drawer.Trigger className="sm:hidden" asChild>
+ <Command ref={commandRef} className="relative flex-shrink-0" loop>
+ <div
+ className={cn(
+ "group relative rounded-md border border-gray-300 bg-white px-1 focus-within:border-gray-500 focus-within:ring-1 focus-within:ring-gray-500",
+ className,
+ )}
+ >
+ <div className="absolute inset-y-0 left-0 flex items-center justify-center pl-3 text-gray-400">
+ {selectedItem && selectedItem.image ? (
+ <img
+ src={selectedItem.image}
+ alt={selectedItem.value}
+ className="h-4 w-4 rounded-full"
+ />
+ ) : (
+ icon || <Search className="h-4 w-4 text-gray-400" />
+ )}
+ </div>
+ <div className="flex h-10 px-8">
+ <CommandInput />
+ {inputValue && selectedItem?.value !== "" ? (
+ <button
+ onClick={() => {
+ setSelectedItem(null);
+ setInputValue("");
+ }}
+ className="absolute inset-y-0 right-0 my-auto"
+ >
+ <X className="h-7 w-7 pr-3 text-gray-400" />
+ </button>
+ ) : (
+ <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400 transition-all" />
+ )}
+ </div>
+ </div>
+ </Command>
+ </Drawer.Trigger>
+ <Drawer.Overlay className="fixed inset-0 z-40 bg-gray-100 bg-opacity-10 backdrop-blur" />
+ <Drawer.Portal>
+ <Drawer.Content className="fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white">
+ <Command ref={commandRef} className="relative" loop>
+ <div
+ className={cn(
+ "group relative mb-2 rounded-t-md border border-gray-300 bg-white px-1 focus-within:border-gray-500 focus-within:ring-1 focus-within:ring-gray-500",
+ className,
+ )}
+ >
+ <div className="absolute inset-y-0 left-0 flex items-center justify-center pl-3 text-gray-400">
+ {selectedItem && selectedItem.image ? (
+ <img
+ src={selectedItem.image}
+ alt={selectedItem.value}
+ className="h-4 w-4 rounded-full"
+ />
+ ) : (
+ icon || <Search className="h-4 w-4 text-gray-400" />
+ )}
+ </div>
+ <div className="flex h-10 px-8">
+ <CommandInput />
+ {inputValue && selectedItem?.value !== "" ? (
+ <button
+ onClick={() => {
+ setSelectedItem(null);
+ setInputValue("");
+ }}
+ className="absolute inset-y-0 right-0 my-auto"
+ >
+ <X className="h-7 w-7 pr-3 text-gray-400" />
+ </button>
+ ) : (
+ <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 rotate-180 pl-3 text-gray-400 transition-all" />
+ )}
+ </div>
+ </div>
+ {openCommandList && (
+ <Command.List className="dub-scrollbar h-[calc(var(--cmdk-list-height)+17px)] max-h-[80vh] p-2">
+ <Command.Empty className="px-4 py-2 text-sm text-gray-600">
+ No results found for "{inputValue}"
+ </Command.Empty>
+ {items.map((item) => (
+ <Command.Item
+ key={item.id}
+ value={item.value}
+ disabled={item.disabled}
+ onSelect={() => {
+ setSelectedItem(item);
+ setInputValue(item.value);
+ setOpenCommandList(false);
+ }}
+ className="group flex cursor-pointer items-center justify-between rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 active:bg-gray-200 aria-disabled:cursor-not-allowed aria-disabled:opacity-75 aria-disabled:hover:bg-white aria-selected:bg-gray-100 aria-selected:text-gray-900"
+ >
+ <div className="flex items-center space-x-2">
+ {item.image && (
+ <img
+ src={item.image}
+ alt={item.value}
+ className="h-4 w-4 rounded-full"
+ />
+ )}
+ <p
+ className={cn(
+ "my-auto whitespace-nowrap rounded-md px-2 py-0.5 text-sm",
+ item.color === "red" && "bg-red-100 text-red-600",
+ item.color === "yellow" &&
+ "bg-yellow-100 text-yellow-600",
+ item.color === "green" &&
+ "bg-green-100 text-green-600",
+ item.color === "blue" &&
+ "bg-blue-100 text-blue-600",
+ item.color === "purple" &&
+ "bg-purple-100 text-purple-600",
+ item.color === "brown" &&
+ "bg-brown-100 text-brown-600",
+ )}
+ >
+ {item.value}
+ </p>
+ {item.label && (
+ <Badge className="text-xs" variant="neutral">
+ {item.label}
+ </Badge>
+ )}
+ </div>
+
+ <Check className="invisible h-5 w-5 text-gray-500 aria-selected:visible" />
+ </Command.Item>
+ ))}
+ </Command.List>
+ )}
+ </Command>
+ </Drawer.Content>
+ <Drawer.Overlay />
+ </Drawer.Portal>
+ </Drawer.Root>
+ );
+ }
+
return (
<Command ref={commandRef} className="relative" loop>
<div