Skip to content

Commit

Permalink
Replace the classNames prop in PointerBox with className and set zmen…
Browse files Browse the repository at this point in the history
…u max-width (#1112)

- Minor refactoring of the PointerBox component and the components that use it,
   to replace the classNames property on PointerBox (an object) with a className property (a string)
- Used this className property after the refactoring to set a max-width of 400px on Zmenu on genome browser page
  • Loading branch information
azangru authored Apr 4, 2024
1 parent 8a080fd commit 48bfc11
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
align-items: center;
}

.toolBox {
max-width: 450px;
.toolbox {
max-width: 400px;
min-width: 250px;
word-break: break-word;
}
1 change: 1 addition & 0 deletions src/content/app/genome-browser/components/zmenu/Zmenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const Zmenu = (props: ZmenuProps) => {
onOutsideClick={destroyZmenu}
anchor={anchorRef.current}
position={toolboxPosition}
className={styles.toolbox}
>
{zmenuContent}
</Toolbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ const GeneAndOneTranscriptZmenu = (props: Props) => {
<ToolboxExpandableContent
mainContent={mainContent}
footerContent={footerContent}
className={styles.toolBox}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,7 @@
}

.tooltip {
background: var(--color-black);
padding: 12px 20px;
filter: drop-shadow(2px 2px 3px var(--shadow-color));
color: var(--color-white);
}

.tooltipTip {
fill: var(--color-black);
--pointer-box-padding: 12px 20px;
}

/* FIXME: remove the pseudo-radio elements when we replace them with real radio buttons */
Expand Down
6 changes: 5 additions & 1 deletion src/shared/components/gene-search-panel/GeneSearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import type { SearchMatch } from 'src/shared/types/search-api/search-match';

import styles from './GeneSearchPanel.module.css';
import radioStyles from 'src/shared/components/radio-group/RadioGroup.module.css';
import pointerBoxStyles from 'src/shared/components/pointer-box/PointerBox.module.css';

type Props = {
onClose: () => void;
Expand Down Expand Up @@ -300,7 +301,10 @@ const GeneMatch = (props: { match: SearchMatch; species: CommittedItem }) => {
{shouldShowTooltip && anchorRef.current && (
<PointerBox
anchor={anchorRef.current}
classNames={{ box: styles.tooltip, pointer: styles.tooltipTip }}
className={classNames(
styles.tooltip,
pointerBoxStyles.pointerBoxShadow
)}
position={PointerBoxPosition.RIGHT_TOP}
onOutsideClick={handleClick}
>
Expand Down
9 changes: 1 addition & 8 deletions src/shared/components/in-app-search/InAppSearch.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,7 @@
}

.tooltip {
background: var(--color-black);
padding: 12px 20px;
filter: drop-shadow(2px 2px 3px var(--shadow-color));
color: var(--color-white);
}

.tooltipTip {
fill: var(--color-black);
--pointer-box-padding: 12px 20px;
}

.tooltipContent {
Expand Down
6 changes: 5 additions & 1 deletion src/shared/components/in-app-search/InAppSearchMatches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type { AppName } from 'src/shared/state/in-app-search/inAppSearchSlice';
import type { InAppSearchMode } from './InAppSearch';

import styles from './InAppSearch.module.css';
import pointerBoxStyles from 'src/shared/components/pointer-box/PointerBox.module.css';

type InAppSearchMatchesProps = SearchResults & {
app: AppName;
Expand Down Expand Up @@ -136,7 +137,10 @@ const InAppSearchMatch = (props: InAppSearchMatchProps) => {
? PointerBoxPosition.RIGHT_BOTTOM
: PointerBoxPosition.BOTTOM_RIGHT
}
classNames={{ box: styles.tooltip, pointer: styles.tooltipTip }}
className={classNames(
styles.tooltip,
pointerBoxStyles.pointerBoxShadow
)}
onOutsideClick={hideTooltip}
>
<MatchDetails {...props} onClick={onAppClick} />
Expand Down
18 changes: 15 additions & 3 deletions src/shared/components/pointer-box/PointerBox.module.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
.pointerBox {
--_pointer-box-color: var(--pointer-box-color, var(--color-black));
color: var(--pointer-box-text-color, var(--color-white));
background-color: var(--_pointer-box-color);
cursor: default; /* to override cursor: pointer if e.g. parent is a button */
position: absolute;
z-index: 1000;
width: max-content;
box-sizing: content-box; /* Safari doesn't seem to respect "width: max-content" if box-sizing is border-box */
padding: 6px;
padding: var(--pointer-box-padding, 6px);
z-index: 1000;
}

/* Class applied to pointer box while the code is finding appropriate position for it.
Expand All @@ -18,6 +21,15 @@ hence it is placed in top left corner of the screen with position: fixed */
}

.pointer {
fill: var(--_pointer-box-color);
position: absolute;
mix-blend-mode: lighten;
}

/* This is a shared class for adding a shadow to PointerBox.
It is passed to PointerBox from parent components
that need PointerBox to have a shadow.
*/
.pointerBoxShadow {
filter: drop-shadow(2px 2px 3px var(--shadow-color));
}
11 changes: 3 additions & 8 deletions src/shared/components/pointer-box/PointerBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export type InlineStylesState = {

type PointerProps = {
style: InlineStyles;
className?: string;
width: number;
height: number;
};
Expand All @@ -60,10 +59,7 @@ export type PointerBoxProps = {
pointerWidth?: number;
pointerHeight?: number;
pointerOffset?: number;
classNames?: {
box?: string;
pointer?: string;
};
className?: string;
children: ReactNode;
onOutsideClick?: (() => void) | ((event: Event) => void);
onClose?: () => void;
Expand Down Expand Up @@ -166,7 +162,7 @@ const PointerBox = (props: PointerBoxProps) => {

const bodyClasses = classNames(
styles.pointerBox,
props.classNames?.box,
props.className,
positionFromProps,
{ [styles.invisible]: isPositioning || !hasInlineStyles() }
);
Expand All @@ -178,7 +174,6 @@ const PointerBox = (props: PointerBoxProps) => {
style={inlineStyles.boxStyles}
>
<Pointer
className={props.classNames?.pointer}
width={pointerWidthFromProps}
height={pointerHeightFromProps}
style={inlineStyles.pointerStyles}
Expand All @@ -201,7 +196,7 @@ const Pointer = (props: PointerProps) => {
height: `${pointerHeight}px`
};

const pointerClasses = classNames(styles.pointer, props.className);
const pointerClasses = classNames(styles.pointer);
const polygonPoints = `0,${pointerHeight} ${pointerWidth},${pointerHeight} ${pointerEndX},0`;

return (
Expand Down
11 changes: 1 addition & 10 deletions src/shared/components/toolbox/Toolbox.module.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@

.toolbox {
background: var(--color-black);
padding: 12px 20px;
filter: drop-shadow(2px 2px 3px var(--shadow-color));
cursor: default;
color: var(--color-white);
--pointer-box-padding: 12px 20px;
min-height: 40px;
font-size: 13px;
}

.tooltipTip {
fill: var(--color-black);
}
11 changes: 10 additions & 1 deletion src/shared/components/toolbox/Toolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/

import React, { ReactNode } from 'react';
import classNames from 'classnames';

import PointerBox, {
Position
} from 'src/shared/components/pointer-box/PointerBox';

import styles from './Toolbox.module.css';
import pointerBoxStyles from 'src/shared/components/pointer-box/PointerBox.module.css';

export enum ToolboxPosition {
LEFT = 'left',
Expand All @@ -31,6 +33,7 @@ type ToolboxProps = {
position?: ToolboxPosition;
anchor: HTMLElement;
onOutsideClick?: () => void;
className?: string;
children: ReactNode;
};

Expand All @@ -41,13 +44,19 @@ const Toolbox = (props: ToolboxProps) => {
? Position.LEFT_BOTTOM
: Position.RIGHT_BOTTOM;

const componentClasses = classNames(
styles.toolbox,
pointerBoxStyles.pointerBoxShadow,
props.className
);

return (
<PointerBox
position={pointerBoxPosition}
anchor={props.anchor}
onOutsideClick={props.onOutsideClick}
renderInsideAnchor={true}
classNames={{ box: styles.toolbox, pointer: styles.tooltipTip }}
className={componentClasses}
>
{props.children}
</PointerBox>
Expand Down
11 changes: 2 additions & 9 deletions src/shared/components/tooltip/Tooltip.module.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
.tooltip {
background: var(--color-dark-grey);
padding: 6px 18px 8px;
filter: drop-shadow(2px 2px 3px var(--shadow-color));
cursor: default;
color: var(--color-white);
--pointer-box-color: var(--color-dark-grey);
--pointer-box-padding: 6px 18px 8px;
border-radius: 4px;
font-size: 14px;
max-width: 300px;
}

.tooltipTip {
fill: var(--color-dark-grey);
}
9 changes: 8 additions & 1 deletion src/shared/components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import React, { ReactNode, useEffect, useState } from 'react';
import classNames from 'classnames';

import { TOOLTIP_TIMEOUT } from './tooltip-constants';

Expand All @@ -25,6 +26,7 @@ import PointerBox, {
import { TooltipPosition } from './tooltip-types';

import styles from './Tooltip.module.css';
import pointerBoxStyles from 'src/shared/components/pointer-box/PointerBox.module.css';

type Props = {
anchor: HTMLElement;
Expand Down Expand Up @@ -62,6 +64,11 @@ const TooltipWithAnchor = (props: Props) => {
return null;
}

const componentClasses = classNames(
styles.tooltip,
pointerBoxStyles.pointerBoxShadow
);

return (
<PointerBox
position={props.position ?? Position.BOTTOM_RIGHT}
Expand All @@ -70,7 +77,7 @@ const TooltipWithAnchor = (props: Props) => {
autoAdjust={props.autoAdjust}
renderInsideAnchor={props.renderInsideAnchor}
onClose={props.onClose}
classNames={{ box: styles.tooltip, pointer: styles.tooltipTip }}
className={componentClasses}
onOutsideClick={props.onClose}
>
{props.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
}

.pointerBox {
padding: 6px 12px;
background: var(--color-black);
color: var(--color-white);
--pointer-box-padding: 6px 12px;
}

.pointerBox p {
max-width: 200px;
}

.pointerBoxPointer {
fill: var(--color-black);
}
5 changes: 1 addition & 4 deletions src/shared/components/view-in-app-popup/ViewInAppPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ const ViewInAppPopup = (props: ViewInAppPopupProps) => {
onClose={onClose}
position={position}
autoAdjust={true}
classNames={{
box: styles.pointerBox,
pointer: styles.pointerBoxPointer
}}
className={styles.pointerBox}
>
<ViewInApp theme="dark" links={links} />
</PointerBox>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.pointerBox {
padding: 6px 12px;
background: black;
color: white;
--pointer-box-padding: 6px 12px;
}

.pointerBox p {
Expand Down
6 changes: 3 additions & 3 deletions stories/shared-components/pointer-box/PointerBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import React from 'react';

import VariantsStory from './variantsStory';
import PositioningStory from './positioningStory';
import ScrollingStory from './scrollingStory';
import VariantsStory from './pointerBoxVariantsStory';
import PositioningStory from './pointerBoxPositioningStory';
import ScrollingStory from './pointerBoxScrollingStory';

export default {
title: 'Components/Shared Components/PointerBox'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ const Item = (props: ItemProps) => {
position={props.position}
container={props.container.current}
autoAdjust={true}
classNames={{
box: styles.pointerBox,
pointer: styles.pointerBoxPointer
}}
className={styles.pointerBox}
pointerOffset={5}
>
Hello sailor!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ const ScrollingStory = () => {
position={Position.BOTTOM_LEFT}
onClose={() => setShowPointerBox(false)}
renderInsideAnchor={renderingTarget === RenderingTarget.ANCHOR}
classNames={{
box: styles.pointerBox,
pointer: styles.pointerBoxPointer
}}
className={styles.pointerBox}
>
Hello sailor!
</PointerBox>
Expand Down
Loading

0 comments on commit 48bfc11

Please sign in to comment.