Skip to content

Commit

Permalink
Add tooltips to app bar (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfheij-sil authored Nov 30, 2023
2 parents 031cfb5 + 789d2da commit 4e47845
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 23 deletions.
6 changes: 5 additions & 1 deletion lib/papi-dts/papi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ declare module 'shared/models/web-view.model' {
iconUrl?: string;
/** Name of the tab for the WebView */
title?: string;
/** Tooltip that is shown when hovering over the webview title */
tooltip?: string;
/** General object to store unique state for this webview */
state?: Record<string, unknown>;
/**
Expand Down Expand Up @@ -162,7 +164,7 @@ declare module 'shared/models/web-view.model' {
/** The properties on a WebViewDefinition that may be updated when that webview is already displayed */
export type WebViewDefinitionUpdatableProperties = Pick<
WebViewDefinitionBase,
'iconUrl' | 'title'
'iconUrl' | 'title' | 'tooltip'
>;
/**
* WebViewDefinition properties for updating a WebView that is already displayed. Any unspecified
Expand Down Expand Up @@ -2602,6 +2604,8 @@ declare module 'shared/models/docking-framework.model' {
tabIconUrl?: string;
/** Text to show on the title bar of the tab */
tabTitle: string;
/** Text to show when hovering over the title bar of the tab */
tabTooltip?: string;
/** Content to show inside the tab. */
content: ReactNode;
/** (optional) Minimum width that the tab can become in CSS `px` units */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ function createRCDockTabFromTabInfo(tabInfo: TabInfo) {
// Translate the data from the loaded tab to be in the form needed by rc-dock
return {
...tabInfo,
title: <PlatformTabTitle iconUrl={tabInfo.tabIconUrl} text={tabInfo.tabTitle} />,
title: (
<PlatformTabTitle
iconUrl={tabInfo.tabIconUrl}
text={tabInfo.tabTitle}
tooltip={tabInfo.tabTooltip}
/>
),
content: <PlatformPanel>{tabInfo.content}</PlatformPanel>,
group: TAB_GROUP,
closable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
height: 16px;
vertical-align: middle;
}

.tooltip {
white-space: pre-wrap;
}
43 changes: 26 additions & 17 deletions src/renderer/components/docking/platform-tab-title.component.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Tooltip } from '@mui/material';
import './platform-tab-title.component.css';
import logger from '@shared/services/logger.service';

Expand All @@ -6,34 +7,42 @@ type PlatformTabTitleProps = {
iconUrl?: string;
/** Text to show on the tab */
text: string;
/** Text to show when hovering over the tab. Defaults to empty string */
tooltip?: string;
};

/**
* Custom tab title for all tabs in Platform
*
* @param iconUrl Url to image to show on the tab. Defaults to Platform.Bible logo
* @param text The text to show on the tab title
* @param tooltip Text to show when hovering over the tab. Defaults to empty string
*/
export default function PlatformTabTitle({ iconUrl, text }: PlatformTabTitleProps) {
export default function PlatformTabTitle({ iconUrl, text, tooltip }: PlatformTabTitleProps) {
const toggleDropdown = () => {
logger.info('Pretend a menu was shown!');
};

const tooltipDiv = tooltip ? <div className="tooltip">{tooltip}</div> : '';

return (
<div className="title">
<button
type="button"
className="tab-menu-button"
style={
iconUrl
? {
backgroundImage: `url(${iconUrl})`,
}
: undefined
}
aria-label="Tab Menu"
onClick={toggleDropdown}
/>
<span>{text}</span>
</div>
<Tooltip title={tooltipDiv}>
<div className="title">
<button
type="button"
className="tab-menu-button"
style={
iconUrl
? {
backgroundImage: `url(${iconUrl})`,
}
: undefined
}
aria-label="Tab Menu"
onClick={toggleDropdown}
/>
<span>{text}</span>
</div>
</Tooltip>
);
}
1 change: 1 addition & 0 deletions src/renderer/components/web-view.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function updateWebViewTab(savedTabInfo: SavedTabInfo, data: WebViewDefini
data,
tabIconUrl: data.iconUrl,
tabTitle: data.title ?? 'Unknown',
tabTooltip: data.tooltip ?? '',
content: <WebView {...data} />,
};
}
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/services/web-view.service-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ export const removeTab = async (tabId: string): Promise<boolean> => {
export function saveTabInfoBase(tabInfo: TabInfo): SavedTabInfo {
// We don't need to use the other properties, but we need to remove them
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { tabTitle, tabIconUrl, content, minWidth, minHeight, ...savedTabInfo } = tabInfo;
const { tabTitle, tabTooltip, tabIconUrl, content, minWidth, minHeight, ...savedTabInfo } =
tabInfo;
return savedTabInfo;
}

Expand Down Expand Up @@ -617,8 +618,8 @@ export function getUpdatablePropertiesFromWebViewDefinition(
| WebViewDefinitionUpdateInfo,
): WebViewDefinitionUpdatableProperties {
// Make sure we're only including the specific properties we allow updates on
const { iconUrl, title } = webViewDefinition;
return { iconUrl, title };
const { iconUrl, title, tooltip } = webViewDefinition;
return { iconUrl, title, tooltip };
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/shared/models/docking-framework.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type TabInfo = SavedTabInfo & {
tabIconUrl?: string;
/** Text to show on the title bar of the tab */
tabTitle: string;
/** Text to show when hovering over the title bar of the tab */
tabTooltip?: string;
/** Content to show inside the tab. */
content: ReactNode;
/** (optional) Minimum width that the tab can become in CSS `px` units */
Expand Down
7 changes: 6 additions & 1 deletion src/shared/models/web-view.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type WebViewDefinitionBase = {
iconUrl?: string;
/** Name of the tab for the WebView */
title?: string;
/** Tooltip that is shown when hovering over the webview title */
tooltip?: string;
/** General object to store unique state for this webview */
state?: Record<string, unknown>;
/**
Expand Down Expand Up @@ -169,7 +171,10 @@ export type SavedWebViewDefinition =
/** The properties on a WebViewDefinition that may be updated when that webview is already displayed */
// To allow more properties to be updated, add them in
// `web-view.service.ts` -> `getUpdatablePropertiesFromWebViewDefinition`
export type WebViewDefinitionUpdatableProperties = Pick<WebViewDefinitionBase, 'iconUrl' | 'title'>;
export type WebViewDefinitionUpdatableProperties = Pick<
WebViewDefinitionBase,
'iconUrl' | 'title' | 'tooltip'
>;

/**
* WebViewDefinition properties for updating a WebView that is already displayed. Any unspecified
Expand Down

0 comments on commit 4e47845

Please sign in to comment.