refactor: Delete isPlainObject type guard and replace its usages with direct typeof checks.

This commit is contained in:
2025-11-24 21:22:38 +01:00
parent 63be4663ab
commit f5ca74b63c
8 changed files with 86 additions and 95 deletions
+10 -10
View File
@@ -1,10 +1,10 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { CSSProperties, ReactNode, FormEvent, MutableRefObject } from 'react';
import { PlusIcon } from './icons';
import { isPlainObject } from '../utils/typeGuards';
import useFloatingMenu from './useFloatingMenu';
type QuickAddOption = string | number | { id?: string | number; label?: string; name?: string; [key: string]: unknown };
type QuickAddOption = string | number | { id?: string | number; label?: string; name?: string;[key: string]: unknown };
interface NormalizedOption {
id?: string | number;
@@ -17,7 +17,7 @@ const normalizeOption = (option: QuickAddOption | null, index: number): Normaliz
if (option == null) {
return null;
}
if (isPlainObject(option)) {
if (typeof option === 'object') {
const label = option.label ?? option.name;
if (label == null) {
return null;
@@ -190,19 +190,19 @@ const QuickAddMenu = ({
const menuClassName = 'menu menu--floating';
const anchoredMenuStyle = isAnchoredMenu && menuStyle
? {
top: menuStyle.top,
left: menuStyle.left,
...(menuStyle.width ? { width: menuStyle.width } : null),
}
top: menuStyle.top,
left: menuStyle.left,
...(menuStyle.width ? { width: menuStyle.width } : null),
}
: undefined;
const menuInlineStyle = (isAnchoredMenu ? anchoredMenuStyle : menuStyle || undefined) as CSSVarStyle | undefined;
const hasFloatingWidthVar = Boolean(menuInlineStyle && Object.prototype.hasOwnProperty.call(menuInlineStyle, '--floating-min-width'));
const menuStyleWithVar: CSSVarStyle | undefined = hasFloatingWidthVar
? menuInlineStyle
: {
...(menuInlineStyle || {}),
'--floating-min-width': `${Math.max(menuMinWidth, 0)}px`,
};
...(menuInlineStyle || {}),
'--floating-min-width': `${Math.max(menuMinWidth, 0)}px`,
};
return (
<div className={className ? `quick-add ${className}` : 'quick-add'}>