Skip to content

Commit

Permalink
Changed "ref" naming to "callback" (deephaven#1909)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 11, 2024
1 parent 4b2cd06 commit ebf1598
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
15 changes: 6 additions & 9 deletions packages/components/src/spectrum/ItemContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useState,
} from 'react';
import cl from 'classnames';
import { isElementOfType, useCheckOverflowRef } from '@deephaven/react-hooks';
import { isElementOfType, useCheckOverflow } from '@deephaven/react-hooks';
import { Text } from './Text';
import { TooltipOptions } from './utils';
import ItemTooltip from './ItemTooltip';
Expand All @@ -27,11 +27,8 @@ export function ItemContent({
children: content,
tooltipOptions,
}: ItemContentProps): JSX.Element | null {
const {
checkOverflowRef,
isOverflowing: isTextOverflowing,
resetIsOverflowing,
} = useCheckOverflowRef();
const { checkOverflow, isOverflowing, resetIsOverflowing } =
useCheckOverflow();

const [previousContent, setPreviousContent] = useState(content);

Expand Down Expand Up @@ -66,7 +63,7 @@ export function ItemContent({
isElementOfType(el, Text)
? cloneElement(el, {
...el.props,
ref: checkOverflowRef,
ref: checkOverflow,
UNSAFE_className: cl(
el.props.UNSAFE_className,
stylesCommon.spectrumEllipsis
Expand All @@ -79,7 +76,7 @@ export function ItemContent({
if (typeof content === 'string' || typeof content === 'number') {
content = (
<Text
ref={checkOverflowRef}
ref={checkOverflow}
UNSAFE_className={stylesCommon.spectrumEllipsis}
>
{content}
Expand All @@ -89,7 +86,7 @@ export function ItemContent({
/* eslint-enable no-param-reassign */

const tooltip =
tooltipOptions == null || !isTextOverflowing ? null : (
tooltipOptions == null || !isOverflowing ? null : (
<ItemTooltip options={tooltipOptions}>{content}</ItemTooltip>
);

Expand Down
2 changes: 1 addition & 1 deletion packages/react-hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from './SelectionUtils';
export * from './SpectrumUtils';
export * from './useAsyncInterval';
export * from './useCallbackWithAction';
export * from './useCheckOverflowRef';
export * from './useCheckOverflow';
export { default as useContextOrThrow } from './useContextOrThrow';
export * from './useDebouncedCallback';
export * from './useDelay';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { useCallback, useState } from 'react';
import type { DOMRefValue } from '@react-types/shared';

export interface CheckOverflowRefResult {
checkOverflowRef: <T extends HTMLElement>(
elRef: DOMRefValue<T> | null
) => void;
export interface CheckOverflowResult {
checkOverflow: <T extends HTMLElement>(elRef: DOMRefValue<T> | null) => void;
isOverflowing: boolean;
resetIsOverflowing: () => void;
}

export function useCheckOverflowRef(): CheckOverflowRefResult {
export function useCheckOverflow(): CheckOverflowResult {
const [isOverflowing, setIsOverflowing] = useState(false);

/**
* Whenever a Spectrum `DOMRefValue` component renders, see if the content is
* overflowing so we know whether to render a tooltip showing the full content
* or not.
*/
const checkOverflowRef = useCallback(
const checkOverflow = useCallback(
<T extends HTMLElement>(elRef: DOMRefValue<T> | null) => {
const el = elRef?.UNSAFE_getDOMNode();

Expand All @@ -38,9 +36,9 @@ export function useCheckOverflowRef(): CheckOverflowRefResult {

return {
isOverflowing,
checkOverflowRef,
checkOverflow,
resetIsOverflowing,
};
}

export default useCheckOverflowRef;
export default useCheckOverflow;

0 comments on commit ebf1598

Please sign in to comment.