Skip to content

Commit 7020d1c

Browse files
paula-stachokmruizhimanshusinghs
authored
fix: new colors for multi-connection sidebar COMPASS-7844 (#5696)
* style: new base colors for sidebar items - with legacy override * StyledNavigationItem * placeholder colors first version * active colors * chore: dark mode support * chore: add placeholder when connecting * chore: poc of tab theming * chore: add tests to new hook * chore: move connection-color hook to compass-connectoins * chore: fix linting issues * chore: linting issues * chore: fix linting issues and dependencies * chore: force CI * chore: remove unused console.log * chore: fix color contrast * chore: fix theme sync * chore: remove cyclick dep * chore: fix linting issues * chore: revert package-lock.json * chore: fix deps * chore: fix dependencies * chore: fix test that depends on the palette * chore: fix placeholders * chore: only enable theme when flag is on * chore: show only new theme on new sidebar * chore: fix theming * chore: fix PR comments * chore: clean up unused legacy sidebar styles * Update packages/compass-connections-navigation/src/tree-item.tsx Co-authored-by: Himanshu Singh <[email protected]> * Update packages/compass-sidebar/src/components/legacy/sidebar.tsx Co-authored-by: Himanshu Singh <[email protected]> * chore: fix linting issues * chore: memo styled component styles * chore: remove marker on new sidebar styles --------- Co-authored-by: Kevin Mas Ruiz <[email protected]> Co-authored-by: Himanshu Singh <[email protected]>
1 parent f5388d4 commit 7020d1c

File tree

24 files changed

+531
-82
lines changed

24 files changed

+531
-82
lines changed

packages/compass-components/src/components/placeholder.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const move = keyframes({
2121
});
2222

2323
const placeholder = css({
24-
'--gradient-start': palette.gray.light2,
25-
'--gradient-end': palette.gray.light3,
2624
alignSelf: 'center',
2725
borderRadius: 3,
2826
maxWidth: '80%',
@@ -39,11 +37,6 @@ const placeholder = css({
3937
animation: `${move} ${scale}s infinite linear`,
4038
});
4139

42-
const placeholderDarkMode = css({
43-
'--gradient-start': palette.gray.dark2,
44-
'--gradient-end': palette.gray.dark4,
45-
});
46-
4740
function getBoundRandom(min: number, max: number) {
4841
return Math.random() * (max - min) + min;
4942
}
@@ -57,6 +50,9 @@ const Placeholder: React.FunctionComponent<
5750
maxChar?: number;
5851
width?: CSSProperties['width'];
5952
height?: CSSProperties['height'];
53+
gradientStart?: CSSProperties['color'];
54+
gradientEnd?: CSSProperties['color'];
55+
style?: CSSProperties;
6056
'data-testid'?: string;
6157
}
6258
> = ({
@@ -65,6 +61,9 @@ const Placeholder: React.FunctionComponent<
6561
maxChar = 15,
6662
width: propsWidth,
6763
height: propsHeight = spacing[3],
64+
gradientStart,
65+
gradientEnd,
66+
style: propsStyle,
6867
...props
6968
}) => {
7069
const darkMode = useDarkMode();
@@ -73,13 +72,26 @@ const Placeholder: React.FunctionComponent<
7372
return propsWidth || `${Math.round(getBoundRandom(minChar, maxChar))}ch`;
7473
}, [minChar, maxChar, propsWidth]);
7574

75+
const style = useMemo(
76+
() => ({
77+
width,
78+
height: propsHeight,
79+
'--gradient-start':
80+
gradientStart || (darkMode ? palette.gray.dark2 : palette.gray.light2),
81+
'--gradient-end':
82+
gradientEnd || (darkMode ? palette.gray.dark4 : palette.gray.light3),
83+
...propsStyle,
84+
}),
85+
[darkMode, width, propsHeight, gradientStart, gradientEnd, propsStyle]
86+
);
87+
7688
return (
7789
<div
7890
{...props}
7991
role="presentation"
8092
data-testid={props['data-testid'] ?? 'placeholder'}
81-
className={cx(placeholder, className, darkMode && placeholderDarkMode)}
82-
style={{ width, height: propsHeight }}
93+
className={cx(placeholder, className)}
94+
style={style}
8395
></div>
8496
);
8597
};

packages/compass-components/src/components/resizeable-sidebar.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ const ResizableSidebar = ({
6363
children,
6464
className,
6565
style,
66+
useNewTheme,
6667
...props
6768
}: {
6869
initialWidth?: number;
6970
minWidth?: number;
7071
children: JSX.Element;
72+
useNewTheme?: boolean;
7173
} & React.HTMLProps<HTMLDivElement>): JSX.Element => {
7274
const darkMode = useDarkMode();
7375
const [width, setWidth] = useState(initialWidth);
76+
const newThemeStyles = useNewTheme
77+
? {
78+
'--item-color-active': darkMode ? palette.white : palette.gray.dark3,
79+
'--item-bg-color-active': darkMode
80+
? palette.gray.dark2
81+
: palette.gray.light2,
82+
}
83+
: {};
7484

7585
const getMaxSidebarWidth = useCallback(() => {
7686
return Math.max(minWidth, 600);
@@ -101,6 +111,7 @@ const ResizableSidebar = ({
101111
minWidth,
102112
width: renderedWidth,
103113
flex: 'none',
114+
...newThemeStyles,
104115
}}
105116
{...props}
106117
>

packages/compass-components/src/components/workspace-tabs/tab.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { css, cx } from '@leafygreen-ui/emotion';
33
import { palette } from '@leafygreen-ui/palette';
44
import { spacing } from '@leafygreen-ui/tokens';
@@ -60,6 +60,18 @@ const animatedSubtitleStyles = css({
6060
},
6161
});
6262

63+
export type TabTheme = {
64+
'--workspace-tab-background-color': string;
65+
'--workspace-tab-selected-background-color': string;
66+
'--workspace-tab-border-color': string;
67+
'--workspace-tab-color': string;
68+
'--workspace-tab-selected-color': string;
69+
'&:focus-visible': {
70+
'--workspace-tab-selected-color': string;
71+
'--workspace-tab-border-color': string;
72+
};
73+
};
74+
6375
const tabLightThemeStyles = css({
6476
'--workspace-tab-background-color': palette.gray.light3,
6577
'--workspace-tab-selected-background-color': palette.white,
@@ -164,6 +176,7 @@ type TabProps = {
164176
iconGlyph: IconGlyph;
165177
tabContentId: string;
166178
subtitle?: string;
179+
tabTheme?: TabTheme;
167180
};
168181

169182
function Tab({
@@ -175,6 +188,7 @@ function Tab({
175188
tabContentId,
176189
iconGlyph,
177190
subtitle,
191+
tabTheme,
178192
...props
179193
}: TabProps & React.HTMLProps<HTMLDivElement>) {
180194
const darkMode = useDarkMode();
@@ -189,6 +203,14 @@ function Tab({
189203
props
190204
);
191205

206+
const themeClass = useMemo(() => {
207+
if (!tabTheme) {
208+
return darkMode ? tabDarkThemeStyles : tabLightThemeStyles;
209+
}
210+
211+
return css(tabTheme);
212+
}, [tabTheme, darkMode]);
213+
192214
const style = {
193215
transform: cssDndKit.Transform.toString(transform),
194216
transition,
@@ -204,7 +226,7 @@ function Tab({
204226
style={style}
205227
className={cx(
206228
tabStyles,
207-
darkMode ? tabDarkThemeStyles : tabLightThemeStyles,
229+
themeClass,
208230
isSelected && selectedTabStyles,
209231
isDragging && draggingTabStyles,
210232
subtitle && animatedSubtitleStyles

packages/compass-components/src/components/workspace-tabs/workspace-tabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export type TabProps = {
172172
id: string;
173173
title: string;
174174
subtitle?: string;
175+
connectionId?: string;
175176
iconGlyph: Extract<keyof typeof glyphs, string>;
176177
} & Omit<React.HTMLProps<HTMLDivElement>, 'id' | 'title' | 'subtitle'>;
177178

packages/compass-components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export {
3737
import { ResizeHandle, ResizeDirection } from './components/resize-handle';
3838
import { Accordion } from './components/accordion';
3939
import { CollapsibleFieldSet } from './components/collapsible-field-set';
40+
export { type TabTheme } from './components/workspace-tabs/tab';
4041
import { WorkspaceTabs } from './components/workspace-tabs/workspace-tabs';
4142
import ResizableSidebar, {
4243
defaultSidebarWidth,

packages/compass-connections-navigation/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"dependencies": {
5050
"@mongodb-js/compass-components": "^1.24.0",
5151
"@mongodb-js/connection-info": "^0.2.1",
52+
"@mongodb-js/connection-form": "^1.24.0",
5253
"@mongodb-js/compass-workspaces": "^0.7.0",
5354
"compass-preferences-model": "^2.20.0",
5455
"react": "^17.0.2",

packages/compass-connections-navigation/src/connections-navigation-tree.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('ConnectionsNavigationTree', function () {
174174
expanded: { connection_initial: {} },
175175
});
176176

177-
expect(screen.getAllByTestId('placeholder')).to.have.lengthOf(2);
177+
expect(screen.getAllByTestId('placeholder')).to.have.lengthOf(5);
178178
});
179179

180180
it('when database is expanded, it should render collections', async function () {

0 commit comments

Comments
 (0)