From 403e73d4da4a260fb41f19c229ace7f488e99867 Mon Sep 17 00:00:00 2001 From: Liad Yosef Date: Wed, 22 May 2024 20:10:49 +0300 Subject: [PATCH] fix border bottom for single line selection (#5713) This small PR adds rounded border bottom for single line navigator selections (single elements or collapsed): image --- .../navigator-item/navigator-item.tsx | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/editor/src/components/navigator/navigator-item/navigator-item.tsx b/editor/src/components/navigator/navigator-item/navigator-item.tsx index 3f9ad2271912..51734b47d127 100644 --- a/editor/src/components/navigator/navigator-item/navigator-item.tsx +++ b/editor/src/components/navigator/navigator-item/navigator-item.tsx @@ -282,6 +282,7 @@ const computeResultingStyle = ( isDescendantOfSelected: boolean, isErroredGroup: boolean, colorTheme: ThemeObject, + isSingleItem: boolean, ) => { let styleType: StyleType = 'default' let selectedType: SelectedType = 'unselected' @@ -323,11 +324,15 @@ const computeResultingStyle = ( let result = getColors(styleType, selectedType, colorTheme) + const borderRadiusTop = selected ? '5px 5px' : '0 0' + // TODO: add the case of a last descendant of a selected component + const borderRadiusBottom = selected && isSingleItem ? '5px 5px' : '0 0' + const borderRadius = `${borderRadiusTop} ${borderRadiusBottom}` + result.style = { ...result.style, fontWeight: isProbablyParentOfSelected || isProbablyScene ? 600 : 'inherit', - // TODO compute bottom borderRadius style by if it has children or siblings - borderRadius: selected ? '5px 5px 0 0' : undefined, + borderRadius: borderRadius, } return result @@ -802,22 +807,6 @@ export const NavigatorItem: React.FunctionComponent< return elementWarnings.invalidGroup != null || elementWarnings.invalidGroupChild != null }, [elementWarnings]) - const resultingStyle = computeResultingStyle( - elementIsData ? false : selected, - emphasis, - isInsideComponent, - isDynamic, - isProbablyScene, - fullyVisible, - isFocusedComponent, - isInFocusedComponentSubtree, - isManuallyFocusableComponent, - isHighlightedForInteraction, - elementIsData && selected ? false : isDescendantOfSelected, - isErroredGroup, - colorTheme, - ) - const collapse = React.useCallback( (event: React.MouseEvent) => { collapseItem(dispatch, navigatorEntry.elementPath, event) @@ -900,14 +889,7 @@ export const NavigatorItem: React.FunctionComponent< const cursorStyle = isConditionalClauseNavigatorEntry(navigatorEntry) ? { cursor: 'pointer' } : {} - const rowStyle = useKeepReferenceEqualityIfPossible({ - paddingLeft: getElementPadding(entryNavigatorDepth), - height: getItemHeight(navigatorEntry), - ...resultingStyle.style, - ...cursorStyle, - }) - - const showExpandableIndicator = React.useMemo(() => { + const canBeExpanded = React.useMemo(() => { return ( isConditional || // if it is a conditional, so it could have no children if both branches are null childComponentCount > 0 || @@ -915,6 +897,32 @@ export const NavigatorItem: React.FunctionComponent< ) }, [childComponentCount, isFocusedComponent, isConditional]) + const isSingleItem = (canBeExpanded && collapsed) || childComponentCount === 0 + + const resultingStyle = computeResultingStyle( + elementIsData ? false : selected, + emphasis, + isInsideComponent, + isDynamic, + isProbablyScene, + fullyVisible, + isFocusedComponent, + isInFocusedComponentSubtree, + isManuallyFocusableComponent, + isHighlightedForInteraction, + elementIsData && selected ? false : isDescendantOfSelected, + isErroredGroup, + colorTheme, + isSingleItem, + ) + + const rowStyle = useKeepReferenceEqualityIfPossible({ + paddingLeft: getElementPadding(entryNavigatorDepth), + height: getItemHeight(navigatorEntry), + ...resultingStyle.style, + ...cursorStyle, + }) + const iconColor = resultingStyle.iconColor const currentlyRenaming = EP.pathsEqual(props.renamingTarget, props.navigatorEntry.elementPath) @@ -1017,7 +1025,7 @@ export const NavigatorItem: React.FunctionComponent< props.navigatorEntry.type === 'CONDITIONAL_CLAUSE',