diff --git a/packages/gamut/src/Tip/shared/FloatingTip.tsx b/packages/gamut/src/Tip/shared/FloatingTip.tsx index 48209166485..1236956f810 100644 --- a/packages/gamut/src/Tip/shared/FloatingTip.tsx +++ b/packages/gamut/src/Tip/shared/FloatingTip.tsx @@ -47,6 +47,7 @@ export const FloatingTip: React.FC = ({ const commonPopoverProps = getPopoverAlignmentAndPattern({ alignment, type }); const dims = getAlignmentStyles({ avatar, alignment, type }); + const isHorizontalCenter = dims === 'horizontalCenter'; const [childRef, { width: tipWidth }] = useMeasure(); const [offset, setOffset] = useState(undefined); @@ -169,8 +170,9 @@ export const FloatingTip: React.FC = ({ widthRestricted={false} > {contents} diff --git a/packages/gamut/src/Tip/shared/InlineTip.tsx b/packages/gamut/src/Tip/shared/InlineTip.tsx index d10dc51f665..dec57516fa9 100644 --- a/packages/gamut/src/Tip/shared/InlineTip.tsx +++ b/packages/gamut/src/Tip/shared/InlineTip.tsx @@ -38,6 +38,7 @@ export const InlineTip: React.FC = ({ const inlineWrapperProps = isHoverType ? {} : { hideTip: isTipHidden }; const tipWrapperProps = isHoverType ? ({ inheritDims } as const) : {}; const tipBodyAlignment = getAlignmentStyles({ alignment, avatar, type }); + const isHorizontalCenter = tipBodyAlignment === 'horizontalCenter'; const target = ( = ({ alignment={tipBodyAlignment} aria-hidden={isHoverType} color="currentColor" + horizNarrow={narrow && isHorizontalCenter} id={id} role={type === 'tool' ? 'tooltip' : undefined} - width={narrow ? narrowWidth : 'max-content'} + width={narrow && !isHorizontalCenter ? narrowWidth : 'max-content'} zIndex="auto" > {type === 'preview' ? ( diff --git a/packages/gamut/src/Tip/shared/elements.tsx b/packages/gamut/src/Tip/shared/elements.tsx index 0649622924d..8a510fea0bf 100644 --- a/packages/gamut/src/Tip/shared/elements.tsx +++ b/packages/gamut/src/Tip/shared/elements.tsx @@ -9,6 +9,7 @@ import { inlineToolTipBodyAlignments, narrowWidth, toolTipBodyCss, + tooltipCenteredPadding, toolTipWidthRestrictions, } from './styles/styles'; @@ -20,7 +21,12 @@ const tipWrapperStyles = { const floatingTipTextStates = states({ isHoverType: { alignItems: 'flexStart' }, - narrow: { width: narrowWidth }, + /* + * Subtract 2x padding to account for the padding within + * the tooltip since this is the inner text wrapper + */ + narrow: { width: narrowWidth - tooltipCenteredPadding * 2 }, + horizNarrow: { maxWidth: narrowWidth - tooltipCenteredPadding * 2 }, }); const inlineTipStates = states({ @@ -85,9 +91,14 @@ export const TargetContainer = styled(Box)( }) ); +const inlineTipBodyStates = states({ + horizNarrow: { maxWidth: narrowWidth }, +}); + export const TipBody = styled(Box)< - StyleProps ->(css({ ...toolTipBodyCss }), inlineToolTipBodyAlignments); + StyleProps & + StyleProps +>(css({ ...toolTipBodyCss }), inlineToolTipBodyAlignments, inlineTipBodyStates); export const FloatingTipBody = styled(Popover)< StyleProps diff --git a/packages/gamut/src/Tip/shared/styles/styles.tsx b/packages/gamut/src/Tip/shared/styles/styles.tsx index c79049d5b44..fb897a6e67d 100644 --- a/packages/gamut/src/Tip/shared/styles/styles.tsx +++ b/packages/gamut/src/Tip/shared/styles/styles.tsx @@ -16,6 +16,7 @@ import { createVariantsFromAlignments } from './createVariantsUtils'; export const tooltipBgColor = `background-contrast`; export const tooltipArrowHeight = `1rem`; +export const tooltipArrowHeightPx = 14; const containerOffsetVertical = 12; const borderColor = 'border-primary'; @@ -140,6 +141,11 @@ export const rightAlignStyles = { export const horizontalCenterStyles = { ...horizontalCenterWidths, ...centerHorizontal, + /* + * This may seem odd, but since this width includes the beak + * we need to add the beak width to the max width to get the correct max width + */ + maxWidth: 124 + tooltipArrowHeightPx, } as const; export const leftAlignStyles = { @@ -184,8 +190,10 @@ export const tooltipVariantStyles = createVariantsFromAlignments( createToolTipVariantFromAlignment ); +export const tooltipCenteredPadding = 4; + const centeredBodyStyles = { - p: 4, + p: tooltipCenteredPadding, textAlign: 'center', minWidth: 'inherit', maxWidth: 'inherit',