Skip to content

Commit 6056b3a

Browse files
authored
feat: make BoardContainer leftOffset and topOffset customizable
Refs: SHELL-281 (#601)
1 parent 459f147 commit 6056b3a

File tree

5 files changed

+85
-10
lines changed

5 files changed

+85
-10
lines changed

src/shell/boards/board-container.test.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import { reduce, sample, size } from 'lodash';
1111
import 'jest-styled-components';
1212

1313
import { BOARD_DEFAULT_POSITION, BoardContainer } from './board-container';
14-
import { BOARD_MIN_VISIBILITY, LOCAL_STORAGE_BOARD_SIZE } from '../../constants';
14+
import {
15+
BOARD_MIN_VISIBILITY,
16+
HEADER_BAR_HEIGHT,
17+
LOCAL_STORAGE_BOARD_SIZE,
18+
PRIMARY_BAR_WIDTH
19+
} from '../../constants';
1520
import { useAppStore } from '../../store/app';
1621
import { reopenBoards, useBoardStore } from '../../store/boards';
1722
import { ICONS, TESTID_SELECTORS } from '../../tests/constants';
@@ -119,6 +124,28 @@ describe('Board container', () => {
119124
});
120125
});
121126

127+
describe('board container offsets', () => {
128+
test('has default values for topOffset and leftOffset ', () => {
129+
setup(<BoardContainer />);
130+
const boardContainer = screen.getByTestId(TESTID_SELECTORS.boardContainerComp);
131+
132+
expect(boardContainer).toHaveStyleRule('height', `calc(100vh - ${HEADER_BAR_HEIGHT})`);
133+
expect(boardContainer).toHaveStyleRule('width', `calc(100vw - ${PRIMARY_BAR_WIDTH})`);
134+
expect(boardContainer).toHaveStyleRule('top', HEADER_BAR_HEIGHT);
135+
expect(boardContainer).toHaveStyleRule('left', PRIMARY_BAR_WIDTH);
136+
});
137+
test('has customizable values for topOffset and leftOffset ', () => {
138+
const leftOffset = '3rem';
139+
const topOffset = '2rem';
140+
setup(<BoardContainer leftOffset={leftOffset} topOffset={topOffset} />);
141+
const boardContainer = screen.getByTestId(TESTID_SELECTORS.boardContainerComp);
142+
143+
expect(boardContainer).toHaveStyleRule('height', `calc(100vh - ${topOffset})`);
144+
expect(boardContainer).toHaveStyleRule('width', `calc(100vw - ${leftOffset})`);
145+
expect(boardContainer).toHaveStyleRule('top', topOffset);
146+
expect(boardContainer).toHaveStyleRule('left', leftOffset);
147+
});
148+
});
122149
describe('Resize a board', () => {
123150
describe('within the resizable area of the document', () => {
124151
describe.each([-10, 0, 10])('with offset %d', (offset) => {

src/shell/boards/board-container.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,17 @@ export const BOARD_DEFAULT_POSITION: Pick<CSSProperties, 'top' | 'left' | 'right
5656
bottom: '0'
5757
};
5858

59-
const BoardContainerComp = styled.div<{ $expanded: boolean; $minimized: boolean }>`
59+
const BoardContainerComp = styled.div<{
60+
$expanded: boolean;
61+
$minimized: boolean;
62+
$topOffset: string;
63+
$leftOffset: string;
64+
}>`
6065
position: fixed;
61-
width: calc(100vw - ${PRIMARY_BAR_WIDTH});
62-
height: calc(100vh - ${HEADER_BAR_HEIGHT});
63-
top: ${HEADER_BAR_HEIGHT};
64-
left: ${PRIMARY_BAR_WIDTH};
66+
width: ${({ $leftOffset }): string => `calc(100vw - ${$leftOffset})`};
67+
height: ${({ $topOffset }): string => `calc(100vh - ${$topOffset})`};
68+
top: ${({ $topOffset }): string => $topOffset};
69+
left: ${({ $leftOffset }): string => $leftOffset};
6570
background-color: rgba(0, 0, 0, 0);
6671
pointer-events: none;
6772
z-index: ${BOARD_CONTAINER_ZINDEX};
@@ -191,8 +196,12 @@ function calcPositionToRemainVisible(
191196
}
192197

193198
export const BoardContainer = ({
199+
topOffset = HEADER_BAR_HEIGHT,
200+
leftOffset = PRIMARY_BAR_WIDTH,
194201
minimizeAllowed = true
195202
}: {
203+
topOffset?: string;
204+
leftOffset?: string;
196205
minimizeAllowed?: boolean;
197206
}): React.JSX.Element | null => {
198207
const t = getT();
@@ -351,7 +360,14 @@ export const BoardContainer = ({
351360

352361
return (
353362
(!isBoardEmpty && current && (
354-
<BoardContainerComp $expanded={expanded} $minimized={minimized} ref={boardContainerRef}>
363+
<BoardContainerComp
364+
$expanded={expanded}
365+
$minimized={minimized}
366+
$topOffset={topOffset}
367+
$leftOffset={leftOffset}
368+
ref={boardContainerRef}
369+
data-testid="BoardContainerComp"
370+
>
355371
<Board
356372
data-testid="NewItemContainer"
357373
background={'gray6'}

src/shell/shell-view.test.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'jest-styled-components';
1111
import { BOARD_DEFAULT_POSITION } from './boards/board-container';
1212
import type { Border } from './hooks/useResize';
1313
import ShellView from './shell-view';
14-
import { LOCAL_STORAGE_BOARD_SIZE } from '../constants';
14+
import { HEADER_BAR_HEIGHT, LOCAL_STORAGE_BOARD_SIZE, PRIMARY_BAR_WIDTH } from '../constants';
1515
import * as constants from '../constants';
1616
import { ICONS, TESTID_SELECTORS } from '../tests/constants';
1717
import { mockedApps, setupAppStore } from '../tests/test-app-utils';
@@ -51,6 +51,33 @@ beforeEach(() => {
5151
});
5252

5353
describe('Shell view', () => {
54+
describe('BoardContainerComp', () => {
55+
test('will have 0 offsets in focus mode', () => {
56+
jest.mocked(constants).IS_FOCUS_MODE = true;
57+
58+
setup(<ShellView />);
59+
60+
const boardContainer = screen.getByTestId(TESTID_SELECTORS.boardContainerComp);
61+
62+
expect(boardContainer).toHaveStyleRule('height', 'calc(100vh - 0rem)');
63+
expect(boardContainer).toHaveStyleRule('width', 'calc(100vw - 0rem)');
64+
expect(boardContainer).toHaveStyleRule('top', '0rem');
65+
expect(boardContainer).toHaveStyleRule('left', '0rem');
66+
});
67+
test('will have offsets if not in focus mode', () => {
68+
jest.mocked(constants).IS_FOCUS_MODE = false;
69+
70+
setup(<ShellView />);
71+
72+
const boardContainer = screen.getByTestId(TESTID_SELECTORS.boardContainerComp);
73+
74+
expect(boardContainer).toHaveStyleRule('height', `calc(100vh - ${HEADER_BAR_HEIGHT})`);
75+
expect(boardContainer).toHaveStyleRule('width', `calc(100vw - ${PRIMARY_BAR_WIDTH})`);
76+
expect(boardContainer).toHaveStyleRule('top', HEADER_BAR_HEIGHT);
77+
expect(boardContainer).toHaveStyleRule('left', PRIMARY_BAR_WIDTH);
78+
});
79+
});
80+
5481
test('When resizing under mobile breakpoint, board does not disappear', () => {
5582
setup(<ShellView />);
5683

src/shell/shell-view.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ShellHeader from './shell-header';
1616
import ShellPrimaryBar from './shell-primary-bar';
1717
import ShellSecondaryBar from './shell-secondary-bar';
1818
import { ThemeCallbacksContext } from '../boot/theme-provider';
19-
import { IS_FOCUS_MODE } from '../constants';
19+
import { HEADER_BAR_HEIGHT, IS_FOCUS_MODE, PRIMARY_BAR_WIDTH } from '../constants';
2020
import { useDarkReaderResultValue } from '../dark-mode/use-dark-reader-result-value';
2121
import { ShellUtilityBar } from '../utility-bar/bar';
2222
import { ShellUtilityPanel } from '../utility-bar/panel';
@@ -69,7 +69,11 @@ const ShellComponent = (): React.JSX.Element => (
6969
<AppViewContainer />
7070
<ShellUtilityPanel />
7171
</Row>
72-
<BoardContainer minimizeAllowed={!IS_FOCUS_MODE} />
72+
<BoardContainer
73+
leftOffset={IS_FOCUS_MODE ? '0rem' : PRIMARY_BAR_WIDTH}
74+
topOffset={IS_FOCUS_MODE ? '0rem' : HEADER_BAR_HEIGHT}
75+
minimizeAllowed={!IS_FOCUS_MODE}
76+
/>
7377
</Background>
7478
);
7579

src/tests/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export const ICONS = {
143143
};
144144

145145
export const TESTID_SELECTORS = {
146+
boardContainerComp: 'BoardContainerComp',
146147
board: 'NewItemContainer',
147148
boardHeader: 'BoardHeader',
148149
checkbox: 'checkbox',

0 commit comments

Comments
 (0)