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.

feat: Hide UI (#5775)

Oleg Isonen6b64477a8374
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsx
index bfc5254448..5d5422f7a2 100644
--- a/apps/builder/app/builder/builder.tsx
+++ b/apps/builder/app/builder/builder.tsx
@@ -50,6 +50,7 @@ import {
$activeSidebarPanel,
$dataLoadingState,
$isCloneDialogOpen,
+ $isUiHidden,
$loadingState,
} from "./shared/nano-states";
import { $pages } from "~/shared/sync/data-stores";
@@ -146,20 +147,35 @@ const Main = ({ children, css }: { children: ReactNode; css?: CSS }) => (
type ChromeWrapperProps = {
children: Array<JSX.Element | null | false>;
isPreviewMode: boolean;
+ isFooterVisible: boolean;
+ isUiHidden: boolean;
navigatorLayout: Settings["navigatorLayout"];
};
const getChromeLayout = ({
isPreviewMode,
+ isUiHidden,
navigatorLayout,
activeSidebarPanel,
leftSidebarWidth,
}: {
isPreviewMode: boolean;
+ isUiHidden: boolean;
navigatorLayout: Settings["navigatorLayout"];
activeSidebarPanel?: SidebarPanelName;
leftSidebarWidth: number;
}) => {
+ if (isUiHidden) {
+ return {
+ gridTemplateColumns: "1fr",
+ gridTemplateAreas: `
+ "header"
+ "main"
+ "footer"
+ `,
+ };
+ }
+
if (isPreviewMode) {
return {
gridTemplateColumns: "auto 1fr",
@@ -197,6 +213,8 @@ const defaultSidebarWidth = Number.parseFloat(rawTheme.spacing[30]);
const ChromeWrapper = ({
children,
isPreviewMode,
+ isFooterVisible,
+ isUiHidden,
navigatorLayout,
}: ChromeWrapperProps) => {
const activeSidebarPanel = useStore($activeSidebarPanel);
@@ -209,6 +227,7 @@ const ChromeWrapper = ({
const gridLayout = getChromeLayout({
isPreviewMode,
+ isUiHidden,
navigatorLayout,
activeSidebarPanel,
leftSidebarWidth,
@@ -217,10 +236,13 @@ const ChromeWrapper = ({
return (
<Grid
css={{
+ position: "relative",
height: "100vh",
overflow: "hidden",
display: "grid",
- gridTemplateRows: "auto 1fr auto",
+ gridTemplateRows: `${isUiHidden ? "0" : "auto"} 1fr ${
+ isFooterVisible ? "auto" : "0"
+ }`,
...gridLayout,
}}
>
@@ -317,6 +339,7 @@ export const Builder = (props: BuilderProps) => {
usePreventUnload();
const isCloneDialogOpen = useStore($isCloneDialogOpen);
const isPreviewMode = useStore($isPreviewMode);
+ const isUiHidden = useStore($isUiHidden);
const isDesignMode = useStore($isDesignMode);
const isContentMode = useStore($isContentMode);
@@ -378,6 +401,7 @@ export const Builder = (props: BuilderProps) => {
const canvasUrl = getCanvasUrl();
const inertHandlers = useInertHandlers();
+ const isFooterVisible = isPreviewMode === false && isUiHidden === false;
// Show loading screen if project isn't ready yet
if (!project || dataLoadingState !== "loaded") {
@@ -398,11 +422,14 @@ export const Builder = (props: BuilderProps) => {
>
<ChromeWrapper
isPreviewMode={isPreviewMode}
+ isFooterVisible={isFooterVisible}
+ isUiHidden={isUiHidden}
navigatorLayout={navigatorLayout}
>
<Box
data-dialog-boundary
css={{
+ display: isUiHidden ? "none" : "block",
gridArea: "sidebar / sidebar / main / inspector",
pointerEvents: "none",
}}
@@ -427,6 +454,7 @@ export const Builder = (props: BuilderProps) => {
<SidePanel
gridArea="sidebar"
css={{
+ display: isUiHidden ? "none" : "flex",
order: navigatorLayout === "docked" ? 1 : undefined,
}}
>
@@ -437,6 +465,7 @@ export const Builder = (props: BuilderProps) => {
gridArea="inspector"
isPreviewMode={isPreviewMode}
css={{
+ display: isUiHidden || isPreviewMode ? "none" : "flex",
overflow: "hidden",
// Drawing border this way to ensure content still has full width, avoid subpixels and give layout round numbers
"&::after": {
@@ -459,6 +488,7 @@ export const Builder = (props: BuilderProps) => {
<Topbar
project={project}
css={{ gridArea: "header" }}
+ isUiHidden={isUiHidden}
loading={
<LoadingBackground
// Looks nicer when topbar is already visible earlier, so user has more sense of progress.
@@ -474,7 +504,7 @@ export const Builder = (props: BuilderProps) => {
<Main css={{ pointerEvents: "none" }}>
<TextToolbar />
</Main>
- {isPreviewMode === false && <Footer />}
+ {isFooterVisible && <Footer />}
{project ? (
<CloneProjectDialog
isOpen={isCloneDialogOpen}
diff --git a/apps/builder/app/builder/features/address-bar.stories.tsx b/apps/builder/app/builder/features/address-bar.stories.tsx
index a6f23802c0..e0dae9ffca 100644
--- a/apps/builder/app/builder/features/address-bar.stories.tsx
+++ b/apps/builder/app/builder/features/address-bar.stories.tsx
@@ -3,7 +3,7 @@ import type { Meta, StoryFn } from "@storybook/react";
import { StorySection, Text } from "@webstudio-is/design-system";
import { ToolbarButton } from "@webstudio-is/design-system";
import { WebstudioIcon } from "@webstudio-is/icons";
-import { TopbarLayout } from "~/builder/shared/topbar-layout";
+import { TopbarLayout } from "~/builder/shared/topbar";
import { AddressBarPopover } from "./address-bar";
import { $dataSources, $pages } from "~/shared/sync/data-stores";
import { registerContainers } from "~/shared/sync/sync-stores";
diff --git a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx
index c2ad54a3e4..a7214f1790 100644
--- a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx
+++ b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.tsx
@@ -88,6 +88,7 @@ export const KeyboardShortcutsDialog = () => {
General: [
"cancelCurrentDrag",
"openCommandPanel",
+ "toggleUiHidden",
"openPublishDialog",
"openExportDialog",
"openKeyboardShortcuts",
diff --git a/apps/builder/app/builder/features/menu/menu.tsx b/apps/builder/app/builder/features/menu/menu.tsx
index 088c1b738a..441ab4028a 100644
--- a/apps/builder/app/builder/features/menu/menu.tsx
+++ b/apps/builder/app/builder/features/menu/menu.tsx
@@ -17,6 +17,7 @@ import {
import {
$isCloneDialogOpen,
$isShareDialogOpen,
+ $isUiHidden,
$publishDialog,
$remoteDialog,
} from "~/builder/shared/nano-states";
@@ -37,11 +38,21 @@ import { help } from "~/shared/help";
const ViewMenuItem = () => {
const navigatorLayout = getSetting("navigatorLayout");
+ const isUiHidden = useStore($isUiHidden);
return (
<DropdownMenuSub>
<DropdownMenuSubTrigger>View</DropdownMenuSubTrigger>
<DropdownMenuSubContent width="regular">
+ <DropdownMenuCheckboxItem
+ checked={isUiHidden}
+ onSelect={() => emitCommand("toggleUiHidden")}
+ >
+ Hide UI
+ <DropdownMenuItemRightSlot>
+ <Kbd value={["meta", "\\"]} />
+ </DropdownMenuItemRightSlot>
+ </DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
checked={navigatorLayout === "undocked"}
onSelect={() => {
diff --git a/apps/builder/app/builder/shared/commands.ts b/apps/builder/app/builder/shared/commands.ts
index bd6a682718..ae92938a70 100644
--- a/apps/builder/app/builder/shared/commands.ts
+++ b/apps/builder/app/builder/shared/commands.ts
@@ -36,6 +36,7 @@ import { serverSyncStore } from "~/shared/sync/sync-stores";
import { $publisher } from "~/shared/pubsub";
import {
$activeInspectorPanel,
+ $isUiHidden,
$publishDialog,
setActiveSidebarPanel,
toggleActiveSidebarPanel,
@@ -142,6 +143,15 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
toggleBuilderMode("preview");
},
},
+ {
+ name: "toggleUiHidden",
+ description: "Hide UI",
+ category: "General",
+ defaultHotkeys: ["meta+\\", "ctrl+\\"],
+ handler: () => {
+ $isUiHidden.set($isUiHidden.get() === false);
+ },
+ },
{
name: "toggleDesignMode",
description: "Toggle design mode",
diff --git a/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts b/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts
index 00882ac30f..bec943d527 100644
--- a/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts
+++ b/apps/builder/app/builder/shared/css-editor/parse-style-input.test.ts
@@ -65,17 +65,22 @@ describe("parseStyleInput", () => {
[
"transition-timing-function",
{
- type: "function",
- name: "cubic-bezier",
- args: {
- type: "layers",
- value: [
- { type: "unit", value: 0.36, unit: "number" },
- { type: "unit", value: 0, unit: "number" },
- { type: "unit", value: 0.66, unit: "number" },
- { type: "unit", value: -0.56, unit: "number" },
- ],
- },
+ type: "layers",
+ value: [
+ {
+ type: "function",
+ name: "cubic-bezier",
+ args: {
+ type: "layers",
+ value: [
+ { type: "unit", value: 0.36, unit: "number" },
+ { type: "unit", value: 0, unit: "number" },
+ { type: "unit", value: 0.66, unit: "number" },
+ { type: "unit", value: -0.56, unit: "number" },
+ ],
+ },
+ },
+ ],
},
],
])
@@ -91,15 +96,20 @@ describe("parseStyleInput", () => {
[
"transition-timing-function",
{
- type: "function",
- name: "steps",
- args: {
- type: "layers",
- value: [
- { type: "unit", value: 4, unit: "number" },
- { type: "keyword", value: "jump-start" },
- ],
- },
+ type: "layers",
+ value: [
+ {
+ type: "function",
+ name: "steps",
+ args: {
+ type: "layers",
+ value: [
+ { type: "unit", value: 4, unit: "number" },
+ { type: "keyword", value: "jump-start" },
+ ],
+ },
+ },
+ ],
},
],
])
@@ -114,7 +124,10 @@ describe("parseStyleInput", () => {
new Map([
[
"transition-timing-function",
- { type: "unparsed", value: "linear(0 0%,1 100%)" },
+ {
+ type: "layers",
+ value: [{ type: "unparsed", value: "linear(0 0%,1 100%)" }],
+ },
],
])
);
diff --git a/apps/builder/app/builder/shared/nano-states.ts b/apps/builder/app/builder/shared/nano-states.ts
index ea7395e788..d1a9f42e68 100644
--- a/apps/builder/app/builder/shared/nano-states.ts
+++ b/apps/builder/app/builder/shared/nano-states.ts
@@ -15,6 +15,8 @@ export const $canvasWidth = atom<number | undefined>();
export const $isCloneDialogOpen = atom<boolean>(false);
+export const $isUiHidden = atom<boolean>(false);
+
export const $canvasRect = atom<DOMRect | undefined>();
export const $workspaceRect = atom<DOMRect | undefined>();
diff --git a/apps/builder/app/builder/shared/topbar-layout.tsx b/apps/builder/app/builder/shared/topbar-layout.tsx
deleted file mode 100644
index bd41c278a0..0000000000
--- a/apps/builder/app/builder/shared/topbar-layout.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-import type { ReactNode } from "react";
-import {
- theme,
- css,
- Flex,
- Toolbar,
- ToolbarToggleGroup,
- type CSS,
-} from "@webstudio-is/design-system";
-
-const topbarContainerStyle = css({
- position: "relative",
- display: "flex",
- justifyContent: "space-between",
- background: theme.colors.backgroundTopbar,
- height: theme.spacing[15],
- paddingRight: theme.panel.paddingInline,
- color: theme.colors.foregroundContrastMain,
-});
-
-type TopbarLayoutProps = {
- menu: ReactNode;
- left?: ReactNode;
- center?: ReactNode;
- right?: ReactNode;
- loading?: ReactNode;
- css?: CSS;
-};
-
-export const TopbarLayout = ({
- menu,
- left,
- center,
- right,
- loading,
- css,
-}: TopbarLayoutProps) => (
- <nav className={topbarContainerStyle({ css })}>
- <Flex css={{ flexBasis: "20%" }}>
- <Flex grow={false} shrink={false}>
- {menu}
- </Flex>
- {left && <Flex align="center">{left}</Flex>}
- </Flex>
- <Flex justify="center">{center}</Flex>
- <Toolbar>
- <ToolbarToggleGroup
- type="single"
- css={{
- isolation: "isolate",
- justifyContent: "flex-end",
- gap: theme.spacing[5],
- flexShrink: 0,
- }}
- >
- {right}
- </ToolbarToggleGroup>
- </Toolbar>
- {loading}
- </nav>
-);
diff --git a/apps/builder/app/builder/shared/topbar-layout.stories.tsx b/apps/builder/app/builder/shared/topbar.stories.tsx
similarity index 98%
rename from apps/builder/app/builder/shared/topbar-layout.stories.tsx
rename to apps/builder/app/builder/shared/topbar.stories.tsx
index 4fd8f95d6c..bd0d7305fd 100644
--- a/apps/builder/app/builder/shared/topbar-layout.stories.tsx
+++ b/apps/builder/app/builder/shared/topbar.stories.tsx
@@ -19,7 +19,7 @@ import { $syncStatus } from "@webstudio-is/sync-client";
import { $authPermit } from "~/shared/nano-states";
import { SyncStatus } from "~/builder/features/sync-status";
import { ViewMode } from "~/builder/features/view-mode";
-import { TopbarLayout } from "./topbar-layout";
+import { TopbarLayout } from "./topbar";
export default {
title: "Topbar layout",
diff --git a/apps/builder/app/builder/shared/topbar.tsx b/apps/builder/app/builder/shared/topbar.tsx
index 29df9a2dae..ac31cbea10 100644
--- a/apps/builder/app/builder/shared/topbar.tsx
+++ b/apps/builder/app/builder/shared/topbar.tsx
@@ -1,8 +1,13 @@
import { useStore } from "@nanostores/react";
import {
+ Box,
+ Flex,
theme,
ToolbarButton,
+ Toolbar,
+ ToolbarToggleGroup,
Text,
+ css,
type CSS,
Tooltip,
Kbd,
@@ -19,14 +24,88 @@ import { BreakpointsContainer } from "~/builder/features/breakpoints";
import { ViewMode } from "~/builder/features/view-mode";
import { AddressBarPopover } from "~/builder/features/address-bar";
import { toggleActiveSidebarPanel } from "~/builder/shared/nano-states";
-import type { ReactNode } from "react";
+import {
+ useEffect,
+ useState,
+ type ComponentProps,
+ type ReactNode,
+} from "react";
+import { useDebounce } from "use-debounce";
import { CloneButton } from "~/builder/features/clone";
import { $selectedPage } from "~/shared/nano-states";
import { BuilderModeDropDown } from "~/builder/features/builder-mode";
import { SafeModeButton } from "~/builder/features/safe-mode";
import { NotificationPopover } from "~/shared/notifications/notification-popover";
import { $notifications } from "~/shared/notifications/subscription";
-import { TopbarLayout } from "./topbar-layout";
+
+const topbarContainerStyle = css({
+ position: "relative",
+ display: "flex",
+ justifyContent: "space-between",
+ background: theme.colors.backgroundTopbar,
+ height: theme.spacing[15],
+ paddingRight: theme.panel.paddingInline,
+ color: theme.colors.foregroundContrastMain,
+});
+
+type TopbarLayoutProps = Omit<ComponentProps<"nav">, "className"> & {
+ menu: ReactNode;
+ left?: ReactNode;
+ center?: ReactNode;
+ right?: ReactNode;
+ loading?: ReactNode;
+ css?: CSS;
+};
+
+export const TopbarLayout = ({
+ menu,
+ left,
+ center,
+ right,
+ loading,
+ css,
+ ...navProps
+}: TopbarLayoutProps) => (
+ <nav {...navProps} className={topbarContainerStyle({ css })}>
+ <Flex css={{ flexBasis: "20%" }}>
+ <Flex grow={false} shrink={false}>
+ {menu}
+ </Flex>
+ {left && <Flex align="center">{left}</Flex>}
+ </Flex>
+ <Flex justify="center">{center}</Flex>
+ <Toolbar>
+ <ToolbarToggleGroup
+ type="single"
+ css={{
+ isolation: "isolate",
+ justifyContent: "flex-end",
+ gap: theme.spacing[5],
+ flexShrink: 0,
+ }}
+ >
+ {right}
+ </ToolbarToggleGroup>
+ </Toolbar>
+ {loading}
+ </nav>
+);
+
+const floatingLayerSelector = "[data-radix-popper-content-wrapper]";
+
+const TopbarRevealTrigger = ({ onReveal }: { onReveal: () => void }) => (
+ <Box
+ onPointerEnter={onReveal}
+ css={{
+ position: "absolute",
+ top: 0,
+ left: 0,
+ right: 0,
+ height: 5,
+ zIndex: 1,
+ }}
+ />
+);
const PagesButton = () => {
const page = useStore($selectedPage);
@@ -64,41 +143,104 @@ type TopbarProps = {
project: Project;
loading: ReactNode;
css: CSS;
+ isUiHidden: boolean;
};
-export const Topbar = ({ project, css, loading }: TopbarProps) => {
+export const Topbar = ({ project, css, loading, isUiHidden }: TopbarProps) => {
const pages = useStore($pages);
const notifications = useStore($notifications);
+ const [isRevealed, setIsRevealed] = useState(false);
+ const [isPointerInside, setIsPointerInside] = useState(false);
+ const [wantsHidden, setWantsHidden] = useState(false);
+ const [debouncedWantsHidden] = useDebounce(wantsHidden, 200);
+
+ useEffect(() => {
+ if (isUiHidden === false) {
+ setWantsHidden(false);
+ setIsPointerInside(false);
+ setIsRevealed(false);
+ }
+ }, [isUiHidden]);
+
+ useEffect(() => {
+ if (debouncedWantsHidden && isPointerInside === false) {
+ if (document.querySelector(floatingLayerSelector)) {
+ setWantsHidden(false);
+ return;
+ }
+ setIsRevealed(false);
+ setWantsHidden(false);
+ }
+ }, [debouncedWantsHidden, isPointerInside]);
+
+ const topbarCss: CSS = isUiHidden
+ ? {
+ position: "absolute",
+ zIndex: 1,
+ top: 0,
+ left: 0,
+ right: 0,
+ transform: isRevealed ? "translateY(0)" : "translateY(-100%)",
+ visibility: isRevealed ? "visible" : "hidden",
+ pointerEvents: isRevealed ? "auto" : "none",
+ transition: "transform 200ms ease-out, visibility 0ms linear 200ms",
+ ...(isRevealed ? { transition: "transform 200ms ease-out" } : {}),
+ }
+ : css;
+ const pointerHandlers = isUiHidden
+ ? {
+ onPointerEnter: () => {
+ setIsPointerInside(true);
+ setWantsHidden(false);
+ },
+ onPointerLeave: () => {
+ setIsPointerInside(false);
+ setWantsHidden(true);
+ },
+ }
+ : undefined;
+
return (
- <TopbarLayout
- css={css}
- menu={<Menu />}
- left={
- pages ? (
+ <>
+ {isUiHidden && isRevealed === false && (
+ <TopbarRevealTrigger
+ onReveal={() => {
+ setWantsHidden(false);
+ setIsRevealed(true);
+ }}
+ />
+ )}
+ <TopbarLayout
+ css={topbarCss}
+ {...pointerHandlers}
+ menu={<Menu />}
+ left={
+ pages ? (
+ <>
+ <PagesButton />
+ <AddressBarPopover />
+ </>
+ ) : undefined
+ }
+ center={<BreakpointsContainer />}
+ right={
<>
- <PagesButton />
- <AddressBarPopover />
+ {notifications.length > 0 && (
+ <NotificationPopover
+ renderTrigger={(props) => <ToolbarButton {...props} />}
+ />
+ )}
+ <SafeModeButton />
+ <ViewMode />
+ <SyncStatus />
+ <BuilderModeDropDown />
+ <ShareButton projectId={project.id} />
+ <PublishButton projectId={project.id} />
+ <CloneButton />
</>
- ) : undefined
- }
- center={<BreakpointsContainer />}
- right={
- <>
- {notifications.length > 0 && (
- <NotificationPopover
- renderTrigger={(props) => <ToolbarButton {...props} />}
- />
- )}
- <SafeModeButton />
- <ViewMode />
- <SyncStatus />
- <BuilderModeDropDown />
- <ShareButton projectId={project.id} />
- <PublishButton projectId={project.id} />
- <CloneButton />
- </>
- }
- loading={loading}
- />
+ }
+ loading={loading}
+ />
+ </>
);
};