From 65e7b30243e376953e20e2126e9a68220e36b8a8 Mon Sep 17 00:00:00 2001 From: Robson Oliveira Date: Wed, 13 Jul 2022 22:26:21 -0300 Subject: [PATCH 1/3] fix(sidebar): update the sidebar style --- src/components/sidebar-section/index.tsx | 6 +--- src/components/sidebar/index.tsx | 6 +++- src/components/sidebar/styles.ts | 44 ++++++++++++++++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/components/sidebar-section/index.tsx b/src/components/sidebar-section/index.tsx index edf340e6d..b1a6e6dd8 100644 --- a/src/components/sidebar-section/index.tsx +++ b/src/components/sidebar-section/index.tsx @@ -1,7 +1,6 @@ import { Flex, Box, Text } from '@vtex/brand-ui' import { useContext, useState } from 'react' -import HelpIcon from 'components/icons/help-icon' import SearchIcon from 'components/icons/search-icon' import SideBarToggleIcon from 'components/icons/sidebar-toggle-icon' import SideBarElements from 'components/sidebar-elements' @@ -30,10 +29,7 @@ const SidebarSection = ({ title, data }: SidebarSectionProps) => { className={sidebarSectionHidden ? 'sidebarHide' : ''} sx={styles.sidebarElementsBox} > - - {title} - - + {title} { : styles.icon } /> + {iconElement.title} @@ -263,6 +264,9 @@ const Sidebar = ({ sectionSelected }: SideBarSectionState) => { /> ))} + +
+
{notesIcons.map((notesIconElement) => ( Date: Fri, 22 Jul 2022 18:57:02 -0300 Subject: [PATCH 2/3] fix(sidebar): sidebar-section title and the icon description behavior on medium screens --- src/components/sidebar-section/index.tsx | 2 +- src/components/sidebar/functions.ts | 15 ++++ src/components/sidebar/index.tsx | 99 ++++++++++++++++++------ src/components/sidebar/styles.ts | 64 +++++++++++---- 4 files changed, 137 insertions(+), 43 deletions(-) create mode 100644 src/components/sidebar/functions.ts diff --git a/src/components/sidebar-section/index.tsx b/src/components/sidebar-section/index.tsx index b1a6e6dd8..a7e2d6e27 100644 --- a/src/components/sidebar-section/index.tsx +++ b/src/components/sidebar-section/index.tsx @@ -36,7 +36,7 @@ const SidebarSection = ({ title, data }: SidebarSectionProps) => { style={styles.searchInput} className="searchComponent" type="text" - placeholder="Filter in Title..." + placeholder={`Search in ${title}...`} value={searchValue} onChange={(e) => setSearchValue(e.currentTarget.value)} /> diff --git a/src/components/sidebar/functions.ts b/src/components/sidebar/functions.ts new file mode 100644 index 000000000..5a7724dc7 --- /dev/null +++ b/src/components/sidebar/functions.ts @@ -0,0 +1,15 @@ +import { SxStyleProp } from '@vtex/brand-ui' + +export const iconTooltipStyle: SxStyleProp = (tooltipState: boolean) => { + const iconTooltip: SxStyleProp = { + display: [ + 'flex', + 'flex', + 'flex', + 'flex', + 'flex', + tooltipState ? 'flex' : 'none !important', + ], + } + return iconTooltip +} diff --git a/src/components/sidebar/index.tsx b/src/components/sidebar/index.tsx index c4392e54a..e5345ef3a 100644 --- a/src/components/sidebar/index.tsx +++ b/src/components/sidebar/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { Flex, Text, Box } from '@vtex/brand-ui' import Link from 'next/link' @@ -12,6 +12,8 @@ import { } from 'utils/constants' import SidebarSection from 'components/sidebar-section' +import Tooltip from 'components/tooltip' +import { iconTooltipStyle } from './functions' interface SideBarSectionState { sectionSelected: DocumentationTitle | UpdatesTitle | '' @@ -19,6 +21,7 @@ interface SideBarSectionState { const Sidebar = ({ sectionSelected }: SideBarSectionState) => { const [activeSectionName, setActiveSectionName] = useState(sectionSelected) + const [expandDelayStatus, setExpandDelayStatus] = useState(true) const sidebarData: SidebarSectionProps[] = [ { @@ -224,38 +227,84 @@ const Sidebar = ({ sectionSelected }: SideBarSectionState) => { }, ] + useEffect(() => { + setTimeout(() => setExpandDelayStatus(false), 5000) + }, []) + const SideBarIcon = (iconElement: DocDataElement | UpdatesDataElement) => { + const [iconTooltip, setIconTooltip] = useState(false) + const [tooltipLabel, setTooltipLabel] = useState(iconElement.title) + const titleRef = useRef() + + useEffect(() => { + const resizeObserver = new MutationObserver(function (entries) { + const target = entries[0].target as HTMLElement + if (target.offsetWidth < target.scrollWidth) setIconTooltip(true) + else setIconTooltip(false) + + if (target.offsetWidth > 0) + setTooltipLabel(target.innerText as DocumentationTitle | UpdatesTitle) + }) + if (titleRef.current) { + if (titleRef.current.offsetWidth < titleRef.current.scrollWidth) + setIconTooltip(true) + resizeObserver.observe(titleRef.current, { + childList: true, + }) + } + return () => { + resizeObserver.disconnect + } + }, [titleRef.current]) + return ( - - { - setActiveSectionName(iconElement.title) - }} + + - - - {iconElement.title} - - - + + { + setActiveSectionName(iconElement.title) + }} + > + + + + {iconElement.title} + + + + + + ) } return ( - + {docsIcons.map((docsIconElement) => ( Date: Fri, 22 Jul 2022 18:57:58 -0300 Subject: [PATCH 3/3] feat(tooltip): add the sx prop to tooltip component --- src/components/tooltip/index.tsx | 9 ++++----- src/components/tooltip/styles.ts | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/tooltip/index.tsx b/src/components/tooltip/index.tsx index 82c71010e..23d9554fb 100644 --- a/src/components/tooltip/index.tsx +++ b/src/components/tooltip/index.tsx @@ -1,17 +1,15 @@ import { useEffect, useRef, useState } from 'react' -import { Box, Flex, TooltipProps } from '@vtex/brand-ui' +import { Box, Flex, TooltipProps, SxStyleProp } from '@vtex/brand-ui' import CaretIcon from 'components/icons/caret' import styles from './styles' - -// type Props = Pick - interface Props extends Pick { + sx?: SxStyleProp isCard?: boolean } -const Tooltip = ({ children, label, placement, isCard }: Props) => { +const Tooltip = ({ children, label, placement, sx, isCard }: Props) => { const box = useRef() const [boxWidth, setBoxWidth] = useState(0) const [boxHeight, setBoxHeight] = useState(0) @@ -43,6 +41,7 @@ const Tooltip = ({ children, label, placement, isCard }: Props) => { {visible && (isCard ?? true) && ( SxStyleProp = (placement, width, height, x, y) => { +) => SxStyleProp = (sx, placement, width, height, x, y) => { const position = { bottom: { left: `${x + width / 2}px`, @@ -43,6 +44,7 @@ const tooltipContainer: ( } return { + ...sx, zIndex: '100', position: 'absolute', alignItems: 'center',