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:
+1
-1
@@ -2,7 +2,7 @@ import { useContext } from 'react';
|
||||
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
|
||||
|
||||
import { SKELETON_LOADER_HEIGHT_SIZES } from '@/activities/components/SkeletonLoader';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { ThemeContext } from 'twenty-ui/theme-constants';
|
||||
|
||||
export const SettingsAdminTabSkeletonLoader = () => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
|
||||
+4
-2
@@ -5,7 +5,8 @@ import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { type IconComponent } from 'twenty-ui/display';
|
||||
import { Card } from 'twenty-ui/layout';
|
||||
import { ICON_SIZES, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
type TableItem = {
|
||||
Icon?: IconComponent;
|
||||
@@ -31,6 +32,7 @@ export const SettingsAdminTableCard = ({
|
||||
valueAlign = 'left',
|
||||
className,
|
||||
}: SettingsAdminTableCardProps) => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
return (
|
||||
<Card
|
||||
rounded={rounded}
|
||||
@@ -51,7 +53,7 @@ export const SettingsAdminTableCard = ({
|
||||
height={themeCssVariables.spacing[6]}
|
||||
gap={themeCssVariables.spacing[2]}
|
||||
>
|
||||
{item.Icon && <item.Icon size={ICON_SIZES.md} />}
|
||||
{item.Icon && <item.Icon size={theme.icon.size.md} />}
|
||||
<span>{item.label}</span>
|
||||
</TableCell>
|
||||
<TableCell
|
||||
|
||||
+2
-4
@@ -10,11 +10,10 @@ import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/Drop
|
||||
import { DropdownMenuSeparator } from '@/ui/layout/dropdown/components/DropdownMenuSeparator';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
||||
import { useContext } from 'react';
|
||||
import { IconChevronLeft, IconEye, IconEyeOff } from 'twenty-ui/display';
|
||||
import { MenuItem, MenuItemSelectTag } from 'twenty-ui/navigation';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext } from 'twenty-ui/theme-constants';
|
||||
type ConfigVariableOptionsDropdownContentProps = {
|
||||
selectedCategory: ConfigVariableFilterCategory | null;
|
||||
onSelectCategory: (category: ConfigVariableFilterCategory | null) => void;
|
||||
@@ -39,7 +38,6 @@ export const ConfigVariableOptionsDropdownContent = ({
|
||||
onShowHiddenChange,
|
||||
}: ConfigVariableOptionsDropdownContentProps) => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
|
||||
const isConfigVariablesInDbEnabled = useAtomStateValue(
|
||||
isConfigVariablesInDbEnabledState,
|
||||
);
|
||||
|
||||
+2
-3
@@ -1,12 +1,11 @@
|
||||
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
||||
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
||||
import { useContext } from 'react';
|
||||
import { styled } from '@linaria/react';
|
||||
import { SettingsPath } from 'twenty-shared/types';
|
||||
import { getSettingsPath } from 'twenty-shared/utils';
|
||||
import { IconChevronRight } from 'twenty-ui/display';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { type ConfigVariable } from '~/generated-metadata/graphql';
|
||||
|
||||
type SettingsAdminConfigVariablesRowProps = {
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { useContext } from 'react';
|
||||
import { CustomError } from 'twenty-shared/utils';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { ThemeContext } from 'twenty-ui/theme-constants';
|
||||
|
||||
import { ConfigSource } from '~/generated-metadata/graphql';
|
||||
|
||||
export const useSourceContent = (source: ConfigSource) => {
|
||||
const { t } = useLingui();
|
||||
const { theme } = useContext(ThemeContext);
|
||||
const { t } = useLingui();
|
||||
|
||||
switch (source) {
|
||||
case ConfigSource.DATABASE:
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import { SettingsListCard } from '@/settings/components/SettingsListCard';
|
||||
import { useContext } from 'react';
|
||||
import { SettingsPath } from 'twenty-shared/types';
|
||||
import { getSettingsPath } from 'twenty-shared/utils';
|
||||
import {
|
||||
@@ -10,7 +9,8 @@ import {
|
||||
IconTool,
|
||||
IconUserCircle,
|
||||
} from 'twenty-ui/display';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext } from 'twenty-ui/theme-constants';
|
||||
import {
|
||||
HealthIndicatorId,
|
||||
type SystemHealthService,
|
||||
|
||||
+2
-3
@@ -1,12 +1,11 @@
|
||||
import { SettingsAdminTableCard } from '@/settings/admin-panel/components/SettingsAdminTableCard';
|
||||
import { SettingsAdminWorkerMetricsTooltip } from '@/settings/admin-panel/health-status/components/SettingsAdminWorkerMetricsTooltip';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useContext } from 'react';
|
||||
import { styled } from '@linaria/react';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { ResponsiveLine } from '@nivo/line';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import {
|
||||
QueueMetricsTimeRange,
|
||||
useGetQueueMetricsQuery,
|
||||
|
||||
Reference in New Issue
Block a user