import { FC } from 'react'; import { imageFrom } from '@uniformdev/assets'; import { ComponentContext, ComponentParameter, UniformText } from '@uniformdev/next-app-router/component'; import { TextParameters } from '@/components/canvas/Text/parameters'; import BaseButton, { ButtonVariant } from '@/components/ui/Button'; import BaseImage from '@/components/ui/Image'; import MediaPlaceholder from '@/components/ui/MediaPlaceholder'; import BaseText from '@/components/ui/Text'; import { ReplaceFieldsWithAssets } from '@/types/cskTypes'; import { formatUniformLink } from '@/utils/routing'; import { BaseButtonParameters, BaseImageParameters } from '.'; type ComponentProps = { isEditorPreviewMode?: boolean; component: Pick; parameter?: ComponentParameter; variant?: string; }; export const BaseHeroText: FC> = ({ component, parameter, text, isEditorPreviewMode, ...props }) => { if (!text && !isEditorPreviewMode) return null; return ( } as={props.tag || undefined} component={component} /> ); }; export const BaseHeroButton: FC< ReplaceFieldsWithAssets & { variant?: ButtonVariant } & Omit > = ({ component, parameter, isEditorPreviewMode, text, ...props }) => { const { link, icon } = props; const href = formatUniformLink(link); if (!text && !href && !isEditorPreviewMode) return null; const Icon = () => { const [resolvedImage] = icon || []; const { url, title = '' } = resolvedImage || {}; return url ? ( ) : undefined; }; return ( // eslint-disable-next-line react-hooks/static-components }> } component={component} /> ); }; export const BaseHeroImage: FC< ReplaceFieldsWithAssets & Omit > = ({ component, isEditorPreviewMode, image, objectFit, width, height, overlayColor, contrastBaseColor, overlayOpacity, border, priority, unoptimized, fill, variant, }) => { const [resolvedImage] = image || []; if (!resolvedImage?.url) { const isPlaceholder = component?._id?.includes('placeholder_'); if (!isEditorPreviewMode || isPlaceholder || !variant) { return null; } return (
); } const { focalPoint, title = '' } = resolvedImage; const imageWidth = width || resolvedImage.width; const imageHeight = height || resolvedImage.height; if (!fill && (!imageWidth || !imageHeight)) { console.warn( 'No dimensions provided for the Next.js Image component. Falling back to a standard tag for rendering.' ); // eslint-disable-next-line @next/next/no-img-element return {title}; } const imageUrl = imageFrom(resolvedImage.url) .transform({ width: width, height: height, fit: objectFit, focal: focalPoint, }) .url(); const variantBasedProps = fill ? { fill: true } : { width: imageWidth, height: imageHeight, }; return ( ); };