multimodal/tarko/ui/README.md
Reusable UI components and utilities for Tarko Agent UI.
pnpm add @tarko/ui
DialogModal dialog component with backdrop and animations.
import { Dialog, DialogPanel, DialogTitle } from '@tarko/ui';
<Dialog open={isOpen} onClose={() => setIsOpen(false)}>
<DialogPanel>
<DialogTitle>Confirm Action</DialogTitle>
<p>Are you sure you want to proceed?</p>
</DialogPanel>
</Dialog>
Props:
open: boolean - Controls dialog visibilityonClose: () => void - Close callbackmaxWidth?: string | false - Maximum width constraintfullWidth?: boolean - Full width modechildren: React.ReactNode - Dialog contentConfirmDialogPre-built confirmation dialog with action buttons.
import { ConfirmDialog } from '@tarko/ui';
<ConfirmDialog
open={showConfirm}
title="Delete File"
message="This action cannot be undone."
confirmText="Delete"
onConfirm={handleDelete}
onCancel={() => setShowConfirm(false)}
variant="danger"
/>
Props:
open: boolean - Controls dialog visibilitytitle: string - Dialog titlemessage: string - Confirmation messageconfirmText?: string - Confirm button text (default: 'Confirm')cancelText?: string - Cancel button text (default: 'Cancel')onConfirm: () => void - Confirm action callbackonCancel: () => void - Cancel action callbackvariant?: 'default' | 'danger' - Visual style variantLoadingSpinnerAnimated loading spinner component.
import { LoadingSpinner } from '@tarko/ui';
<LoadingSpinner size={8} className="border-blue-500 border-t-transparent" />
Props:
size?: number - Spinner size (default: 8)className?: string - Additional CSS classes for stylingTooltipTooltip component for displaying contextual information.
import { Tooltip } from '@tarko/ui';
<Tooltip content="This is a helpful tip">
<button>Hover me</button>
</Tooltip>
ActionBlockDisplays AI action blocks with status indicators and animations.
import { ActionBlock } from '@tarko/ui';
<ActionBlock
title="Processing Request"
status="running"
description="Analyzing user input..."
/>
BrowserShellBrowser-like interface shell for displaying web content.
import { BrowserShell } from '@tarko/ui';
<BrowserShell
url="https://example.com"
title="Example Site"
onNavigate={(url) => console.log('Navigate to:', url)}
/>
ThinkingAnimationAnimated thinking indicator for AI processing states.
import { ThinkingAnimation } from '@tarko/ui';
<ThinkingAnimation message="Thinking..." />
CodeEditorLightweight code viewer with syntax highlighting using highlight.js.
import { CodeEditor } from '@tarko/ui';
<CodeEditor
code="console.log('Hello World');"
fileName="example.js"
readOnly={true}
showLineNumbers={true}
maxHeight="400px"
onCopy={() => console.log('Copied!')}
/>
Props:
code: string - Source code to displayfileName?: string - File name for language detectionfilePath?: string - Full file path for displayfileSize?: string - File size for displayreadOnly?: boolean - Read-only mode (default: true)showLineNumbers?: boolean - Show line numbers (default: true)maxHeight?: string - Maximum height (default: 'none')className?: string - Additional CSS classesonCopy?: () => void - Copy button callbackMonacoCodeEditorFull-featured code editor powered by Monaco Editor with IntelliSense and editing capabilities.
import { MonacoCodeEditor } from '@tarko/ui';
<MonacoCodeEditor
code="const x = 42;"
fileName="script.ts"
readOnly={false}
onChange={(value) => console.log(value)}
/>
Props:
code: string - Source code to display/editfileName?: string - File name for language detectionfilePath?: string - Full file path for displayfileSize?: string - File size for displayreadOnly?: boolean - Read-only mode (default: true)showLineNumbers?: boolean - Show line numbers (default: true)maxHeight?: string - Maximum height (default: 'none')className?: string - Additional CSS classesonCopy?: () => void - Copy button callbackonChange?: (value: string | undefined) => void - Content change callbackDiffViewerSide-by-side diff viewer for comparing code changes.
import { DiffViewer } from '@tarko/ui';
const diffContent = `
--- a/file.js
+++ b/file.js
@@ -1,3 +1,3 @@
-const x = 1;
+const x = 2;
`;
<DiffViewer
diffContent={diffContent}
fileName="file.js"
maxHeight="500px"
/>
Props:
diffContent: string - Git-style diff contentfileName?: string - File name for displaymaxHeight?: string - Maximum height (default: '400px')className?: string - Additional CSS classesgetMonacoLanguage(extension: string): stringMaps file extensions to Monaco Editor language identifiers.
import { getMonacoLanguage } from '@tarko/ui';
getMonacoLanguage('ts'); // 'typescript'
getMonacoLanguage('py'); // 'python'
getMonacoLanguage('unknown'); // 'plaintext'
getDisplayFileName(fileName?: string, filePath?: string): stringExtracts display name from file name or path.
import { getDisplayFileName } from '@tarko/ui';
getDisplayFileName('script.js'); // 'script.js'
getDisplayFileName(undefined, '/path/to/file.ts'); // 'file.ts'
getDisplayFileName(); // 'Untitled'
getFileExtension(fileName?: string): stringExtracts file extension from file name.
import { getFileExtension } from '@tarko/ui';
getFileExtension('script.js'); // 'js'
getFileExtension('README.md'); // 'md'
getFileExtension('noext'); // ''
normalizeFilePath(absolutePath: string): stringNormalizes file paths by replacing user directories with ~ for privacy.
import { normalizeFilePath } from '@tarko/ui';
// macOS/Linux
normalizeFilePath('/Users/john/project/file.js'); // '~/project/file.js'
normalizeFilePath('/home/jane/code/app.py'); // '~/code/app.py'
// Windows
normalizeFilePath('C:\\Users\\john\\project\\file.js'); // '~\\project\\file.js'
normalizeFilePathsBatch(paths: string[]): string[]Batch normalize multiple file paths for better performance.
isAbsolutePath(path: string): booleanChecks if a path is absolute (starts with / on Unix or drive letter on Windows).
clearPathNormalizationCache(): void - Clear normalization cachegetPathNormalizationCacheSize(): number - Get cache sizeMarkdownRendererFull-featured markdown renderer with syntax highlighting, math support, and interactive elements.
import { MarkdownRenderer } from '@tarko/ui';
const markdownContent = `
# Hello World
This is **bold** text with \`code\` and [links](https://example.com).
\`\`\`javascript
console.log('Hello!');
\`\`\`
`;
<MarkdownRenderer
content={markdownContent}
className="prose"
forceDarkTheme={false}
/>
Props:
content: string - Markdown content to renderpublishDate?: string - Publication date for displayauthor?: string - Author informationclassName?: string - Additional CSS classesforceDarkTheme?: boolean - Force dark theme (default: false)codeBlockStyle?: React.CSSProperties - Custom code block stylesFeatures:
JSONViewerInteractive JSON tree viewer with expand/collapse, copy functionality, and syntax highlighting.
import { JSONViewer, JSONViewerRef } from '@tarko/ui';
const data = {
name: "John Doe",
age: 30,
skills: ["JavaScript", "React", "Node.js"],
address: {
city: "New York",
country: "USA"
}
};
const viewerRef = useRef<JSONViewerRef>(null);
<JSONViewer
data={data}
emptyMessage="No data available"
className="max-h-96 overflow-auto"
ref={viewerRef}
/>
// Copy all data as JSON
const copyAll = () => {
const jsonString = viewerRef.current?.copyAll();
if (jsonString) {
navigator.clipboard.writeText(jsonString);
}
};
Props:
data: any - JSON data to displayclassName?: string - Additional CSS classesemptyMessage?: string - Message for empty data (default: 'No data available')ref?: JSONViewerRef - Reference for programmatic accessFeatures:
useDarkModeHook for detecting and managing dark mode state.
import { useDarkMode } from '@tarko/ui';
function MyComponent() {
const isDarkMode = useDarkMode();
return (
<div className={isDarkMode ? 'dark-theme' : 'light-theme'}>
Current theme: {isDarkMode ? 'Dark' : 'Light'}
</div>
);
}
useCopyToClipboardHook for copying text to clipboard with feedback state.
import { useCopyToClipboard } from '@tarko/ui';
function CopyButton({ text }: { text: string }) {
const { copied, copyToClipboard } = useCopyToClipboard();
return (
<button onClick={() => copyToClipboard(text)}>
{copied ? 'Copied!' : 'Copy'}
</button>
);
}
formatDuration(ms: number): stringFormats milliseconds into human-readable duration.
import { formatDuration } from '@tarko/ui';
formatDuration(1500); // '1.5s'
formatDuration(65000); // '1m 5s'
formatDuration(3661000); // '1h 1m 1s'
createMuiTheme(isDarkMode: boolean): ThemeCreates Material-UI theme based on dark mode preference.
import { createMuiTheme } from '@tarko/ui';
import { ThemeProvider } from '@mui/material/styles';
function App() {
const isDarkMode = useDarkMode();
const theme = createMuiTheme(isDarkMode);
return (
<ThemeProvider theme={theme}>
</ThemeProvider>
);
}