fix: support additional theme names

This commit is contained in:
Gustav
2025-01-09 15:06:32 -05:00
parent 58293b4dc4
commit d758b54ef8

View File

@@ -1,15 +1,17 @@
import { useEffect, useState } from 'react';
import { BackgroundVariant } from 'reactflow';
export function useBackgroundVars(themeName?: string) {
const [variant, setVariant] = useState<BackgroundVariant>(BackgroundVariant.Dots);
const [gap, setGap] = useState<number>(16);
const [size, setSize] = useState<number>(1);
const [color, setColor] = useState('#81818b')
const [color, setColor] = useState('#81818b');
useEffect(() => {
let themeEl = document.querySelector('.pathfinder-theme, .default-theme');
useEffect(() => {
// 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) {
themeEl = document.documentElement;
}
@@ -18,6 +20,7 @@ export function useBackgroundVars(themeName?: string) {
const rawVariant = style.getPropertyValue('--rf-bg-variant').replace(/['"]/g, '').trim().toLowerCase();
let finalVariant: BackgroundVariant = BackgroundVariant.Dots;
if (rawVariant === 'lines') {
finalVariant = BackgroundVariant.Lines;
} else if (rawVariant === 'cross') {
@@ -35,8 +38,7 @@ export function useBackgroundVars(themeName?: string) {
setGap(gapNum);
setSize(sizeNum);
setColor(cssColor);
}, [themeName]);
}, [themeName]);
return { variant, gap, size, color };
}