A sleek, animated React component that lets users ask ChatGPT questions with the current page context. Built with TypeScript and Tailwind CSS.
- π Instant Integration - Drop the component anywhere in your React app
- β¨ Smooth Animations - Beautiful hover effects and focus transitions
- π― Smart Context Menu - Select text to trigger AI assistance with automatic context
- π― Flexible Positioning - Position anywhere on screen with simple props
- π± Mobile Responsive - Works perfectly on all device sizes
- π¨ Customizable - Built with Tailwind CSS for easy styling
- π§ TypeScript Ready - Full TypeScript support with proper type definitions
npm install ask-chatgpt-react
yarn add ask-chatgpt-react
pnpm add ask-chatgpt-react
import React from "react";
import { AskChatGPT } from "ask-chatgpt-react";
function App() {
return (
<div>
<h1>My App</h1>
{/* Default: Fixed position at bottom center */}
<AskChatGPT />
</div>
);
}
import { AskChatGPT } from 'ask-chatgpt-react';
// Top right corner
<AskChatGPT
position="fixed"
top="20px"
right="20px"
/>
// Bottom left corner
<AskChatGPT
position="fixed"
bottom="20px"
left="20px"
/>
// Center aligned in content
<AskChatGPT
position="static"
left="50%"
/>
Enable the smart context menu that appears when users select text:
// Basic context menu
<AskChatGPT enableContextMenu={true} />
// Context menu with custom settings
<AskChatGPT
enableContextMenu={true}
contextMenuOffset={15}
selectionMinLength={5}
/>
Context Menu Features:
- π Text Selection Detection - Automatically detects when text is selected
- π― Smart Positioning - Appears near the selected text with intelligent placement
- π¨ Clean Input Experience - Shows selected text preview while keeping input field clean
- π Automatic Context - Includes selected text context in ChatGPT queries behind the scenes
- π± Touch Support - Works on mobile devices with touch selection
- β‘ Instant Feedback - Beautiful preview badge shows selected text
- β¨οΈ Keyboard Support - Press Escape to close context menu
Take full control over how queries are formatted before sending to ChatGPT:
<AskChatGPT
enableContextMenu={true}
formatQuery={({ userQuestion, selectedText, currentUrl }) => {
if (selectedText) {
return `Role: You are a helpful AI assistant.
Context: "${selectedText}"
Question: ${userQuestion}
Source: ${currentUrl}
Please provide a detailed explanation.`;
}
return `Question: ${userQuestion}`;
}}
/>
formatQuery Parameters:
userQuestion
(string) - The user's typed questionselectedText
(string | undefined) - Selected text from the pagecurrentUrl
(string) - Current page URL
Best Practices:
- Define clear roles and instructions for ChatGPT
- Include relevant context and formatting
- Handle both selected text and regular question scenarios
- Keep prompts concise but descriptive
<AskChatGPT className="my-custom-class" style={{ zIndex: 1000 }} />
Prop | Type | Default | Description |
---|---|---|---|
className |
string |
"" |
Additional CSS classes |
style |
CSSProperties |
{} |
Inline styles |
position |
"fixed" | "static" | "absolute" | "relative" |
"fixed" |
CSS position type |
bottom |
string | number |
"1.25rem" |
Bottom position |
right |
string | number |
undefined |
Right position |
left |
string | number |
"50%" |
Left position |
top |
string | number |
undefined |
Top position |
enableContextMenu |
boolean |
false |
Enable text selection context menu |
contextMenuOffset |
number |
10 |
Distance from selected text (in pixels) |
selectionMinLength |
number |
3 |
Minimum text length to trigger context menu |
formatQuery |
function |
undefined |
Custom prompt engineering function |
- Input Expansion: The input field expands horizontally when focused
- Smart Scaling: Hover effects only apply when not focused
- Auto-centering: When
left="50%"
, the component auto-centers - Page Context: Automatically includes the current page URL in ChatGPT queries
- New Tab: Opens ChatGPT in a new tab/window
- Keyboard Navigation: Press Escape to close context menu
- Custom Formatting: Use
formatQuery
for advanced prompt engineering
The component uses Tailwind CSS classes internally but can be customized:
/* Custom styles for the component */
.my-custom-class {
/* Your custom styles */
}
// Add to product pages for customer support
<AskChatGPT position="fixed" bottom="20px" right="20px" />
// Context menu for product descriptions
<AskChatGPT enableContextMenu={true} />
// Add to articles for content-related questions
<AskChatGPT position="static" left="50%" />
// Context menu for technical articles with shorter trigger
<AskChatGPT
enableContextMenu={true}
selectionMinLength={5}
contextMenuOffset={15}
/>
// Context menu for learning materials with custom formatting
<AskChatGPT
enableContextMenu={true}
selectionMinLength={10}
formatQuery={({ userQuestion, selectedText, currentUrl }) => {
if (selectedText) {
return `You are an educational AI tutor. Help explain this concept:
"${selectedText}"
Student question: ${userQuestion}
Please provide:
1. A simple explanation
2. Key concepts
3. Real-world examples
4. Further learning suggestions`;
}
return userQuestion;
}}
/>
// Context menu for technical documentation
<AskChatGPT
enableContextMenu={true}
formatQuery={({ userQuestion, selectedText, currentUrl }) => {
if (selectedText) {
return `You are a technical documentation assistant.
Code/Documentation: "${selectedText}"
Developer question: ${userQuestion}
Source: ${currentUrl}
Please provide clear technical guidance with code examples if relevant.`;
}
return `Technical question: ${userQuestion}`;
}}
/>
// Add to admin panels for help
<AskChatGPT position="fixed" top="20px" right="20px" />
- React 18.0.0 or higher
- React DOM 18.0.0 or higher
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
MIT Β© Burak Sakalli
Made with β€οΈ by Burak Sakalli