Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-rockets-win.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': major
---

Update Tooltip component to no longer support sx.
7 changes: 1 addition & 6 deletions packages/react/src/Tooltip/Tooltip.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
"name": "wrap",
"type": "boolean",
"description": "Use `true` to allow text within tooltip to wrap."
},
{
"name": "sx",
"type": "SystemStyleObject",
"deprecated": true
}
],
"subcomponents": []
}
}
6 changes: 1 addition & 5 deletions packages/react/src/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import {clsx} from 'clsx'
import React, {useMemo} from 'react'
import styled from 'styled-components'
import {get} from '../constants'
import type {SxProp} from '../sx'
import sx from '../sx'
import type {ComponentProps} from '../utils/types'
import {useId} from '../hooks'

/* Tooltip v1 */

const TooltipBase = styled.span<SxProp>`
const TooltipBase = styled.span`
position: relative;
display: inline-block;

Expand Down Expand Up @@ -182,8 +180,6 @@ const TooltipBase = styled.span<SxProp>`
left: 0;
margin-left: 0;
}

${sx};
`

/**
Expand Down
7 changes: 1 addition & 6 deletions packages/react/src/TooltipV2/Tooltip.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@
"name": "keybindingHint",
"type": "string",
"description": "Optional keybinding hint to indicate the availability of a keyboard shortcut. Supported syntax is described in the docs for the `KeybindingHint` component."
},
{
"name": "sx",
"type": "SystemStyleObject",
"deprecated": true
}
],
"subcomponents": []
}
}
21 changes: 8 additions & 13 deletions packages/react/src/TooltipV2/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {Children, useEffect, useRef, useState, useMemo} from 'react'
import type {SxProp} from '../sx'
import {useId, useProvidedRefOrCreate, useOnEscapePress, useIsMacOS} from '../hooks'
import {invariant} from '../utils/invariant'
import {warning} from '../utils/warning'
Expand All @@ -11,17 +10,14 @@ import classes from './Tooltip.module.css'
import {getAccessibleKeybindingHintString, KeybindingHint, type KeybindingHintProps} from '../KeybindingHint'
import VisuallyHidden from '../_VisuallyHidden'
import useSafeTimeout from '../hooks/useSafeTimeout'
import {BoxWithFallback} from '../internal/components/BoxWithFallback'

export type TooltipDirection = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w'
export type TooltipProps = React.PropsWithChildren<
{
direction?: TooltipDirection
text: string
type?: 'label' | 'description'
keybindingHint?: KeybindingHintProps['keys']
} & SxProp
> &
export type TooltipProps = React.PropsWithChildren<{
direction?: TooltipDirection
text: string
type?: 'label' | 'description'
keybindingHint?: KeybindingHintProps['keys']
}> &
React.HTMLAttributes<HTMLElement>

type TriggerPropsType = Pick<
Expand Down Expand Up @@ -298,8 +294,7 @@ export const Tooltip = React.forwardRef(
child.props.onMouseLeave?.(event)
},
})}
<BoxWithFallback
as="span"
<span
className={clsx(className, classes.Tooltip)}
ref={tooltipElRef}
data-direction={calculatedDirection}
Expand Down Expand Up @@ -332,7 +327,7 @@ export const Tooltip = React.forwardRef(
) : (
text
)}
</BoxWithFallback>
</span>
</>
</TooltipContext.Provider>
)
Expand Down
25 changes: 25 additions & 0 deletions packages/styled-react/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Tooltip as PrimerTooltip, type TooltipProps as PrimerTooltipProps, type SxProp} from '@primer/react'
import {
Tooltip as PrimerDeprecatedTooltip,
type TooltipProps as PrimerDeprecatedTooltipProps,
} from '@primer/react/deprecated'
import {Box} from './Box'
import {forwardRef, type ForwardRefExoticComponent, type RefAttributes} from 'react'

type TooltipProps = PrimerTooltipProps & SxProp

const Tooltip: ForwardRefExoticComponent<TooltipProps & RefAttributes<HTMLDivElement>> = forwardRef<
HTMLDivElement,
TooltipProps
>(function Tooltip(props, ref) {
return <Box as={PrimerTooltip} ref={ref} {...props} />
})

export {Tooltip, type TooltipProps}

type DeprecatedTooltipProps = PrimerDeprecatedTooltipProps & SxProp

function DeprecatedTooltip(props: DeprecatedTooltipProps) {
return <Box as={PrimerDeprecatedTooltip} {...props} />
}
Comment on lines +11 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do the new as hack just in case? I think in theory it affects every component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this only affects polymorphic components that take an as prop, Tooltip isn’t one of them, so it should be fine.
I tested it in primer-react.browser.test.tsx and confirmed that the props and children are passed correctly for Tooltip.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah got it, thanks! ❤️

export {DeprecatedTooltip, type DeprecatedTooltipProps}
3 changes: 2 additions & 1 deletion packages/styled-react/src/deprecated.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export {TabNav, type TabNavProps, type TabNavLinkProps} from './components/TabNav'
export {Dialog, type DialogProps, type DialogHeaderProps} from './components/DialogV1'
export {Octicon, Tooltip, type TooltipProps} from '@primer/react/deprecated'
export {Octicon} from '@primer/react/deprecated'
export {DeprecatedTooltip as Tooltip, type DeprecatedTooltipProps as TooltipProps} from './components/Tooltip'
5 changes: 4 additions & 1 deletion packages/styled-react/src/experimental.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ export {
type UnderlinePanelsTabProps,
type UnderlinePanelsPanelProps,
} from './components/UnderlinePanels'
export {Table, Tooltip} from '@primer/react/experimental'

export {Tooltip, type TooltipProps} from './components/Tooltip'

export {Table} from '@primer/react/experimental'
2 changes: 1 addition & 1 deletion packages/styled-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export {Select} from '@primer/react'
export {Text} from '@primer/react'
export {Textarea} from '@primer/react'
export {TextInput} from '@primer/react'
export {Tooltip} from '@primer/react'
export {type TextInputProps} from '@primer/react'

// theming depends on styled-components
Expand Down Expand Up @@ -64,6 +63,7 @@ export {
type TimelineBreakProps,
} from './components/Timeline'
export {ToggleSwitch, type ToggleSwitchProps} from './components/ToggleSwitch'
export {Tooltip, type TooltipProps} from './components/Tooltip'
export {Token, type TokenProps} from './components/Token'
export {Truncate, type TruncateProps} from './components/Truncate'
export {UnderlineNav, type UnderlineNavProps, type UnderlineNavItemProps} from './components/UnderlineNav'
Expand Down
Loading