Unverified Commit ae431f2d authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[DevOverlay] Add Pagination (#74583)

This PR added style for pagination and has no logic difference.
Changed the filename from `ErrorPagination` to `error-overlay-pagination` for consistency.

### Light

![CleanShot 2025-01-07 at 21 37 29](https://github.com/user-attachments/assets/dd7d63e8-cb1c-4c5b-bd10-939501e2ef1d)

### Dark

![CleanShot 2025-01-07 at 21 37 37](https://github.com/user-attachments/assets/41012b6a-9d9c-4463-863b-8a200d4fc057)

Closes NDX-576
parent 67c3d7a5
import { noop as css } from '../../../helpers/noop-template'
const styles = css`
[data-nextjs-dialog-left-right] {
display: flex;
flex-direction: row;
align-content: center;
align-items: center;
justify-content: space-between;
}
[data-nextjs-dialog-left-right] > nav {
flex: 1;
display: flex;
align-items: center;
margin-right: var(--size-gap);
}
[data-nextjs-dialog-left-right] > nav > button {
display: inline-flex;
align-items: center;
justify-content: center;
width: calc(var(--size-gap-double) + var(--size-gap));
height: calc(var(--size-gap-double) + var(--size-gap));
font-size: 0;
border: none;
background-color: rgba(255, 85, 85, 0.1);
color: var(--color-ansi-red);
cursor: pointer;
transition: background-color 0.25s ease;
}
[data-nextjs-dialog-left-right] > nav > button > svg {
width: auto;
height: calc(var(--size-gap) + var(--size-gap-half));
}
[data-nextjs-dialog-left-right] > nav > button:hover {
background-color: rgba(255, 85, 85, 0.2);
}
[data-nextjs-dialog-left-right] > nav > button:disabled {
background-color: rgba(255, 85, 85, 0.1);
color: rgba(255, 85, 85, 0.4);
cursor: not-allowed;
}
[data-nextjs-dialog-left-right] > nav > button:first-of-type {
border-radius: var(--size-gap-half) 0 0 var(--size-gap-half);
margin-right: 1px;
}
[data-nextjs-dialog-left-right] > nav > button:last-of-type {
border-radius: 0 var(--size-gap-half) var(--size-gap-half) 0;
}
[data-nextjs-dialog-left-right] > button:last-of-type {
border: 0;
padding: 0;
background-color: transparent;
appearance: none;
opacity: 0.4;
transition: opacity 0.25s ease;
color: var(--color-font);
}
[data-nextjs-dialog-left-right] > button:last-of-type:hover {
opacity: 0.7;
}
`
export { styles }
import type { ReadyRuntimeError } from '../../../helpers/get-error-by-type' import type { ReadyRuntimeError } from '../../../helpers/get-error-by-type'
import type { VersionInfo } from '../../../../../../../../server/dev/parse-version-info' import type { VersionInfo } from '../../../../../../../../server/dev/parse-version-info'
import { ErrorPagination } from '../ErrorPagination/ErrorPagination' import { ErrorOverlayPagination } from '../error-overlay-pagination/error-overlay-pagination'
import { VersionStalenessInfo } from '../../VersionStalenessInfo' import { VersionStalenessInfo } from '../../VersionStalenessInfo'
import { noop as css } from '../../../helpers/noop-template' import { noop as css } from '../../../helpers/noop-template'
...@@ -21,7 +21,7 @@ export function ErrorOverlayFloatingHeader({ ...@@ -21,7 +21,7 @@ export function ErrorOverlayFloatingHeader({
return ( return (
<div className="error-overlay-floating-header"> <div className="error-overlay-floating-header">
{/* TODO: better passing data instead of nullish coalescing */} {/* TODO: better passing data instead of nullish coalescing */}
<ErrorPagination <ErrorOverlayPagination
readyErrors={readyErrors ?? []} readyErrors={readyErrors ?? []}
activeIdx={activeIdx ?? 0} activeIdx={activeIdx ?? 0}
onActiveIndexChange={setActiveIndex ?? (() => {})} onActiveIndexChange={setActiveIndex ?? (() => {})}
...@@ -39,7 +39,7 @@ export const styles = css` ...@@ -39,7 +39,7 @@ export const styles = css`
width: 100%; width: 100%;
position: absolute; position: absolute;
transform: translateY(-32px); transform: translateY(-42px);
outline: none; outline: none;
......
import type { Meta, StoryObj } from '@storybook/react' import type { Meta, StoryObj } from '@storybook/react'
import { ErrorPagination } from './ErrorPagination' import { ErrorOverlayPagination } from './error-overlay-pagination'
import { withShadowPortal } from '../../../storybook/with-shadow-portal' import { withShadowPortal } from '../../../storybook/with-shadow-portal'
import { useState } from 'react' import { useState } from 'react'
const meta: Meta<typeof ErrorPagination> = { const meta: Meta<typeof ErrorOverlayPagination> = {
title: 'ErrorPagination', title: 'ErrorOverlayPagination',
component: ErrorPagination, component: ErrorOverlayPagination,
parameters: { parameters: {
layout: 'centered', layout: 'centered',
}, },
...@@ -13,7 +13,7 @@ const meta: Meta<typeof ErrorPagination> = { ...@@ -13,7 +13,7 @@ const meta: Meta<typeof ErrorPagination> = {
} }
export default meta export default meta
type Story = StoryObj<typeof ErrorPagination> type Story = StoryObj<typeof ErrorOverlayPagination>
// Mock errors for stories // Mock errors for stories
const mockErrors = [ const mockErrors = [
...@@ -38,10 +38,10 @@ const mockErrors = [ ...@@ -38,10 +38,10 @@ const mockErrors = [
] ]
export const SingleError: Story = { export const SingleError: Story = {
render: function ErrorPaginationStory() { render: function ErrorOverlayPaginationStory() {
const [activeIdx, setActiveIdx] = useState(0) const [activeIdx, setActiveIdx] = useState(0)
return ( return (
<ErrorPagination <ErrorOverlayPagination
activeIdx={activeIdx} activeIdx={activeIdx}
readyErrors={[mockErrors[0]]} readyErrors={[mockErrors[0]]}
onActiveIndexChange={setActiveIdx} onActiveIndexChange={setActiveIdx}
...@@ -51,10 +51,10 @@ export const SingleError: Story = { ...@@ -51,10 +51,10 @@ export const SingleError: Story = {
} }
export const MultipleErrors: Story = { export const MultipleErrors: Story = {
render: function ErrorPaginationStory() { render: function ErrorOverlayPaginationStory() {
const [activeIdx, setActiveIdx] = useState(1) const [activeIdx, setActiveIdx] = useState(1)
return ( return (
<ErrorPagination <ErrorOverlayPagination
activeIdx={activeIdx} activeIdx={activeIdx}
readyErrors={mockErrors} readyErrors={mockErrors}
onActiveIndexChange={setActiveIdx} onActiveIndexChange={setActiveIdx}
...@@ -64,10 +64,10 @@ export const MultipleErrors: Story = { ...@@ -64,10 +64,10 @@ export const MultipleErrors: Story = {
} }
export const LastError: Story = { export const LastError: Story = {
render: function ErrorPaginationStory() { render: function ErrorOverlayPaginationStory() {
const [activeIdx, setActiveIdx] = useState(2) const [activeIdx, setActiveIdx] = useState(2)
return ( return (
<ErrorPagination <ErrorOverlayPagination
activeIdx={activeIdx} activeIdx={activeIdx}
readyErrors={mockErrors} readyErrors={mockErrors}
onActiveIndexChange={setActiveIdx} onActiveIndexChange={setActiveIdx}
...@@ -75,3 +75,16 @@ export const LastError: Story = { ...@@ -75,3 +75,16 @@ export const LastError: Story = {
) )
}, },
} }
export const VeryManyErrors: Story = {
render: function ErrorOverlayPaginationStory() {
const [activeIdx, setActiveIdx] = useState(1233)
return (
<ErrorOverlayPagination
activeIdx={activeIdx}
readyErrors={Array(780).fill(mockErrors).flat()}
onActiveIndexChange={setActiveIdx}
/>
)
},
}
import type { ReadyRuntimeError } from '../../../helpers/get-error-by-type' import type { ReadyRuntimeError } from '../../../helpers/get-error-by-type'
import { useCallback, useEffect, useRef, useState } from 'react' import { useCallback, useEffect, useRef, useState } from 'react'
import { noop as css } from '../../../helpers/noop-template'
import { LeftArrow } from '../../../icons/LeftArrow' import { LeftArrow } from '../../../icons/LeftArrow'
import { RightArrow } from '../../../icons/RightArrow' import { RightArrow } from '../../../icons/RightArrow'
...@@ -9,7 +11,7 @@ type ErrorPaginationProps = { ...@@ -9,7 +11,7 @@ type ErrorPaginationProps = {
onActiveIndexChange: (index: number) => void onActiveIndexChange: (index: number) => void
} }
export function ErrorPagination({ export function ErrorOverlayPagination({
readyErrors, readyErrors,
activeIdx, activeIdx,
onActiveIndexChange, onActiveIndexChange,
...@@ -114,35 +116,99 @@ export function ErrorPagination({ ...@@ -114,35 +116,99 @@ export function ErrorPagination({
}, [nav, activeIdx, readyErrors.length]) }, [nav, activeIdx, readyErrors.length])
return ( return (
<div data-nextjs-dialog-left-right> <>
<nav ref={onNav}> {readyErrors.length > 0 && (
<button <nav
ref={buttonLeft} className="error-overlay-pagination dialog-exclude-closing-from-outside-click"
type="button" ref={onNav}
disabled={activeIdx === 0}
aria-disabled={activeIdx === 0}
onClick={handlePrevious}
>
<LeftArrow title="previous" />
</button>
<button
ref={buttonRight}
type="button"
disabled={activeIdx === readyErrors.length - 1}
aria-disabled={activeIdx === readyErrors.length - 1}
onClick={handleNext}
> >
<RightArrow title="next" /> <button
</button> ref={buttonLeft}
<small> type="button"
<span>{activeIdx + 1}</span> of{' '} disabled={activeIdx === 0}
<span data-nextjs-dialog-header-total-count> aria-disabled={activeIdx === 0}
{readyErrors.length} onClick={handlePrevious}
</span> className="error-overlay-pagination-button"
{' issue'} >
{readyErrors.length < 2 ? '' : 's'} <LeftArrow
</small> title="previous"
</nav> className="error-overlay-pagination-button-icon"
</div> />
</button>
<div className="error-overlay-pagination-count">
<span>{activeIdx + 1}/</span>
<span data-nextjs-dialog-header-total-count>
{readyErrors.length}
</span>
</div>
<button
ref={buttonRight}
type="button"
disabled={activeIdx === readyErrors.length - 1}
aria-disabled={activeIdx === readyErrors.length - 1}
onClick={handleNext}
className="error-overlay-pagination-button"
>
<RightArrow
title="next"
className="error-overlay-pagination-button-icon"
/>
</button>
</nav>
)}
</>
) )
} }
export const styles = css`
.error-overlay-pagination {
display: flex;
justify-content: center;
align-items: center;
padding: 4px;
gap: 8px;
background: var(--color-background-100);
box-shadow: var(--shadow-sm);
border: 1px solid var(--color-gray-400);
border-radius: var(--rounded-full);
}
.error-overlay-pagination-count {
color: var(--color-gray-900);
text-align: center;
font-size: var(--size-font-small);
font-weight: 500;
line-height: 16px;
}
.error-overlay-pagination-button {
display: flex;
justify-content: center;
align-items: center;
padding: 4px;
background: var(--color-gray-300);
border: none;
border-radius: var(--rounded-full);
&:focus {
outline: none;
}
&:not(:disabled):active {
background: var(--color-gray-500);
}
&:disabled {
opacity: 0.5;
cursor: not-allowed;
}
}
.error-overlay-pagination-button-icon {
color: var(--color-gray-1000);
}
`
export function LeftArrow({ title }: { title: string }) { export function LeftArrow({
title,
className,
}: {
title?: string
className?: string
}) {
return ( return (
<svg viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg
className={className}
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<title>{title}</title> <title>{title}</title>
<path <path
d="M6.99996 1.16666L1.16663 6.99999L6.99996 12.8333M12.8333 6.99999H1.99996H12.8333Z" fillRule="evenodd"
stroke="currentColor" clipRule="evenodd"
strokeWidth="2" d="M6.46963 13.7804L6.99996 14.3108L8.06062 13.2501L7.53029 12.7198L3.56062 8.75011H14.25H15V7.25011H14.25H3.56062L7.53029 3.28044L8.06062 2.75011L6.99996 1.68945L6.46963 2.21978L1.39641 7.29301C1.00588 7.68353 1.00588 8.3167 1.39641 8.70722L6.46963 13.7804Z"
strokeLinecap="round" fill="currentColor"
strokeLinejoin="round"
/> />
</svg> </svg>
) )
......
export function RightArrow({ title }: { title: string }) { export function RightArrow({
title,
className,
}: {
title?: string
className?: string
}) {
return ( return (
<svg viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg
className={className}
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<title>{title}</title> <title>{title}</title>
<path <path
d="M6.99996 1.16666L12.8333 6.99999L6.99996 12.8333M1.16663 6.99999H12H1.16663Z" fillRule="evenodd"
stroke="currentColor" clipRule="evenodd"
strokeWidth="2" d="M9.53033 2.21978L9 1.68945L7.93934 2.75011L8.46967 3.28044L12.4393 7.25011H1.75H1V8.75011H1.75H12.4393L8.46967 12.7198L7.93934 13.2501L9 14.3108L9.53033 13.7804L14.6036 8.70722C14.9941 8.3167 14.9941 7.68353 14.6036 7.29301L9.53033 2.21978Z"
strokeLinecap="round" fill="currentColor"
strokeLinejoin="round"
/> />
</svg> </svg>
) )
......
...@@ -2,7 +2,7 @@ import { styles as codeFrame } from '../components/CodeFrame/styles' ...@@ -2,7 +2,7 @@ import { styles as codeFrame } from '../components/CodeFrame/styles'
import { styles as dialog } from '../components/Dialog' import { styles as dialog } from '../components/Dialog'
import { styles as errorLayout } from '../components/Errors/error-overlay-layout/error-overlay-layout' import { styles as errorLayout } from '../components/Errors/error-overlay-layout/error-overlay-layout'
import { styles as bottomStacks } from '../components/Errors/error-overlay-bottom-stacks/error-overlay-bottom-stacks' import { styles as bottomStacks } from '../components/Errors/error-overlay-bottom-stacks/error-overlay-bottom-stacks'
import { styles as pagination } from '../components/Errors/ErrorPagination/styles' import { styles as pagination } from '../components/Errors/error-overlay-pagination/error-overlay-pagination'
import { styles as overlay } from '../components/Overlay/styles' import { styles as overlay } from '../components/Overlay/styles'
import { styles as footer } from '../components/Errors/error-overlay-footer/styles' import { styles as footer } from '../components/Errors/error-overlay-footer/styles'
import { styles as terminal } from '../components/Terminal/styles' import { styles as terminal } from '../components/Terminal/styles'
......
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