fix(web): merge button fits its label and animates width changes (#18478)
This commit is contained in:
1 parent
05e4f888a0
commit
6a68bee34f
2 files changed
+53
-14
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { type ReactNode, useLayoutEffect, useRef, useState } from "react";
|
||||
|
||||
import { observeResize } from "~/lib/observeResize";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
export function AnimatedWidth({
|
||||
children,
|
||||
className,
|
||||
}: {
|
||||
readonly children: ReactNode;
|
||||
readonly className?: string;
|
||||
}) {
|
||||
const contentRef = useRef<HTMLSpanElement>(null);
|
||||
const [width, setWidth] = useState<number | null>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const element = contentRef.current;
|
||||
if (!element) return;
|
||||
return observeResize(element, () => {
|
||||
const nextWidth = Math.ceil(element.getBoundingClientRect().width);
|
||||
if (nextWidth > 0) setWidth(nextWidth);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<span
|
||||
data-slot="animated-width"
|
||||
className={cn(
|
||||
"inline-block overflow-hidden transition-[width] duration-150 ease-out motion-reduce:transition-none",
|
||||
className,
|
||||
)}
|
||||
style={width === null ? undefined : { width }}
|
||||
>
|
||||
<span ref={contentRef} className="block w-max whitespace-nowrap">
|
||||
{children}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { parseChangeRequestUrl } from "@t3tools/shared/changeRequestUrl";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { usePullRequestStack } from "~/state/usePullRequestStack";
|
||||
import { RefreshIcon } from "~/components/ui/refresh-icon";
|
||||
import { AnimatedWidth } from "~/components/AnimatedWidth";
|
||||
import {
|
||||
scopedThreadKey,
|
||||
scopeProjectRef,
|
||||
@@ -2122,21 +2123,20 @@ export function PullRequestDetailPanel({
|
||||
) : (
|
||||
<PullRequestGlyph.merged aria-hidden className="size-3.5" />
|
||||
)}
|
||||
<span className="inline-grid @max-[30rem]/pr-header:hidden">
|
||||
<span aria-hidden className="invisible col-start-1 row-start-1">
|
||||
{selectedMergeMethodLabel}
|
||||
<AnimatedWidth className="@max-[30rem]/pr-header:hidden">
|
||||
<span className="grid">
|
||||
<span aria-hidden className="invisible col-start-1 row-start-1">
|
||||
{selectedMergeMethodLabel}
|
||||
</span>
|
||||
<span className="col-start-1 row-start-1">
|
||||
{pendingAction === "merge"
|
||||
? "Merging..."
|
||||
: inlineConfirm.isArmed("merge")
|
||||
? "Confirm merge?"
|
||||
: selectedMergeMethodLabel}
|
||||
</span>
|
||||
</span>
|
||||
<span aria-hidden className="invisible col-start-1 row-start-1">
|
||||
Confirm merge?
|
||||
</span>
|
||||
<span className="col-start-1 row-start-1">
|
||||
{pendingAction === "merge"
|
||||
? "Merging..."
|
||||
: inlineConfirm.isArmed("merge")
|
||||
? "Confirm merge?"
|
||||
: selectedMergeMethodLabel}
|
||||
</span>
|
||||
</span>
|
||||
</AnimatedWidth>
|
||||
</Button>
|
||||
</span>
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user