fix: retina images
This commit is contained in:
1 parent
0cface89bf
commit
8473a104ca
4 files changed
+29
-16
No files matched your search
@@ -22,12 +22,16 @@ const Poster: FC<Props> = ({ show, onClick, className, rounded, containerProps,
|
||||
className={cn('card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg', className, rounded)}
|
||||
>
|
||||
<div className='flex size-full'>
|
||||
<img
|
||||
className={cn('size-full rounded-lg object-cover', rounded)}
|
||||
loading={lazy ? 'lazy' : 'eager'}
|
||||
src={show.poster}
|
||||
alt={show.title}
|
||||
/>
|
||||
<picture>
|
||||
<source srcSet={show.poster['1x']} media='(min-width: 601px)' />
|
||||
<source srcSet={show.poster['2x']} media='(max-width: 600px)' />
|
||||
<img
|
||||
className={cn('size-full rounded-lg object-cover', rounded)}
|
||||
loading={lazy ? 'lazy' : 'eager'}
|
||||
src={show.poster['1x']}
|
||||
alt={show.title}
|
||||
/>
|
||||
</picture>
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
|
||||
+10
-7
@@ -4,11 +4,12 @@ import { cn } from '@/lib/utils';
|
||||
|
||||
type Tab = { title: string };
|
||||
|
||||
type CursorProps = { left: number; width: number; opacity: number };
|
||||
type CursorProps = { left: number; width: number; opacity: number; onTransitionEnd: () => void };
|
||||
|
||||
const Cursor: FC<CursorProps> = ({ width, left, opacity }) => (
|
||||
const Cursor: FC<CursorProps> = ({ width, left, opacity, onTransitionEnd }) => (
|
||||
<li
|
||||
className='pointer-events-none absolute z-0 h-full rounded-2xl bg-primary transition-all'
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
style={{ width, left, opacity }}
|
||||
/>
|
||||
);
|
||||
@@ -23,12 +24,14 @@ export type NavProps<T extends Tab> = {
|
||||
|
||||
function Nav<T extends Tab>({ tabs, active, className, children, onChange }: NavProps<T>) {
|
||||
const [cursor, setCursor] = useState({ left: 0, width: 0, opacity: 0 });
|
||||
const [transitionEnded, setTransitionEnded] = useState(false);
|
||||
const currentRef = useRef<HTMLLIElement>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const link = currentRef.current;
|
||||
|
||||
setCursor({ width: link?.clientWidth || 0, left: link?.offsetLeft || 0, opacity: link ? 1 : 0 });
|
||||
setTransitionEnded(false);
|
||||
}, [active?.title]);
|
||||
|
||||
return (
|
||||
@@ -43,16 +46,16 @@ function Nav<T extends Tab>({ tabs, active, className, children, onChange }: Nav
|
||||
key={title}
|
||||
ref={isActive ? currentRef : undefined}
|
||||
onClick={() => onChange?.(tab)}
|
||||
className={cn(
|
||||
'mix-blend-difference text-white z-10 px-2.5 py-0.5 font-normal cursor-default',
|
||||
!isActive && 'cursor-pointer'
|
||||
)}
|
||||
className={cn('z-10 px-2.5 py-0.5 font-normal cursor-pointer', {
|
||||
'cursor-default text-secondary': isActive,
|
||||
'mix-blend-difference text-white': !transitionEnded
|
||||
})}
|
||||
>
|
||||
{children?.(tab) || <div>{title}</div>}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
<Cursor {...cursor} />
|
||||
<Cursor {...cursor} onTransitionEnd={() => setTransitionEnded(true)} />
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user