From cfdde51ee6eea6b3b2bcb0dfe5c2661224c5f3ba Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Tue, 23 Apr 2024 16:57:45 -0500 Subject: [PATCH] Constraining listview icon height (#1890) --- .../src/spectrum/listView/ListViewNormalized.tsx | 7 +++++++ .../src/spectrum/utils/itemWrapperUtils.tsx | 6 ++++-- .../spectrum/utils/useRenderNormalizedItem.tsx | 12 ++++++++++-- packages/utils/src/UIConstants.ts | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/components/src/spectrum/listView/ListViewNormalized.tsx b/packages/components/src/spectrum/listView/ListViewNormalized.tsx index 0c3a33ed45..f3b067d2fd 100644 --- a/packages/components/src/spectrum/listView/ListViewNormalized.tsx +++ b/packages/components/src/spectrum/listView/ListViewNormalized.tsx @@ -1,5 +1,6 @@ import { useMemo } from 'react'; import cl from 'classnames'; +import { LIST_VIEW_ICON_SIZES } from '@deephaven/utils'; import { NormalizedItem, normalizeTooltipOptions, @@ -8,6 +9,7 @@ import { } from '../utils'; import type { ListViewProps } from './ListView'; import { ListViewWrapper } from './ListViewWrapper'; +import { useSpectrumThemeProvider } from '../../theme'; export interface ListViewNormalizedProps extends Omit { @@ -29,6 +31,10 @@ export function ListViewNormalized({ onSelectionChange, ...props }: ListViewNormalizedProps): JSX.Element { + const { scale } = useSpectrumThemeProvider(); + + const iconSize = LIST_VIEW_ICON_SIZES[props.density ?? 'regular'][scale]; + const tooltipOptions = useMemo( () => normalizeTooltipOptions(tooltip, 'bottom'), [tooltip] @@ -39,6 +45,7 @@ export function ListViewNormalized({ showItemDescriptions, showItemIcons, tooltipOptions, + iconSize, }); // Spectrum doesn't re-render if only the `renderNormalizedItems` function diff --git a/packages/components/src/spectrum/utils/itemWrapperUtils.tsx b/packages/components/src/spectrum/utils/itemWrapperUtils.tsx index efed25cbeb..1d7e6011f3 100644 --- a/packages/components/src/spectrum/utils/itemWrapperUtils.tsx +++ b/packages/components/src/spectrum/utils/itemWrapperUtils.tsx @@ -25,11 +25,13 @@ import { Text } from '../Text'; * the vsBlank icon will be used. * @param maybeIconKey The content to wrap * @param slot The slot to use for the Icon component + * @param iconSize The size of the icon * @returns The wrapped content or original content if not a string */ export function wrapIcon( maybeIconKey: ReactNode, - slot: ItemIconSlot + slot: ItemIconSlot, + iconSize?: number ): ReactNode { // eslint-disable-next-line no-param-reassign maybeIconKey = maybeIconKey ?? ''; @@ -39,7 +41,7 @@ export function wrapIcon( } return ( - + ); diff --git a/packages/components/src/spectrum/utils/useRenderNormalizedItem.tsx b/packages/components/src/spectrum/utils/useRenderNormalizedItem.tsx index 025417e119..b3e00c24dc 100644 --- a/packages/components/src/spectrum/utils/useRenderNormalizedItem.tsx +++ b/packages/components/src/spectrum/utils/useRenderNormalizedItem.tsx @@ -15,6 +15,7 @@ export interface UseRenderNormalizedItemOptions { showItemDescriptions: boolean; showItemIcons: boolean; tooltipOptions: TooltipOptions | null; + iconSize?: number; } /** @@ -28,6 +29,7 @@ export function useRenderNormalizedItem({ showItemDescriptions, showItemIcons, tooltipOptions, + iconSize, }: UseRenderNormalizedItemOptions): ( normalizedItem: NormalizedItem ) => JSX.Element { @@ -42,7 +44,7 @@ export function useRenderNormalizedItem({ : null; const icon = showItemIcons - ? wrapIcon(normalizedItem.item?.icon, itemIconSlot) + ? wrapIcon(normalizedItem.item?.icon, itemIconSlot, iconSize) : null; return ( @@ -71,7 +73,13 @@ export function useRenderNormalizedItem({ ); }, - [itemIconSlot, showItemDescriptions, showItemIcons, tooltipOptions] + [ + iconSize, + itemIconSlot, + showItemDescriptions, + showItemIcons, + tooltipOptions, + ] ); } diff --git a/packages/utils/src/UIConstants.ts b/packages/utils/src/UIConstants.ts index 98ce05e307..e58f3c6f31 100644 --- a/packages/utils/src/UIConstants.ts +++ b/packages/utils/src/UIConstants.ts @@ -32,6 +32,21 @@ export const LIST_VIEW_ROW_HEIGHTS = { }, } as const; +export const LIST_VIEW_ICON_SIZES = { + compact: { + medium: 24, + large: 30, + }, + regular: { + medium: 26, + large: 32, + }, + spacious: { + medium: 32, + large: 40, + }, +} as const; + export const LIST_VIEW_ROW_HEIGHTS_WITH_DESCRIPTIONS = { compact: { medium: 48,