Files
twenty/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx
T
Charles Bochet 3bfdc2c83f chore(twenty-front): migrate command-menu, workflow, page-layout and UI modules from Emotion to Linaria (PR 4-6/10) (#18342)
## Summary

Continues the Emotion → Linaria migration (PR 4-6 from the [migration
plan](docs/emotion-to-linaria-migration-plan.md)). Migrates **311
files** across four module groups:

| Module | Files |
|---|---|
| command-menu | 53 |
| workflow | 84 |
| page-layout | 84 |
| UI (partial - first ~80 files) | ~80 |
| twenty-ui (TEXT_INPUT_STYLE) | 1 |
| misc (hooks, keyboard-shortcut-menu, file-upload) | ~9 |

### Migration patterns applied

- `import styled from '@emotion/styled'` → `import { styled } from
'@linaria/react'`
- `import { useTheme } from '@emotion/react'` → `import { useContext }
from 'react'` + `import { ThemeContext } from 'twenty-ui/theme'`
- `${({ theme }) => theme.X.Y.Z}` → `${themeCssVariables.X.Y.Z}` (static
CSS variables)
- `theme.spacing(N)` → `themeCssVariables.spacing[N]`
- `styled(motion.div)` → `motion.create(StyledBase)` (11 components)
- `styled(Component)<TypeParams>` → wrapper div approach for non-HTML
elements
- Multi-declaration interpolations split into one CSS property per
interpolation
- Interpolation return types fixed (`&&` → ternary `? : ''`)
- `TEXT_INPUT_STYLE` converted from function to static string constant
(backward compatible)
- Emotion `<Global>` replaced with `useEffect` style injection
- Complex runtime-dependent styles use CSS custom properties via
`style={}` prop

### After this PR

- **Remaining files**: ~400 (object-record: ~160, settings: ~200, UI:
~44)
- **No breaking changes**: CSS variables resolve identically to the
previous Emotion theme values
2026-03-03 16:42:03 +01:00

116 lines
3.2 KiB
TypeScript

import { styled } from '@linaria/react';
import {
type DraggableProvided,
type DraggableRubric,
type DraggableStateSnapshot,
Droppable,
} from '@hello-pangea/dnd';
import { TabButton } from 'twenty-ui/input';
import { TAB_LIST_GAP } from '@/ui/layout/tab-list/constants/TabListGap';
import { type SingleTabProps } from '@/ui/layout/tab-list/types/SingleTabProps';
import { PAGE_LAYOUT_TAB_LIST_DROPPABLE_IDS } from '@/page-layout/components/PageLayoutTabListDroppableIds';
import { PageLayoutTabListReorderableTab } from '@/page-layout/components/PageLayoutTabListReorderableTab';
import { PageLayoutTabRenderClone } from '@/page-layout/components/PageLayoutTabRenderClone';
type PageLayoutTabListVisibleTabsProps = {
visibleTabs: SingleTabProps[];
visibleTabCount: number;
activeTabId: string | null;
behaveAsLinks: boolean;
loading?: boolean;
onChangeTab?: (tabId: string) => void;
onSelectTab: (tabId: string) => void;
canReorder: boolean;
};
const StyledTabContainer = styled.div`
display: flex;
position: relative;
overflow: hidden;
max-width: 100%;
> *:not(:last-child) {
margin-right: ${TAB_LIST_GAP}px;
}
`;
export const PageLayoutTabListVisibleTabs = ({
visibleTabs,
visibleTabCount,
activeTabId,
behaveAsLinks,
loading,
onChangeTab,
onSelectTab,
canReorder,
}: PageLayoutTabListVisibleTabsProps) => {
if (canReorder) {
return (
<Droppable
droppableId={PAGE_LAYOUT_TAB_LIST_DROPPABLE_IDS.VISIBLE_TABS}
direction="horizontal"
renderClone={(
provided: DraggableProvided,
_snapshot: DraggableStateSnapshot,
rubric: DraggableRubric,
) => {
const tab = visibleTabs[rubric.source.index];
return (
<PageLayoutTabRenderClone
provided={provided}
tab={tab}
activeTabId={activeTabId}
/>
);
}}
>
{(provided) => (
<StyledTabContainer
ref={provided.innerRef}
// eslint-disable-next-line react/jsx-props-no-spreading
{...provided.droppableProps}
>
{visibleTabs.slice(0, visibleTabCount).map((tab, index) => (
<PageLayoutTabListReorderableTab
key={tab.id}
tab={tab}
index={index}
isActive={tab.id === activeTabId}
disabled={tab.disabled ?? loading}
onSelect={() => onSelectTab(tab.id)}
/>
))}
{provided.placeholder}
</StyledTabContainer>
)}
</Droppable>
);
}
return (
<StyledTabContainer>
{visibleTabs.slice(0, visibleTabCount).map((tab) => (
<TabButton
key={tab.id}
id={tab.id}
title={tab.title}
LeftIcon={tab.Icon}
logo={tab.logo}
active={tab.id === activeTabId}
disabled={tab.disabled ?? loading}
pill={tab.pill}
to={behaveAsLinks ? `#${tab.id}` : undefined}
onClick={
behaveAsLinks
? () => onChangeTab?.(tab.id)
: () => onSelectTab(tab.id)
}
/>
))}
</StyledTabContainer>
);
};