Deprecate runtime theme objects in favor of CSS variables (#18402)
## Summary
- **Eliminate `ICON_SIZES` / `ICON_STROKES` constants**: all icon
dimensions are now resolved at runtime via
`resolveThemeVariableAsNumber(themeCssVariables.icon.size.X)`, ensuring
values always come from computed CSS variables
- **No more consumer imports from `twenty-ui/theme`**: moved
`ColorSchemeContext`, `ColorSchemeProvider`, `ThemeColor`,
`MAIN_COLOR_NAMES`, `getNextThemeColor`, `AnimationDuration` to
`twenty-ui/theme-constants`
- **Remove `ThemeContext` / `ThemeContextProvider` / `ThemeProvider` /
`ThemeType`**: replaced across ~300 files with `themeCssVariables` (for
CSS contexts) or `resolveThemeVariable` / `resolveThemeVariableAsNumber`
(for JS runtime values)
- **Simplify provider chain**: only `ColorSchemeProvider` remains — it
toggles `light`/`dark` class on `document.documentElement` and provides
`colorScheme` via React context
- **Fix pre-existing test failures**: `useIcons.test.ts`
(non-configurable ES module spy) and
`turnRecordFilterGroupIntoGqlOperationFilter.test.ts`
(`Omit<RecordFilter, 'id'>` type mismatch)
### Theme access pattern (before → after)
| Context | Before | After |
|---------|--------|-------|
| CSS (Linaria) | `${({ theme }) => theme.font.color.primary}` |
`${themeCssVariables.font.color.primary}` |
| JS runtime (icon size, animation) | `theme.icon.size.md` /
`ICON_SIZES.md` |
`resolveThemeVariableAsNumber(themeCssVariables.icon.size.md)` |
| Color scheme check | `theme.name === 'dark'` |
`useContext(ColorSchemeContext).colorScheme === 'dark'` |
This commit is contained in:
@@ -4,7 +4,7 @@ import { useSystemColorScheme } from '@/ui/theme/hooks/useSystemColorScheme';
|
||||
import { persistedColorSchemeState } from '@/ui/theme/states/persistedColorSchemeState';
|
||||
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
|
||||
import { type ColorScheme } from 'twenty-ui/input';
|
||||
import { THEME_DARK, THEME_LIGHT, ThemeContextProvider } from 'twenty-ui/theme';
|
||||
import { ThemeProvider } from 'twenty-ui/theme-constants';
|
||||
|
||||
type BaseThemeProviderProps = {
|
||||
children: JSX.Element | JSX.Element[];
|
||||
@@ -24,14 +24,13 @@ export const BaseThemeProvider = ({ children }: BaseThemeProviderProps) => {
|
||||
? systemColorScheme
|
||||
: persistedColorScheme;
|
||||
|
||||
document.documentElement.className =
|
||||
effectiveColorScheme === 'Dark' ? 'dark' : 'light';
|
||||
|
||||
const theme = effectiveColorScheme === 'Dark' ? THEME_DARK : THEME_LIGHT;
|
||||
|
||||
return (
|
||||
<ThemeSchemeContext.Provider value={setPersistedColorScheme}>
|
||||
<ThemeContextProvider theme={theme}>{children}</ThemeContextProvider>
|
||||
<ThemeProvider
|
||||
colorScheme={effectiveColorScheme === 'Dark' ? 'dark' : 'light'}
|
||||
>
|
||||
{children}
|
||||
</ThemeProvider>
|
||||
</ThemeSchemeContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user