Skip to content

Commit

Permalink
feat(tooltip): add the sx prop to tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
RobsonOlv committed Jul 22, 2022
1 parent df88d6b commit d5db1d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/components/tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -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<TooltipProps, 'children' | 'label' | 'placement'>

interface Props extends Pick<TooltipProps, 'children' | 'label' | 'placement'> {
sx?: SxStyleProp
isCard?: boolean
}

const Tooltip = ({ children, label, placement, isCard }: Props) => {
const Tooltip = ({ children, label, placement, sx, isCard }: Props) => {
const box = useRef<HTMLDivElement>()
const [boxWidth, setBoxWidth] = useState(0)
const [boxHeight, setBoxHeight] = useState(0)
Expand Down Expand Up @@ -43,6 +41,7 @@ const Tooltip = ({ children, label, placement, isCard }: Props) => {
{visible && (isCard ?? true) && (
<Flex
sx={styles.tooltipContainer(
sx,
placement || 'top',
boxWidth,
boxHeight,
Expand Down
4 changes: 3 additions & 1 deletion src/components/tooltip/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { SxStyleProp } from '@vtex/brand-ui'
type Placement = 'top' | 'right' | 'bottom' | 'left'

const tooltipContainer: (
sx: SxStyleProp,
placement: Placement,
width: number,
height: number,
x: number,
y: number
) => SxStyleProp = (placement, width, height, x, y) => {
) => SxStyleProp = (sx, placement, width, height, x, y) => {
const position = {
bottom: {
left: `${x + width / 2}px`,
Expand Down Expand Up @@ -43,6 +44,7 @@ const tooltipContainer: (
}

return {
...sx,
zIndex: '100',
position: 'absolute',
alignItems: 'center',
Expand Down

0 comments on commit d5db1d9

Please sign in to comment.