Skip to content

Commit 974f613

Browse files
authored
feat: Plus button hover polygon and menu icons (#4487)
## Description ref #3994 Menu Icons are now from meta <img width="229" alt="image" src="https://github.com/user-attachments/assets/5e6e0fcd-6c1c-4eab-b493-94d70f2162f7"> Red is hover polygon (used to not lost hover) (small quad before was not enough) <img width="404" alt="image" src="https://github.com/user-attachments/assets/0395d0db-3ec8-493f-b1b8-b40e117026e6"> <img width="383" alt="image" src="https://github.com/user-attachments/assets/36544e8d-bda5-4a06-bfe4-a92d93247333"> <img width="417" alt="image" src="https://github.com/user-attachments/assets/6ce49c43-cc37-4ba9-94cd-bb0bb6930253"> <img width="372" alt="image" src="https://github.com/user-attachments/assets/8771b051-09a5-43fe-9903-5d8e60dc72a3"> ## 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: 0000) - [ ] 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
1 parent d22dbd0 commit 974f613

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

apps/builder/app/builder/features/workspace/canvas-tools/outline/editable-block-instance-outline.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
$editableBlockChildOutline,
44
$instances,
55
$isContentMode,
6+
$registeredComponentMetas,
67
type EditableBlockChildOutline,
78
} from "~/shared/nano-states";
89
import {
@@ -20,11 +21,13 @@ import {
2021
toast,
2122
Kbd,
2223
Text,
24+
iconButtonSize,
2325
} from "@webstudio-is/design-system";
2426
import { EditableBlockChildAddButtonOutline } from "./outline";
2527
import { applyScale } from "./apply-scale";
2628
import { $scale } from "~/builder/shared/nano-states";
27-
import { BoxIcon, PlusIcon } from "@webstudio-is/icons";
29+
import { PlusIcon } from "@webstudio-is/icons";
30+
import { BoxIcon } from "@webstudio-is/icons/svg";
2831
import { useRef, useState } from "react";
2932
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
3033
import type { DroppableTarget, InstanceSelector } from "~/shared/tree-utils";
@@ -42,6 +45,7 @@ import {
4245
updateWebstudioData,
4346
} from "~/shared/instance-utils";
4447
import { shallowEqual } from "shallow-equal";
48+
import { MetaIcon } from "~/builder/shared/meta-icon";
4549

4650
export const findEditableBlockSelector = (
4751
anchor: InstanceSelector,
@@ -182,6 +186,7 @@ const TemplatesMenu = ({
182186
anchor: InstanceSelector;
183187
}) => {
184188
const instances = useStore($instances);
189+
const metas = useStore($registeredComponentMetas);
185190

186191
const optionPointerDownTime = useRef(0);
187192
const isMenuOpenedWithOption = useRef(false);
@@ -197,7 +202,7 @@ const TemplatesMenu = ({
197202

198203
const menuItems = templates?.map(([template, templateSelector]) => ({
199204
id: template.id,
200-
icon: <BoxIcon />,
205+
icon: <MetaIcon icon={metas.get(template.component)?.icon ?? BoxIcon} />,
201206
title: template.label ?? template.component,
202207
value: templateSelector,
203208
}));
@@ -352,8 +357,8 @@ export const EditableBlockChildHoveredInstanceOutline = () => {
352357
<Flex
353358
css={{
354359
width: "min-content",
355-
height: "min-content",
356360
pointerEvents: isMenuOpen ? "none" : "all",
361+
clipPath: `polygon(0% 0%, 100% 0%, 100% 100%, 0% ${iconButtonSize})`,
357362
}}
358363
onMouseEnter={() => {
359364
clearTimeout(timeoutRef.current);
@@ -385,20 +390,14 @@ export const EditableBlockChildHoveredInstanceOutline = () => {
385390
<IconButton
386391
variant={"local"}
387392
css={{
393+
mr: theme.spacing[4],
388394
borderStyle: "solid",
389395
borderColor: `oklch(from ${theme.colors.backgroundPrimary} l c h / 0.7)`,
390396
}}
391397
>
392398
<PlusIcon />
393399
</IconButton>
394400
</TemplatesMenu>
395-
<Box
396-
css={{
397-
width: theme.spacing[4],
398-
// For easier hover
399-
height: theme.spacing[12],
400-
}}
401-
></Box>
402401
</Flex>
403402
</EditableBlockChildAddButtonOutline>
404403
);

apps/builder/app/builder/features/workspace/canvas-tools/outline/outline.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,11 @@ export const EditableBlockChildAddButtonOutline = ({
8989
>
9090
<div
9191
style={{
92-
height: 0,
9392
width: 0,
9493
display: "grid",
9594

96-
alignContent: "start",
95+
alignContent: "stretch",
9796
justifyContent: "end",
98-
99-
justifySelf: "start",
100-
alignSelf: "start",
10197
}}
10298
>
10399
{children}

packages/design-system/src/components/icon-button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const disabledVariantStyles = {
2020
},
2121
};
2222

23+
export const iconButtonSize = theme.spacing[11];
24+
2325
export const IconButton = styled("button", {
2426
// reset styles
2527
boxSizing: "border-box",
@@ -33,8 +35,8 @@ export const IconButton = styled("button", {
3335
alignItems: "center",
3436
// prevent shrinking inside flex box
3537
flexShrink: 0,
36-
width: theme.spacing[11],
37-
height: theme.spacing[11],
38+
width: iconButtonSize,
39+
height: iconButtonSize,
3840
borderRadius: theme.borderRadius[3],
3941
minWidth: 0,
4042
outline: "none",

0 commit comments

Comments
 (0)