import { Popover } from '@/internal/components/Popover'; import { useBreakpoints } from '@/internal/hooks/useBreakpoints'; import { useIcon } from '@/internal/hooks/useIcon'; import { cn, pressable, text } from '@/styles/theme'; import { useCallback, useRef, useState } from 'react'; import type { SwapSettingsProps } from '../types'; import { SwapSettingsSlippageDescription } from './SwapSettingsSlippageDescription'; import { SwapSettingsSlippageInput } from './SwapSettingsSlippageInput'; import { SwapSettingsSlippageLayout } from './SwapSettingsSlippageLayout'; import { SwapSettingsSlippageLayoutBottomSheet } from './SwapSettingsSlippageLayoutBottomSheet'; import { SwapSettingsSlippageTitle } from './SwapSettingsSlippageTitle'; import { Sheet } from '@/internal/components/Sheet'; const DEFAULT_CHILDREN = ( <> Max. slippage Your swap will revert if the prices change by more than the selected percentage. ); export function SwapSettings({ children = DEFAULT_CHILDREN, className, icon = 'swapSettings', text: buttonText = '', }: SwapSettingsProps) { const breakpoint = useBreakpoints(); const [isOpen, setIsOpen] = useState(false); const dropdownRef = useRef(null); const triggerRef = useRef(null); const handleToggle = useCallback((e: React.MouseEvent) => { e.stopPropagation(); setIsOpen((prev) => !prev); }, []); const handleClose = useCallback(() => { setIsOpen(false); }, []); const iconSvg = useIcon({ icon }); const trigger = ( ); return (
{buttonText && {buttonText}}
{breakpoint === 'sm' ? ( <> {trigger}
{children}
) : (
{children}
)}
); }