Files
twenty/packages/twenty-ui/src/display/info/components/Info.tsx
T
Charles Bochet 647c32ff3e 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'` |
2026-03-05 14:39:01 +01:00

104 lines
2.4 KiB
TypeScript

import { styled } from '@linaria/react';
import { IconInfoCircle } from '@ui/display/icon/components/TablerIcons';
import { ThemeContext, themeCssVariables } from '@ui/theme-constants';
import { Button } from '@ui/input/button/components/Button/Button';
import React, { useContext } from 'react';
import { Link } from 'react-router-dom';
export type InfoAccent = 'blue' | 'danger';
export type InfoProps = {
accent?: InfoAccent;
text: string;
buttonTitle?: string;
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
to?: string;
};
const StyledTextContainer = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[2]};
& > svg {
flex-shrink: 0;
}
`;
const StyledInfo = styled.div<Pick<InfoProps, 'accent'>>`
align-items: center;
border-radius: ${themeCssVariables.border.radius.md};
display: flex;
font-weight: ${themeCssVariables.font.weight.medium};
justify-content: space-between;
max-width: 512px;
gap: ${themeCssVariables.spacing[2]};
padding: ${themeCssVariables.spacing[2]};
background: ${({ accent }) => {
switch (accent) {
case 'blue':
return themeCssVariables.color.blue5;
case 'danger':
return themeCssVariables.color.red3;
default:
return 'transparent';
}
}};
color: ${({ accent }) => {
switch (accent) {
case 'blue':
return themeCssVariables.color.blue10;
case 'danger':
return themeCssVariables.color.red;
default:
return 'inherit';
}
}};
`;
const StyledLinkContainer = styled.span`
& > a {
text-decoration: none;
}
`;
export const Info = ({
accent = 'blue',
text,
buttonTitle,
onClick,
to,
}: InfoProps) => {
const { theme } = useContext(ThemeContext);
return (
<StyledInfo accent={accent}>
<StyledTextContainer>
<IconInfoCircle size={theme.icon.size.md} />
{text}
</StyledTextContainer>
{buttonTitle && to && (
<StyledLinkContainer>
<Link to={to}>
<Button
title={buttonTitle}
size="small"
variant="secondary"
accent={accent}
/>
</Link>
</StyledLinkContainer>
)}
{buttonTitle && onClick && !to && (
<Button
title={buttonTitle}
onClick={onClick}
size="small"
variant="secondary"
accent={accent}
/>
)}
</StyledInfo>
);
};