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:
+3
-4
@@ -8,9 +8,8 @@ import { createGraphiQLFetcher } from '@graphiql/toolkit';
|
||||
import { GraphiQL } from 'graphiql';
|
||||
import 'graphiql/graphiql.css';
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
type GraphQLPlaygroundProps = {
|
||||
onError(): void;
|
||||
@@ -39,7 +38,7 @@ export const GraphQLPlayground = ({
|
||||
const playgroundApiKey = useAtomStateValue(playgroundApiKeyState);
|
||||
const baseUrl = REACT_APP_SERVER_BASE_URL + '/' + schemaToPath[schema];
|
||||
|
||||
const { theme } = useContext(ThemeContext);
|
||||
const { colorScheme } = useContext(ThemeContext);
|
||||
|
||||
if (!playgroundApiKey) {
|
||||
onError();
|
||||
@@ -57,7 +56,7 @@ export const GraphQLPlayground = ({
|
||||
return (
|
||||
<StyledGraphiQLContainer>
|
||||
<GraphiQL
|
||||
forcedTheme={theme.name as 'light' | 'dark'}
|
||||
forcedTheme={colorScheme}
|
||||
plugins={[explorer]}
|
||||
fetcher={fetcher}
|
||||
defaultHeaders={JSON.stringify({
|
||||
|
||||
@@ -6,9 +6,8 @@ import { styled } from '@linaria/react';
|
||||
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
|
||||
import { SettingsPath } from 'twenty-shared/types';
|
||||
import { getSettingsPath } from 'twenty-shared/utils';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
const StyledContainer = styled.div`
|
||||
border: 1px solid ${themeCssVariables.border.color.medium};
|
||||
@@ -51,7 +50,7 @@ type RestPlaygroundProps = {
|
||||
};
|
||||
|
||||
export const RestPlayground = ({ onError, schema }: RestPlaygroundProps) => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
const { theme, colorScheme } = useContext(ThemeContext);
|
||||
const playgroundApiKey = useAtomStateValue(playgroundApiKeyState);
|
||||
|
||||
if (!playgroundApiKey) {
|
||||
@@ -85,7 +84,7 @@ export const RestPlayground = ({ onError, schema }: RestPlaygroundProps) => {
|
||||
},
|
||||
},
|
||||
baseServerURL: REACT_APP_SERVER_BASE_URL + '/' + schema,
|
||||
forceDarkModeState: theme.name === 'dark' ? 'dark' : 'light',
|
||||
forceDarkModeState: colorScheme === 'dark' ? 'dark' : 'light',
|
||||
hideClientButton: true,
|
||||
hideDarkModeToggle: true,
|
||||
hideModels: schema === 'metadata',
|
||||
|
||||
+4
-5
@@ -4,9 +4,7 @@ import { type ReactNode, useContext } from 'react';
|
||||
import DarkCoverImage from '@/settings/playground/assets/cover-dark.png';
|
||||
import LightCoverImage from '@/settings/playground/assets/cover-light.png';
|
||||
import { Card } from 'twenty-ui/layout';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
const StyledCard = styled(Card)`
|
||||
align-items: center;
|
||||
background-size: cover;
|
||||
@@ -29,9 +27,10 @@ export const StyledSettingsApiPlaygroundCoverImage = ({
|
||||
children,
|
||||
className,
|
||||
}: StyledSettingsApiPlaygroundCoverImageProps) => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
const { colorScheme } = useContext(ThemeContext);
|
||||
|
||||
const coverImage =
|
||||
theme.name === 'light'
|
||||
colorScheme === 'light'
|
||||
? LightCoverImage.toString()
|
||||
: DarkCoverImage.toString();
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user