import React, { memo, useState, useCallback, useMemo } from 'react'; import * as Ariakit from '@ariakit/react'; import { CheckboxButton } from '@librechat/client'; import { ArtifactModes } from 'librechat-data-provider'; import { WandSparkles, ChevronDown } from 'lucide-react'; import { useBadgeRowContext } from '~/Providers'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; interface ArtifactsToggleState { enabled: boolean; mode: string; } function Artifacts() { const localize = useLocalize(); const { artifacts } = useBadgeRowContext(); const { toggleState, debouncedChange, isPinned } = artifacts; const [isPopoverOpen, setIsPopoverOpen] = useState(false); const currentState = useMemo(() => { if (typeof toggleState === 'string' && toggleState) { return { enabled: true, mode: toggleState }; } return { enabled: false, mode: '' }; }, [toggleState]); const isEnabled = currentState.enabled; const isShadcnEnabled = currentState.mode === ArtifactModes.SHADCNUI; const isCustomEnabled = currentState.mode === ArtifactModes.CUSTOM; const handleToggle = useCallback(() => { if (isEnabled) { debouncedChange({ value: '' }); } else { debouncedChange({ value: ArtifactModes.DEFAULT }); } }, [isEnabled, debouncedChange]); const handleShadcnToggle = useCallback(() => { if (isShadcnEnabled) { debouncedChange({ value: ArtifactModes.DEFAULT }); } else { debouncedChange({ value: ArtifactModes.SHADCNUI }); } }, [isShadcnEnabled, debouncedChange]); const handleCustomToggle = useCallback(() => { if (isCustomEnabled) { debouncedChange({ value: ArtifactModes.DEFAULT }); } else { debouncedChange({ value: ArtifactModes.CUSTOM }); } }, [isCustomEnabled, debouncedChange]); if (!isEnabled && !isPinned) { return null; } return (
} /> {isEnabled && ( e.stopPropagation()} >
{localize('com_ui_artifacts_options')}
{/* Include shadcn/ui Option */} { event.preventDefault(); event.stopPropagation(); handleShadcnToggle(); }} disabled={isCustomEnabled} className={cn( 'mb-1 flex items-center justify-between rounded-lg px-2 py-2', 'cursor-pointer outline-none transition-colors', 'hover:bg-black/[0.075] dark:hover:bg-white/10', 'data-[active-item]:bg-black/[0.075] dark:data-[active-item]:bg-white/10', isCustomEnabled && 'cursor-not-allowed opacity-50', )} >
{localize('com_ui_include_shadcnui' as any)}
{/* Custom Prompt Mode Option */} { event.preventDefault(); event.stopPropagation(); handleCustomToggle(); }} className={cn( 'flex items-center justify-between rounded-lg px-2 py-2', 'cursor-pointer outline-none transition-colors', 'hover:bg-black/[0.075] dark:hover:bg-white/10', 'data-[active-item]:bg-black/[0.075] dark:data-[active-item]:bg-white/10', )} >
{localize('com_ui_custom_prompt_mode' as any)}
)}
); } export default memo(Artifacts);