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(webv2): give canvas tool-option toggles icons
joshistoast1811055162c6
diff --git a/invokeai/frontend/webv2/src/platform/ui/Button.tsx b/invokeai/frontend/webv2/src/platform/ui/Button.tsxindex 4c6e337b09..be62b86c24 100644--- a/invokeai/frontend/webv2/src/platform/ui/Button.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/Button.tsx@@ -1,10 +1,14 @@-import type { ComponentProps } from 'react';+import type { ComponentProps, ReactNode } from 'react';import {Button as ChakraButton,CloseButton as ChakraCloseButton,+ Icon,IconButton as ChakraIconButton,} from '@chakra-ui/react';+import { useCallback } from 'react';++import { Tooltip } from './Tooltip';type ButtonProps = ComponentProps<typeof ChakraButton>;type CloseButtonProps = ComponentProps<typeof ChakraCloseButton>;@@ -40,3 +44,48 @@ export const IconButton = ({ colorPalette, ...props }: IconButtonProps) => ();export const CloseButton = (props: CloseButtonProps) => <ChakraCloseButton {...props} />;++export interface ToggleIconButtonProps extends Omit<+ IconButtonProps,+ 'aria-label' | 'aria-labelledby' | 'aria-pressed' | 'children' | 'onClick'+> {+ checked: boolean;+ icon: React.ElementType;+ /** Names the control for assistive tech and, unless overridden, the tooltip. */+ label: string;+ tooltip?: ReactNode;+ onCheckedChange: (checked: boolean) => void;+}++/**+ * A compact on/off control that states what it toggles. Prefer this over+ * {@link ToggleDot} wherever the setting is not self-evident from its+ * neighbours — the icon carries the meaning, `aria-pressed` carries the state,+ * and the filled variant makes "on" readable at a glance.+ */+export const ToggleIconButton = ({+ checked,+ icon,+ label,+ onCheckedChange,+ tooltip = label,+ ...props+}: ToggleIconButtonProps) => {+ const handleClick = useCallback(() => onCheckedChange(!checked), [checked, onCheckedChange]);++ return (+ <Tooltip content={tooltip}>+ <IconButton+ aria-label={label}+ aria-pressed={checked}+ color={checked ? undefined : 'fg.muted'}+ size="2xs"+ variant={checked ? 'solid' : 'ghost'}+ {...props}+ onClick={handleClick}+ >+ <Icon as={icon} boxSize="3.5" />+ </IconButton>+ </Tooltip>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/BrushOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/BrushOptions.tsxindex c5df6e82b1..95c20092ba 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/BrushOptions.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/BrushOptions.tsx@@ -1,9 +1,10 @@import type { NumberInput as ChakraNumberInput, SliderValueChangeDetails } from '@chakra-ui/react';import { HStack, NumberInput } from '@chakra-ui/react';-import { ColorPicker, Slider, ToggleDot } from '@platform/ui';+import { ColorPicker, Slider, ToggleIconButton } from '@platform/ui';import { MAX_BRUSH_SIZE, MIN_BRUSH_SIZE } from '@workbench/canvas-engine/api';import { useBrushOptions } from '@workbench/widgets/canvas/engineStoreHooks';+import { DropletIcon, PenLineIcon } from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -120,18 +121,20 @@ export const BrushOptions = ({ engine }: ToolOptionsComponentProps) => {onValueChange={onOpacityChange}/>{/*- Two independent dots rather than one pressure switch: width and opacity are separate+ Two independent toggles rather than one pressure switch: width and opacity are separatepressure responses, and opacity additionally costs a full scratch refill per frame.- Each ToggleDot is an aria-labelled button, so unlike sibling switches sharing a+ Each is an aria-labelled button, so unlike sibling switches sharing aField.Root they cannot collide on a hidden-input id.*/}- <ToggleDot+ <ToggleIconButtonchecked={options.pressureAffectsWidth}+ icon={PenLineIcon}label={t('widgets.canvas.toolOptions.pressureAffectsWidth')}onCheckedChange={onPressureWidthToggle}/>- <ToggleDot+ <ToggleIconButtonchecked={options.pressureAffectsOpacity}+ icon={DropletIcon}label={t('widgets.canvas.toolOptions.pressureAffectsOpacity')}onCheckedChange={onPressureOpacityToggle}/>diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsxindex a54b872e46..be25dd31a0 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/ShapeOptions.tsx@@ -2,10 +2,11 @@ import type { NumberInput as ChakraNumberInput, SelectValueChangeDetails } fromimport type { CanvasLayerSourceContract, ShapeToolOptions } from '@workbench/canvas-engine/api';import { createListCollection, HStack, NumberInput, Text } from '@chakra-ui/react';-import { ColorPicker, Select, ToggleDot } from '@platform/ui';+import { ColorPicker, Select, ToggleIconButton } from '@platform/ui';import { MAX_SHAPE_STROKE_WIDTH } from '@workbench/canvas-engine/api';import { useShapeOptions } from '@workbench/widgets/canvas/engineStoreHooks';import { useActiveProjectSelector } from '@workbench/WorkbenchContext';+import { PaintBucketIcon, SquareIcon } from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -140,8 +141,9 @@ export const ShapeOptions = ({ engine }: ToolOptionsComponentProps) => {/><HStack align="center" gap="1.5">- <ToggleDot+ <ToggleIconButtonchecked={fill !== null}+ icon={PaintBucketIcon}label={t('widgets.canvas.toolOptions.shapeFill')}onCheckedChange={onFillToggle}/>@@ -156,8 +158,9 @@ export const ShapeOptions = ({ engine }: ToolOptionsComponentProps) => {</HStack><HStack align="center" gap="1.5">- <ToggleDot+ <ToggleIconButtonchecked={stroke !== null}+ icon={SquareIcon}label={t('widgets.canvas.toolOptions.shapeStroke')}onCheckedChange={onStrokeToggle}/>