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
feat: AI Command Bar design changes (#2442)
Ivan Starkovf8b238e469c8
diff --git a/apps/builder/app/builder/features/ai/ai-button.tsx b/apps/builder/app/builder/features/ai/ai-button.tsxnew file mode 100644index 0000000000..a1bff31f2d--- /dev/null+++ b/apps/builder/app/builder/features/ai/ai-button.tsx@@ -0,0 +1,24 @@+/**+ * AI Button has own style override https://www.figma.com/file/xCBegXEWxROLqA1Y31z2Xo/%F0%9F%93%96-Webstudio-Design-Docs?node-id=7579%3A43452&mode=dev+ * what make it different from Button component styling+ */++import { CommandBarButton, styled, theme } from "@webstudio-is/design-system";++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,+ },+ },+ },+ },+});diff --git a/apps/builder/app/builder/features/ai/ai-command-bar.tsx b/apps/builder/app/builder/features/ai/ai-command-bar.tsxindex 8769ce1a43..846770f665 100644--- a/apps/builder/app/builder/features/ai/ai-command-bar.tsx+++ b/apps/builder/app/builder/features/ai/ai-command-bar.tsx@@ -13,6 +13,7 @@ import {Grid,ScrollArea,Text,+ Tooltip,theme,useDisableCanvasPointerEvents,} from "@webstudio-is/design-system";@@ -22,12 +23,19 @@ import {ChevronUpIcon,ExternalLinkIcon,StopIcon,+ LargeXIcon,} from "@webstudio-is/icons";-import { useRef, useState } from "react";+import {+ useRef,+ useState,+ type MouseEvent,+ type ComponentPropsWithoutRef,+} from "react";import { $isAiCommandBarVisible } from "~/shared/nano-states";import { useMediaRecorder } from "./hooks/media-recorder";import { useLongPressToggle } from "./hooks/long-press-toggle";import { restAi } from "~/shared/router-utils";+import { AiCommandBarButton } from "./ai-button";const fetchTranscription = async (file: File) => {const formData = new FormData();@@ -49,6 +57,10 @@ const fetchTranscription = async (file: File) => {return text;};+type PartialButtonProps<T = ComponentPropsWithoutRef<typeof Button>> = {+ [key in keyof T]?: T[key];+};+export const AiCommandBar = () => {const [value, setValue] = useState("");const [open, setOpen] = useState(false);@@ -103,20 +115,54 @@ export const AiCommandBar = () => {return;}- const textAreaDisabled =- mediaRecorderState === "recording" || isAudioTranscribing;+ let textAreaPlaceholder = "Enter value...";+ let textAreaValue = value;+ let textAreaDisabled = false;++ let recordButtonTooltipContent = "Start recording";+ let recordButtonColor: ComponentPropsWithoutRef<typeof Button>["color"] =+ "dark-ghost";+ let recordButtonProps: PartialButtonProps = longPressToggleProps;+ let recordButtonIcon = <MicIcon />;++ let aiButtonTooltip: string | undefined = "Generate AI results";+ let aiButtonDisabled = value.length === 0;+ const aiButtonPending = false;++ if (isAudioTranscribing) {+ textAreaPlaceholder = "Transcribing voice...";+ // Show placeholder instead+ textAreaValue = "";+ textAreaDisabled = true;++ recordButtonTooltipContent = "Cancel";+ recordButtonColor = "neutral";+ recordButtonProps = {+ onClick: (event: MouseEvent<HTMLButtonElement>) => {+ // Cancel transcription+ uploadIdRef.current++;+ setIsAudioTranscribing(false);+ },+ };+ recordButtonIcon = <LargeXIcon />;++ aiButtonTooltip = undefined;+ aiButtonDisabled = true;+ }- const recordButtonDisabled = isAudioTranscribing;+ if (mediaRecorderState === "recording") {+ textAreaPlaceholder = "Recording voice...";+ // Show placeholder instead+ textAreaValue = "";+ textAreaDisabled = true;+ aiButtonDisabled = true;- const aiButtonDisabled =- mediaRecorderState === "recording" || isAudioTranscribing;+ recordButtonTooltipContent = "Stop recording";+ recordButtonColor = "destructive";+ recordButtonIcon = <StopIcon />;- const actionPlaceholder =- mediaRecorderState === "recording"- ? "Recording voice..."- : isAudioTranscribing- ? "Transcribing voice..."- : undefined;+ aiButtonTooltip = undefined;+ }return (<Box@@ -154,8 +200,8 @@ export const AiCommandBar = () => {<AutogrowTextAreaautoFocusdisabled={textAreaDisabled}- placeholder={actionPlaceholder ?? "Enter value..."}- value={actionPlaceholder !== undefined ? "" : value}+ placeholder={textAreaPlaceholder}+ value={textAreaValue}onChange={setValue}onKeyDown={(event) => {if (event.key === "Enter" && event.shiftKey === false) {@@ -167,60 +213,80 @@ export const AiCommandBar = () => {</ScrollArea></Grid>- <CommandBarButton- disabled={recordButtonDisabled}- ref={recordButtonRef}- css={{- opacity: "calc(1 - 0.5 * var(--amplitude, 0))",- transition: "opacity 0.1s ease-in-out",- }}- color={- mediaRecorderState === "recording" ? "destructive" : "dark-ghost"- }- {...longPressToggleProps}+ <Tooltip+ side="top"+ sideOffset={10}+ delayDuration={100}+ content={recordButtonTooltipContent}>- {mediaRecorderState === "recording" ? <StopIcon /> : <MicIcon />}- </CommandBarButton>+ <CommandBarButton+ ref={recordButtonRef}+ css={{+ "--amplitude": 0,+ opacity: "calc(1 - 0.5 * var(--amplitude, 0))",+ transition: "opacity 0.1s ease-in-out",+ }}+ color={recordButtonColor}+ {...recordButtonProps}+ >+ {recordButtonIcon}+ </CommandBarButton>+ </Tooltip>- <CommandBarButton color="gradient" disabled={aiButtonDisabled}>- <AiIcon />- </CommandBarButton>+ <Tooltip+ side="top"+ sideOffset={10}+ delayDuration={0}+ content={aiButtonTooltip}+ >+ <AiCommandBarButton+ color="gradient"+ data-pending={aiButtonPending}+ disabled={aiButtonDisabled}+ >+ <AiIcon />+ </AiCommandBarButton>+ </Tooltip></CommandBar></Box>);};const CommandBarContent = () => {+ const shortcutText = "⌘⇧Q";return (<><CommandBarContentSection>- <Text variant={"labelsSentenceCase"} align={"center"}>- Welcome to Webstudio AI alpha!- </Text>- <div />- <Text variant={"labelsSentenceCase"}>- Ask me to generate or edit sections, text, or images.- <br /> For example you can say: ”Make a new contact section”- </Text>- <Flex align={"end"}>- <Button- color="dark"- css={{- width: theme.spacing[30],- }}- suffix={<ExternalLinkIcon />}- >- Learn more- </Button>+ <Flex justify={"between"}><Textvariant={"labelsSentenceCase"}color={"subtle"}- css={{ flex: 1 }}- align={"center"}+ css={{ visibility: "hidden" }}>- shortcut ⌘⇧Q+ {shortcutText}+ </Text>+ <Text variant={"labelsSentenceCase"} align={"center"}>+ Welcome to Webstudio AI alpha!+ </Text>+ <Text variant={"labelsSentenceCase"} color={"subtle"}>+ {shortcutText}</Text></Flex>+ <div />+ <Text variant={"labelsSentenceCase"}>+ Ask me to generate or edit sections, text, or images.+ <br />+ For example you can say: ”Make a new contact section”+ </Text>+ {/* @todo: change color on theme when available */}+ <Text variant={"labelsSentenceCase"} css={{ color: "#828486" }}>+ Powered by ChatGPT - By using Webstudio AI, you consent to OpenAI+ storing interactions without personal data.+ </Text>+ <div />+ <Button color="dark" suffix={<ExternalLinkIcon />}>+ Learn more+ </Button></CommandBarContentSection><CommandBarContentSeparator />diff --git a/packages/design-system/src/components/ai-command-bar/command-bar.tsx b/packages/design-system/src/components/ai-command-bar/command-bar.tsxindex 7221232700..93864fe20f 100644--- a/packages/design-system/src/components/ai-command-bar/command-bar.tsx+++ b/packages/design-system/src/components/ai-command-bar/command-bar.tsx@@ -7,7 +7,7 @@ import * as Separator from "@radix-ui/react-separator";import { styled, theme } from "../../stitches.config";import { Grid } from "../grid";import { Button } from "../button";-import { type ReactNode } from "react";+import { forwardRef, type ReactNode } from "react";type Props = {children: React.ReactNode;@@ -68,9 +68,11 @@ export const CommandBar = (props: Props) => {);};-export const CommandBarTrigger = (props: { children: ReactNode }) => (- <Collapsible.Trigger asChild {...props} />-);+export const CommandBarTrigger = forwardRef<+ HTMLButtonElement,+ { children: ReactNode }+>((props, ref) => <Collapsible.Trigger ref={ref} asChild {...props} />);+CommandBarTrigger.displayName = "CommandBarTrigger";export const CommandBarContentSection = (props: { children: ReactNode }) => (<Griddiff --git a/packages/icons/icons/ai.svg b/packages/icons/icons/ai.svgindex 02d77306d4..17838b13bc 100644--- a/packages/icons/icons/ai.svg+++ b/packages/icons/icons/ai.svg@@ -1,3 +1,3 @@<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">- <path d="M11.4582 13.305C13.1832 13.305 14.6292 11.8576 14.6292 10.1301V3.9965C14.6292 3.27884 14.0472 2.69531 13.3292 2.69531C12.6122 2.69531 12.0292 3.27884 12.0292 3.9965V10.1301C12.0292 10.4412 11.7694 10.7024 11.4585 10.7026C11.1995 10.7026 10.9663 10.5213 10.9043 10.27C10.6233 9.14402 10.2023 7.46048 9.74527 5.63082C9.31626 3.91025 7.77125 2.70216 5.99824 2.70216C4.22622 2.70216 2.68021 3.91025 2.25021 5.63182L0.738198 11.6883C0.564197 12.385 0.9882 13.0916 1.68421 13.2658C2.38021 13.4399 3.08622 13.0155 3.26022 12.3189C3.26022 12.3189 3.95922 9.51936 4.77323 6.26239C4.91323 5.69988 5.41923 5.30452 5.99824 5.30452C6.57724 5.30452 7.08224 5.69988 7.22325 6.26239C7.67925 8.09106 8.10025 9.77559 8.38125 10.9006C8.73023 12.2988 10.0193 13.3048 11.4582 13.305Z"/>+ <path fill-rule="evenodd" clip-rule="evenodd" d="M3.03963 12.3265C2.89263 12.9155 2.29463 13.2735 1.70563 13.1265C1.11663 12.9795 0.757634 12.3815 0.905634 11.7925C0.905634 11.7925 1.60463 8.99548 2.41863 5.74147C2.82563 4.11047 4.29163 2.96647 5.97263 2.96647C7.65463 2.96647 9.11963 4.11047 9.52663 5.74147C9.98363 7.56848 10.4046 9.25148 10.6856 10.3755C10.7706 10.7155 11.0846 10.9595 11.4346 10.9595C11.8546 10.9595 12.2066 10.6075 12.2066 10.1875V4.05947C12.2066 3.45247 12.6996 2.95947 13.3066 2.95947C13.9136 2.95947 14.4066 3.45247 14.4066 4.05947V10.1875C14.4066 11.8045 13.0516 13.1595 11.4346 13.1595C10.0856 13.1595 8.87763 12.2175 8.55163 10.9095C8.27063 9.78448 7.84963 8.10248 7.39263 6.27447C7.22963 5.62347 6.64463 5.16647 5.97263 5.16647C5.30063 5.16647 4.71563 5.62347 4.55263 6.27447C3.73863 9.52948 3.03963 12.3265 3.03963 12.3265Z"/></svg>\ No newline at end of filediff --git a/packages/icons/src/__generated__/ai.tsx b/packages/icons/src/__generated__/ai.tsxindex f39dd24363..a71aa5a66f 100644--- a/packages/icons/src/__generated__/ai.tsx+++ b/packages/icons/src/__generated__/ai.tsx@@ -7,7 +7,7 @@ import type { IconProps } from "../types";export const AiIcon = forwardRef<SVGSVGElement, IconProps>(({ color = "currentColor", size = 16, ...props }, forwardedRef) => {return (- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path d="M11.458 13.305c1.725 0 3.171-1.447 3.171-3.175V3.996a1.301 1.301 0 0 0-2.6 0v6.134c0 .311-.26.572-.57.573a.576.576 0 0 1-.555-.433c-.28-1.126-.702-2.81-1.159-4.64a3.862 3.862 0 0 0-7.495.002L.738 11.688a1.3 1.3 0 1 0 2.522.63l1.513-6.056a1.263 1.263 0 0 1 2.45 0l1.158 4.639a3.2 3.2 0 0 0 3.077 2.404Z" /></svg>+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path fillRule="evenodd" d="M3.04 12.326a1.1 1.1 0 0 1-2.134-.534l1.513-6.05a3.663 3.663 0 0 1 7.108 0l1.159 4.634c.085.34.399.584.749.584a.78.78 0 0 0 .772-.773V4.06a1.1 1.1 0 0 1 2.2 0v6.128c0 1.618-1.355 2.973-2.972 2.973a2.996 2.996 0 0 1-2.883-2.25l-1.16-4.636a1.464 1.464 0 0 0-2.84 0L3.04 12.326Z" clipRule="evenodd" /></svg>);});diff --git a/packages/icons/src/__generated__/svg/ai.ts b/packages/icons/src/__generated__/svg/ai.tsindex 0d039ccb2f..ee77d7ea24 100644--- a/packages/icons/src/__generated__/svg/ai.ts+++ b/packages/icons/src/__generated__/svg/ai.ts@@ -1 +1 @@-export const AiIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%" style="display: block;"><path d="M11.458 13.305c1.725 0 3.171-1.447 3.171-3.175V3.996a1.301 1.301 0 0 0-2.6 0v6.134c0 .311-.26.572-.57.573a.576.576 0 0 1-.555-.433c-.28-1.126-.702-2.81-1.159-4.64a3.862 3.862 0 0 0-7.495.002L.738 11.688a1.3 1.3 0 1 0 2.522.63l1.513-6.056a1.263 1.263 0 0 1 2.45 0l1.158 4.639a3.2 3.2 0 0 0 3.077 2.404Z"/></svg>`;+export const AiIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%" style="display: block;"><path fill-rule="evenodd" d="M3.04 12.326a1.1 1.1 0 0 1-2.134-.534l1.513-6.05a3.663 3.663 0 0 1 7.108 0l1.159 4.634c.085.34.399.584.749.584a.78.78 0 0 0 .772-.773V4.06a1.1 1.1 0 0 1 2.2 0v6.128c0 1.618-1.355 2.973-2.972 2.973a2.996 2.996 0 0 1-2.883-2.25l-1.16-4.636a1.464 1.464 0 0 0-2.84 0L3.04 12.326Z" clip-rule="evenodd"/></svg>`;