diff --git a/src/components/primitives/ResponsiveText.tsx b/src/components/primitives/ResponsiveText.tsx index c4175f23..a130c0a5 100644 --- a/src/components/primitives/ResponsiveText.tsx +++ b/src/components/primitives/ResponsiveText.tsx @@ -1,5 +1,11 @@ import clsx from 'clsx/lite'; -import { ReactNode } from 'react'; +import { ReactNode, useMemo } from 'react'; + +// Show long text at 'lg' breakpoint when 32 characters +const CHARACTER_CUTOFF_LG = 32; +// Show long text at 'md' breakpoint when 24 characters +const CHARACTER_CUTOFF_MD = 24; +// Otherwise show long text at 'sm' breakpoint export default function ResponsiveText({ shortText, @@ -10,17 +16,29 @@ export default function ResponsiveText({ className?: string children: ReactNode }) { + const cutoffClasses = useMemo(() => { + const textLength = typeof children === 'string' + ? children.length + : 0; + console.log(textLength); + return textLength >= CHARACTER_CUTOFF_LG + ? { short: 'lg:hidden', long: 'max-lg:hidden' } + : textLength >= CHARACTER_CUTOFF_MD + ? { short: 'md:hidden', long: 'max-md:hidden' } + : { short: 'sm:hidden', long: 'max-sm:hidden' }; + }, [children]); + return ( <> {/* Short text */} {shortText ?? children} {/* Full text */} - + {children} diff --git a/src/lens/LensHeader.tsx b/src/lens/LensHeader.tsx index 6bf99b36..9f41cb75 100644 --- a/src/lens/LensHeader.tsx +++ b/src/lens/LensHeader.tsx @@ -31,6 +31,7 @@ export default async function LensHeader({ {...{ lens }} contrast="high" showHover={false} + longText />} entityDescription={ descriptionForLensPhotos( diff --git a/src/lens/PhotoLens.tsx b/src/lens/PhotoLens.tsx index 579032f7..786acaab 100644 --- a/src/lens/PhotoLens.tsx +++ b/src/lens/PhotoLens.tsx @@ -9,16 +9,17 @@ import IconLens from '@/components/icons/IconLens'; export default function PhotoLens({ lens, - shortText, + longText, ...props }: { lens: Lens - shortText?: boolean + longText?: boolean } & EntityLinkExternalProps) { return ( } }