CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-tooltip

React tooltip component library with customizable positioning, styling, and accessibility features

Pending
Overview
Eval results
Files

styling-utilities.mddocs/

Styling and Utilities

Utility functions and configuration options for managing tooltip styles, CSS injection, and visual customization.

Capabilities

Style Management

Utility function for removing injected tooltip styles. This function is deprecated in favor of the disableStyleInjection prop on the Tooltip component.

/**
 * Remove injected tooltip styles (deprecated)
 * Use disableStyleInjection tooltip prop instead
 * @param options - Style removal configuration
 */
function removeStyle(options?: {
  type?: 'core' | 'base';
  id?: string;
}): void;

Usage Example:

import { removeStyle } from "react-tooltip";

// Remove base styles
removeStyle({ type: 'base' });

// Remove core styles  
removeStyle({ type: 'core' });

// Remove styles with custom ID
removeStyle({ type: 'base', id: 'custom-tooltip-styles' });

CSS Injection Control

Automatic Style Injection

React Tooltip automatically injects required CSS styles. For versions 5.13.0+, this happens automatically. For earlier versions, you must manually import the CSS file.

// Manual CSS import (required for versions < 5.13.0)
import 'react-tooltip/dist/react-tooltip.css';

Disabling Style Injection

Control CSS injection using the disableStyleInjection prop on the Tooltip component.

// Tooltip component prop for controlling style injection
interface ITooltipController {
  /** 
   * Disable CSS injection
   * - true: Disable both core and base styles
   * - false: Enable automatic injection (default)
   * - 'core': Disable only core styles, keep base styles
   */
  disableStyleInjection?: boolean | 'core';
}

Usage Examples:

import { Tooltip } from "react-tooltip";

// Disable all automatic style injection
<Tooltip 
  id="no-styles" 
  disableStyleInjection={true}
/>

// Disable only core styles, keep base styles
<Tooltip 
  id="no-core-styles" 
  disableStyleInjection="core"
/>

// Default behavior - automatic injection
<Tooltip id="auto-styles" />

Environment Variables

Control style injection globally using environment variables.

# Disable core styles globally
REACT_TOOLTIP_DISABLE_CORE_STYLES=true

# Disable base styles globally  
REACT_TOOLTIP_DISABLE_BASE_STYLES=true

Custom Styling

Inline Styles

Apply custom styles directly to tooltip components using standard React style props.

interface ITooltipController {
  /** Inline CSS styles for the tooltip */
  style?: CSSProperties;
  /** Border styling (width > 3px may affect arrow positioning) */
  border?: CSSProperties['border'];
  /** Tooltip opacity */
  opacity?: CSSProperties['opacity'];
  /** Arrow background color */
  arrowColor?: CSSProperties['backgroundColor'];
  /** Arrow size in pixels */
  arrowSize?: number;
}

Usage Examples:

import { Tooltip } from "react-tooltip";

// Custom inline styles
<Tooltip 
  id="styled-tooltip"
  style={{
    backgroundColor: '#333',
    color: '#fff',
    fontSize: '14px',
    padding: '8px 12px',
    borderRadius: '4px'
  }}
  border="2px solid #555"
  opacity={0.95}
  arrowColor="#333"
  arrowSize={8}
/>

CSS Classes

Apply custom CSS classes for advanced styling.

interface ITooltipController {
  /** CSS class name for the tooltip container */
  className?: string;
  /** CSS class name for the tooltip arrow */
  classNameArrow?: string;
}

Usage Examples:

// Custom CSS classes
<Tooltip 
  id="custom-classes"
  className="my-custom-tooltip"
  classNameArrow="my-custom-arrow"
/>

// Via data attributes
<button
  data-tooltip-id="data-classes"
  data-tooltip-content="Styled tooltip"
  data-tooltip-class-name="my-data-tooltip"
>
  Styled button
</button>
/* Custom CSS styles */
.my-custom-tooltip {
  background: linear-gradient(45deg, #ff6b6b, #ee5a24);
  color: white;
  font-weight: bold;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.my-custom-arrow {
  color: #ff6b6b;
}

.my-data-tooltip {
  border: 2px dashed #333;
  background: #f0f0f0;
  color: #333;
}

Visual Variants

Built-in visual themes for consistent styling across different tooltip types.

type VariantType = 'dark' | 'light' | 'success' | 'warning' | 'error' | 'info';

Usage Examples:

// Different visual variants
<Tooltip id="dark-tooltip" variant="dark" />
<Tooltip id="success-tooltip" variant="success" />
<Tooltip id="warning-tooltip" variant="warning" />
<Tooltip id="error-tooltip" variant="error" />
<Tooltip id="info-tooltip" variant="info" />
<Tooltip id="light-tooltip" variant="light" />

CSS File Exports

Available CSS files for manual import and customization:

  • react-tooltip/dist/react-tooltip.css - Complete stylesheet with all styles
  • react-tooltip/dist/react-tooltip.min.css - Minified complete stylesheet

Package Exports:

{
  "exports": {
    "./dist/react-tooltip.css": "./dist/react-tooltip.min.css"
  }
}

Style Injection Implementation

Internal Style Management

The library uses internal functions for CSS injection that are not part of the public API but provide context for understanding style behavior.

// Internal constants (not exported from main package)
const REACT_TOOLTIP_CORE_STYLES_ID = 'react-tooltip-core-styles';
const REACT_TOOLTIP_BASE_STYLES_ID = 'react-tooltip-base-styles';

/**
 * Internal style injection function (not exported from main package)
 * Used internally for CSS injection. For custom styling needs, use the
 * disableStyleInjection prop and provide your own CSS instead.
 */
function injectStyle(options: {
  css: string;
  id?: string;
  type?: 'core' | 'base';
  ref?: any;
}): void;

Custom Event Integration

The library dispatches custom events for style injection that can be intercepted for advanced use cases.

window.addEventListener('react-tooltip-inject-styles', (event) => {
  // Custom event payload
  const { disableCore, disableBase } = event.detail;
  // Handle custom style injection logic
});

Migration from removeStyle

Old Approach (Deprecated)

import { removeStyle } from "react-tooltip";

// Remove styles programmatically
useEffect(() => {
  removeStyle({ type: 'base' });
}, []);

New Approach (Recommended)

import { Tooltip } from "react-tooltip";

// Disable injection via component prop
<Tooltip 
  id="no-injection"
  disableStyleInjection={true}
/>

Advanced Styling Patterns

Conditional Styling

function ConditionalTooltip({ theme }: { theme: 'light' | 'dark' }) {
  return (
    <Tooltip
      id="conditional"
      variant={theme}
      style={{
        ...(theme === 'dark' && { 
          backgroundColor: '#1a1a1a',
          border: '1px solid #333'
        }),
        ...(theme === 'light' && {
          backgroundColor: '#ffffff',
          border: '1px solid #ccc',
          color: '#333'
        })
      }}
    />
  );
}

Responsive Styling

function ResponsiveTooltip() {
  const [isMobile, setIsMobile] = useState(false);
  
  useEffect(() => {
    const checkMobile = () => setIsMobile(window.innerWidth < 768);
    checkMobile();
    window.addEventListener('resize', checkMobile);
    return () => window.removeEventListener('resize', checkMobile);
  }, []);
  
  return (
    <Tooltip
      id="responsive"
      style={{
        fontSize: isMobile ? '12px' : '14px',
        padding: isMobile ? '6px 8px' : '8px 12px'
      }}
      arrowSize={isMobile ? 6 : 8}
    />
  );
}

Install with Tessl CLI

npx tessl i tessl/npm-react-tooltip

docs

index.md

legacy-components.md

styling-utilities.md

tooltip-component.md

tile.json