Conditionally show lens make text
This commit is contained in:
parent
d77ad59eb2
commit
8fbfd0fcb6
@ -1,5 +1,11 @@
|
|||||||
import clsx from 'clsx/lite';
|
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({
|
export default function ResponsiveText({
|
||||||
shortText,
|
shortText,
|
||||||
@ -10,17 +16,29 @@ export default function ResponsiveText({
|
|||||||
className?: string
|
className?: string
|
||||||
children: ReactNode
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Short text */}
|
{/* Short text */}
|
||||||
<span
|
<span
|
||||||
className={clsx('inline sm:hidden', className)}
|
className={clsx(cutoffClasses.short, className)}
|
||||||
aria-hidden
|
aria-hidden
|
||||||
>
|
>
|
||||||
{shortText ?? children}
|
{shortText ?? children}
|
||||||
</span>
|
</span>
|
||||||
{/* Full text */}
|
{/* Full text */}
|
||||||
<span className={clsx('hidden sm:inline', className)}>
|
<span className={clsx(cutoffClasses.long, className)}>
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -31,6 +31,7 @@ export default async function LensHeader({
|
|||||||
{...{ lens }}
|
{...{ lens }}
|
||||||
contrast="high"
|
contrast="high"
|
||||||
showHover={false}
|
showHover={false}
|
||||||
|
longText
|
||||||
/>}
|
/>}
|
||||||
entityDescription={
|
entityDescription={
|
||||||
descriptionForLensPhotos(
|
descriptionForLensPhotos(
|
||||||
|
|||||||
@ -9,16 +9,17 @@ import IconLens from '@/components/icons/IconLens';
|
|||||||
|
|
||||||
export default function PhotoLens({
|
export default function PhotoLens({
|
||||||
lens,
|
lens,
|
||||||
shortText,
|
longText,
|
||||||
...props
|
...props
|
||||||
}: {
|
}: {
|
||||||
lens: Lens
|
lens: Lens
|
||||||
shortText?: boolean
|
longText?: boolean
|
||||||
} & EntityLinkExternalProps) {
|
} & EntityLinkExternalProps) {
|
||||||
return (
|
return (
|
||||||
<EntityLink
|
<EntityLink
|
||||||
{...props}
|
{...props}
|
||||||
label={formatLensText(lens, shortText ? 'short' : 'medium')}
|
label={formatLensText(lens, longText ? 'long' : 'short')}
|
||||||
|
labelSmall={formatLensText(lens, 'short')}
|
||||||
path={pathForLens(lens)}
|
path={pathForLens(lens)}
|
||||||
hoverPhotoQueryOptions={{ lens }}
|
hoverPhotoQueryOptions={{ lens }}
|
||||||
icon={<IconLens
|
icon={<IconLens
|
||||||
|
|||||||
@ -114,7 +114,7 @@ export const formatLensText = (
|
|||||||
|
|
||||||
switch (length) {
|
switch (length) {
|
||||||
case 'long':
|
case 'long':
|
||||||
return make ? `${make} ${modelRaw}` : modelRaw;
|
return make ? `${make} ${model}` : modelRaw;
|
||||||
case 'medium':
|
case 'medium':
|
||||||
case 'short':
|
case 'short':
|
||||||
return model;
|
return model;
|
||||||
|
|||||||
@ -341,7 +341,6 @@ export default function PhotoLarge({
|
|||||||
lens={lens}
|
lens={lens}
|
||||||
contrast="medium"
|
contrast="medium"
|
||||||
prefetch={prefetchRelatedLinks}
|
prefetch={prefetchRelatedLinks}
|
||||||
shortText
|
|
||||||
countOnHover={lensCount}
|
countOnHover={lensCount}
|
||||||
/>}
|
/>}
|
||||||
</div>}
|
</div>}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user