mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-24 10:15:37 +03:00
Further extend theme-color coloring
This commit is contained in:
parent
5360951c03
commit
dcc73d0d28
2 changed files with 56 additions and 3 deletions
|
@ -1,13 +1,20 @@
|
||||||
import './modal.css';
|
import './modal.css';
|
||||||
|
|
||||||
import { createPortal } from 'preact/compat';
|
import { createPortal } from 'preact/compat';
|
||||||
import { useEffect, useRef } from 'preact/hooks';
|
import { useEffect, useLayoutEffect, useRef } from 'preact/hooks';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
|
|
||||||
|
import store from '../utils/store';
|
||||||
import useCloseWatcher from '../utils/useCloseWatcher';
|
import useCloseWatcher from '../utils/useCloseWatcher';
|
||||||
|
|
||||||
const $modalContainer = document.getElementById('modal-container');
|
const $modalContainer = document.getElementById('modal-container');
|
||||||
|
|
||||||
|
function getBackdropThemeColor() {
|
||||||
|
return getComputedStyle(document.documentElement).getPropertyValue(
|
||||||
|
'--backdrop-theme-color',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function Modal({ children, onClose, onClick, class: className, minimized }) {
|
function Modal({ children, onClose, onClick, class: className, minimized }) {
|
||||||
if (!children) return null;
|
if (!children) return null;
|
||||||
|
|
||||||
|
@ -68,6 +75,50 @@ function Modal({ children, onClose, onClick, class: className, minimized }) {
|
||||||
};
|
};
|
||||||
}, [children, minimized]);
|
}, [children, minimized]);
|
||||||
|
|
||||||
|
const $meta = useRef();
|
||||||
|
const metaColor = useRef();
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (children && !minimized) {
|
||||||
|
const theme = store.local.get('theme');
|
||||||
|
if (theme) {
|
||||||
|
const backdropColor = getBackdropThemeColor();
|
||||||
|
console.log({ backdropColor });
|
||||||
|
$meta.current = document.querySelector(
|
||||||
|
`meta[name="theme-color"][data-theme-setting="manual"]`,
|
||||||
|
);
|
||||||
|
if ($meta.current) {
|
||||||
|
metaColor.current = $meta.current.content;
|
||||||
|
$meta.current.content = backdropColor;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const colorScheme = window.matchMedia('(prefers-color-scheme: dark)')
|
||||||
|
.matches
|
||||||
|
? 'dark'
|
||||||
|
: 'light';
|
||||||
|
const backdropColor = getBackdropThemeColor();
|
||||||
|
console.log({ backdropColor });
|
||||||
|
$meta.current = document.querySelector(
|
||||||
|
`meta[name="theme-color"][media*="${colorScheme}"]`,
|
||||||
|
);
|
||||||
|
if ($meta.current) {
|
||||||
|
metaColor.current = $meta.current.content;
|
||||||
|
$meta.current.content = backdropColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Reset meta color
|
||||||
|
if ($meta.current && metaColor.current) {
|
||||||
|
$meta.current.content = metaColor.current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
// Reset meta color
|
||||||
|
if ($meta.current && metaColor.current) {
|
||||||
|
$meta.current.content = metaColor.current;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [children, minimized]);
|
||||||
|
|
||||||
const Modal = (
|
const Modal = (
|
||||||
<div
|
<div
|
||||||
ref={(node) => {
|
ref={(node) => {
|
||||||
|
|
|
@ -88,8 +88,9 @@
|
||||||
--outline-hover-color: rgba(128, 128, 128, 0.7);
|
--outline-hover-color: rgba(128, 128, 128, 0.7);
|
||||||
--divider-color: rgba(0, 0, 0, 0.1);
|
--divider-color: rgba(0, 0, 0, 0.1);
|
||||||
--backdrop-color: rgba(0, 0, 0, 0.1);
|
--backdrop-color: rgba(0, 0, 0, 0.1);
|
||||||
|
--backdrop-solid-color: color-mix(in srgb, var(--bg-color) 90%, #000 10%);
|
||||||
|
--backdrop-theme-color: #e5e5e5;
|
||||||
--backdrop-darker-color: rgba(0, 0, 0, 0.25);
|
--backdrop-darker-color: rgba(0, 0, 0, 0.25);
|
||||||
--backdrop-solid-color: #eee;
|
|
||||||
--img-bg-color: rgba(128, 128, 128, 0.2);
|
--img-bg-color: rgba(128, 128, 128, 0.2);
|
||||||
--loader-color: #1c1e2199;
|
--loader-color: #1c1e2199;
|
||||||
--comment-line-color: #e5e5e5;
|
--comment-line-color: #e5e5e5;
|
||||||
|
@ -161,7 +162,8 @@
|
||||||
--divider-color: rgba(255, 255, 255, 0.1);
|
--divider-color: rgba(255, 255, 255, 0.1);
|
||||||
--bg-blur-color: #24252699;
|
--bg-blur-color: #24252699;
|
||||||
--backdrop-color: rgba(0, 0, 0, 0.5);
|
--backdrop-color: rgba(0, 0, 0, 0.5);
|
||||||
--backdrop-solid-color: #111;
|
--backdrop-solid-color: color-mix(in srgb, var(--bg-color) 50%, #000 50%);
|
||||||
|
--backdrop-theme-color: #121213; /* same as backdrop-solid-color but without color-mix, to be used for meta[theme-color] */
|
||||||
--loader-color: #f0f2f599;
|
--loader-color: #f0f2f599;
|
||||||
--comment-line-color: #565656;
|
--comment-line-color: #565656;
|
||||||
--drop-shadow-color: rgba(0, 0, 0, 0.5);
|
--drop-shadow-color: rgba(0, 0, 0, 0.5);
|
||||||
|
|
Loading…
Reference in a new issue