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) => (