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
-5
@@ -2,10 +2,8 @@ import { styled } from '@linaria/react';
|
||||
import { useContext } from 'react';
|
||||
// @ts-expect-error // Todo: remove usage of react-data-grid
|
||||
import DataGrid, { type DataGridProps } from 'react-data-grid';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
import { useSpreadsheetImportInternal } from '@/spreadsheet-import/hooks/useSpreadsheetImportInternal';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
|
||||
const StyledDataGrid = styled(DataGrid)`
|
||||
--rdg-background-color: ${themeCssVariables.background.primary};
|
||||
@@ -132,9 +130,10 @@ export const SpreadsheetImportTable = <Data,>({
|
||||
onSelectedRowsChange,
|
||||
selectedRows,
|
||||
}: SpreadsheetImportTableProps<Data>) => {
|
||||
const { colorScheme } = useContext(ThemeContext);
|
||||
|
||||
const { rtl } = useSpreadsheetImportInternal();
|
||||
const { theme } = useContext(ThemeContext);
|
||||
const themeClassName = theme.name === 'dark' ? 'rdg-dark' : 'rdg-light';
|
||||
const themeClassName = colorScheme === 'dark' ? 'rdg-dark' : 'rdg-light';
|
||||
|
||||
if (!rows?.length || !columns?.length) return null;
|
||||
|
||||
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
import React, { useContext } from 'react';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
|
||||
import { ThemeContext } from 'twenty-ui/theme-constants';
|
||||
|
||||
import { SKELETON_LOADER_HEIGHT_SIZES } from '@/activities/components/SkeletonLoader';
|
||||
import { SPREADSHEET_IMPORT_MODAL_ID } from '@/spreadsheet-import/constants/SpreadsheetImportModalId';
|
||||
@@ -18,7 +18,6 @@ const SpreadsheetImport = React.lazy(() =>
|
||||
|
||||
const LoadingSkeleton = () => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
|
||||
return (
|
||||
<SkeletonTheme
|
||||
baseColor={theme.background.tertiary}
|
||||
|
||||
+2
-5
@@ -9,8 +9,7 @@ import { type SpreadsheetMatchedOptions } from '@/spreadsheet-import/types/Sprea
|
||||
import { getFieldOptions } from '@/spreadsheet-import/utils/getFieldOptions';
|
||||
import { styled } from '@linaria/react';
|
||||
import { useContext } from 'react';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
|
||||
import { Tag, type TagColor } from 'twenty-ui/components';
|
||||
import { IconChevronDown } from 'twenty-ui/display';
|
||||
import { type SelectOption } from 'twenty-ui/input';
|
||||
@@ -31,12 +30,10 @@ export const SubMatchingSelectDropdownButton = ({
|
||||
column,
|
||||
placeholder,
|
||||
}: SubMatchingSelectDropdownButtonProps) => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
const { spreadsheetImportFields: fields } = useSpreadsheetImportInternal();
|
||||
const options = getFieldOptions(fields, column.value) as SelectOption[];
|
||||
const value = options.find((opt) => opt.value === option.value);
|
||||
|
||||
const { theme } = useContext(ThemeContext);
|
||||
|
||||
return (
|
||||
<SubMatchingSelectControlContainer cursor="pointer" id="control">
|
||||
<Tag
|
||||
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
import { styled } from '@linaria/react';
|
||||
import { useContext } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { Banner, IconChevronDown, IconInfoCircle } 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';
|
||||
|
||||
const StyledBanner = styled(Banner)<{ allMatched: boolean }>`
|
||||
background: ${({ allMatched }) =>
|
||||
|
||||
+1
-3
@@ -1,6 +1,4 @@
|
||||
import { useCallback, useContext, useState } from 'react';
|
||||
import { ThemeContext } from 'twenty-ui/theme';
|
||||
|
||||
import { useSpreadsheetImportInternal } from '@/spreadsheet-import/hooks/useSpreadsheetImportInternal';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { ModalContent } from 'twenty-ui/layout';
|
||||
@@ -14,6 +12,7 @@ import { SelectHeaderStep } from './SelectHeaderStep/SelectHeaderStep';
|
||||
import { SelectSheetStep } from './SelectSheetStep/SelectSheetStep';
|
||||
import { UploadStep } from './UploadStep/UploadStep';
|
||||
import { ValidationStep } from './ValidationStep/ValidationStep';
|
||||
import { ThemeContext } from 'twenty-ui/theme-constants';
|
||||
|
||||
type SpreadsheetImportStepperProps = {
|
||||
nextStep: () => void;
|
||||
@@ -25,7 +24,6 @@ export const SpreadsheetImportStepper = ({
|
||||
prevStep,
|
||||
}: SpreadsheetImportStepperProps) => {
|
||||
const { theme } = useContext(ThemeContext);
|
||||
|
||||
const { initialStepState } = useSpreadsheetImportInternal();
|
||||
|
||||
const [currentStepState, setCurrentStepState] =
|
||||
|
||||
Reference in New Issue
Block a user