Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Scoped PAT: use CSS for the long text reveal animation (#49245)

Gildas Garcia54f56a1baa51
diff --git a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/TokenCapabilities/EndpointRow.tsx b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/TokenCapabilities/EndpointRow.tsx
index bec181ee517..ccaf55a4852 100644
--- a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/TokenCapabilities/EndpointRow.tsx
+++ b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/TokenCapabilities/EndpointRow.tsx
@@ -13,9 +13,6 @@ interface EndpointRowProps {
methodColumnWidth: string
}
-/** Pan slowly enough to read while revealing (~70px/s), but never snap for short distances. */
-const panDurationMs = (distance: number) => Math.max(300, Math.round(distance * 14))
-
/**
* One copyable endpoint. The muted prefix span shrinks with an end-ellipsis while the
* distinguishing segment stays fixed-width — visually equivalent to truncating the full path in
@@ -33,23 +30,12 @@ export const EndpointRow = ({
const { prefix, distinguishing } = splitEndpointPath(path, sharedPrefix)
const pathContainerRef = useRef<HTMLSpanElement>(null)
- const [panDistance, setPanDistance] = useState(0)
- const [isRevealed, setIsRevealed] = useState(false)
const [isCopied, setIsCopied] = useState(false)
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
const [showCopiedIcon, setShowCopiedIcon] = useState(false)
useEffect(() => () => clearTimeout(copiedTimerRef.current), [])
- // Measured when the reveal starts, not on mount: rows live inside accordion content that mounts
- // collapsed, so resting measurements are taken before the row has its real width.
- const handleRevealStart = () => {
- const container = pathContainerRef.current
- if (container) setPanDistance(Math.max(0, container.scrollWidth - container.clientWidth))
- setIsRevealed(true)
- }
- const handleRevealEnd = () => setIsRevealed(false)
-
const handleCopy = () => {
copyToClipboard(path, () => {
setIsCopied(true)
@@ -64,10 +50,6 @@ export const EndpointRow = ({
type="button"
tabIndex={0}
onClick={handleCopy}
- onMouseEnter={handleRevealStart}
- onMouseLeave={handleRevealEnd}
- onFocus={handleRevealStart}
- onBlur={handleRevealEnd}
aria-label={`Copy ${method} ${path}`}
className="group flex w-full items-center gap-2 py-1.5 text-left"
>
@@ -80,27 +62,35 @@ export const EndpointRow = ({
<span
ref={pathContainerRef}
className={cn(
- 'flex min-w-0 flex-1 overflow-hidden whitespace-nowrap font-mono text-xs',
- // The fade only paints over text that reaches the container's right edge, so short rows
- // are unaffected; dropped while panning so the revealed tail stays readable.
- !isRevealed && '[mask-image:linear-gradient(to_right,black_calc(100%-2rem),transparent)]'
+ 'block inline-full overflow-hidden',
+ // group allows to have the hover effect on children (see below)
+ 'group',
+ // container to allow hover effect size computations
+ '@container',
+ '[mask-image:linear-gradient(to_right,black_calc(100%-2rem),transparent)]'
)}
>
<span
- className="flex min-w-0 transition-transform ease-linear motion-reduce:transition-none"
- style={{
- transform:
- isRevealed && panDistance > 0 ? `translateX(-${panDistance}px)` : 'translateX(0)',
- // Pausing before panning lets a quick mouse pass leave the row untouched; the pan
- // back starts immediately and faster, so the row settles as soon as it's left.
- transitionDuration: isRevealed ? `${panDurationMs(panDistance)}ms` : '200ms',
- transitionDelay: isRevealed ? '400ms' : '0ms',
- }}
- >
- {prefix !== '' && (
- <span className="overflow-hidden text-ellipsis text-foreground-lighter">{prefix}</span>
+ className={cn(
+ 'font-mono text-xs',
+ // This is necessary for the reveal on hover animation
+ 'block inline-[max-content] whitespace-nowrap text-nowrap',
+ 'transition-transform ease-linear motion-reduce:transition-none duration-1000 delay-400',
+ // This ensure no GPU jump when non-scrolling items are hovered
+ 'translate-0',
+ // If the content (102% to have a small right margin) exceeds the container size (100cqi), the calc result will be a negative number
+ // This ensures small items don't translate
+ 'group-hover:translate-x-[min(0px,calc(100cqi-102%))]'
)}
- <span className="shrink-0 text-foreground">{distinguishing}</span>
+ >
+ <span>
+ {prefix !== '' && (
+ <span className="overflow-hidden text-ellipsis text-foreground-lighter">
+ {prefix}
+ </span>
+ )}
+ <span className="shrink-0 text-foreground">{distinguishing}</span>
+ </span>
</span>
</span>
<span className="shrink-0 pl-2">