mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 10:45:54 +00:00
fix: support additional theme names
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { BackgroundVariant } from 'reactflow';
|
import { BackgroundVariant } from 'reactflow';
|
||||||
|
|
||||||
|
|
||||||
export function useBackgroundVars(themeName?: string) {
|
export function useBackgroundVars(themeName?: string) {
|
||||||
const [variant, setVariant] = useState<BackgroundVariant>(BackgroundVariant.Dots);
|
const [variant, setVariant] = useState<BackgroundVariant>(BackgroundVariant.Dots);
|
||||||
const [gap, setGap] = useState<number>(16);
|
const [gap, setGap] = useState<number>(16);
|
||||||
const [size, setSize] = useState<number>(1);
|
const [size, setSize] = useState<number>(1);
|
||||||
const [color, setColor] = useState('#81818b')
|
const [color, setColor] = useState('#81818b');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let themeEl = document.querySelector('.pathfinder-theme, .default-theme');
|
// match any element whose entire `class` attribute ends with "-theme"
|
||||||
|
let themeEl = document.querySelector('[class$="-theme"]');
|
||||||
|
|
||||||
|
// If none is found, fall back to the <html> element
|
||||||
if (!themeEl) {
|
if (!themeEl) {
|
||||||
themeEl = document.documentElement;
|
themeEl = document.documentElement;
|
||||||
}
|
}
|
||||||
@@ -18,6 +20,7 @@ export function useBackgroundVars(themeName?: string) {
|
|||||||
|
|
||||||
const rawVariant = style.getPropertyValue('--rf-bg-variant').replace(/['"]/g, '').trim().toLowerCase();
|
const rawVariant = style.getPropertyValue('--rf-bg-variant').replace(/['"]/g, '').trim().toLowerCase();
|
||||||
let finalVariant: BackgroundVariant = BackgroundVariant.Dots;
|
let finalVariant: BackgroundVariant = BackgroundVariant.Dots;
|
||||||
|
|
||||||
if (rawVariant === 'lines') {
|
if (rawVariant === 'lines') {
|
||||||
finalVariant = BackgroundVariant.Lines;
|
finalVariant = BackgroundVariant.Lines;
|
||||||
} else if (rawVariant === 'cross') {
|
} else if (rawVariant === 'cross') {
|
||||||
@@ -35,7 +38,6 @@ export function useBackgroundVars(themeName?: string) {
|
|||||||
setGap(gapNum);
|
setGap(gapNum);
|
||||||
setSize(sizeNum);
|
setSize(sizeNum);
|
||||||
setColor(cssColor);
|
setColor(cssColor);
|
||||||
|
|
||||||
}, [themeName]);
|
}, [themeName]);
|
||||||
|
|
||||||
return { variant, gap, size, color };
|
return { variant, gap, size, color };
|
||||||
|
|||||||
Reference in New Issue
Block a user