Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(webv2): highlight the applied prompt template

joshistoast50586653625f
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx
index 5bf7dec0fd..5a59c58b8c 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx
@@ -1,7 +1,8 @@
+import type { PromptTemplateSnapshot } from '@features/generation/core/promptTemplates';
import type { PromptTemplateRecord } from '@features/generation/data/promptTemplates';
import type { PromptTemplateCatalog } from '@features/generation/ui/usePromptTemplates';
-import { ChakraProvider } from '@chakra-ui/react';
+import { Box, ChakraProvider } from '@chakra-ui/react';
import { promptTemplateKeys } from '@features/generation/data/promptTemplates';
import { PromptTemplateEditor } from '@features/generation/ui/promptFields/PromptTemplateEditor';
import { PromptTemplateImage } from '@features/generation/ui/promptFields/PromptTemplateImage';
@@ -9,7 +10,7 @@ import { PromptTemplatesPanel } from '@features/generation/ui/promptFields/Promp
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { system } from '@theme/system';
import i18next from 'i18next';
-import { act, isValidElement, StrictMode } from 'react';
+import { act, isValidElement, StrictMode, useState } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { I18nextProvider, initReactI18next } from 'react-i18next';
import { afterEach, describe, expect, it, vi } from 'vitest';
@@ -157,6 +158,25 @@ const createCatalog = (overrides: Partial<PromptTemplateCatalog> = {}): PromptTe
...overrides,
});
+const StatefulPromptTemplatesPanel = ({ catalog }: { catalog: PromptTemplateCatalog }) => {
+ const [activeTemplate, setActiveTemplate] = useState<PromptTemplateSnapshot | null>(null);
+
+ return (
+ <>
+ <Box aria-hidden bg="accent.solid" color="accent.contrast" data-testid="accent-style-probe" />
+ <PromptTemplatesPanel
+ activeTemplate={activeTemplate}
+ catalog={catalog}
+ isActiveTemplateMissing={false}
+ onApply={setActiveTemplate}
+ onCreate={vi.fn()}
+ onDetach={vi.fn()}
+ onEdit={vi.fn()}
+ />
+ </>
+ );
+};
+
const render = async (element: React.ReactNode, seed?: (queryClient: QueryClient) => void) => {
host = document.createElement('div');
host.style.width = '400px';
@@ -224,6 +244,33 @@ describe('the prompt templates panel', () => {
});
});
+ it('marks the applied template as current with the accent surface and contrast text', async () => {
+ await render(<StatefulPromptTemplatesPanel catalog={createCatalog()} />);
+
+ const activeButton = buttonWithText('Cinematic');
+ const inactiveButton = buttonWithText('Community');
+ await act(async () => {
+ await userEvent.click(activeButton);
+ });
+ await act(
+ () =>
+ new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, 200);
+ })
+ );
+
+ const probeStyle = getComputedStyle(host!.querySelector('[data-testid="accent-style-probe"]')!);
+ const activeText = activeButton.querySelectorAll('span');
+
+ expect(activeButton.getAttribute('aria-current')).toBe('true');
+ expect(inactiveButton.hasAttribute('aria-current')).toBe(false);
+ expect(getComputedStyle(activeButton).backgroundColor).toBe(probeStyle.backgroundColor);
+ expect(getComputedStyle(inactiveButton).backgroundColor).not.toBe(probeStyle.backgroundColor);
+ expect(activeText).toHaveLength(2);
+ expect(getComputedStyle(activeText[0]!).color).toBe(probeStyle.color);
+ expect(getComputedStyle(activeText[1]!).color).toBe(probeStyle.color);
+ });
+
it('clears the applied template', async () => {
const onApply = vi.fn();
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx
index 3121976140..83e020fd7f 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx
@@ -14,6 +14,7 @@ import { downloadBlob } from '@platform/browser/downloadBlob';
import { getApiErrorMessage } from '@platform/transport/http';
import { Button, IconButton } from '@platform/ui/Button';
import { ConfirmDialog } from '@platform/ui/ConfirmDialog';
+import { Row } from '@platform/ui/Row';
import { Scrollable } from '@platform/ui/Scrollable';
import { Tooltip } from '@platform/ui/Tooltip';
import { DownloadIcon, ImageIcon, PencilIcon, PlusIcon, TrashIcon, UploadIcon } from 'lucide-react';
@@ -366,28 +367,41 @@ const TemplateRow = ({
return (
<HStack align="center" gap="1" pr="1">
- <Button
- alignItems="center"
+ <Row
+ active={isActive ? 'accent' : 'none'}
+ aria-current={isActive || undefined}
+ asChild
flex="1"
h="auto"
justifyContent="start"
minW="0"
px="2"
py="1.5"
- size="xs"
- variant="ghost"
- onClick={handleApply}
+ rounded="sm"
>
- <TemplateThumbnail template={template} />
- <Stack align="start" flex="1" gap="0" minW="0">
- <Text as="span" color={isActive ? 'fg' : 'fg.muted'} fontSize="xs" fontWeight={isActive ? '600' : '400'}>
- {template.name}
- </Text>
- <Text as="span" color="fg.subtle" fontFamily="mono" fontSize="2xs" truncate>
- {summary}
- </Text>
- </Stack>
- </Button>
+ <button type="button" onClick={handleApply}>
+ <TemplateThumbnail template={template} />
+ <Stack align="start" flex="1" gap="0" minW="0">
+ <Text
+ as="span"
+ color={isActive ? 'accent.contrast' : 'fg.muted'}
+ fontSize="xs"
+ fontWeight={isActive ? '600' : '400'}
+ >
+ {template.name}
+ </Text>
+ <Text
+ as="span"
+ color={isActive ? 'accent.contrast' : 'fg.subtle'}
+ fontFamily="mono"
+ fontSize="2xs"
+ truncate
+ >
+ {summary}
+ </Text>
+ </Stack>
+ </button>
+ </Row>
{onEdit ? (
<Tooltip content={t('common.edit')}>
<IconButton aria-label={t('common.edit')} size="2xs" variant="ghost" onClick={handleEdit}>