Skip to content

Commit 645102b

Browse files
committed
feat: add useVisibility hook and optimize toolbar UI performance
## New Features - Add useVisibility hook for intersection observer-based lazy loading - Supports configurable root margin (default: 300px) - Includes fallback for environments without IntersectionObserver - Provides ref and visible state for component integration ## UI Improvements - Optimize toolbar image thumbnail dimensions - Reduce thumbnail height from 32 to 24 units - Reduce thumbnail width from 40 to 32 units - Adjust minimum width from 40 to 32 units - Improve toolbar scrolling behavior - Add overflowY: hidden to prevent vertical scrolling - Add vertical padding (pt: 2.5, pb: 2) for better spacing - Remove hover scale transform effect for smoother interactions - Commented out transform: "scale(1.02)" on hover - Maintains box shadow hover effect for visual feedback ## Performance Enhancements - Smaller thumbnail sizes reduce memory usage and improve rendering - useVisibility hook enables lazy loading capabilities for better performance - Optimized scrolling container prevents unnecessary overflow ## Technical Details - useVisibility hook uses TypeScript generics for type safety - Includes proper cleanup and cancellation handling - Fallback detection for elements already in viewport - Compatible with custom root elements and configurable margins
1 parent 9b3f179 commit 645102b

File tree

9 files changed

+322
-253
lines changed

9 files changed

+322
-253
lines changed

examples/react-example/src/index.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,43 @@ function App() {
3636
requireSignedUrl: false,
3737
},
3838
},
39+
...Array.from({ length: 10000 }).map((_, i) => ({
40+
url: `https://ik.imagekit.io/v3sxk1svj/placeholder.jpg?updatedAt=${Date.now()}&v=${i}`,
41+
metadata: {
42+
requireSignedUrl: false,
43+
},
44+
})),
3945
],
4046
onAddImage: handleAddImage,
4147
onClose: () => setOpen(false),
42-
exportOptions: {
43-
label: "Export",
44-
icon: <Icon boxSize={"5"} as={PiDownload} />,
45-
onClick: (images) => {
46-
console.log(images)
48+
exportOptions: [
49+
{
50+
type: "button",
51+
label: "Export",
52+
icon: <Icon boxSize={"5"} as={PiDownload} />,
53+
isVisible: true,
54+
onClick: (images) => {
55+
console.log(images)
56+
},
4757
},
48-
},
58+
{
59+
type: "menu",
60+
label: "Export",
61+
icon: <Icon boxSize={"5"} as={PiDownload} />,
62+
isVisible: true,
63+
options: [
64+
{
65+
type: "button",
66+
label: "Export",
67+
icon: <Icon boxSize={"5"} as={PiDownload} />,
68+
isVisible: true,
69+
onClick: (images) => {
70+
console.log(images)
71+
},
72+
},
73+
],
74+
},
75+
],
4976
signer: async (request) => {
5077
console.log(request)
5178
await new Promise((resolve) => setTimeout(resolve, 10000))

packages/imagekit-editor-dev/src/ImageKitEditor.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ChakraProvider, theme as defaultTheme } from "@chakra-ui/react"
22
import type { Dict } from "@chakra-ui/utils"
3-
import { isEqual } from "lodash"
43
import merge from "lodash/merge"
54
import React, { forwardRef, useImperativeHandle } from "react"
65
import { EditorLayout, EditorWrapper } from "./components/editor"
6+
import type { HeaderProps } from "./components/header"
77
import {
88
type FileElement,
99
type RequiredMetadata,
@@ -23,21 +23,7 @@ interface EditorProps<Metadata extends RequiredMetadata = RequiredMetadata> {
2323
initialImages?: Array<string | FileElement<Metadata>>
2424
signer?: Signer<Metadata>
2525
onAddImage?: () => void
26-
exportOptions?:
27-
| {
28-
label: string
29-
icon?: React.ReactElement
30-
onClick: (images: string[]) => void
31-
}
32-
| {
33-
label: string
34-
icon?: React.ReactElement
35-
options: Array<{
36-
label: string
37-
isVisible: boolean | ((images: string[]) => boolean)
38-
onClick: (images: string[]) => void
39-
}>
40-
}
26+
exportOptions?: HeaderProps["exportOptions"]
4127

4228
onClose: (args: { dirty: boolean; destroy: () => void }) => void
4329
}

0 commit comments

Comments
 (0)