Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(PowerSearch): render entity photo as token icon + tokenizer spacing fixes (#2280)

Andrey Goder5139fcca9444
diff --git a/apps/storybook/stories/PowerSearch.stories.tsx b/apps/storybook/stories/PowerSearch.stories.tsx
index eda8a64406..0fcd0d6025 100644
--- a/apps/storybook/stories/PowerSearch.stories.tsx
+++ b/apps/storybook/stories/PowerSearch.stories.tsx
@@ -38,12 +38,36 @@ const tagValues = [
];
const users: XDSSearchableItem[] = [
- {id: 'user-1', label: 'Alice Johnson'},
- {id: 'user-2', label: 'Bob Smith'},
- {id: 'user-3', label: 'Charlie Brown'},
- {id: 'user-4', label: 'Diana Prince'},
- {id: 'user-5', label: 'Eve Williams'},
- {id: 'user-6', label: 'Frank Miller'},
+ {
+ id: 'user-1',
+ label: 'Alice Johnson',
+ auxiliaryData: {photo: 'https://i.pravatar.cc/150?u=alice'},
+ },
+ {
+ id: 'user-2',
+ label: 'Bob Smith',
+ auxiliaryData: {photo: 'https://i.pravatar.cc/150?u=bob'},
+ },
+ {
+ id: 'user-3',
+ label: 'Charlie Brown',
+ auxiliaryData: {photo: 'https://i.pravatar.cc/150?u=charlie'},
+ },
+ {
+ id: 'user-4',
+ label: 'Diana Prince',
+ auxiliaryData: {photo: 'https://i.pravatar.cc/150?u=diana'},
+ },
+ {
+ id: 'user-5',
+ label: 'Eve Williams',
+ auxiliaryData: {photo: 'https://i.pravatar.cc/150?u=eve'},
+ },
+ {
+ id: 'user-6',
+ label: 'Frank Miller',
+ auxiliaryData: {photo: 'https://i.pravatar.cc/150?u=frank'},
+ },
];
const userSource: XDSSearchSource = {
diff --git a/packages/core/src/PowerSearch/XDSPowerSearch.tsx b/packages/core/src/PowerSearch/XDSPowerSearch.tsx
index fe5ed6bae5..0a35a476dc 100644
--- a/packages/core/src/PowerSearch/XDSPowerSearch.tsx
+++ b/packages/core/src/PowerSearch/XDSPowerSearch.tsx
@@ -30,6 +30,7 @@ import {
} from '../Tokenizer';
import {XDSTypeaheadItem} from '../Typeahead/XDSTypeaheadItem';
import {XDSToken} from '../Token';
+import {XDSAvatar} from '../Avatar';
import {layerAnimations} from '../Layer/layerAnimations.stylex';
import {XDSIcon} from '../Icon';
import type {XDSIconType} from '../Icon';
@@ -779,9 +780,23 @@ export function XDSPowerSearch({
/>
) : undefined;
+ // Show entity photo as token icon for single-entity filters
+ let tokenIcon: ReactNode | undefined;
+ if (
+ filter?.value.type === 'entity_list' &&
+ filter.value.value.length === 1 &&
+ filter.value.value[0].photo
+ ) {
+ const entity = filter.value.value[0];
+ tokenIcon = (
+ <XDSAvatar src={entity.photo} name={entity.label} size={16} />
+ );
+ }
+
return (
<XDSToken
label={tokenLabel}
+ icon={tokenIcon}
endContent={valueContent}
onClick={
handleClick
diff --git a/packages/core/src/Tokenizer/XDSTokenizer.tsx b/packages/core/src/Tokenizer/XDSTokenizer.tsx
index 95e97158bf..f5c715333a 100644
--- a/packages/core/src/Tokenizer/XDSTokenizer.tsx
+++ b/packages/core/src/Tokenizer/XDSTokenizer.tsx
@@ -217,8 +217,11 @@ const styles = stylex.create({
// = 8 - 4 - 1 = 3px.
paddingBlock: `calc(${spacingVars['--spacing-1']} - 1px)`,
paddingInline: `calc(${spacingVars['--spacing-1']} - 1px)`,
+ // Row gap must match paddingBlock so wrapped rows look evenly spaced.
+ rowGap: `calc(${spacingVars['--spacing-1']} - 1px)`,
},
token: {
+ display: 'flex',
flexShrink: 0,
},
clearAllButton: {