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
hovered/selected states
Oleg Isonen15f831b29720
diff --git a/app/canvas/shared/use-outline.tsx b/app/canvas/shared/use-outline.tsxindex c8c037f7cd..5212fbb8bf 100644--- a/app/canvas/shared/use-outline.tsx+++ b/app/canvas/shared/use-outline.tsx@@ -7,13 +7,19 @@ import { useHoveredElement, useSelectedElement } from "./nano-values";import { styled, darkTheme } from "~/shared/design-system";import { useOnRender } from "./use-on-render";-const useElement = (currentInstance: Instance) => {+const useElement = (+ currentInstance: Instance+): { element: HTMLElement; type: "selected" | "hovered" } | undefined => {const [selectedElement] = useSelectedElement();const [hoveredElement] = useHoveredElement();return useMemo(() => {- if (selectedElement?.id === currentInstance.id) return selectedElement;- if (hoveredElement?.id === currentInstance.id) return hoveredElement;+ if (selectedElement?.id === currentInstance.id) {+ return { element: selectedElement, type: "selected" };+ }+ if (hoveredElement?.id === currentInstance.id) {+ return { element: hoveredElement, type: "hovered" };+ }}, [currentInstance, hoveredElement, selectedElement]);};@@ -30,46 +36,70 @@ const useStyle = (element?: HTMLElement) => {useOnRender(handleUpdate);- return useMemo(() => {- if (element === undefined) return;+ return useMemo(+ () => {+ if (element === undefined) return;- const rect = getBoundingClientRect(element);+ const rect = getBoundingClientRect(element);- return {- top: rect.top,- left: rect.left,- width: rect.width,- height: rect.height,- };- }, [element, rerenderFlag]);+ return {+ top: rect.top,+ left: rect.left,+ width: rect.width,+ height: rect.height,+ };+ },+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [element, rerenderFlag]+ );};-const Outline = styled("div", {- position: "absolute",- pointerEvents: "none",- outline: "2px solid $blue9",- outlineOffset: -2,- // This can be rewriten using normal node once needed- "&::before": {- display: "flex",- content: "attr(data-label)",- padding: "0 $1",- marginTop: "-$4",- height: "$4",+const Outline = styled(+ "div",+ {position: "absolute",- backgroundColor: "$blue9",- color: "$hiContrast",- alignItems: "center",- justifyContent: "center",- fontSize: "$2",- fontFamily: "$sans",- lineHeight: 1,- minWidth: "$6",+ pointerEvents: "none",+ outline: "2px solid $blue9",+ outlineOffset: -2,+ // This can be rewriten using normal node once needed+ "&::before": {+ display: "flex",+ content: "attr(data-label)",+ padding: "0 $1",+ marginTop: "-$4",+ height: "$4",+ position: "absolute",+ color: "$hiContrast",+ alignItems: "center",+ justifyContent: "center",+ fontSize: "$2",+ fontFamily: "$sans",+ lineHeight: 1,+ minWidth: "$6",+ },},-});+ {+ variants: {+ state: {+ selected: {+ zIndex: "$4",+ "&::before": {+ backgroundColor: "$blue9",+ },+ },+ hovered: {+ zIndex: "$3",+ "&::before": {+ color: "$blue9",+ },+ },+ },+ },+ }+);export const useOutline = (currentInstance: Instance) => {- const element = useElement(currentInstance);+ const { element, type } = useElement(currentInstance) ?? {};const style = useStyle(element);const component = element?.dataset?.component;@@ -81,6 +111,7 @@ export const useOutline = (currentInstance: Instance) => {return createPortal(<Outline+ state={type}data-label={primitive.label}style={style}className={darkTheme}