inject css vars

This commit is contained in:
Nate Kelley 2025-08-01 19:25:57 -06:00
parent dee28ed951
commit f20cf2812b
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 28 additions and 38 deletions

View File

@ -2,26 +2,30 @@
import { useMounted } from '@/hooks/useMount';
import { useThemesConfig } from './useThemesConfig';
import React from 'react';
export function ThemesStyle() {
const { activeTheme } = useThemesConfig();
export const ThemesStyle = React.memo(() => {
const { activeTheme, BASE_THEME } = useThemesConfig();
const mounted = useMounted();
if (!activeTheme || !mounted) {
return null;
}
console.log(activeTheme);
return (
<style>
{`
.themes-wrapper,
[data-chart] {
background-color: red;
${Object.entries(activeTheme.light)
.map(([key, value]) => `${key}: hsl(${value});`)
.join('\n')}
${Object.entries(BASE_THEME)
.map(([key, value]) => `${key}: ${value};`)
.join('\n')}
}
.dark .themes-wrapper,
@ -34,4 +38,6 @@ export function ThemesStyle() {
`}
</style>
);
}
});
ThemesStyle.displayName = 'ThemesStyle';

View File

@ -10,16 +10,18 @@ interface ThemeWrapperProps extends React.ComponentProps<'div'> {
export function ThemeWrapper({ children, className, defaultTheme }: ThemeWrapperProps) {
return (
<div
className={cn(
// `theme-${defaultTheme || config.theme}`,
'themes-wrapper',
'w-full',
className
)}>
<ThemesStyle />
<>
<div
className={cn(
// `theme-${defaultTheme || config.theme}`,
'themes-wrapper',
'w-full',
className
)}>
{children}
</div>
{children}
</div>
<ThemesStyle />
</>
);
}

View File

@ -1,4 +1,4 @@
const BASE_THEME = {
export const BASE_THEME = {
'--spacing': '0.25rem',
'--breakpoint-xl': '80rem',
'--breakpoint-2xl': '96rem',
@ -567,7 +567,6 @@ const _THEMES = {
Object.entries(_THEMES).forEach(([key, theme]) => {
// @ts-expect-error - key is a string
_THEMES[key] = {
...BASE_THEME,
...theme,
dark: themeColorsToCssVariables(theme.dark),
light: themeColorsToCssVariables(theme.light)
@ -595,7 +594,7 @@ export function themeColorsToCssVariables(colors: Record<string, string>): Recor
// `${cssVars["--primary"]} / ${100 - key * 20}%`
// }
return cssVars;
return { ...cssVars, ...BASE_THEME };
}
export function themeColorNameToCssVariable(name: string) {

View File

@ -1,5 +1,5 @@
import { create } from 'zustand';
import { THEMES, type Theme } from './themes';
import { THEMES, BASE_THEME, type Theme } from './themes';
const useThemesConfigStore = create<{
activeTheme: Theme;
@ -13,5 +13,5 @@ export function useThemesConfig() {
const activeTheme = useThemesConfigStore((state) => state.activeTheme);
const setActiveTheme = useThemesConfigStore((state) => state.setActiveTheme);
return { activeTheme, setActiveTheme, allThemes: THEMES };
return { activeTheme, setActiveTheme, allThemes: THEMES, BASE_THEME };
}

View File

@ -5,23 +5,6 @@ import * as React from 'react';
import { AIChatPlugin, AIPlugin, useEditorChat, useLastAssistantMessage } from '@platejs/ai/react';
import { BlockSelectionPlugin, useIsSelecting } from '@platejs/selection/react';
import { Command as CommandPrimitive } from 'cmdk';
// import {
// Album,
// BadgeHelp,
// BookOpenCheck,
// Check,
// CornerUpLeft,
// FeatherIcon,
// ListEnd,
// ListMinus,
// ListPlus,
// Loader2Icon,
// PauseIcon,
// PenLine,
// SmileIcon,
// Wand,
// X
// } from 'lucide-react';
import {
Album,
CircleQuestion,