Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

PRD-8478: Keep new-tab file actions available with AI sidebar open (#4310)

sarah88f0beff157f
diff --git a/.changeset/new-tab-file-actions.md b/.changeset/new-tab-file-actions.md
new file mode 100644
index 000000000..87c5c4c18
--- /dev/null
+++ b/.changeset/new-tab-file-actions.md
@@ -0,0 +1,7 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+New tabs keep their file-creation actions while the Agents panel or terminal is open.
+
+Previously, opening either panel hid the template list and the "or create a new file" link. Both actions now remain available in empty and existing projects. Loaded templates stay visible across panel toggles, and wheel or trackpad scrolling over the end of a template list continues through a short pane to reach the file action. The compact view remains centered beside a right-docked terminal and bottom-aligned above a bottom-docked terminal. The duplicate AI composer remains suppressed.
diff --git a/packages/app/src/components/EditorArea.dom.test.tsx b/packages/app/src/components/EditorArea.dom.test.tsx
index 6a51924cf..5eb29065c 100644
--- a/packages/app/src/components/EditorArea.dom.test.tsx
+++ b/packages/app/src/components/EditorArea.dom.test.tsx
@@ -130,14 +130,17 @@ vi.doMock('@/editor/DocumentContext', () => ({
vi.doMock('@/components/EmptyEditorState', () => ({
EmptyEditorState: ({
terminalOpen,
+ bottomDockOpen,
agentsOpen,
}: {
terminalOpen?: boolean;
+ bottomDockOpen?: boolean;
agentsOpen?: boolean;
}) => (
<div
data-testid="empty-editor-state"
data-terminal-open={String(terminalOpen === true)}
+ data-bottom-dock-open={String(bottomDockOpen === true)}
data-agents-open={String(agentsOpen === true)}
/>
),
@@ -408,6 +411,62 @@ describe('EditorArea empty-state terminal host', () => {
expect(emptyState.getAttribute('data-terminal-open')).toBe('false');
expect(emptyState.getAttribute('data-agents-open')).toBe('false');
});
+
+ test('reports the bottom dock as open when a visible terminal is docked at the bottom', () => {
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalVisible
+ terminalPlacement="bottom"
+ onTerminalVisibleChange={() => {}}
+ />,
+ );
+
+ const emptyState = screen.getByTestId('empty-editor-state');
+ expect(emptyState.getAttribute('data-terminal-open')).toBe('true');
+ expect(emptyState.getAttribute('data-bottom-dock-open')).toBe('true');
+ });
+
+ test('reports the bottom dock as closed when the visible terminal is docked to the right', () => {
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalVisible
+ terminalPlacement="right"
+ onTerminalVisibleChange={() => {}}
+ />,
+ );
+
+ const emptyState = screen.getByTestId('empty-editor-state');
+ expect(emptyState.getAttribute('data-terminal-open')).toBe('true');
+ expect(emptyState.getAttribute('data-bottom-dock-open')).toBe('false');
+ });
+
+ test('reports the bottom dock as closed when a bottom-placed terminal is not visible', () => {
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalPlacement="bottom"
+ onTerminalVisibleChange={() => {}}
+ />,
+ );
+
+ const emptyState = screen.getByTestId('empty-editor-state');
+ expect(emptyState.getAttribute('data-terminal-open')).toBe('false');
+ expect(emptyState.getAttribute('data-bottom-dock-open')).toBe('false');
+ });
});
describe('EditorArea right-rail layout assert on column mount/unmount', () => {
diff --git a/packages/app/src/components/EditorArea.tsx b/packages/app/src/components/EditorArea.tsx
index c0d18ac46..31e576797 100644
--- a/packages/app/src/components/EditorArea.tsx
+++ b/packages/app/src/components/EditorArea.tsx
@@ -1060,6 +1060,7 @@ function EditorAreaInner({
) : (
<EmptyEditorState
terminalOpen={terminalVisible}
+ bottomDockOpen={terminalVisible && terminalPlacement === 'bottom'}
agentsOpen={agentsVisible}
onRageStreak={
activeNewTabId
diff --git a/packages/app/src/components/EmptyEditorState.dom.test.tsx b/packages/app/src/components/EmptyEditorState.dom.test.tsx
index 6e68e75f1..9c478e088 100644
--- a/packages/app/src/components/EmptyEditorState.dom.test.tsx
+++ b/packages/app/src/components/EmptyEditorState.dom.test.tsx
@@ -1,7 +1,11 @@
+import type { TemplatesListEntry } from '@inkeep/open-knowledge-core';
+import { DocumentListSuccessSchema } from '@inkeep/open-knowledge-core';
import * as actualLinguiMacro from '@lingui/react/macro';
-import { cleanup, render, screen, waitFor } from '@testing-library/react';
-import type { ReactNode } from 'react';
-import { afterEach, describe, expect, test, vi } from 'vitest';
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { type ReactNode, useEffect, useState } from 'react';
+import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
+import type { AsyncState } from '@/hooks/use-folder-config';
+import type { DocumentListFetchResult } from '@/lib/documents-fetch';
vi.doMock('@lingui/react/macro', () => ({
...actualLinguiMacro,
@@ -20,9 +24,6 @@ vi.doMock('@/components/empty-state/EmptyStateHeader', () => ({
vi.doMock('@/components/empty-state/empty-state-copy', () => ({
getEmptyStateCopy: () => ({ title: 'title', subtitle: 'subtitle' }),
}));
-vi.doMock('@/components/empty-state/CreateView', () => ({
- CreateView: () => <div data-testid="create-view" />,
-}));
vi.doMock('@/components/empty-state/CreatePromptComposer', () => ({
CreatePromptComposer: () => <div data-testid="create-prompt-composer" />,
}));
@@ -41,42 +42,229 @@ vi.doMock('@/hooks/use-is-embedded', () => ({
vi.doMock('@/lib/documents-events', () => ({
subscribeToDocumentsChanged: () => () => {},
}));
-vi.doMock('@/lib/documents-fetch', () => ({
- fetchDocumentListShared: async () => ({
- ok: true,
- body: { documents: [{ kind: 'document', docName: 'welcome' }] },
- }),
-}));
+const fetchDocumentListShared = vi.fn<() => Promise<DocumentListFetchResult>>();
+vi.doMock('@/lib/documents-fetch', () => ({ fetchDocumentListShared }));
+const useAllTemplates = vi.fn<() => AsyncState<readonly TemplatesListEntry[]>>();
+vi.doMock('@/hooks/use-folder-config', () => ({ useAllTemplates }));
+
+const templateFixture: TemplatesListEntry = {
+ name: 'meeting-notes',
+ title: 'Meeting Notes',
+ path: 'meetings/meeting-notes.md',
+ source_folder: 'meetings',
+};
+
+const templateRowName =
+ 'New file from template "Meeting Notes" (meeting-notes.md) in meetings/' as const;
+
+function documentListBody(docNames: readonly string[]) {
+ return {
+ documents: docNames.map((docName) => ({
+ kind: 'document' as const,
+ docName,
+ docExt: '.md',
+ size: 12,
+ modified: '2026-01-01T00:00:00.000Z',
+ })),
+ };
+}
+
+function documentListResult(docNames: readonly string[]): DocumentListFetchResult {
+ return { ok: true, status: 200, body: documentListBody(docNames) };
+}
+
+beforeEach(() => {
+ fetchDocumentListShared.mockResolvedValue(documentListResult(['welcome']));
+ useAllTemplates.mockReset();
+ useAllTemplates.mockReturnValue({ status: 'ready', data: [templateFixture] });
+});
afterEach(cleanup);
const { EmptyEditorState } = await import('./EmptyEditorState');
-describe('EmptyEditorState session-panel-aware collapse', () => {
- test('neither panel open: renders the full view (composer surface present)', async () => {
- render(<EmptyEditorState />);
- await waitFor(() => expect(screen.getByTestId('create-view')).toBeTruthy());
- expect(screen.queryByTestId('empty-state-header')).toBeNull();
+const { subscribeToCreateTopLevelFile } = await import('@/lib/create-file-events');
+
+const { TooltipProvider } = await import('@/components/ui/tooltip');
+
+describe('EmptyEditorState file creation with session panels', () => {
+ test.each([[[]], [['welcome']]])(
+ 'the document-list fixture satisfies the real success schema: %j',
+ (docNames) => {
+ expect(DocumentListSuccessSchema.safeParse(documentListBody(docNames)).success).toBe(true);
+ },
+ );
+
+ test('closed panels show the composer, the starter-pack action and both create paths', async () => {
+ const onCreate = vi.fn();
+ const unsubscribe = subscribeToCreateTopLevelFile(onCreate);
+ try {
+ render(<EmptyEditorState />);
+ await screen.findByRole('region', { name: 'From template' });
+ expect(screen.getByTestId('create-prompt-composer')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Add a starter pack' })).toBeTruthy();
+
+ fireEvent.click(screen.getByRole('button', { name: templateRowName }));
+ expect(onCreate).toHaveBeenLastCalledWith({
+ template: { folder: 'meetings', name: 'meeting-notes' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: /or create a new file/ }));
+ expect(onCreate).toHaveBeenLastCalledWith({ initialDir: '' });
+ } finally {
+ unsubscribe();
+ }
+ });
+
+ test('closed panels on an empty project show the onboarding starter packs', async () => {
+ fetchDocumentListShared.mockResolvedValue(documentListResult([]));
+ render(
+ <TooltipProvider>
+ <EmptyEditorState />
+ </TooltipProvider>,
+ );
+ expect(await screen.findByTestId('pack-card-grid')).toBeTruthy();
+ });
+
+ describe.each([
+ { name: 'agents', agentsOpen: true, terminalOpen: false },
+ { name: 'terminal', agentsOpen: false, terminalOpen: true },
+ { name: 'both panels', agentsOpen: true, terminalOpen: true },
+ ])('$name open', ({ agentsOpen, terminalOpen }) => {
+ test.each([false, true])('file actions work when project is empty: %s', async (empty) => {
+ if (empty) fetchDocumentListShared.mockResolvedValue(documentListResult([]));
+ const onCreate = vi.fn();
+ const unsubscribe = subscribeToCreateTopLevelFile(onCreate);
+ try {
+ render(<EmptyEditorState agentsOpen={agentsOpen} terminalOpen={terminalOpen} />);
+ const template = await screen.findByRole('button', { name: templateRowName });
+ fireEvent.click(template);
+ expect(onCreate).toHaveBeenLastCalledWith({
+ template: { folder: 'meetings', name: 'meeting-notes' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: /or create a new file/ }));
+ expect(onCreate).toHaveBeenLastCalledWith({ initialDir: '' });
+ expect(screen.queryByTestId('create-prompt-composer')).toBeNull();
+ expect(screen.queryByTestId('pack-card-grid')).toBeNull();
+ expect(screen.queryByRole('button', { name: 'Add a starter pack' })).toBeNull();
+ } finally {
+ unsubscribe();
+ }
+ });
+ });
+
+ describe.each([
+ {
+ name: 'terminal docked bottom',
+ props: { terminalOpen: true, bottomDockOpen: true },
+ pose: 'mt-auto',
+ notPose: 'my-auto',
+ },
+ {
+ name: 'terminal docked right',
+ props: { terminalOpen: true },
+ pose: 'my-auto',
+ notPose: 'mt-auto',
+ },
+ {
+ name: 'agents only',
+ props: { agentsOpen: true },
+ pose: 'my-auto',
+ notPose: 'mt-auto',
+ },
+ {
+ name: 'agents plus terminal docked bottom',
+ props: { agentsOpen: true, terminalOpen: true, bottomDockOpen: true },
+ pose: 'mt-auto',
+ notPose: 'my-auto',
+ },
+ {
+ name: 'agents plus terminal docked right',
+ props: { agentsOpen: true, terminalOpen: true },
+ pose: 'my-auto',
+ notPose: 'mt-auto',
+ },
+ ])('$name', ({ props, pose, notPose }) => {
+ test(`anchors the panel content via .${pose}`, async () => {
+ render(<EmptyEditorState {...props} />);
+ const header = await screen.findByTestId('empty-state-header');
+ expect(header.closest(`.${pose}`)).not.toBeNull();
+ expect(header.closest(`.${notPose}`)).toBeNull();
+ });
+ });
+
+ test('toggling the AI sidebar keeps file actions available and restores the composer', async () => {
+ const { rerender } = render(<EmptyEditorState />);
+ await screen.findByRole('region', { name: 'From template' });
+ rerender(<EmptyEditorState agentsOpen />);
+ expect(screen.getByRole('region', { name: 'From template' })).toBeTruthy();
+ expect(screen.getByRole('button', { name: /or create a new file/ })).toBeTruthy();
+ expect(screen.queryByTestId('create-prompt-composer')).toBeNull();
+ rerender(<EmptyEditorState />);
+ expect(screen.getByTestId('create-prompt-composer')).toBeTruthy();
+ expect(screen.getByRole('region', { name: 'From template' })).toBeTruthy();
});
- test('terminal open: header-only, bottom-anchored above the dock', async () => {
- render(<EmptyEditorState terminalOpen />);
- const header = await screen.findByTestId('empty-state-header');
- expect(screen.queryByTestId('create-view')).toBeNull();
- expect(header.closest('.justify-end')).not.toBeNull();
+ test.each([
+ { agentsOpen: true },
+ { terminalOpen: true },
+ { agentsOpen: true, terminalOpen: true },
+ ])('preserves loaded templates across panel toggles: %j', async (panelProps) => {
+ fetchDocumentListShared.mockClear();
+ const onMount = vi.fn();
+ const onUnmount = vi.fn();
+ let finishLoading: () => void = () => {};
+ useAllTemplates.mockImplementation(function useTemplatesState() {
+ const [state, setState] = useState<AsyncState<readonly TemplatesListEntry[]>>({
+ status: 'loading',
+ });
+ useEffect(() => {
+ onMount();
+ finishLoading = () => setState({ status: 'ready', data: [templateFixture] });
+ return onUnmount;
+ }, []);
+ return state;
+ });
+
+ const { rerender } = render(<EmptyEditorState />);
+ await screen.findByText('Loading templates');
+ act(() => finishLoading());
+ expect(screen.getByRole('button', { name: templateRowName })).toBeTruthy();
+
+ rerender(<EmptyEditorState {...panelProps} />);
+ expect(screen.getByRole('button', { name: templateRowName })).toBeTruthy();
+ expect(screen.queryByText('Loading templates')).toBeNull();
+
+ rerender(<EmptyEditorState />);
+ expect(screen.getByRole('button', { name: templateRowName })).toBeTruthy();
+ expect(screen.queryByText('Loading templates')).toBeNull();
+ expect(onMount).toHaveBeenCalledTimes(1);
+ expect(onUnmount).not.toHaveBeenCalled();
+ expect(fetchDocumentListShared).toHaveBeenCalledTimes(1);
});
- test('agents panel open: header-only too (the composer bubble must not compete), centered', async () => {
+ test.each<AsyncState<readonly TemplatesListEntry[]>>([
+ { status: 'idle' },
+ { status: 'loading' },
+ { status: 'error', message: 'boom' },
+ { status: 'ready', data: [] },
+ ])('blank-file action remains available with templates %j', async (templatesState) => {
+ useAllTemplates.mockReturnValue(templatesState);
render(<EmptyEditorState agentsOpen />);
- const header = await screen.findByTestId('empty-state-header');
- expect(screen.queryByTestId('create-view')).toBeNull();
- expect(header.closest('.justify-center')).not.toBeNull();
+ expect(await screen.findByRole('button', { name: /or create a new file/ })).toBeTruthy();
});
- test('both panels open: the bottom dock wins the pose (it is what takes the space)', async () => {
- render(<EmptyEditorState terminalOpen agentsOpen />);
- const header = await screen.findByTestId('empty-state-header');
- expect(screen.queryByTestId('create-view')).toBeNull();
- expect(header.closest('.justify-end')).not.toBeNull();
+ test('the action row drops its negative margin when no template section renders', async () => {
+ useAllTemplates.mockReturnValue({ status: 'ready', data: [] });
+ render(<EmptyEditorState agentsOpen />);
+ const row = await screen.findByTestId('file-creation-action-row');
+ expect(screen.queryByRole('region', { name: 'From template' })).toBeNull();
+ expect(row.classList.contains('-mt-6')).toBe(false);
+ });
+
+ test('the action row keeps its negative margin beneath a rendered template section', async () => {
+ render(<EmptyEditorState agentsOpen />);
+ const row = await screen.findByTestId('file-creation-action-row');
+ expect(screen.getByRole('region', { name: 'From template' })).toBeTruthy();
+ expect(row.classList.contains('-mt-6')).toBe(true);
});
});
diff --git a/packages/app/src/components/EmptyEditorState.tsx b/packages/app/src/components/EmptyEditorState.tsx
index 01aa1566b..a0b0fe557 100644
--- a/packages/app/src/components/EmptyEditorState.tsx
+++ b/packages/app/src/components/EmptyEditorState.tsx
@@ -1,16 +1,17 @@
-import { DocumentListSuccessSchema } from '@inkeep/open-knowledge-core';
+import { DocumentListSuccessSchema, type TemplatesListEntry } from '@inkeep/open-knowledge-core';
import { Trans, useLingui } from '@lingui/react/macro';
import { Info } from 'lucide-react';
import { useEffect, useRef, useState } from 'react';
import { CopyablePromptList } from '@/components/empty-state/CopyablePromptList';
import { CreatePromptComposer } from '@/components/empty-state/CreatePromptComposer';
-import { CreateView } from '@/components/empty-state/CreateView';
+import { CreateView, FileCreationActions } from '@/components/empty-state/CreateView';
import { EmptyStateHeader } from '@/components/empty-state/EmptyStateHeader';
import { getEmptyStateCopy } from '@/components/empty-state/empty-state-copy';
import { filterVisibleEntries } from '@/components/file-tree-utils';
import { PackCardGrid } from '@/components/PackCardGrid';
import { SeedDialog } from '@/components/SeedDialog';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
+import { type AsyncState, useAllTemplates } from '@/hooks/use-folder-config';
import { useIsEmbedded } from '@/hooks/use-is-embedded';
import { emitCreateTopLevelFile } from '@/lib/create-file-events';
import type { OkPackId } from '@/lib/desktop-bridge-types';
@@ -20,13 +21,16 @@ import { cn } from '@/lib/utils';
export function EmptyEditorState({
terminalOpen = false,
+ bottomDockOpen = false,
agentsOpen = false,
onRageStreak,
}: {
terminalOpen?: boolean;
+ bottomDockOpen?: boolean;
agentsOpen?: boolean;
onRageStreak?: () => void;
}) {
+ const templatesState = useAllTemplates();
const [seedDialogOpen, setSeedDialogOpen] = useState(false);
const [seedDialogInitialPackId, setSeedDialogInitialPackId] = useState<OkPackId | undefined>(
undefined,
@@ -97,14 +101,17 @@ export function EmptyEditorState({
return (
<div
data-testid="empty-editor-state"
- className={cn(
- '@container/emptystate flex min-h-0 flex-1 flex-col items-center pb-8 pt-10',
- terminalOpen ? 'justify-end' : 'justify-center',
- )}
+ className="@container/emptystate flex min-h-0 flex-1 flex-col items-center overflow-y-auto subtle-scrollbar pb-8 pt-10"
>
- <div className="flex w-full flex-col items-center px-4 @md/emptystate:px-10 @2xl/emptystate:px-16">
+ <div
+ className={cn(
+ 'flex w-full shrink-0 flex-col items-center px-4 @md/emptystate:px-10 @2xl/emptystate:px-16',
+ bottomDockOpen ? 'mt-auto' : 'my-auto',
+ )}
+ >
{messageReady ? (
- <TerminalEmptyHeader
+ <PanelEmptyState
+ templatesState={templatesState}
isOnboarding={isOnboarding}
celebrateSignal={celebrateSignal}
onRageStreak={onRageStreak}
@@ -133,6 +140,7 @@ export function EmptyEditorState({
/>
) : (
<CreateView
+ templatesState={templatesState}
onRageStreak={onRageStreak}
celebrateSignal={celebrateSignal}
onAddStarterPack={() => {
@@ -160,11 +168,13 @@ export function countEntries(
).length;
}
-function TerminalEmptyHeader({
+function PanelEmptyState({
+ templatesState,
isOnboarding,
celebrateSignal,
onRageStreak,
}: {
+ templatesState: AsyncState<readonly TemplatesListEntry[]>;
isOnboarding: boolean;
celebrateSignal: number;
onRageStreak?: () => void;
@@ -173,13 +183,14 @@ function TerminalEmptyHeader({
const isEmbedded = useIsEmbedded();
const { title, subtitle } = getEmptyStateCopy({ isOnboarding, isEmbedded });
return (
- <div className="w-full max-w-5xl">
+ <div className="flex w-full max-w-5xl flex-col gap-8">
<EmptyStateHeader
title={t(title)}
subtitle={t(subtitle)}
celebrateSignal={celebrateSignal}
onRageStreak={onRageStreak}
/>
+ <FileCreationActions templatesState={templatesState} compact />
</div>
);
}
diff --git a/packages/app/src/components/empty-state/CreateView.tsx b/packages/app/src/components/empty-state/CreateView.tsx
index c64df5031..31991b96e 100644
--- a/packages/app/src/components/empty-state/CreateView.tsx
+++ b/packages/app/src/components/empty-state/CreateView.tsx
@@ -7,26 +7,27 @@ import { EmptyStateHeader } from '@/components/empty-state/EmptyStateHeader';
import { getEmptyStateCopy } from '@/components/empty-state/empty-state-copy';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
-import { useAllTemplates } from '@/hooks/use-folder-config';
+import type { AsyncState } from '@/hooks/use-folder-config';
import { useIsEmbedded } from '@/hooks/use-is-embedded';
import { emitCreateTopLevelFile } from '@/lib/create-file-events';
+import { cn } from '@/lib/utils';
interface CreateViewProps {
+ readonly templatesState: AsyncState<readonly TemplatesListEntry[]>;
readonly celebrateSignal: number;
readonly onAddStarterPack: () => void;
readonly onRageStreak?: () => void;
}
-export function CreateView({ celebrateSignal, onAddStarterPack, onRageStreak }: CreateViewProps) {
+export function CreateView({
+ templatesState,
+ celebrateSignal,
+ onAddStarterPack,
+ onRageStreak,
+}: CreateViewProps) {
const { t } = useLingui();
const isEmbedded = useIsEmbedded();
const { title, subtitle } = getEmptyStateCopy({ isOnboarding: false, isEmbedded });
- const templatesState = useAllTemplates();
- const initialDir = '';
-
- const templates = templatesState.status === 'ready' ? templatesState.data : [];
- const templatesLoading = templatesState.status === 'loading' || templatesState.status === 'idle';
- const templatesError = templatesState.status === 'error';
return (
<div className="flex w-full flex-col gap-8 py-12 max-w-5xl my-auto" data-testid="create-view">
@@ -44,52 +45,84 @@ export function CreateView({ celebrateSignal, onAddStarterPack, onRageStreak }:
<CreatePromptComposer scenario="existing-repo" />
)}
- <div className="flex w-full flex-col gap-8">
- {templatesLoading || templatesError || templates.length > 0 ? (
- <TemplatesSection
- templates={templates}
- loading={templatesLoading}
- error={templatesError}
- onSelect={(folder, name) => emitCreateTopLevelFile({ template: { folder, name } })}
- />
- ) : null}
+ <FileCreationActions templatesState={templatesState} onAddStarterPack={onAddStarterPack} />
+ </div>
+ );
+}
- {}
- <div className="-mt-6 flex w-full items-center justify-between gap-4">
+interface FileCreationActionsProps {
+ readonly templatesState: AsyncState<readonly TemplatesListEntry[]>;
+ readonly compact?: boolean;
+ readonly onAddStarterPack?: () => void;
+}
+
+export function FileCreationActions({
+ templatesState,
+ compact = false,
+ onAddStarterPack,
+}: FileCreationActionsProps) {
+ const initialDir = '';
+
+ const templates = templatesState.status === 'ready' ? templatesState.data : [];
+ const templatesLoading = templatesState.status === 'loading' || templatesState.status === 'idle';
+ const templatesError = templatesState.status === 'error';
+ const templatesSectionVisible = templatesLoading || templatesError || templates.length > 0;
+
+ return (
+ <div className="flex w-full flex-col gap-8">
+ {templatesSectionVisible ? (
+ <TemplatesSection
+ compact={compact}
+ templates={templates}
+ loading={templatesLoading}
+ error={templatesError}
+ onSelect={(folder, name) => emitCreateTopLevelFile({ template: { folder, name } })}
+ />
+ ) : null}
+
+ {}
+ <div
+ data-testid="file-creation-action-row"
+ className={cn(
+ 'flex w-full flex-wrap items-center justify-end gap-4',
+ templatesSectionVisible && '-mt-6',
+ )}
+ >
+ {onAddStarterPack ? (
<Button
onClick={onAddStarterPack}
variant="link-muted"
size="xs"
- className="font-mono text-xs uppercase tracking-wider"
+ className="me-auto font-mono text-xs uppercase tracking-wider"
>
<Plus aria-hidden="true" className="size-3" />
<Trans>Add a starter pack</Trans>
</Button>
- {}
- <Button
- variant="link-muted"
- className="justify-end"
- size="sm"
- onClick={() => emitCreateTopLevelFile({ initialDir })}
- >
- <Trans>
- or create a new file <ArrowRightIcon aria-hidden="true" className="size-3" />
- </Trans>
- </Button>
- </div>
+ ) : null}
+ {}
+ <Button
+ variant="link-muted"
+ size="sm"
+ onClick={() => emitCreateTopLevelFile({ initialDir })}
+ >
+ <Trans>
+ or create a new file <ArrowRightIcon aria-hidden="true" className="size-3" />
+ </Trans>
+ </Button>
</div>
</div>
);
}
interface TemplatesSectionProps {
+ readonly compact: boolean;
readonly templates: readonly TemplatesListEntry[];
readonly loading: boolean;
readonly error: boolean;
readonly onSelect: (folder: string, name: string) => void;
}
-function TemplatesSection({ templates, loading, error, onSelect }: TemplatesSectionProps) {
+function TemplatesSection({ compact, templates, loading, error, onSelect }: TemplatesSectionProps) {
const { t } = useLingui();
return (
<section aria-label={t`From template`} className="flex w-full flex-col gap-3">
@@ -114,7 +147,10 @@ function TemplatesSection({ templates, loading, error, onSelect }: TemplatesSect
aria-label={t`Template list`}
// biome-ignore lint/a11y/noNoninteractiveTabindex: focusable scroll region per WCAG 2.1.1 (keyboard-operable)
tabIndex={0}
- className="subtle-scrollbar scroll-fade-mask flex max-h-[260px] w-full flex-col overflow-y-auto overscroll-contain focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
+ className={cn(
+ 'subtle-scrollbar scroll-fade-mask flex max-h-[260px] w-full flex-col overflow-y-auto focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/50',
+ !compact && 'overscroll-contain',
+ )}
>
{loading ? (
<p className="p-4 text-1sm text-muted-foreground">