feat(editor): one tab order, vertical Plus list with the error count
This commit is contained in:
1 parent
b41c24b29d
commit
ff21b0315e
11 files changed
+155
-75
No files matched your search
@@ -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>
|
||||
|
||||
@@ -14,11 +14,11 @@ export const EDITOR_TABS = [
|
||||
] as const
|
||||
export type EditorTabId = (typeof EDITOR_TABS)[number]
|
||||
|
||||
/** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */
|
||||
/** The tabs shown beside « Plus » at each width; the rest sit under « Plus », in tab order. */
|
||||
const SHOWN: Record<TabTier, readonly EditorTabId[]> = {
|
||||
wide: EDITOR_TABS,
|
||||
medium: EDITOR_TABS,
|
||||
small: ['annotations', 'verification'],
|
||||
small: ['general', 'annotations'],
|
||||
}
|
||||
|
||||
export function tabsFor(tier: TabTier): {
|
||||
@@ -31,13 +31,12 @@ export function tabsFor(tier: TabTier): {
|
||||
|
||||
/**
|
||||
* The tab a version opens on: Annotations once a view can be annotated, Général while
|
||||
* there is nothing to annotate yet. A tier that does not list Général keeps Annotations.
|
||||
* there is nothing to annotate yet. Both are shown at every width.
|
||||
*/
|
||||
export function initialTab(state: PreviewState, tier: TabTier): EditorTabId {
|
||||
export function initialTab(state: PreviewState): EditorTabId {
|
||||
const unmeasured = unmeasuredViews(state)
|
||||
const measurable = state.document.views.some((v) => !unmeasured.has(v.id))
|
||||
const wanted = measurable ? 'annotations' : 'general'
|
||||
return SHOWN[tier].includes(wanted) ? wanted : 'annotations'
|
||||
return measurable ? 'annotations' : 'general'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user