-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Builder mode switch menu (#4423)
## Description ref #3994 <img width="256" alt="image" src="https://github.com/user-attachments/assets/ee37fe7d-41ed-40f3-909f-a29d12d07e4b"> ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
- Loading branch information
Showing
16 changed files
with
258 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
apps/builder/app/builder/features/topbar/builder-mode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { useStore } from "@nanostores/react"; | ||
import { EditIcon, PaintBrushIcon, PlayIcon } from "@webstudio-is/icons"; | ||
import { | ||
Box, | ||
DropdownMenuItemRightSlot, | ||
DropdownMenuRadioGroup, | ||
DropdownMenuRadioItem, | ||
DropdownMenuSeparator, | ||
Flex, | ||
Kbd, | ||
menuItemCss, | ||
styled, | ||
theme, | ||
ToolbarToggleItem, | ||
} from "@webstudio-is/design-system"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuPortal, | ||
DropdownMenuTrigger, | ||
} from "@webstudio-is/design-system"; | ||
import { | ||
$builderMode, | ||
$isContentModeAllowed, | ||
$isDesignModeAllowed, | ||
isBuilderMode, | ||
setBuilderMode, | ||
type BuilderMode, | ||
} from "~/shared/nano-states"; | ||
import { useState } from "react"; | ||
|
||
const StyledMenuItem = styled(DropdownMenuRadioItem, { | ||
"&:where([data-state='checked'])": { | ||
backgroundColor: `oklch(from ${theme.colors.backgroundItemMenuItemHover} l c h / 0.3)`, | ||
}, | ||
}); | ||
|
||
export const BuilderModeDropDown = () => { | ||
const builderMode = useStore($builderMode); | ||
const isContentModeAllowed = useStore($isContentModeAllowed); | ||
const isDesignModeAllowed = useStore($isDesignModeAllowed); | ||
|
||
const menuItems = { | ||
preview: { | ||
icon: <PlayIcon />, | ||
description: "View the page as it will appear to users", | ||
title: "Preview", | ||
shortcut: ["cmd", "shift", "p"], | ||
enabled: true, | ||
}, | ||
design: { | ||
icon: <PaintBrushIcon />, | ||
description: "Edit components, styles, and properties", | ||
title: "Design", | ||
shortcut: ["cmd", "shift", "d"], | ||
enabled: isDesignModeAllowed, | ||
}, | ||
content: { | ||
icon: <EditIcon />, | ||
description: "Modify the page content", | ||
title: "Build", | ||
shortcut: ["cmd", "shift", "b"], | ||
enabled: isContentModeAllowed, | ||
}, | ||
} as const; | ||
|
||
const [activeMode, setActiveMode] = useState<BuilderMode | undefined>(); | ||
|
||
const handleFocus = (mode: BuilderMode) => () => { | ||
setActiveMode(mode); | ||
}; | ||
|
||
const handleBlur = () => { | ||
setActiveMode(undefined); | ||
}; | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<ToolbarToggleItem | ||
value="preview" | ||
aria-label="Toggle Preview" | ||
variant="preview" | ||
tabIndex={0} | ||
> | ||
{menuItems[builderMode].icon} | ||
</ToolbarToggleItem> | ||
</DropdownMenuTrigger> | ||
|
||
<DropdownMenuPortal> | ||
<DropdownMenuContent | ||
sideOffset={4} | ||
collisionPadding={16} | ||
side="bottom" | ||
loop | ||
> | ||
<DropdownMenuRadioGroup | ||
value={builderMode} | ||
onValueChange={(value) => { | ||
if (isBuilderMode(value)) { | ||
setBuilderMode(value); | ||
} | ||
}} | ||
> | ||
{Object.entries(menuItems) | ||
.filter(([_, { enabled }]) => enabled) | ||
.map(([mode, { icon, title, shortcut }]) => ( | ||
<StyledMenuItem | ||
key={mode} | ||
value={mode} | ||
onFocus={handleFocus(mode as BuilderMode)} | ||
onBlur={handleBlur} | ||
> | ||
<Flex | ||
css={{ py: theme.spacing[4], px: theme.spacing[5] }} | ||
gap={2} | ||
> | ||
{icon} | ||
<Box>{title}</Box> | ||
</Flex> | ||
<DropdownMenuItemRightSlot> | ||
<Kbd value={shortcut} /> | ||
</DropdownMenuItemRightSlot> | ||
</StyledMenuItem> | ||
))} | ||
</DropdownMenuRadioGroup> | ||
<DropdownMenuSeparator /> | ||
|
||
<div className={menuItemCss({ hint: true })}> | ||
<Box css={{ width: theme.spacing[25] }}> | ||
{menuItems[activeMode ?? builderMode].description} | ||
</Box> | ||
</div> | ||
</DropdownMenuContent> | ||
</DropdownMenuPortal> | ||
</DropdownMenu> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.