Skip to content

Commit

Permalink
Merge 3bb0774 into c3c8ad5
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack authored Apr 12, 2023
2 parents c3c8ad5 + 3bb0774 commit cb9aec8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-files-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update TooltipProps to extend from StyledTooltip props
54 changes: 29 additions & 25 deletions src/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,9 @@ import {invariant} from '../utils/invariant'
import styled from 'styled-components'
import {get} from '../constants'
import {useOnEscapePress} from '../hooks/useOnEscapePress'
import {ComponentProps} from '../utils/types'

export type TooltipProps = {
direction?: 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'
text?: string
noDelay?: boolean
align?: 'left' | 'right'
wrap?: boolean
type?: 'label' | 'description'
'aria-label'?: React.AriaAttributes['aria-label']
} & SxProp

export type TriggerPropsType = {
'aria-describedby'?: string
'aria-labelledby'?: string
'aria-label'?: string
onBlur?: React.FocusEventHandler
onFocus?: React.FocusEventHandler
onMouseEnter?: React.MouseEventHandler
ref?: React.RefObject<HTMLElement>
}

const TooltipEL = styled.div<TooltipProps>`
const StyledTooltip = styled.div`
// tooltip element itself
position: absolute;
z-index: 1000000;
Expand Down Expand Up @@ -294,7 +275,30 @@ const TooltipEL = styled.div<TooltipProps>`
${sx};
`

export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
export type TooltipProps = React.PropsWithChildren<
{
direction?: 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'
text?: string
noDelay?: boolean
align?: 'left' | 'right'
wrap?: boolean
type?: 'label' | 'description'
'aria-label'?: React.AriaAttributes['aria-label']
} & SxProp &
ComponentProps<typeof StyledTooltip>
>

export type TriggerPropsType = {
'aria-describedby'?: string
'aria-labelledby'?: string
'aria-label'?: string
onBlur?: React.FocusEventHandler
onFocus?: React.FocusEventHandler
onMouseEnter?: React.MouseEventHandler
ref?: React.RefObject<HTMLElement>
}

export const Tooltip = ({
direction = 'n',
// used for description type
text,
Expand All @@ -306,7 +310,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
type = 'label',
children,
...rest
}) => {
}: TooltipProps) => {
const id = useId()
const triggerRef = useRef<HTMLElement>(null)
const child = Children.only(children)
Expand Down Expand Up @@ -376,7 +380,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
child.props.onMouseEnter?.(event)
},
})}
<TooltipEL
<StyledTooltip
data-direction={direction}
data-state={open ? 'open' : undefined}
data-align={align}
Expand All @@ -390,7 +394,7 @@ export const Tooltip: React.FC<React.PropsWithChildren<TooltipProps>> = ({
id={id}
>
{text ?? label}
</TooltipEL>
</StyledTooltip>
</Box>
)
}
4 changes: 4 additions & 0 deletions src/Tooltip/__tests__/Tooltip.types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export function shouldAcceptCallWithNoProps() {
return <Tooltip />
}

export function shouldAcceptAdditionalProps() {
return <Tooltip id="test" style={{}} className="test" />
}

export function shouldNotAcceptSystemProps() {
// @ts-expect-error system props should not be accepted
return <Tooltip backgroundColor="thistle" />
Expand Down

0 comments on commit cb9aec8

Please sign in to comment.