Skip to content

Commit

Permalink
fix(theme): separate static theme variables from scoped style definition
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Nov 5, 2024
1 parent e6cdebd commit dc6fbbd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 4 additions & 3 deletions packages/theme/src/index.css.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { globalStyle } from '@vanilla-extract/css';

import {
combinedDarkCssVariables,
combinedLightCssVariables,
printCssVariables,
scopedDarkCssVariables,
scopedLightCssVariables,
} from './index';

globalStyle(':root', {
vars: combinedLightCssVariables,
});

globalStyle('[data-theme="light"]', {
vars: combinedLightCssVariables,
vars: scopedLightCssVariables,
});

globalStyle('[data-theme="dark"]', {
vars: combinedDarkCssVariables,
vars: scopedDarkCssVariables,
});

globalStyle(':root', {
Expand Down
24 changes: 17 additions & 7 deletions packages/theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export type AffineCssVariables = {
const basicFontFamily = `apple-system, BlinkMacSystemFont, 'Helvetica Neue', Tahoma, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji','Segoe UI Symbol', 'Noto Color Emoji'`;
const basicPrintFontFamily = `'Helvetica Neue', Tahoma, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji','Segoe UI Symbol', 'Noto Color Emoji'`;

/**
* Static theme that should not affected by `data-theme`
*/
export const baseTheme = {
// font
fontFamily: `'Inter', 'Source Sans 3', Poppins, ${basicFontFamily}`,
Expand Down Expand Up @@ -126,9 +129,7 @@ export const baseTheme = {
};

// Refs: https://github.com/toeverything/AFFiNE/issues/1796
export const lightTheme = {
...baseTheme,

const pureLightTheme = {
themeMode: 'light',

brandColor: '#1E96EB',
Expand Down Expand Up @@ -279,10 +280,9 @@ export const lightTheme = {
noteBackgroundGrey: 'rgba(230, 230, 230, 1)',
noteBackgroundWhite: 'rgba(255, 255, 255, 1)',
};
export const lightTheme = { ...baseTheme, ...pureLightTheme };

export const darkTheme = {
...baseTheme,

const pureDarkTheme = {
themeMode: 'dark',

brandColor: '#1E96EB',
Expand Down Expand Up @@ -433,7 +433,8 @@ export const darkTheme = {
noteBackgroundBlack: 'rgba(255, 255, 255, 1)',
noteBackgroundGrey: 'rgba(86, 86, 86, 1)',
noteBackgroundWhite: 'rgba(0, 0, 0, 1)',
} satisfies Omit<AffineTheme, 'editorMode'>;
} satisfies typeof pureLightTheme;
export const darkTheme = { ...baseTheme, ...pureDarkTheme };

export const printTheme = {
fontFamily: `'Inter', 'Source Sans 3', Poppins, ${basicPrintFontFamily}`,
Expand Down Expand Up @@ -465,6 +466,15 @@ export const combinedDarkCssVariables = {
...darkCssVariablesV2,
};

export const scopedLightCssVariables = {
...createVariables(pureLightTheme),
...lightCssVariablesV2,
};
export const scopedDarkCssVariables = {
...createVariables(pureDarkTheme),
...darkCssVariablesV2,
};

/**
* Get AFFiNE css variable name type safely
* @param key in camel or kebab format
Expand Down

0 comments on commit dc6fbbd

Please sign in to comment.