Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5421 box shadow on frozen header and first column #6130

Merged
merged 14 commits into from
Jul 5, 2024
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
charlesBochet committed Jul 5, 2024
commit 2b408d137c89ab9f8673fb57aa70a772793820f2

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export const RecordTableBodyEffect = () => {

useEffect(() => {
setIsRecordTableScrolledTop(scrollTop === 0);
if (scrollTop > 0) {
document
.getElementById('record-table-header')
?.classList.add('header-sticky');
} else {
document
.getElementById('record-table-header')
?.classList.remove('header-sticky');
}
}, [scrollTop, setIsRecordTableScrolledTop]);

const scrollLeft = useRecoilValue(scrollLeftState);
Expand All @@ -54,10 +63,16 @@ export const RecordTableBodyEffect = () => {
document
.getElementById('record-table-body')
?.classList.add('first-columns-sticky');
document
.getElementById('record-table-header')
?.classList.add('first-columns-sticky');
} else {
document
.getElementById('record-table-body')
?.classList.remove('first-columns-sticky');
document
.getElementById('record-table-header')
?.classList.remove('first-columns-sticky');
}
}, [scrollLeft, setIsRecordTableScrolledLeft]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,59 @@ import { RecordTableHeaderCell } from '@/object-record/record-table/record-table
import { RecordTableHeaderCheckboxColumn } from '@/object-record/record-table/record-table-header/components/RecordTableHeaderCheckboxColumn';
import { RecordTableHeaderDragDropColumn } from '@/object-record/record-table/record-table-header/components/RecordTableHeaderDragDropColumn';
import { RecordTableHeaderLastColumn } from '@/object-record/record-table/record-table-header/components/RecordTableHeaderLastColumn';
import { isRecordTableScrolledLeftComponentState } from '@/object-record/record-table/states/isRecordTableScrolledLeftComponentState';
import { isRecordTableScrolledTopComponentState } from '@/object-record/record-table/states/isRecordTableScrolledTopComponentState';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';

const StyledTableHead = styled.thead<{
isScrolledTop?: boolean;
isScrolledLeft?: boolean;
}>`
cursor: pointer;

th {
border-block: 1px solid ${({ theme }) => theme.border.color.light};
color: ${({ theme }) => theme.font.color.tertiary};
padding: 0;
text-align: left;

:last-child {
border-right-color: transparent;
}
:first-of-type {
border-top-color: transparent;
border-bottom-color: transparent;
}
}

th {
background-color: ${({ theme }) => theme.background.primary};
border-right: 1px solid ${({ theme }) => theme.border.color.light};
top: 0;
z-index: ${({ isScrolledTop, isScrolledLeft }) =>
!isScrolledLeft && !isScrolledTop
? 2
: !isScrolledLeft
? 0
: !isScrolledTop
? 2
: 0};
position: sticky;
}

th:nth-of-type(1),
th:nth-of-type(2),
th:nth-of-type(3) {
z-index: ${({ isScrolledTop, isScrolledLeft }) =>
!isScrolledLeft && !isScrolledTop
? 7
: !isScrolledLeft
? 3
: !isScrolledTop
? 6
: 0};

background-color: ${({ theme }) => theme.background.primary};
}

th:nth-of-type(1) {
width: 9px;
left: 0;
border-right-color: ${({ theme }) => theme.background.primary};
}

th:nth-of-type(2) {
left: 9px;
border-right-color: ${({ theme }) => theme.background.primary};
}

th:nth-of-type(3) {
left: 39px;
&.first-columns-sticky {
th:nth-child(1) {
position: sticky;
left: 0;
z-index: 5;
}
th:nth-child(2) {
position: sticky;
left: 9px;
z-index: 5;
}
th:nth-child(3) {
position: sticky;
left: 39px;
z-index: 5;
@media (max-width: ${MOBILE_VIEWPORT}px) {
width: 35px;
max-width: 35px;
}
}
}

&.header-sticky {
th {
position: sticky;
top: 0;
z-index: 5;
}
}

${({ isScrolledLeft }) =>
!isScrolledLeft
? `@media (max-width: ${MOBILE_VIEWPORT}px) {
width: 35px;
max-width: 35px;
}`
: ''}
&.header-sticky.first-columns-sticky {
th:nth-child(1),
th:nth-child(2),
th:nth-child(3) {
z-index: 10;
}
}
`;

Expand All @@ -95,20 +72,8 @@ export const RecordTableHeader = ({

const visibleTableColumns = useRecoilValue(visibleTableColumnsSelector());

const isRecordTableScrolledTop = useRecoilComponentValue(
isRecordTableScrolledTopComponentState,
);

const isRecordTableScrolledLeft = useRecoilComponentValue(
isRecordTableScrolledLeftComponentState,
);

return (
<StyledTableHead
data-select-disable
isScrolledTop={isRecordTableScrolledTop}
isScrolledLeft={isRecordTableScrolledLeft}
>
<StyledTableHead id="record-table-header" data-select-disable>
<tr>
<RecordTableHeaderDragDropColumn />
<RecordTableHeaderCheckboxColumn />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useCallback, useMemo, useState } from 'react';
import styled from '@emotion/styled';
import { useCallback, useMemo, useState } from 'react';
import { useRecoilCallback, useRecoilState, useRecoilValue } from 'recoil';
import { IconPlus } from 'twenty-ui';

import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { RecordTableColumnHead } from '@/object-record/record-table/record-table-header/components/RecordTableColumnHead';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { useTableColumns } from '@/object-record/record-table/hooks/useTableColumns';
import { RecordTableColumnHead } from '@/object-record/record-table/record-table-header/components/RecordTableColumnHead';
import { isRecordTableScrolledLeftComponentState } from '@/object-record/record-table/states/isRecordTableScrolledLeftComponentState';
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
Expand All @@ -24,6 +24,14 @@ const StyledColumnHeaderCell = styled.th<{
columnWidth: number;
isResizing?: boolean;
}>`
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
border-top: 1px solid ${({ theme }) => theme.border.color.light};
color: ${({ theme }) => theme.font.color.tertiary};
padding: 0;
text-align: left;

background-color: ${({ theme }) => theme.background.primary};
border-right: 1px solid ${({ theme }) => theme.border.color.light};
${({ columnWidth }) => `
min-width: ${columnWidth}px;
width: ${columnWidth}px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRecoilValue } from 'recoil';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
import { Checkbox } from '@/ui/input/components/Checkbox';
import { useTheme } from '@emotion/react';

const StyledContainer = styled.div`
align-items: center;
Expand Down Expand Up @@ -35,9 +36,13 @@ export const RecordTableHeaderCheckboxColumn = () => {
}
};

const theme = useTheme();

return (
<th
style={{
borderBottom: `1px solid ${theme.border.color.light}`,
borderTop: `1px solid ${theme.border.color.light}`,
width: 30,
minWidth: 30,
maxWidth: 30,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { styled } from '@linaria/react';

const StyledTh = styled.th`
border-bottom: none;
border-top: none;
`;

export const RecordTableHeaderDragDropColumn = () => {
return <th></th>;
return <StyledTh></StyledTh>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ const StyledPlusIconHeaderCell = styled.th<{
padding-left: ${theme.spacing(3)};
`;
}};
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
border-top: 1px solid ${({ theme }) => theme.border.color.light};
border-left: none !important;
color: ${({ theme }) => theme.font.color.tertiary};
min-width: 32px;
border-right: none !important;

${({ isTableWiderThanScreen, theme }) =>
isTableWiderThanScreen
? `
width: 32px;
border-right: none !important;
background-color: ${theme.background.primary};
`
: ''};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AtomEffect, atomFamily } from 'recoil';

import { ScopeInternalContext } from '@/ui/utilities/recoil-scope/scopes-internal/types/ScopeInternalContext';
import { ComponentState } from '@/ui/utilities/state/component-state/types/ComponentState';
import { ComponentStateKey } from '@/ui/utilities/state/component-state/types/ComponentStateKey';
import { isDefined } from '~/utils/isDefined';

Expand All @@ -16,7 +17,7 @@ export const createComponentStateV2 = <ValueType>({
defaultValue,
componentContext,
effects,
}: CreateComponentStateV2Type<ValueType>) => {
}: CreateComponentStateV2Type<ValueType>): ComponentState<ValueType> => {
if (isDefined(componentContext)) {
if (!isDefined((window as any).componentContextStateMap)) {
(window as any).componentContextStateMap = new Map();
Expand Down
1 change: 1 addition & 0 deletions packages/twenty-front/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default defineConfig(({ command, mode }) => {
'**/RecordTableCellBaseContainer.tsx',
'**/RecordTableCellTd.tsx',
'**/RecordTableTd.tsx',
'**/RecordTableHeaderDragDropColumn.tsx',
],
babelOptions: {
presets: ['@babel/preset-typescript', '@babel/preset-react'],
Expand Down
Loading