Skip to content

Commit f154256

Browse files
authored
feat(sidebar): New sidebar title and favorite color area COMPASS-5961 (#3336)
* WIP * not necesary to create an alias * sidebar title * some debugging * darkmode for the title * reformat * database item and collection item actions are mode hover * rm comments * rm console.log * lint warnings
1 parent a307348 commit f154256

File tree

11 files changed

+380
-76
lines changed

11 files changed

+380
-76
lines changed

packages/compass-databases-navigation/src/icon-button.tsx renamed to packages/compass-components/src/components/icon-button.tsx

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/* eslint-disable react/prop-types */
22
import React, { forwardRef } from 'react';
3-
import {
4-
Icon,
5-
IconButton,
6-
spacing,
7-
css,
8-
cx,
9-
} from '@mongodb-js/compass-components';
3+
import { Icon, IconButton } from '../index';
4+
5+
import { spacing } from '@leafygreen-ui/tokens';
6+
import { css, cx } from '@leafygreen-ui/emotion';
107

118
const iconContainer = css({
129
display: 'block',
@@ -21,9 +18,28 @@ const icons = {
2118
hovered: css({
2219
color: 'var(--hover-icon-color)',
2320
}),
21+
inherit: css({
22+
color: 'inherit',
23+
}),
2424
} as const;
2525

26-
type IconMode = keyof typeof icons;
26+
const buttons = {
27+
normal: css({
28+
color: 'var(--icon-color)',
29+
':hover': {
30+
color: 'var(--icon-color-hover)',
31+
},
32+
}),
33+
hovered: css({
34+
color: 'var(--hover-icon-color)',
35+
':hover': {
36+
color: 'var(--hover-icon-color-hover)',
37+
},
38+
}),
39+
inherit: css({}),
40+
} as const;
41+
42+
export type IconMode = keyof typeof icons;
2743

2844
export const SmallIcon: React.FunctionComponent<
2945
{ glyph: string; mode: IconMode } & React.HTMLProps<HTMLSpanElement>
@@ -44,20 +60,34 @@ const iconButtonSmall = css({
4460
});
4561

4662
const iconButtonSmallActive = css({
47-
color: 'currentColor !important',
63+
color: 'var(--color) !important',
64+
':hover': {
65+
color: 'var(--hover-icon-color-hover) !important',
66+
},
4867
});
4968

5069
export const IconButtonSmall = forwardRef<
5170
HTMLButtonElement,
5271
{
5372
glyph: string;
73+
mode: IconMode;
5474
label: string;
5575
title?: string;
5676
onClick(evt: React.MouseEvent<HTMLButtonElement>): void;
5777
isActive: boolean;
5878
} & React.HTMLProps<HTMLButtonElement>
5979
>(function IconButtonSmall(
60-
{ glyph, label, onClick, isActive, children, title, className, ...rest },
80+
{
81+
glyph,
82+
mode,
83+
label,
84+
onClick,
85+
isActive,
86+
children,
87+
title,
88+
className,
89+
...rest
90+
},
6191
ref
6292
) {
6393
return (
@@ -68,14 +98,15 @@ export const IconButtonSmall = forwardRef<
6898
className={cx(
6999
iconButtonSmall,
70100
isActive && iconButtonSmallActive,
101+
buttons[mode],
71102
className
72103
)}
73104
aria-label={label}
74105
title={title}
75106
onClick={onClick}
76107
{...rest}
77108
>
78-
<SmallIcon role="presentation" glyph={glyph} mode="hovered"></SmallIcon>
109+
<SmallIcon role="presentation" glyph={glyph} mode="inherit"></SmallIcon>
79110
{/* Only here to make leafygreen menus work */}
80111
{children}
81112
</IconButton>

packages/compass-databases-navigation/src/item-action-controls.tsx renamed to packages/compass-components/src/components/item-action-controls.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
/* eslint-disable react/prop-types */
22
import React, { useCallback, useState, useRef } from 'react';
3-
import {
4-
Menu,
5-
MenuItem,
6-
spacing,
7-
css,
8-
cx,
9-
} from '@mongodb-js/compass-components';
3+
import { Menu, MenuItem } from '../index';
4+
5+
import { spacing } from '@leafygreen-ui/tokens';
6+
import { css, cx } from '@leafygreen-ui/emotion';
7+
108
import { IconButtonSmall } from './icon-button';
11-
import type { Actions } from './constants';
9+
import type { IconMode } from './icon-button';
1210

13-
export type NamespaceAction = {
11+
export type ItemAction<Actions> = {
1412
action: Actions;
1513
label: string;
1614
icon: string;
1715
};
1816

19-
type ActionControlOptions = NamespaceAction[];
20-
2117
const actionControls = css({
2218
flex: 'none',
2319
marginLeft: 'auto',
@@ -31,21 +27,23 @@ const actionIconButton = css({
3127
},
3228
});
3329

34-
export const ActionControls: React.FunctionComponent<{
35-
actions: ActionControlOptions;
36-
onAction(actionName: Actions): void;
37-
className?: string;
38-
isActive: boolean;
39-
isHovered: boolean;
40-
shouldCollapseActionsToMenu?: boolean;
41-
}> = ({
30+
export function ItemActionControls<Actions extends string>({
31+
mode = 'hovered',
4232
actions,
4333
onAction,
4434
className,
4535
isActive,
4636
isHovered,
4737
shouldCollapseActionsToMenu = false,
48-
}) => {
38+
}: {
39+
mode: IconMode;
40+
actions: ItemAction<Actions>[];
41+
onAction(actionName: Actions): void;
42+
className?: string;
43+
isActive: boolean;
44+
isHovered: boolean;
45+
shouldCollapseActionsToMenu?: boolean;
46+
}) {
4947
const menuTriggerRef = useRef<HTMLButtonElement | null>(null);
5048
const [isMenuOpen, setIsMenuOpen] = useState(false);
5149

@@ -62,7 +60,10 @@ export const ActionControls: React.FunctionComponent<{
6260
[onAction]
6361
);
6462

65-
if (actions.length === 0 || (!isActive && !isHovered && !isMenuOpen)) {
63+
if (
64+
actions.length === 0 ||
65+
(!isActive && !isHovered && !isMenuOpen && mode === 'hovered')
66+
) {
6667
return null;
6768
}
6869

@@ -84,6 +85,7 @@ export const ActionControls: React.FunctionComponent<{
8485
<IconButtonSmall
8586
ref={menuTriggerRef}
8687
glyph="Ellipsis"
88+
mode={mode}
8789
label="Show actions"
8890
title="Show actions"
8991
data-testid="show-actions"
@@ -123,6 +125,7 @@ export const ActionControls: React.FunctionComponent<{
123125
<IconButtonSmall
124126
key={action}
125127
glyph={icon}
128+
mode={mode}
126129
label={label}
127130
title={label}
128131
isActive={isActive}
@@ -134,4 +137,4 @@ export const ActionControls: React.FunctionComponent<{
134137
})}
135138
</div>
136139
);
137-
};
140+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ const containerStylesDark = css({
2525
'--color': 'white',
2626
'--bg-color': uiColors.gray.dark3,
2727

28+
'--title-color': uiColors.gray.dark3,
29+
'--title-bg-color': '#71F6BA', // TODO: there is no uiColors.green.light1,
30+
2831
'--icon-color': 'white',
32+
'--icon-color-hover': uiColors.black,
2933
// NOTE: This is for icons that only display when hovering over an item,
3034
// not the color used for the icon when hovering over the icon itself.
3135
'--hover-icon-color': 'white',
36+
'--hover-icon-color-hover': uiColors.black,
3237

3338
'--item-color': 'white',
3439
'--item-color-hover': 'white',
@@ -45,8 +50,13 @@ const containerStylesLight = css({
4550
'--color': uiColors.gray.dark3,
4651
'--bg-color': uiColors.gray.light3,
4752

53+
'--title-color': 'white',
54+
'--title-bg-color': uiColors.green.dark2,
55+
4856
'--icon-color': uiColors.gray.dark3,
57+
'--icon-color-hover': uiColors.black,
4958
'--hover-icon-color': uiColors.gray.dark1,
59+
'--hover-icon-color-hover': uiColors.black,
5060

5161
'--item-color': uiColors.gray.dark3,
5262
'--item-color-hover': uiColors.gray.dark3,

packages/compass-components/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import { ResizeHandle, ResizeDirection } from './components/resize-handle';
3030
import { Accordion } from './components/accordion';
3131
import { WorkspaceTabs } from './components/workspace-tabs/workspace-tabs';
3232
import ResizableSidebar from './components/resizeable-sidebar';
33+
import {
34+
ItemAction,
35+
ItemActionControls,
36+
} from './components/item-action-controls';
37+
import { SmallIcon, IconButtonSmall } from './components/icon-button';
3338
export {
3439
Editor,
3540
EditorVariant,
@@ -85,6 +90,10 @@ export {
8590
Toolbar,
8691
WarningSummary,
8792
WorkspaceTabs,
93+
ItemAction,
94+
ItemActionControls,
95+
SmallIcon,
96+
IconButtonSmall,
8897
};
8998
export {
9099
useFocusState,

packages/compass-databases-navigation/src/collection-item.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import {
55
spacing,
66
css,
77
cx,
8+
ItemActionControls,
9+
SmallIcon,
810
} from '@mongodb-js/compass-components';
11+
import type { ItemAction } from '@mongodb-js/compass-components';
912
import { COLLECTION_ROW_HEIGHT } from './constants';
10-
import { ActionControls } from './item-action-controls';
11-
import type { NamespaceAction } from './item-action-controls';
1213
import { ItemContainer, ItemLabel } from './tree-item';
1314
import type {
1415
VirtualListItemProps,
1516
TreeItemProps,
1617
NamespaceItemProps,
1718
} from './tree-item';
18-
import { SmallIcon } from './icon-button';
1919
import type { Actions } from './constants';
2020

2121
const CollectionIcon: React.FunctionComponent<{
@@ -87,7 +87,7 @@ export const CollectionItem: React.FunctionComponent<
8787
);
8888

8989
const actions = useMemo(() => {
90-
const actions: NamespaceAction[] = [
90+
const actions: ItemAction<Actions>[] = [
9191
{
9292
action: 'open-in-new-tab',
9393
label: 'Open in New Tab',
@@ -150,14 +150,15 @@ export const CollectionItem: React.FunctionComponent<
150150
>
151151
<CollectionIcon type={type} />
152152
<ItemLabel className={collectionItemLabel}>{name}</ItemLabel>
153-
<ActionControls
153+
<ItemActionControls<Actions>
154154
className={collectionActions}
155155
onAction={onAction}
156156
isActive={isActive}
157157
isHovered={isHovered}
158158
actions={actions}
159159
shouldCollapseActionsToMenu
160-
></ActionControls>
160+
mode="hovered"
161+
></ItemActionControls>
161162
</ItemContainer>
162163
);
163164
};

packages/compass-databases-navigation/src/database-item.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import {
55
spacing,
66
css,
77
cx,
8+
ItemActionControls,
9+
SmallIcon,
810
} from '@mongodb-js/compass-components';
11+
import type { ItemAction } from '@mongodb-js/compass-components';
912
import { DATABASE_ROW_HEIGHT } from './constants';
10-
import { ActionControls } from './item-action-controls';
11-
import type { NamespaceAction } from './item-action-controls';
1213
import { ItemContainer, ItemLabel } from './tree-item';
1314
import type {
1415
VirtualListItemProps,
1516
TreeItemProps,
1617
NamespaceItemProps,
1718
} from './tree-item';
18-
import { SmallIcon } from './icon-button';
1919
import type { Actions } from './constants';
2020

2121
const buttonReset = css({
@@ -134,7 +134,7 @@ export const DatabaseItem: React.FunctionComponent<
134134
[id, onNamespaceAction]
135135
);
136136

137-
const actions: NamespaceAction[] = useMemo(() => {
137+
const actions: ItemAction<Actions>[] = useMemo(() => {
138138
return [
139139
{
140140
action: 'create-collection',
@@ -185,13 +185,14 @@ export const DatabaseItem: React.FunctionComponent<
185185
{name}
186186
</ItemLabel>
187187
{!isReadOnly && (
188-
<ActionControls
188+
<ItemActionControls<Actions>
189189
className={databaseActions}
190190
onAction={onAction}
191191
isActive={isActive}
192192
isHovered={isHovered}
193193
actions={actions}
194-
></ActionControls>
194+
mode="hovered"
195+
></ItemActionControls>
195196
)}
196197
</ItemContainer>
197198
);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ function ThemedHome(
259259

260260
const [theme, setTheme] = useState<ThemeState>({
261261
theme: (global as any).hadronApp?.theme ?? Theme.Light,
262+
// useful for quickly testing the new dark sidebar without rebuilding
263+
//theme: Theme.Dark, enabled: true
262264
});
263265

264266
function onDarkModeEnabled() {

packages/compass-sidebar/src/components-legacy/sidebar/sidebar.module.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
--bg-color: @compass-sidebar-base-background-color;
2525

2626
--icon-color: @pw;
27+
--icon-color-hover: @pw;
2728
// NOTE: This is for icons that only display when hovering over an item,
2829
// not the color used for the icon when hovering over the icon itself.
2930
--hover-icon-color: @pw;
31+
--hover-icon-color-hover: @pw;
3032

3133
--item-color: @pw;
3234
--item-color-hover: @pw;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
3+
import type { ConnectionFavoriteOptions } from 'mongodb-data-service';
4+
import { useConnectionColor } from '@mongodb-js/connection-form';
5+
6+
import { css, spacing } from '@mongodb-js/compass-components';
7+
8+
export default function FavoriteIndicator({
9+
favorite,
10+
}: {
11+
favorite: ConnectionFavoriteOptions;
12+
}) {
13+
const { connectionColorToHex } = useConnectionColor();
14+
15+
const favoriteColorHex = connectionColorToHex(favorite.color) ?? '';
16+
17+
const favoriteCSS = css({
18+
backgroundColor: favoriteColorHex || 'transparent',
19+
height: spacing[2],
20+
});
21+
22+
return <div className={favoriteCSS} />;
23+
}

0 commit comments

Comments
 (0)