Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
style: AI Command Bar improvements (#2456)
Ivan Starkov5f19f5e49bca
diff --git a/apps/builder/app/builder/features/ai/ai-button.tsx b/apps/builder/app/builder/features/ai/ai-button.tsxindex a1bff31f2d..0a0d08c530 100644--- a/apps/builder/app/builder/features/ai/ai-button.tsx+++ b/apps/builder/app/builder/features/ai/ai-button.tsx@@ -4,21 +4,31 @@*/import { CommandBarButton, styled, theme } from "@webstudio-is/design-system";+import { forwardRef, type ComponentProps } from "react";-export const AiCommandBarButton = styled(CommandBarButton, {- // @todo switch to theme variables when available- variants: {- color: {- gradient: {- "&[data-state=disabled]": {- background: "#687076",- color: "#1D1D1D",- },- "&[data-state=disabled]&[data-pending=true]": {- background: "#1D1D1D",- color: theme.colors.foregroundContrastMain,- },- },+type CommandButtonProps = ComponentProps<typeof CommandBarButton>;++// @todo: Move to design system, if no additional changes are needed+const AiCommandBarButtonStyled = styled(CommandBarButton, {+ "&[data-state=disabled]": {+ "&[data-state=disabled]": {+ background: "#1D1D1D",+ color: "#646464",+ outline: "1px solid #646464",+ },+ "&[data-pending=true]": {+ background: "#1D1D1D",+ color: theme.colors.foregroundContrastMain,+ outline: "none",},},});++export const AiCommandBarButton = forwardRef<+ HTMLButtonElement,+ CommandButtonProps+>((props, ref) => {+ return <AiCommandBarButtonStyled ref={ref} {...props} />;+});++AiCommandBarButton.displayName = "AiCommandBarButton";diff --git a/apps/builder/app/builder/features/ai/ai-command-bar.tsx b/apps/builder/app/builder/features/ai/ai-command-bar.tsxindex 5c5e75ac0d..ac21e4f664 100644--- a/apps/builder/app/builder/features/ai/ai-command-bar.tsx+++ b/apps/builder/app/builder/features/ai/ai-command-bar.tsx@@ -38,6 +38,7 @@ import { useLongPressToggle } from "./hooks/long-press-toggle";import { AiCommandBarButton } from "./ai-button";import { fetchTranscription } from "./ai-fetch-transcription";import { fetchResult } from "./ai-fetch-result";+import { useEffectEvent } from "./hooks/effect-event";type PartialButtonProps<T = ComponentPropsWithoutRef<typeof Button>> = {[key in keyof T]?: T[key];@@ -56,6 +57,10 @@ export const AiCommandBar = () => {const { enableCanvasPointerEvents, disableCanvasPointerEvents } =useDisableCanvasPointerEvents();+ const getValue = useEffectEvent(() => {+ return value;+ });+const {start,stop,@@ -70,13 +75,13 @@ export const AiCommandBar = () => {if (guardId !== guardIdRef.current) {return;}- setValue((previousText) => `${previousText} ${text}`);++ const currentValue = getValue();+ const newValue = `${currentValue} ${text}`;+ setValue(newValue);setIsAudioTranscribing(false);- setValue((value) => {- Promise.resolve(true).then(() => handleAiRequest(value));- return value;- });+ handleAiRequest(newValue);},onReportSoundAmplitude: (amplitude) => {recordButtonRef.current?.style.setProperty(@@ -147,14 +152,17 @@ export const AiCommandBar = () => {let textAreaValue = value;let textAreaDisabled = false;- let recordButtonTooltipContent = "Start recording";+ let recordButtonTooltipContent = undefined;let recordButtonColor: ComponentPropsWithoutRef<typeof Button>["color"] ="dark-ghost";let recordButtonProps: PartialButtonProps = longPressToggleProps;let recordButtonIcon = <MicIcon />;+ let recordButtonDisabled = false;- let aiButtonTooltip: string | undefined = "Generate AI results";let aiButtonDisabled = value.length === 0;+ let aiButtonTooltip: string | undefined = aiButtonDisabled+ ? undefined+ : "Generate AI results";let aiButtonPending = false;if (isAudioTranscribing) {@@ -163,16 +171,7 @@ export const AiCommandBar = () => {textAreaValue = "";textAreaDisabled = true;- recordButtonTooltipContent = "Cancel";- recordButtonColor = "neutral";- recordButtonProps = {- onClick: (event: MouseEvent<HTMLButtonElement>) => {- // Cancel transcription- guardIdRef.current++;- setIsAudioTranscribing(false);- },- };- recordButtonIcon = <LargeXIcon />;+ recordButtonDisabled = true;aiButtonTooltip = undefined;aiButtonDisabled = true;@@ -185,7 +184,6 @@ export const AiCommandBar = () => {textAreaDisabled = true;aiButtonDisabled = true;- recordButtonTooltipContent = "Stop recording";recordButtonColor = "destructive";recordButtonIcon = <StopIcon />;@@ -207,7 +205,7 @@ export const AiCommandBar = () => {};recordButtonIcon = <LargeXIcon />;- aiButtonTooltip = undefined;+ aiButtonTooltip = "Generating ...";aiButtonDisabled = true;aiButtonPending = true;}@@ -267,7 +265,8 @@ export const AiCommandBar = () => {delayDuration={100}content={recordButtonTooltipContent}>- <CommandBarButton+ <AiCommandBarButton+ disabled={recordButtonDisabled}ref={recordButtonRef}css={{"--ws-ai-command-bar-amplitude": 0,@@ -278,7 +277,7 @@ export const AiCommandBar = () => {{...recordButtonProps}>{recordButtonIcon}- </CommandBarButton>+ </AiCommandBarButton></Tooltip><Tooltip@@ -338,23 +337,27 @@ const CommandBarContent = (props: { prompts: string[] }) => {</Button></CommandBarContentSection>- <CommandBarContentSeparator />-- <CommandBarContentSection>- <Text variant={"labelsSentenceCase"} align={"center"}>- Previous prompts- </Text>- <div />- <ScrollArea css={{ maxHeight: theme.spacing[29] }}>- <Grid gap={2}>- {props.prompts.map((prompt, index) => (- <CommandBarContentPrompt key={index}>- {prompt}- </CommandBarContentPrompt>- ))}- </Grid>- </ScrollArea>- </CommandBarContentSection>+ {props.prompts.length > 0 && (+ <>+ <CommandBarContentSeparator />++ <CommandBarContentSection>+ <Text variant={"labelsSentenceCase"} align={"center"}>+ Previous prompts+ </Text>+ <div />+ <ScrollArea css={{ maxHeight: theme.spacing[29] }}>+ <Grid gap={2}>+ {props.prompts.map((prompt, index) => (+ <CommandBarContentPrompt key={index}>+ {prompt}+ </CommandBarContentPrompt>+ ))}+ </Grid>+ </ScrollArea>+ </CommandBarContentSection>+ </>+ )}</>);};