Skip to content

Commit 8d479ac

Browse files
[WEB-5822] fix: migrate ImagePickerPopover to Propel Tabs component and render only enabled tabs #8290
- Replace custom tab implementation with Propel Tabs - Dynamically render only enabled tabs based on configuration - Filter tabs by isEnabled property for cleaner conditional rendering - Improve tab navigation and accessibility with Propel components
1 parent 94d5779 commit 8d479ac

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

apps/web/core/components/core/image-picker-popover.tsx

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { useDropzone } from "react-dropzone";
55
import type { Control } from "react-hook-form";
66
import { Controller } from "react-hook-form";
77
import useSWR from "swr";
8-
import { Tab, Popover } from "@headlessui/react";
8+
import { Popover } from "@headlessui/react";
99
// plane imports
1010
import { ACCEPTED_COVER_IMAGE_MIME_TYPES_FOR_REACT_DROPZONE, MAX_FILE_SIZE } from "@plane/constants";
1111
import { useOutsideClickDetector } from "@plane/hooks";
12+
import { Tabs } from "@plane/propel/tabs";
1213
import { Button, getButtonStyling } from "@plane/propel/button";
1314
import { TOAST_TYPE, setToast } from "@plane/propel/toast";
1415
import { EFileAssetType } from "@plane/types";
@@ -80,6 +81,8 @@ export const ImagePickerPopover = observer(function ImagePickerPopover(props: Pr
8081
[hasUnsplashConfigured]
8182
);
8283

84+
const enabledTabs = useMemo(() => tabOptions.filter((tab) => tab.isEnabled), [tabOptions]);
85+
8386
const { data: unsplashImages, error: unsplashError } = useSWR(
8487
`UNSPLASH_IMAGES_${searchParams}`,
8588
() => fileService.getUnsplashImages(searchParams),
@@ -191,25 +194,19 @@ export const ImagePickerPopover = observer(function ImagePickerPopover(props: Pr
191194
>
192195
<div
193196
ref={imagePickerRef}
194-
className="flex h-96 w-80 flex-col overflow-auto rounded-sm border border-strong bg-surface-1 p-3 shadow-2xl md:h-[28rem] md:w-[36rem]"
197+
className="flex h-96 w-80 flex-col overflow-auto rounded border border-subtle bg-surface-1 shadow-raised-200 md:h-[36rem] md:w-[36rem]"
195198
>
196-
<Tab.Group>
197-
<Tab.List as="span" className="inline-block rounded-sm bg-layer-1 p-1">
198-
{tabOptions.map((tab) => (
199-
<Tab
200-
key={tab.key}
201-
className={({ selected }) =>
202-
`rounded-sm px-4 py-1 text-center text-13 outline-none transition-colors ${
203-
selected ? "bg-accent-primary text-on-color" : "text-primary"
204-
}`
205-
}
206-
>
199+
<Tabs defaultValue={enabledTabs[0]?.key || "images"} className="flex h-full flex-col p-3">
200+
<Tabs.List className="flex rounded bg-layer-3 p-1">
201+
{enabledTabs.map((tab) => (
202+
<Tabs.Trigger key={tab.key} value={tab.key} size="md">
207203
{tab.title}
208-
</Tab>
204+
</Tabs.Trigger>
209205
))}
210-
</Tab.List>
211-
<Tab.Panels className="vertical-scrollbar scrollbar-md h-full w-full flex-1 overflow-y-auto overflow-x-hidden">
212-
<Tab.Panel className="mt-4 h-full w-full space-y-4">
206+
<Tabs.Indicator />
207+
</Tabs.List>
208+
<div className="vertical-scrollbar scrollbar-sm p-3 mt-3 flex-1 overflow-y-auto overflow-x-hidden">
209+
<Tabs.Content value="unsplash" className="h-full w-full space-y-4">
213210
{(unsplashImages || !unsplashError) && (
214211
<>
215212
<div className="flex items-center gap-x-2">
@@ -276,8 +273,8 @@ export const ImagePickerPopover = observer(function ImagePickerPopover(props: Pr
276273
)}
277274
</>
278275
)}
279-
</Tab.Panel>
280-
<Tab.Panel className="mt-4 h-full w-full space-y-4">
276+
</Tabs.Content>
277+
<Tabs.Content value="images" className="h-full w-full space-y-4">
281278
<div className="grid grid-cols-4 gap-4">
282279
{Object.values(STATIC_COVER_IMAGES).map((imageUrl, index) => (
283280
<div
@@ -293,8 +290,8 @@ export const ImagePickerPopover = observer(function ImagePickerPopover(props: Pr
293290
</div>
294291
))}
295292
</div>
296-
</Tab.Panel>
297-
<Tab.Panel className="mt-4 h-full w-full">
293+
</Tabs.Content>
294+
<Tabs.Content value="upload" className="h-full w-full">
298295
<div className="flex h-full w-full flex-col gap-y-2">
299296
<div className="flex w-full flex-1 items-center gap-3">
300297
<div
@@ -357,13 +354,13 @@ export const ImagePickerPopover = observer(function ImagePickerPopover(props: Pr
357354
disabled={!image}
358355
loading={isImageUploading}
359356
>
360-
{isImageUploading ? "Uploading..." : "Upload & Save"}
357+
{isImageUploading ? "Uploading" : "Upload & Save"}
361358
</Button>
362359
</div>
363360
</div>
364-
</Tab.Panel>
365-
</Tab.Panels>
366-
</Tab.Group>
361+
</Tabs.Content>
362+
</div>
363+
</Tabs>
367364
</div>
368365
</Popover.Panel>
369366
)}

0 commit comments

Comments
 (0)