Unverified Commit 386a89b9 authored by rauno's avatar rauno Committed by GitHub

[DevOverlay] Polish new Error Overlay badge (#74975)

This PR adds some polish to the `NextLogo` component to bring it closer
to design:







https://github.com/user-attachments/assets/f9758747-2ea5-4df4-90bc-d8654b3a1e56
parent 2eb590bc
......@@ -5,6 +5,7 @@ import React, { useState, useEffect, useRef } from 'react'
import { NextLogo } from './internal/next-logo'
import { useIsDevBuilding } from '../../../../../../../dev/dev-build-indicator/internal/initialize-for-new-overlay'
import { useIsDevRendering } from './internal/dev-render-indicator'
import { useDelayedRender } from './internal/use-delayed-render'
// TODO: test a11y
// TODO: add E2E tests to cover different scenarios
......@@ -36,6 +37,9 @@ export function DevToolsIndicator({
)
}
const ANIMATE_OUT_DURATION_MS = 200
const ANIMATE_OUT_TIMING_FUNCTION = 'cubic-bezier(0.175, 0.885, 0.32, 1.1)'
const DevToolsPopover = ({
onIssuesClick,
issueCount,
......@@ -55,6 +59,13 @@ const DevToolsPopover = ({
const buttonRef = useRef<HTMLDivElement>(null)
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
const { mounted, rendered } = useDelayedRender(isPopoverOpen, {
// Intentionally no fade in, makes the UI feel more immediate
enterDelay: 0,
// Graceful fade out to confirm that the UI did not break
exitDelay: ANIMATE_OUT_DURATION_MS,
})
useEffect(() => {
// Close popover when clicking outside of it or its button
const handleClickOutside = (event: MouseEvent) => {
......@@ -114,13 +125,20 @@ const DevToolsPopover = ({
/>
</div>
{isPopoverOpen && (
{mounted && (
<div
ref={popoverRef}
id="dev-tools-popover"
role="dialog"
aria-labelledby="dev-tools-title"
data-nextjs-dev-tools-popover
data-rendered={rendered}
style={
{
'--animate-out-duration-ms': `${ANIMATE_OUT_DURATION_MS}ms`,
'--animate-out-timing-function': ANIMATE_OUT_TIMING_FUNCTION,
} as React.CSSProperties
}
tabIndex={-1}
>
<div data-nextjs-dev-tools-content>
......
import { useState, useRef, useCallback } from 'react'
interface Options {
enterDelay?: number
exitDelay?: number
onUnmount?: () => void
}
/** Useful to perform CSS animations on React components */
export function useDelayedRender(
active: boolean = false,
options: Options = {}
) {
const [, force] = useState<any>()
const mounted = useRef(active)
const rendered = useRef(false)
const renderTimer = useRef<NodeJS.Timeout | null>(null)
const unmountTimer = useRef<NodeJS.Timeout | null>(null)
const prevActive = useRef(active)
const recalculate = useCallback(() => {
const { enterDelay = 1, exitDelay = 0 } = options
if (prevActive.current) {
// Mount immediately
mounted.current = true
if (unmountTimer.current) clearTimeout(unmountTimer.current)
if (enterDelay <= 0) {
// Render immediately
rendered.current = true
} else {
if (renderTimer.current) return
// Render after a delay
renderTimer.current = setTimeout(() => {
rendered.current = true
renderTimer.current = null
force({})
}, enterDelay)
}
} else {
// Immediately set to unrendered
rendered.current = false
if (exitDelay <= 0) {
mounted.current = false
} else {
if (unmountTimer.current) return
// Unmount after a delay
unmountTimer.current = setTimeout(() => {
mounted.current = false
unmountTimer.current = null
force({})
}, exitDelay)
}
}
}, [options])
// When the active prop changes, need to re-calculate
if (active !== prevActive.current) {
prevActive.current = active
// We want to do this synchronously with the render, not in an effect
// this way when active → true, mounted → true in the same pass
recalculate()
}
return {
mounted: mounted.current,
rendered: rendered.current,
}
}
......@@ -14,19 +14,29 @@ export const styles = css`
}
[data-nextjs-dev-tools-popover] {
-webkit-font-smoothing: antialiased;
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 0px;
background: var(--color-background-100);
border: 1px solid var(--color-gray-alpha-400);
box-shadow: var(--shadow-sm), var(--shadow-lg);
border-radius: var(--rounded-lg);
background-clip: padding-box;
box-shadow: var(--shadow-menu);
border-radius: var(--rounded-xl);
position: absolute;
bottom: calc(100% + var(--size-gap));
left: 0;
z-index: 1000;
overflow: hidden;
opacity: 0;
transition: opacity var(--animate-out-duration-ms)
var(--animate-out-timing-function);
&[data-rendered='true'] {
opacity: 1;
scale: 1;
}
}
[data-nextjs-dev-tools-content] {
......@@ -75,6 +85,7 @@ export const styles = css`
width: 248px;
height: 36px;
border-radius: var(--rounded-md);
cursor: pointer;
}
[data-nextjs-dev-tools-row]:hover {
......@@ -92,7 +103,6 @@ export const styles = css`
[data-nextjs-dev-tools-row-value] {
font-family: var(--font-stack-sans);
font-style: normal;
font-weight: 400;
font-size: var(--size-font-small);
line-height: var(--size-5);
......@@ -114,7 +124,6 @@ export const styles = css`
[data-nextjs-dev-tools-issue-text] {
font-family: var(--font-stack-sans);
font-style: normal;
font-weight: 500;
font-size: 11px;
line-height: var(--size-4);
......@@ -152,15 +161,13 @@ export const styles = css`
[data-nextjs-dev-tools-icon] {
display: flex;
min-width: var(--size-5);
width: var(--size-5);
height: var(--size-5);
padding: var(--size-1) var(--size-1_5);
justify-content: center;
align-items: center;
border-radius: var(--rounded-md);
border: 1px solid var(--color-gray-alpha-400);
border: 1px solid var(--color-gray-400);
background: var(--color-background-100);
color: var(--color-gray-1000);
text-align: center;
font-size: var(--size-font-smaller);
......
......@@ -59,6 +59,9 @@ export function Base() {
--shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
--shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
--shadow-none: 0 0 #0000;
--shadow-menu: 0px 1px 1px rgba(0, 0, 0, 0.02),
0px 4px 8px -4px rgba(0, 0, 0, 0.04),
0px 16px 24px -8px rgba(0, 0, 0, 0.06);
--rounded-none: 0px;
--rounded-sm: 0.125rem; /* 2px */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment