Skip to content

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.

fix: Navigator toolbar fixes (#2825)

Oleg Isonen5468bbd05fd8
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsx
index 81eebba88b..2b1c12194f 100644
--- a/apps/builder/app/builder/builder.tsx
+++ b/apps/builder/app/builder/builder.tsx
@@ -40,7 +40,7 @@ import {
$resources,
subscribeResources,
} from "~/shared/nano-states";
-import { type Settings, useClientSettings } from "./shared/client-settings";
+import { type Settings } from "./shared/client-settings";
import { getBuildUrl } from "~/shared/router-utils";
import { useCopyPaste } from "~/shared/copy-paste";
import { BlockingAlerts } from "./features/blocking-alerts";
@@ -51,6 +51,7 @@ import { AiCommandBar } from "./features/ai/ai-command-bar";
import { ProjectSettings } from "./features/seo/project-settings";
import type { UserPlanFeatures } from "~/shared/db/user-plan-features.server";
import { $userPlanFeatures } from "./shared/nano-states";
+import { useNavigatorLayout } from "./features/sidebar-left/navigator";
registerContainers();
@@ -62,13 +63,6 @@ export const links = () => {
];
};
-const useNavigatorLayout = () => {
- // We need to render the detached state only once the setting was actually loaded from local storage.
- // Otherwise we may show the detached state because its the default and then hide it immediately.
- const [clientSettings, _, isLoaded] = useClientSettings();
- return isLoaded ? clientSettings.navigatorLayout : "undocked";
-};
-
const useSetWindowTitle = () => {
const project = useStore($project);
useEffect(() => {
@@ -204,7 +198,7 @@ const NavigatorPanel = ({
navigatorLayout,
}: NavigatorPanelProps) => {
if (navigatorLayout === "docked") {
- return null;
+ return;
}
return (
diff --git a/apps/builder/app/builder/features/sidebar-left/navigator/navigator.tsx b/apps/builder/app/builder/features/sidebar-left/navigator/navigator.tsx
index 446e3a14a5..0cb6822bcb 100644
--- a/apps/builder/app/builder/features/sidebar-left/navigator/navigator.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/navigator/navigator.tsx
@@ -4,13 +4,30 @@ import { Header, CloseButton } from "../header";
import { CssPreview } from "./css-preview";
import { useHotkeys } from "react-hotkeys-hook";
import { emitCommand } from "~/builder/shared/commands";
+import {
+ useClientSettings,
+ type Settings,
+} from "~/builder/shared/client-settings";
+
+export const useNavigatorLayout = (
+ onChange?: (navigatorLayout: Settings["navigatorLayout"]) => void
+) => {
+ // We need to render the detached state only once the setting was actually loaded from local storage.
+ // Otherwise we may show the detached state because its the default and then hide it immediately.
+ const [clientSettings, _, isLoaded] = useClientSettings();
+ const navigatorLayout = isLoaded
+ ? clientSettings.navigatorLayout
+ : "undocked";
+ onChange?.(navigatorLayout);
+ return navigatorLayout;
+};
type NavigatorProps = {
isClosable?: boolean;
onClose?: () => void;
};
-export const Navigator = ({ isClosable, onClose }: NavigatorProps) => {
+export const Navigator = ({ isClosable = true, onClose }: NavigatorProps) => {
const shortcutRef = useHotkeys<HTMLDivElement>(
"enter",
() => emitCommand("editInstanceText"),
diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
index 9852387344..ae1d699c6d 100644
--- a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
@@ -1,12 +1,5 @@
import { useState } from "react";
-import {
- Box,
- SidebarTabs,
- SidebarTabsContent,
- SidebarTabsList,
- SidebarTabsTrigger,
- Tooltip,
-} from "@webstudio-is/design-system";
+import { Box, Tooltip } from "@webstudio-is/design-system";
import { useSubscribe, type Publish } from "~/shared/pubsub";
import { $dragAndDropState } from "~/shared/nano-states";
import { panels } from "./panels";
@@ -18,47 +11,58 @@ import { AiIcon, BugIcon, HelpIcon } from "@webstudio-is/icons";
import { HelpPopover } from "./help-popover";
import { useStore } from "@nanostores/react";
import { $activeSidebarPanel } from "~/builder/shared/nano-states";
+import {
+ SidebarTabs,
+ SidebarTabsContent,
+ SidebarTabsList,
+ SidebarTabsTrigger,
+} from "./sidebar-tabs";
const none = { TabContent: () => null };
+const useActiveTab = () => {
+ const activeTab = useStore($activeSidebarPanel);
+ const [clientSettings] = useClientSettings();
+ let nextTab = activeTab;
+ if (
+ nextTab === "navigator" &&
+ clientSettings.navigatorLayout === "undocked"
+ ) {
+ nextTab = "none";
+ }
+ return [nextTab, $activeSidebarPanel.set] as const;
+};
+
type SidebarLeftProps = {
publish: Publish;
};
export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
+ const [activeTab, setActiveTab] = useActiveTab();
const dragAndDropState = useStore($dragAndDropState);
- const activeTab = useStore($activeSidebarPanel);
- const { TabContent } = activeTab === "none" ? none : panels[activeTab];
const [helpIsOpen, setHelpIsOpen] = useState(false);
const [clientSettings, setClientSetting] = useClientSettings();
+ const { TabContent } = activeTab === "none" ? none : panels[activeTab];
useSubscribe("dragEnd", () => {
- $activeSidebarPanel.set("none");
+ setActiveTab("none");
});
- const enabledPanels = (Object.keys(panels) as Array<TabName>).filter(
- (panel) => {
- switch (panel) {
- case "navigator":
- return clientSettings.navigatorLayout === "docked";
- }
- return true;
- }
- );
-
return (
<Flex grow>
- <SidebarTabs activationMode="manual" value={activeTab}>
+ <SidebarTabs
+ activationMode="manual"
+ value={activeTab}
+ orientation="vertical"
+ >
<SidebarTabsList>
- {enabledPanels.map((tabName: TabName) => (
+ {(Object.keys(panels) as Array<TabName>).map((tabName: TabName) => (
<SidebarTabsTrigger
aria-label={tabName}
key={tabName}
value={tabName}
onClick={() => {
- $activeSidebarPanel.set(
- activeTab !== tabName ? tabName : "none"
- );
+ setActiveTab(activeTab !== tabName ? tabName : "none");
}}
>
{tabName === "none" ? null : panels[tabName].icon}
@@ -131,10 +135,7 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
: "visible",
}}
>
- <TabContent
- publish={publish}
- onSetActiveTab={$activeSidebarPanel.set}
- />
+ <TabContent publish={publish} onSetActiveTab={setActiveTab} />
</SidebarTabsContent>
</SidebarTabs>
</Flex>
diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-tabs.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-tabs.tsx
new file mode 100644
index 0000000000..49ac5af8c7
--- /dev/null
+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-tabs.tsx
@@ -0,0 +1,81 @@
+import {
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ styled,
+ theme,
+} from "@webstudio-is/design-system";
+
+export const SidebarTabs = styled(Tabs, {
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ position: "relative",
+ boxSizing: "border-box",
+});
+
+const triggerFocusRing = {
+ "&::after": {
+ content: '""',
+ position: "absolute",
+ inset: 4,
+ outlineWidth: 2,
+ outlineStyle: "solid",
+ outlineColor: theme.colors.borderFocus,
+ borderRadius: theme.borderRadius[3],
+ },
+};
+
+export const SidebarTabsTrigger = styled(TabsTrigger, {
+ position: "relative",
+ boxSizing: "border-box",
+ flexShrink: 0,
+ display: "flex",
+ size: theme.spacing[15],
+ m: 0,
+ userSelect: "none",
+ outline: "none",
+ alignItems: "center",
+ justifyContent: "center",
+ color: theme.colors.foregroundSubtle,
+ backgroundColor: theme.colors.backgroundPanel,
+ border: "none",
+ "&:focus-visible": triggerFocusRing,
+ "@hover": {
+ "&:hover": {
+ color: theme.colors.foregroundMain,
+ backgroundColor: theme.colors.backgroundHover,
+ },
+ },
+
+ '&[data-state="active"]': {
+ color: theme.colors.foregroundMain,
+ backgroundColor: theme.colors.backgroundHover,
+ },
+});
+
+export const SidebarTabsList = styled(TabsList, {
+ boxSizing: "border-box",
+ flexShrink: 0,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ outline: "none",
+ borderRight: `1px solid ${theme.colors.borderMain}`,
+ flexGrow: 1,
+ backgroundColor: theme.colors.backgroundPanel,
+});
+
+export const SidebarTabsContent = styled(TabsContent, {
+ flexGrow: 1,
+ position: "absolute",
+ top: 0,
+ left: "100%",
+ height: "100%",
+ bc: theme.colors.backgroundPanel,
+ outline: "none",
+ '&[data-state="active"]': {
+ borderRight: `1px solid ${theme.colors.borderMain}`,
+ },
+});
diff --git a/apps/builder/app/builder/shared/client-settings/settings.ts b/apps/builder/app/builder/shared/client-settings/settings.ts
index 2c83b85c35..e5a6daf264 100644
--- a/apps/builder/app/builder/shared/client-settings/settings.ts
+++ b/apps/builder/app/builder/shared/client-settings/settings.ts
@@ -1,19 +1,19 @@
-import { useEffect, useState } from "react";
+import { useEffect } from "react";
import { atom } from "nanostores";
import { useStore } from "@nanostores/react";
import { sentryMessage } from "~/shared/sentry";
import { z } from "zod";
-export const zSettings = z.object({
+const Settings = z.object({
navigatorLayout: z.enum(["docked", "undocked"]).default("undocked"),
isAiMenuOpen: z.boolean().default(true),
isAiCommandBarVisible: z.boolean().default(true),
});
-export type Settings = z.infer<typeof zSettings>;
+export type Settings = z.infer<typeof Settings>;
-const defaultSettings = zSettings.parse({});
+const defaultSettings = Settings.parse({});
const namespace = "__webstudio_user_settings__";
@@ -30,7 +30,7 @@ const read = (): Settings => {
}
try {
- return zSettings.parse(JSON.parse(settingsString));
+ return Settings.parse(JSON.parse(settingsString));
} catch (error) {
if (error instanceof Error) {
sentryMessage({
@@ -66,17 +66,13 @@ export const setSetting = <Name extends keyof Settings>(
write({ ...settings, [name]: value });
};
-const settingsContainer = atom<Settings>(defaultSettings);
+const $settings = atom<Settings>(defaultSettings);
export const useClientSettings = (): [Settings, typeof setSetting, boolean] => {
- const settings = useStore(settingsContainer);
- // We need to know if the settings were loaded from local storage.
- // E.g. to decide if we should wait till the actual setting is loaded or use the default.
- const [isLoaded, setIsLoaded] = useState(false);
+ const settings = useStore($settings);
useEffect(() => {
- settingsContainer.set(read());
- setIsLoaded(true);
+ $settings.set(read());
}, []);
const setSettingValue = <Name extends keyof Settings>(
@@ -86,8 +82,11 @@ export const useClientSettings = (): [Settings, typeof setSetting, boolean] => {
if (settings[name] === value) {
return;
}
- settingsContainer.set({ ...settings, [name]: value });
+ $settings.set({ ...settings, [name]: value });
setSetting(name, value);
};
+
+ const isLoaded = settings !== defaultSettings;
+
return [settings, setSettingValue, isLoaded];
};
diff --git a/packages/design-system/src/components/sidebar-tabs.tsx b/packages/design-system/src/components/sidebar-tabs.tsx
deleted file mode 100644
index bdfd9b956e..0000000000
--- a/packages/design-system/src/components/sidebar-tabs.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-// @todo this should be a local customization in sidebar left, not a reusable component
-import { type ComponentProps, type ElementRef, forwardRef } from "react";
-import { type CSS, styled } from "../stitches.config";
-import * as TabsPrimitive from "@radix-ui/react-tabs";
-import { theme } from "../stitches.config";
-
-export const SidebarTabs = styled(TabsPrimitive.Root, {
- display: "flex",
- flexDirection: "column",
- alignItems: "center",
- position: "relative",
- boxSizing: "border-box",
-});
-
-export const SidebarTabsTrigger = styled(TabsPrimitive.Trigger, {
- boxSizing: "border-box",
- flexShrink: 0,
- display: "flex",
- size: theme.spacing[15],
- m: 0,
- userSelect: "none",
- outline: "none",
- alignItems: "center",
- justifyContent: "center",
- color: theme.colors.slate11,
- border: "1px solid transparent",
- backgroundColor: "transparent",
-
- "@hover": {
- "&:hover": {
- backgroundColor: theme.colors.slateA3,
- color: theme.colors.hiContrast,
- },
- },
-
- '&[data-state="active"]': {
- color: theme.colors.hiContrast,
- backgroundColor: theme.colors.slateA4,
- borderColor: theme.colors.slate6,
- },
-});
-
-const StyledTabsList = styled(TabsPrimitive.List, {
- boxSizing: "border-box",
- flexShrink: 0,
- display: "flex",
- flexDirection: "column",
- alignItems: "center",
- outline: "none",
- borderRight: `1px solid ${theme.colors.borderMain}`,
- flexGrow: 1,
-});
-
-type TabsListPrimitiveProps = ComponentProps<typeof TabsPrimitive.List>;
-type TabsListProps = TabsListPrimitiveProps & { css?: CSS };
-
-export const SidebarTabsList = forwardRef<
- ElementRef<typeof StyledTabsList>,
- TabsListProps
->((props, forwardedRef) => (
- <>
- <StyledTabsList {...props} ref={forwardedRef} />
- </>
-));
-
-SidebarTabsList.displayName = "SidebarTabsList";
-
-export const SidebarTabsContent = styled(TabsPrimitive.Content, {
- flexGrow: 1,
- position: "absolute",
- top: 0,
- left: "100%",
- height: "100%",
- bc: theme.colors.backgroundPanel,
- outline: "none",
- '&[data-state="active"]': {
- borderRight: `1px solid ${theme.colors.borderMain}`,
- },
-});
diff --git a/packages/design-system/src/components/tabs.tsx b/packages/design-system/src/components/tabs.tsx
deleted file mode 100644
index ba9834ab2a..0000000000
--- a/packages/design-system/src/components/tabs.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import { type ComponentProps, type ElementRef, forwardRef } from "react";
-import { styled, type CSS } from "../stitches.config";
-import * as TabsPrimitive from "@radix-ui/react-tabs";
-import { DeprecatedText2 } from "./__DEPRECATED__/text2";
-import { theme } from "../stitches.config";
-
-export const Tabs = styled(TabsPrimitive.Root, {
- display: "flex",
- '&[data-orientation="horizontal"]': {
- flexDirection: "column",
- },
-});
-
-export const TabsTrigger = styled(TabsPrimitive.Trigger, {
- flexShrink: 0,
- height: theme.spacing[17],
- display: "inline-flex",
- lineHeight: 1,
- fontFamily: "inherit",
- WebkitFontSmoothing: "antialiased",
- fontSize: theme.deprecatedFontSize[3],
- px: theme.spacing[5],
- userSelect: "none",
- outline: "none",
- alignItems: "center",
- justifyContent: "center",
- border: "none",
- backgroundColor: "transparent",
- ["&:first-child"]: {
- paddingLeft: theme.spacing[9],
- },
- [`& > ${DeprecatedText2}`]: {
- color: theme.colors.gray9,
- fontSize: theme.deprecatedFontSize[3],
- fontWeight: "500",
- },
- "@hover": {
- "&:hover": {
- color: theme.colors.hiContrast,
- },
- },
-
- '&[data-state="active"]': {
- [`& > ${DeprecatedText2}`]: {
- color: theme.colors.hiContrast,
- },
- },
-
- '&[data-orientation="vertical"]': {
- justifyContent: "flex-start",
- },
-});
-
-const StyledTabsList = styled(TabsPrimitive.List, {
- flexShrink: 0,
- display: "flex",
- "&:focus": {
- outline: "none",
- },
- '&[data-orientation="vertical"]': {
- flexDirection: "column",
- },
-});
-
-type TabsListPrimitiveProps = ComponentProps<typeof TabsPrimitive.List>;
-type TabsListProps = TabsListPrimitiveProps & { css?: CSS };
-
-export const TabsList = forwardRef<
- ElementRef<typeof StyledTabsList>,
- TabsListProps
->((props, forwardedRef) => (
- <>
- <StyledTabsList {...props} ref={forwardedRef} />
- </>
-));
-
-TabsList.displayName = "TabsList";
-
-export const TabsContent = styled(TabsPrimitive.Content, {
- flexGrow: 1,
- "&:focus": {
- outline: "none",
- },
- '&[data-state="inactive"]': {
- display: "none",
- },
-});
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index d4f327c2fe..79fedbdbd7 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -51,13 +51,7 @@ export { AccessibleIcon } from "@radix-ui/react-accessible-icon";
export * from "./components/toggle-group";
export * from "./components/progress-radial";
export { SearchField } from "./components/search-field";
-export { Tabs, TabsContent, TabsList, TabsTrigger } from "./components/tabs";
-export {
- SidebarTabs,
- SidebarTabsContent,
- SidebarTabsList,
- SidebarTabsTrigger,
-} from "./components/sidebar-tabs";
+export { Tabs, TabsContent, TabsList, TabsTrigger } from "@radix-ui/react-tabs";
export { Card } from "./components/card";
export {
Tooltip,