import {Trans} from '@common/i18n/trans'; import {DialogTrigger} from '@common/ui/overlays/dialog/dialog-trigger'; import {GradientIcon} from '@common/icons/material/Gradient'; import {Dialog} from '@common/ui/overlays/dialog/dialog'; import {DialogHeader} from '@common/ui/overlays/dialog/dialog-header'; import {DialogBody} from '@common/ui/overlays/dialog/dialog-body'; import {DialogFooter} from '@common/ui/overlays/dialog/dialog-footer'; import {Button} from '@common/ui/buttons/button'; import {useDialogContext} from '@common/ui/overlays/dialog/dialog-context'; import {useCallback, useState} from 'react'; import clsx from 'clsx'; import {ColorPickerDialog} from '@common/ui/color-picker/color-picker-dialog'; import {IconButton} from '@common/ui/buttons/icon-button'; import {ArrowDownwardIcon} from '@common/icons/material/ArrowDownward'; import {ArrowForwardIcon} from '@common/icons/material/ArrowForward'; import {Tooltip} from '@common/ui/tooltip/tooltip'; import {ArrowUpwardIcon} from '@common/icons/material/ArrowUpward'; import { BaseGradientBg, GradientBackgrounds, } from '@common/background-selector/gradient-backgrounds'; import {BackgroundSelectorButton} from '@common/background-selector/background-selector-button'; import {BgSelectorTabProps} from '@common/background-selector/bg-selector-tab-props'; import {BackgroundSelectorConfig} from '@common/background-selector/background-selector-config'; export function GradientBackgroundTab({ value, onChange, className, isInsideDialog, }: BgSelectorTabProps) { return (
{GradientBackgrounds.map(gradient => ( } isActive={value?.id === gradient.id} style={{backgroundImage: gradient.backgroundImage}} onClick={() => { onChange?.({ ...BaseGradientBg, ...gradient, }); }} /> ))}
); } function CustomGradientButton({ value, onChange, isInsideDialog, }: BgSelectorTabProps) { const isCustomGradient = value?.id === BaseGradientBg.id; return ( onChange?.(newValue)} alwaysReturnCurrentValueOnClose={isInsideDialog} onOpenChange={isOpen => { // on dialog open set default gradient as active, if no other gradient is selected if (isOpen && !value) { onChange?.(GradientBackgrounds[0]); } }} onClose={gradient => onChange?.(gradient)} > } className="border-2 border-dashed" style={{ backgroundImage: isCustomGradient ? value?.backgroundImage : undefined, }} > ); } interface CustomGradientState { colorOne: string; colorTwo: string; angle: string; } interface CustomGradientDialogProps { hideFooter?: boolean; } function CustomGradientDialog({hideFooter}: CustomGradientDialogProps) { const { close, value: dialogValue, setValue, } = useDialogContext(); const [state, setLocalState] = useState(() => { const parts = dialogValue?.backgroundImage?.match(/\(([0-9]+deg),.?(.+?),.?(.+?)\)/) || []; return { angle: parts[1] || '45deg', colorOne: parts[2] || '#ff9a9e', colorTwo: parts[3] || '#fad0c4', }; }); const buildGradientBackground = (s: CustomGradientState) => { return { ...BaseGradientBg, backgroundImage: `linear-gradient(${s.angle}, ${s.colorOne}, ${s.colorTwo})`, }; }; const setState = useCallback( (newValues: Partial) => { const newState = { ...state, ...newValues, }; setLocalState(newState); setValue(buildGradientBackground(newState)); }, [state, setValue], ); return (
setState({colorOne: value})} />
setState({colorTwo: value})} />
setState({angle: value})} /> {!hideFooter && ( )}
); } interface ColorPickerButtonProps { className: string; value: string; onChange: (value: string) => void; } function ColorPickerButton({ className, value, onChange, }: ColorPickerButtonProps) { return ( }>