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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(ui): share the input chrome with composite fields via InputShell
Josh Corbetta15238e4ebe5
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryItemSearch.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryItemSearch.tsxindex ebea33ca38..75383607e0 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryItemSearch.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryItemSearch.tsx@@ -4,6 +4,7 @@ import { Box, Code, HStack, Icon, Popover, Portal, Stack, Text } from '@chakra-uimport { semanticReferenceFromDataTransfer } from '@features/gallery/core/semanticImageQuery';import { describeDateRange, findInvalidDateToken, formatIsoDate, parseDateTokens } from '@platform/search/dateTokens';import { CloseButton, IconButton } from '@platform/ui/Button';+import { InputShell } from '@platform/ui/InputShell';import { PopoverContent } from '@platform/ui/Popover';import { CircleHelpIcon, ImageIcon, MapIcon, SparklesIcon } from 'lucide-react';import { useCallback, useMemo, useState } from 'react';@@ -199,7 +200,7 @@ export const GalleryItemSearch = () => {outline={isDropTargetActive ? '2px solid' : undefined}outlineColor={isDropTargetActive ? 'accent.solid' : undefined}position="relative"- rounded="md"+ rounded="l2"w="full"onDragLeave={handleNativeDragLeave}onDragOver={handleNativeDragOver}@@ -253,26 +254,36 @@ const GallerySemanticChip = ({ onClear, reference }: { onClear: () => void; refeconst isText = reference.kind === 'text';const isCluster = reference.kind === 'cluster';const name = getSemanticReferenceName(reference) || t('widgets.gallery.semanticWebImage');-- return (- <HStack- bg="bg"- borderColor="border.emphasized"- borderWidth="1px"- gap="1.5"- h="8"- minW="0"- px="2"- rounded="md"- title={getSemanticReferenceTitle(reference)}- w="full"- >+ const clearButton = useMemo(+ () => (+ <CloseButton+ aria-label={+ isText+ ? t('widgets.gallery.clearSemanticSearch')+ : isCluster+ ? t('widgets.gallery.clearClusterSearch')+ : t('widgets.gallery.clearImageSearch')+ }+ size="2xs"+ onClick={onClear}+ />+ ),+ [isCluster, isText, onClear, t]+ );+ const kindIcon = useMemo(+ () => (<Iconas={isText ? SparklesIcon : isCluster ? MapIcon : ImageIcon}boxSize="3.5"color="fg.subtle"flexShrink={0}/>+ ),+ [isCluster, isText]+ );++ return (+ <InputShell endElement={clearButton} startElement={kindIcon} title={getSemanticReferenceTitle(reference)}><Text color="fg.muted" flex="1" fontSize="xs" minW="0" truncate>{isText? t('widgets.gallery.semanticTextSearch', { name })@@ -280,18 +291,7 @@ const GallerySemanticChip = ({ onClear, reference }: { onClear: () => void; refe? t('widgets.gallery.semanticCluster', { name }): t('widgets.gallery.semanticSimilarTo', { name })}</Text>- <CloseButton- aria-label={- isText- ? t('widgets.gallery.clearSemanticSearch')- : isCluster- ? t('widgets.gallery.clearClusterSearch')- : t('widgets.gallery.clearImageSearch')- }- size="2xs"- onClick={onClear}- />- </HStack>+ </InputShell>);};diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GallerySearchField.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GallerySearchField.tsxindex 2b819faa49..e826cbfa30 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GallerySearchField.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GallerySearchField.tsx@@ -2,7 +2,7 @@ import type { DateTokenParse } from '@platform/search/dateTokens';import { Box, Icon, Input } from '@chakra-ui/react';import { parseDateTokens } from '@platform/search/dateTokens';-import { formControlInteraction } from '@theme/recipes';+import { InputShell } from '@platform/ui/InputShell';import { SearchIcon } from 'lucide-react';import { useCallback, useMemo, useRef, type ReactNode } from 'react';@@ -52,13 +52,10 @@ export const getGallerySearchSegments = (value: string, parse: DateTokenParse):return segments;};-const FIELD_CSS = {- ...formControlInteraction,- _focusWithin: { borderColor: 'accent.solid', outline: '1px solid {colors.accent.solid}' },-} as const;-const PLACEHOLDER_PROPS = { color: 'fg.subtle' } as const;+const SEARCH_START_ELEMENT = <Icon as={SearchIcon} boxSize="3.5" color="fg.subtle" flexShrink={0} />;+const MIRROR_CHIP_CSS = {borderRadius: 'sm',marginInline: '-0.5',@@ -105,78 +102,64 @@ export const GallerySearchField = ({}, []);return (- <Box- alignItems="center"+ <InputShellaria-invalid={isInvalid || undefined}- bg="bg"- borderColor="border.emphasized"- borderWidth="1px"- css={FIELD_CSS}- display="flex"- gap="1.5"- h="8"- minW="0"+ endElement={endElement}position="relative"- px="2"- rounded="md"- w="full"+ startElement={SEARCH_START_ELEMENT}>- <Icon as={SearchIcon} boxSize="3.5" color="fg.subtle" flexShrink={0} />- <Box flex="1" minW="0" position="relative">- {/* Flex-centred: Chakra reads a scale number in `lineHeight` as a- unitless multiplier, which drops the text out of the field. */}- <Box- ref={mirrorRef}- alignItems="center"- aria-hidden="true"- display="flex"- fontSize="xs"- inset="0"- pointerEvents="none"- position="absolute"- whiteSpace="pre"- >- {segments.map((segment, index) =>- segment.kind === 'chip' ? (- <Box- key={`${segment.text}-${String(index)}`}- as="span"- bg={segment.isInvalid ? 'bg.error' : 'accent.subtle'}- color={segment.isInvalid ? 'fg.error' : 'accent.fg'}- css={MIRROR_CHIP_CSS}- >- {segment.text}- </Box>- ) : (- <Box key={`text-${String(index)}`} as="span">- {segment.text}- </Box>- )- )}- </Box>- <Input- aria-describedby={describedById}- aria-invalid={isInvalid || undefined}- aria-label={ariaLabel}- bg="transparent"- border="0"- borderRadius="0"- caretColor="fg"- color="transparent"- fontSize="xs"- h="8"- minW="0"- px="0"- _placeholder={PLACEHOLDER_PROPS}- placeholder={placeholder}- position="relative"- w="full"- value={value}- onChange={handleChange}- onScroll={handleScroll}- />+ {/* Flex-centred: Chakra reads a scale number in `lineHeight` as a+ unitless multiplier, which drops the text out of the field. */}+ <Box+ ref={mirrorRef}+ alignItems="center"+ aria-hidden="true"+ display="flex"+ fontSize="xs"+ inset="0"+ pointerEvents="none"+ position="absolute"+ whiteSpace="pre"+ >+ {segments.map((segment, index) =>+ segment.kind === 'chip' ? (+ <Box+ key={`${segment.text}-${String(index)}`}+ as="span"+ bg={segment.isInvalid ? 'bg.error' : 'accent.subtle'}+ color={segment.isInvalid ? 'fg.error' : 'accent.fg'}+ css={MIRROR_CHIP_CSS}+ >+ {segment.text}+ </Box>+ ) : (+ <Box key={`text-${String(index)}`} as="span">+ {segment.text}+ </Box>+ )+ )}</Box>- {endElement}- </Box>+ <Input+ aria-describedby={describedById}+ aria-invalid={isInvalid || undefined}+ aria-label={ariaLabel}+ bg="transparent"+ border="0"+ borderRadius="0"+ caretColor="fg"+ color="transparent"+ fontSize="xs"+ h="8"+ minW="0"+ px="0"+ _placeholder={PLACEHOLDER_PROPS}+ placeholder={placeholder}+ position="relative"+ w="full"+ value={value}+ onChange={handleChange}+ onScroll={handleScroll}+ />+ </InputShell>);};diff --git a/invokeai/frontend/webv2/src/platform/ui/InputShell.tsx b/invokeai/frontend/webv2/src/platform/ui/InputShell.tsxnew file mode 100644index 0000000000..2e56de77f1--- /dev/null+++ b/invokeai/frontend/webv2/src/platform/ui/InputShell.tsx@@ -0,0 +1,45 @@+import type { BoxProps } from '@chakra-ui/react';+import type { ReactNode, Ref } from 'react';++import { Box } from '@chakra-ui/react';+import { inputShellInteraction } from '@theme/recipes';++export interface InputShellProps extends BoxProps {+ ref?: Ref<HTMLDivElement>;+ /** Leading adornment (e.g. a search icon), outside the content cell. */+ startElement?: ReactNode;+ /** Trailing adornments (clear/help buttons), outside the content cell. */+ endElement?: ReactNode;+}++/**+ * The themed input's chrome for composite fields whose focusable element lives+ * inside the frame — a transparent input under a rendered mirror, a query+ * chip. Metrics and states match `<Input size="xs">`, keyed on focus-within so+ * the frame responds to the inner control; `aria-invalid` on the shell drives+ * the invalid border like the input's own.+ */+export const InputShell = ({ children, endElement, ref, startElement, ...boxProps }: InputShellProps) => (+ <Box+ ref={ref}+ alignItems="center"+ borderColor="border"+ borderRadius="l2"+ borderWidth="1px"+ css={inputShellInteraction}+ display="flex"+ gap="1.5"+ h="8"+ minW="0"+ px="2"+ textStyle="xs"+ w="full"+ {...boxProps}+ >+ {startElement}+ <Box alignItems="center" display="flex" flex="1" minW="0" position="relative">+ {children}+ </Box>+ {endElement}+ </Box>+);diff --git a/invokeai/frontend/webv2/src/platform/ui/index.ts b/invokeai/frontend/webv2/src/platform/ui/index.tsindex ba073f05f5..a519c44e7a 100644--- a/invokeai/frontend/webv2/src/platform/ui/index.ts+++ b/invokeai/frontend/webv2/src/platform/ui/index.ts@@ -7,6 +7,7 @@ export * from './DropTargetOverlay';export * from './DropZone';export * from './Field';export * from './Group';+export * from './InputShell';export * from './JsonPreview';export * from './Menu';export * from './Panel';diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts b/invokeai/frontend/webv2/src/platform/ui/theme/recipes.tsindex e19651a381..3917c1c3b7 100644--- a/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts+++ b/invokeai/frontend/webv2/src/platform/ui/theme/recipes.ts@@ -304,6 +304,16 @@ export const formControlInteraction = {const formControlOpen = { borderColor: 'accent.solid' };+/**+ * `formControlInteraction` keyed on focus-within, for composite fields whose+ * focusable element lives inside the frame (see `platform/ui/InputShell`).+ */+export const inputShellInteraction = {+ ...formControlInteraction,+ _focusWithin: formControlFocused,+ _hover: { ...formControlInteraction._hover, _focusWithin: formControlFocused },+};+export const inputRecipe = defineRecipe({...chakraRecipes.input,variants: {