mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-31 02:51:36 +02:00
Slight adjustments to carousel modal
- Gap between media - Gradiented backgrounds
This commit is contained in:
parent
82a9a7212d
commit
97188391df
2 changed files with 64 additions and 16 deletions
src
|
@ -1135,6 +1135,7 @@ a[href^='http'][rel*='nofollow']:visited:not(:has(div)) {
|
||||||
touch-action: pan-x;
|
touch-action: pan-x;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
gap: 16px;
|
||||||
}
|
}
|
||||||
.carousel::-webkit-scrollbar {
|
.carousel::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import { Menu } from '@szhsin/react-menu';
|
import { Menu } from '@szhsin/react-menu';
|
||||||
import { getBlurHashAverageColor } from 'fast-blurhash';
|
import { getBlurHashAverageColor } from 'fast-blurhash';
|
||||||
import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
|
import {
|
||||||
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'preact/hooks';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
|
|
||||||
import { oklab2rgb, rgb2oklab } from '../utils/color-utils';
|
import { oklab2rgb, rgb2oklab } from '../utils/color-utils';
|
||||||
|
@ -102,6 +108,41 @@ function MediaModal({
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const mediaAccentColors = useMemo(() => {
|
||||||
|
return mediaAttachments?.map((media) => {
|
||||||
|
const { blurhash } = media;
|
||||||
|
if (blurhash) {
|
||||||
|
const averageColor = getBlurHashAverageColor(blurhash);
|
||||||
|
const labAverageColor = rgb2oklab(averageColor);
|
||||||
|
return oklab2rgb([0.6, labAverageColor[1], labAverageColor[2]]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}, [mediaAttachments]);
|
||||||
|
const mediaAccentGradient = useMemo(() => {
|
||||||
|
const gap = 5;
|
||||||
|
const range = 100 / mediaAccentColors.length;
|
||||||
|
return (
|
||||||
|
mediaAccentColors
|
||||||
|
?.map((color, i) => {
|
||||||
|
const start = i * range + gap;
|
||||||
|
const end = (i + 1) * range - gap;
|
||||||
|
if (color) {
|
||||||
|
return `
|
||||||
|
rgba(${color?.join(',')}, 0.4) ${start}%,
|
||||||
|
rgba(${color?.join(',')}, 0.4) ${end}%
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
transparent ${start}%,
|
||||||
|
transparent ${end}%
|
||||||
|
`;
|
||||||
|
})
|
||||||
|
?.join(', ') || 'transparent'
|
||||||
|
);
|
||||||
|
}, [mediaAccentColors]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={`media-modal-container media-modal-count-${mediaAttachments?.length}`}
|
class={`media-modal-container media-modal-count-${mediaAttachments?.length}`}
|
||||||
|
@ -120,26 +161,32 @@ function MediaModal({
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
style={
|
||||||
|
mediaAttachments.length > 1
|
||||||
|
? {
|
||||||
|
backgroundAttachment: 'local',
|
||||||
|
backgroundImage: `linear-gradient(
|
||||||
|
to right, ${mediaAccentGradient})`,
|
||||||
|
}
|
||||||
|
: {}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{mediaAttachments?.map((media, i) => {
|
{mediaAttachments?.map((media, i) => {
|
||||||
const { blurhash } = media;
|
const accentColor =
|
||||||
let accentColor;
|
mediaAttachments.length === 1 ? mediaAccentColors[i] : null;
|
||||||
if (blurhash) {
|
|
||||||
const averageColor = getBlurHashAverageColor(blurhash);
|
|
||||||
const labAverageColor = rgb2oklab(averageColor);
|
|
||||||
accentColor = oklab2rgb([
|
|
||||||
0.6,
|
|
||||||
labAverageColor[1],
|
|
||||||
labAverageColor[2],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class="carousel-item"
|
class="carousel-item"
|
||||||
style={{
|
style={
|
||||||
'--accent-color': `rgb(${accentColor?.join(',')})`,
|
accentColor
|
||||||
'--accent-alpha-color': `rgba(${accentColor?.join(',')}, 0.4)`,
|
? {
|
||||||
}}
|
'--accent-color': `rgb(${accentColor?.join(',')})`,
|
||||||
|
'--accent-alpha-color': `rgba(${accentColor?.join(
|
||||||
|
',',
|
||||||
|
)}, 0.4)`,
|
||||||
|
}
|
||||||
|
: {}
|
||||||
|
}
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
key={media.id}
|
key={media.id}
|
||||||
ref={i === currentIndex ? carouselFocusItem : null}
|
ref={i === currentIndex ? carouselFocusItem : null}
|
||||||
|
|
Loading…
Add table
Reference in a new issue