feat(editor): one tab order, vertical Plus list with the error count

This commit is contained in:
bchanot committed 2026-11-15 15:52:28 +01:00
1 parent b41c24b29d
commit ff21b0315e
11 files changed
+155 -75

No files matched your search

+24 -9
View File
@@ -15,6 +15,7 @@ import {
type EditorTabId,
} from '@/editor/tabs'
import type { TabTier } from '@/editor/useViewport'
import Icon from '@/components/ui/Icon'
import { useT } from '@/i18n/useT'
import HistoryButtons from './HistoryButtons'
import { MORE_LIST_ID, useMoreDismiss, useMoreMenu } from './useMoreMenu'
@@ -26,15 +27,25 @@ const ACTIVE =
const IDLE =
'border-transparent text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]'
const ROW =
'flex min-h-12 w-full items-center justify-between gap-3 rounded-md px-4 text-left text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
const ROW_ACTIVE =
'bg-[var(--color-accent)]/10 font-medium text-[var(--color-accent-strong)]'
/** The blocking-error count on the Vérification tab, as text; absent at zero. */
function ErrorCount({ tab }: { tab: EditorTabId }) {
return tab === 'verification' ? <ErrorBadge /> : null
}
/** The count badge itself; also shown on « Plus » while Vérification sits under it. */
function ErrorBadge() {
const plural = usePlural()
const count = useEditorStore(
(s) =>
s.previewState?.report.issues.filter((i) => i.severity === 'error')
.length ?? 0,
)
if (tab !== 'verification' || count === 0) return null
if (count === 0) return null
return (
<>
{' '}
@@ -127,19 +138,22 @@ function MoreList({ more, active, onPick }: MoreListProps) {
transition: { duration: reduced ? 0 : 0.15 },
}}
exit={{ ...hidden, transition: { duration: reduced ? 0 : 0.12 } }}
className="absolute inset-x-0 top-full z-20 flex flex-wrap gap-1 border border-[var(--color-border)] bg-[var(--color-surface)] p-1 shadow-md"
className="absolute inset-x-0 top-full z-20 mt-1 flex flex-col gap-1 rounded-lg border border-[var(--color-border)] bg-[var(--color-surface)] p-2 shadow-lg"
>
{more.map((tab) => (
<li key={tab}>
<button
id={tabDomId(tab)}
type="button"
aria-pressed={tab === active}
aria-current={tab === active ? 'true' : undefined}
onClick={() => onPick(tab)}
className={`rounded-md px-3 ${BASE} border-b-0 ${tab === active ? ACTIVE : IDLE}`}
className={`${ROW} ${tab === active ? ROW_ACTIVE : IDLE}`}
>
{t(`editor.tab.${tab}`)}
<ErrorCount tab={tab} />
<span>
{t(`editor.tab.${tab}`)}
<ErrorCount tab={tab} />
</span>
{tab === active && <Icon name="check" size={18} />}
</button>
</li>
))}
@@ -169,7 +183,7 @@ function usePanelPick(
}
}
/** Below 640 px: « Plus » and its dropdown of the tabs that do not fit. */
/** Below 640 px: « Plus » (with the Vérification count) and its list of the other tabs. */
function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
const t = useT()
const { open, close, toggle } = useMoreMenu(active)
@@ -186,6 +200,7 @@ function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
className={`-mb-px ${BASE} ${more.includes(active) ? ACTIVE : IDLE}`}
>
{t('editor.tab.more')}
{more.includes('verification') && <ErrorBadge />}
</button>
<AnimatePresence>
{open && <MoreList more={more} active={active} onPick={pick} />}
@@ -202,8 +217,8 @@ interface EditorTabsProps {
/**
* The draft's tab row (boards 04 and 05): the five tabs from 640 px (the row may wrap
* between 640 and 1 023 px, never scroll sideways), Annotations and
* Vérification below it with « Plus » opening a dropdown overlay of the others (no measurement).
* between 640 and 1 023 px, never scroll sideways), Général and Annotations below it with
* « Plus » opening a vertical dropdown overlay of the others, in the same order (no measurement).
* « Défaire » and « Refaire » sit at the right end of the row on every tab.
*/
export default function EditorTabs({
@@ -187,9 +187,9 @@ function useShowRestored(nav: EditorNavigation) {
* confirmation before a history jump leaves with a dirty dialog, and whether the last
* editor left a dirty dialog behind.
*/
function useWorkspaceNavigation(sheetId: string, tier: TabTier, who: Who) {
function useWorkspaceNavigation(sheetId: string, who: Who) {
const previewState = useEditorStore((s) => s.previewState)
const tab = previewState ? initialTab(previewState, tier) : 'annotations'
const tab = previewState ? initialTab(previewState) : 'annotations'
const owner = useOwner(sheetId, who.tag)
const nav = useEditorNavigation(tab, useRestoredView(owner))
useEditorHistory(nav, owner, defaultView(tab))
@@ -212,11 +212,7 @@ function LeftDraftNotice({ shown }: { shown: boolean }) {
*/
function Workspace(props: Props & Who) {
const { sheet, mode, readOnly } = props
const { nav, left } = useWorkspaceNavigation(
sheet.sheet_id,
props.tier,
props,
)
const { nav, left } = useWorkspaceNavigation(sheet.sheet_id, props)
return (
<EditingState readOnly={readOnly} mode={mode}>
<div className="space-y-4" data-editor-workspace>