Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: collapsible list dyanmic collapse button (#1544)

gbirman3256fddd7041
diff --git a/js/app/packages/entity/src/components/CollapsibleList.tsx b/js/app/packages/entity/src/components/CollapsibleList.tsx
index f40d37c908..e73daa1b61 100644
--- a/js/app/packages/entity/src/components/CollapsibleList.tsx
+++ b/js/app/packages/entity/src/components/CollapsibleList.tsx
@@ -1,4 +1,4 @@
-import { For, Show, createSignal, type JSX } from 'solid-js';
+import { For, Show, createSignal, onCleanup, type JSX } from 'solid-js';
import ChevronDownIcon from '@icon/regular/caret-down.svg?component-solid';
import { cn } from '@ui/utils/classname';
@@ -22,6 +22,10 @@ interface CollapsibleListProps<T> {
*/
export function CollapsibleList<T>(props: CollapsibleListProps<T>) {
const [showAll, setShowAll] = createSignal(false);
+ const [isCollapseInView, setIsCollapseInView] = createSignal(true);
+ let collapseButtonRef: HTMLDivElement | undefined;
+ let observer: IntersectionObserver | undefined;
+
const visibleCount = () => props.visibleCount ?? 3;
const visibleItems = () => {
@@ -37,13 +41,38 @@ export function CollapsibleList<T>(props: CollapsibleListProps<T>) {
const getExpandTextFn = () =>
props.expandText ?? ((count: number) => `Show ${count} More`);
+ const collapse = (e: MouseEvent) => {
+ e.stopPropagation();
+ setShowAll(false);
+ requestAnimationFrame(() => {
+ const scrollTarget =
+ collapseButtonRef?.closest('[data-entity]') ?? collapseButtonRef;
+ scrollTarget?.scrollIntoView({
+ block: 'nearest',
+ behavior: 'smooth',
+ });
+ });
+ };
+
+ const observeCollapseButton = (el: HTMLDivElement) => {
+ collapseButtonRef = el;
+ observer?.disconnect();
+ observer = new IntersectionObserver(
+ ([entry]) => setIsCollapseInView(entry.isIntersecting),
+ { threshold: 0 }
+ );
+ observer.observe(el);
+ };
+
+ onCleanup(() => observer?.disconnect());
+
return (
<>
- <For each={visibleItems()}>
- {(child, index) => props.children(child, index(), count())}
- </For>
<Show when={hasMore()}>
- <div class="w-full flex items-center gap-2 my-2">
+ <div
+ ref={observeCollapseButton}
+ class="w-full flex items-center gap-2 my-2"
+ >
<button
type="button"
class="flex items-center gap-1 text-xs bracket-never hover:text-accent"
@@ -61,7 +90,23 @@ export function CollapsibleList<T>(props: CollapsibleListProps<T>) {
{getExpandTextFn()(props.items.length - visibleCount())}
</Show>
</button>
- <div class="border-t border-edge-muted/50 grow"></div>
+ <div class="border-t border-edge-muted/50 grow" />
+ </div>
+ </Show>
+ <For each={visibleItems()}>
+ {(child, index) => props.children(child, index(), count())}
+ </For>
+ <Show when={showAll() && hasMore() && !isCollapseInView()}>
+ <div class="w-full flex items-center gap-2 my-2">
+ <button
+ type="button"
+ class="flex items-center gap-1 text-xs bracket-never hover:text-accent"
+ onClick={collapse}
+ >
+ <ChevronDownIcon class="w-3 h-3 rotate-180 transition-transform duration-100" />
+ Collapse
+ </button>
+ <div class="border-t border-edge-muted/50 grow" />
</div>
</Show>
</>