@designbasekorea/figma-ui 0.1.49 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +40 -67
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +40 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -111,31 +111,23 @@ const FigmaSection = ({ title, dataCategory, iconButton, children, marginBottom,
|
|
|
111
111
|
.filter(Boolean)
|
|
112
112
|
.join(' ');
|
|
113
113
|
React.useEffect(() => {
|
|
114
|
-
if (!enableScrollNavigation || !onActiveSectionChange)
|
|
114
|
+
if (!enableScrollNavigation || !onActiveSectionChange || !sectionRef.current)
|
|
115
115
|
return;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const scrollPosition = window.scrollY + headerHeight;
|
|
125
|
-
const sectionTop = sectionRef.current.getBoundingClientRect().top + window.scrollY - headerHeight;
|
|
126
|
-
const sectionBottom = sectionRef.current.getBoundingClientRect().bottom + window.scrollY - headerHeight;
|
|
127
|
-
if (scrollPosition >= sectionTop && scrollPosition < sectionBottom) {
|
|
116
|
+
const observerOptions = {
|
|
117
|
+
root: null,
|
|
118
|
+
rootMargin: `-${headerHeight}px 0px -50% 0px`,
|
|
119
|
+
threshold: 0
|
|
120
|
+
};
|
|
121
|
+
const observer = new IntersectionObserver((entries) => {
|
|
122
|
+
entries.forEach((entry) => {
|
|
123
|
+
if (entry.isIntersecting) {
|
|
128
124
|
onActiveSectionChange(dataCategory);
|
|
129
125
|
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
handleScroll();
|
|
126
|
+
});
|
|
127
|
+
}, observerOptions);
|
|
128
|
+
observer.observe(sectionRef.current);
|
|
134
129
|
return () => {
|
|
135
|
-
|
|
136
|
-
if (scrollTimeout) {
|
|
137
|
-
clearTimeout(scrollTimeout);
|
|
138
|
-
}
|
|
130
|
+
observer.disconnect();
|
|
139
131
|
};
|
|
140
132
|
}, [enableScrollNavigation, dataCategory, headerHeight, onActiveSectionChange]);
|
|
141
133
|
return (React.createElement("section", { ref: sectionRef, className: classes, ...(dataCategory ? { 'data-category': dataCategory } : {}), style: sectionStyle },
|
|
@@ -227,56 +219,37 @@ const FigmaSidebar = ({ categories, categoryGroups = {}, categoryLabels = {}, ac
|
|
|
227
219
|
}
|
|
228
220
|
}, [currentActiveCategory, scrollPadding]);
|
|
229
221
|
React.useEffect(() => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (!category)
|
|
248
|
-
continue;
|
|
249
|
-
const sectionRect = section.getBoundingClientRect();
|
|
250
|
-
const sectionTop = sectionRect.top - containerRect.top + containerElement.scrollTop - headerHeight;
|
|
251
|
-
const sectionBottom = sectionTop + section.clientHeight;
|
|
252
|
-
if (scrollPosition >= sectionTop && scrollPosition < sectionBottom) {
|
|
253
|
-
activeSection = category;
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
222
|
+
const sections = document.querySelectorAll('section[data-category]');
|
|
223
|
+
if (sections.length === 0)
|
|
224
|
+
return;
|
|
225
|
+
const observerOptions = {
|
|
226
|
+
root: scrollContainerId ? document.getElementById(scrollContainerId) : null,
|
|
227
|
+
rootMargin: `-${headerHeight}px 0px -50% 0px`,
|
|
228
|
+
threshold: 0
|
|
229
|
+
};
|
|
230
|
+
const observer = new IntersectionObserver((entries) => {
|
|
231
|
+
let maxRatio = 0;
|
|
232
|
+
let activeSection = null;
|
|
233
|
+
entries.forEach((entry) => {
|
|
234
|
+
if (entry.isIntersecting && entry.intersectionRatio > maxRatio) {
|
|
235
|
+
maxRatio = entry.intersectionRatio;
|
|
236
|
+
const category = entry.target.getAttribute('data-category');
|
|
237
|
+
if (category) {
|
|
238
|
+
activeSection = category;
|
|
256
239
|
}
|
|
257
240
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (activeSection && activeSection !== currentActiveCategory) {
|
|
262
|
-
setInternalActiveCategory(activeSection);
|
|
263
|
-
onCategoryClick?.(activeSection);
|
|
264
|
-
}
|
|
265
|
-
}, 50);
|
|
266
|
-
};
|
|
267
|
-
if (scrollContainer) {
|
|
268
|
-
scrollContainer.addEventListener('scroll', handleScroll);
|
|
269
|
-
handleScroll();
|
|
270
|
-
}
|
|
271
|
-
return () => {
|
|
272
|
-
if (scrollContainer) {
|
|
273
|
-
scrollContainer.removeEventListener('scroll', handleScroll);
|
|
274
|
-
}
|
|
275
|
-
if (scrollTimeout) {
|
|
276
|
-
clearTimeout(scrollTimeout);
|
|
241
|
+
});
|
|
242
|
+
if (activeSection && activeSection !== currentActiveCategory) {
|
|
243
|
+
setInternalActiveCategory(activeSection);
|
|
277
244
|
}
|
|
245
|
+
}, observerOptions);
|
|
246
|
+
sections.forEach((section) => {
|
|
247
|
+
observer.observe(section);
|
|
248
|
+
});
|
|
249
|
+
return () => {
|
|
250
|
+
observer.disconnect();
|
|
278
251
|
};
|
|
279
|
-
}, [currentActiveCategory, headerHeight,
|
|
252
|
+
}, [currentActiveCategory, headerHeight, scrollContainerId]);
|
|
280
253
|
const classes = [
|
|
281
254
|
'designbase-figma-sidebar',
|
|
282
255
|
className,
|