Skip to content

Commit

Permalink
fix: improve tooltip in different color theme (#304)
Browse files Browse the repository at this point in the history
* fix: improve tooltip in different color theme

* fix(components): add font-family in mac for tooltip
  • Loading branch information
mortalYoung authored and ProfBramble committed Aug 5, 2021
1 parent 9380573 commit 48ba958
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/common/className.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Utils } from '@dtinsight/dt-utils/lib';
import { isEmpty } from 'lodash';
import { APP_PREFIX } from 'mo/common/const';
/**
Expand Down Expand Up @@ -55,3 +56,11 @@ export function getBEMElement(block: string, element: string) {
export function getBEMModifier(blockOrElement: string, modifier: string) {
return `${blockOrElement}--${modifier}`;
}

/**
* Returns the className of font-family in mac
* @returns
*/
export function getFontInMac() {
return Utils.isMacOs() ? 'mac' : '';
}
8 changes: 6 additions & 2 deletions src/components/tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { default as RcTooltip } from 'rc-tooltip';
import 'rc-tooltip/assets/bootstrap.css';
import { TooltipProps } from 'rc-tooltip/lib/Tooltip';
import type { TooltipProps } from 'rc-tooltip/lib/Tooltip';
import { classNames, getFontInMac } from 'mo/common/className';

export interface IToolTipProps extends TooltipProps {}

Expand All @@ -10,15 +11,18 @@ const Tooltip = ({
children,
placement = 'bottom',
trigger = 'hover',
overlayClassName,
mouseEnterDelay,
...rest
}: IToolTipProps) => {
if (overlay) {
return (
<RcTooltip
overlayClassName={classNames(getFontInMac(), overlayClassName)}
placement={placement}
trigger={trigger}
overlay={overlay}
mouseEnterDelay={0.1}
mouseEnterDelay={mouseEnterDelay || 0.1}
{...rest}
>
{children}
Expand Down
12 changes: 8 additions & 4 deletions src/components/tooltip/style.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
@import 'mo/style/common';

#{$rcTooltip} {
background-color: var(--menu-background);
box-sizing: border-box;
color: var(--tooltip-color);
color: var(--menu-foreground);
font-size: 13px;
margin: 0;
opacity: 1;
padding: 0;

&-inner {
background-color: var(--tooltip-background);
background-color: inherit;
border-radius: 2px;
box-shadow: 0 2px 8px rgb(0 0 0 / 15%);
box-shadow: 0 2px 8px var(--widget-shadow);
box-sizing: border-box;
color: inherit;
min-height: auto;
min-width: 30px;
padding: 6px 8px;
}
}

#{$rcTooltip}-placement-bottom #{$rcTooltip}-arrow {
border-bottom-color: var(--tooltip-background);
border-bottom-color: var(--menu-background);
top: -5px;
}
4 changes: 1 addition & 3 deletions src/extensions/theme-defaults/themes/dark_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
"tab.activeForeground": "#fff",
"diffEditor.insertedTextBackground": "#9bb95533",
"diffEditor.removedTextBackground": "#ff000033",
"actionBar.checkedBackground": "rgba(0, 127, 212, 0.4)",
"tooltip.color": "#333",
"tooltip.background": "rgba(0, 0, 0, 0.75)"
"actionBar.checkedBackground": "rgba(0, 127, 212, 0.4)"
},
"semanticHighlighting": true
}
4 changes: 1 addition & 3 deletions src/extensions/theme-defaults/themes/light_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
"tab.inactiveBackground": "rgb(236, 236, 236)",
"tab.inactiveForeground": "rgba(51, 51, 51, 0.7)",
"tab.activeBackground": "#fffffe",
"tab.activeForeground": "#333333",
"tooltip.color": "#333",
"tooltip.background": "rgba(0, 0, 0, 0.75)"
"tab.activeForeground": "#333333"
},
"semanticHighlighting": true
}
5 changes: 2 additions & 3 deletions src/workbench/workbench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SplitPane from 'react-split-pane';
import Pane from 'react-split-pane/lib/Pane';
import { container } from 'tsyringe';

import { classNames, prefixClaName } from 'mo/common/className';
import { classNames, getFontInMac, prefixClaName } from 'mo/common/className';

import { EditorView } from 'mo/workbench/editor';
import { SidebarView } from 'mo/workbench/sidebar';
Expand All @@ -13,7 +13,6 @@ import { ActivityBarView } from 'mo/workbench/activityBar';
import { StatusBarView } from 'mo/workbench/statusBar';
import { PanelView } from 'mo/workbench/panel';
import { ID_APP } from 'mo/common/id';
import { Utils } from '@dtinsight/dt-utils';
import { APP_PREFIX } from 'mo/common/const';

import { connect } from 'mo/react';
Expand All @@ -27,7 +26,7 @@ import { IWorkbench } from 'mo/model';
const mainBenchClassName = prefixClaName('mainBench');
const workbenchClassName = prefixClaName('workbench');
const compositeBarClassName = prefixClaName('compositeBar');
const appClassName = classNames(APP_PREFIX, Utils.isMacOs() ? 'mac' : '');
const appClassName = classNames(APP_PREFIX, getFontInMac());

const layoutController = container.resolve(LayoutController);
const layoutService = container.resolve(LayoutService);
Expand Down

0 comments on commit 48ba958

Please sign in to comment.