Skip to content

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

TypeScript

Add startIcon (#584)

Andrey Goderf87ae98909f5
diff --git a/apps/storybook/stories/PowerSearch.stories.tsx b/apps/storybook/stories/PowerSearch.stories.tsx
index c33f1706f6..f4190a0b93 100644
--- a/apps/storybook/stories/PowerSearch.stories.tsx
+++ b/apps/storybook/stories/PowerSearch.stories.tsx
@@ -7,6 +7,7 @@ import type {
PowerSearchChangeType,
} from '@xds/core/PowerSearch';
import type {XDSSearchSource, XDSSearchableItem} from '@xds/core/Typeahead';
+import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
// =============================================================================
// Sample data
@@ -893,3 +894,24 @@ export const WithNestedFilters: Story = {
],
name: 'Nested Filters',
};
+
+export const WithStartIcon: Story = {
+ render: args => {
+ const [filters, setFilters] = useState<PowerSearchFilter[]>([]);
+ return (
+ <XDSPowerSearch
+ {...args}
+ config={basicConfig}
+ filters={filters}
+ onChange={newFilters => setFilters([...newFilters])}
+ startIcon={MagnifyingGlassIcon}
+ />
+ );
+ },
+ args: {
+ label: 'Search',
+ isLabelHidden: true,
+ placeholder: 'Search...',
+ },
+ name: 'With Start Icon',
+};
diff --git a/apps/storybook/stories/Tokenizer.stories.tsx b/apps/storybook/stories/Tokenizer.stories.tsx
index e4f14c91cf..a62fd766dd 100644
--- a/apps/storybook/stories/Tokenizer.stories.tsx
+++ b/apps/storybook/stories/Tokenizer.stories.tsx
@@ -2,6 +2,7 @@ import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {XDSTokenizer} from '@xds/core/Tokenizer';
import type {XDSSearchableItem, XDSSearchSource} from '@xds/core/Typeahead';
+import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
// Sample data
const users: XDSSearchableItem[] = [
@@ -158,3 +159,31 @@ export const Disabled: Story = {
isDisabled: true,
},
};
+
+export const WithStartIcon: Story = {
+ ...Default,
+ args: {
+ ...Default.args,
+ startIcon: MagnifyingGlassIcon,
+ },
+ name: 'With Start Icon',
+};
+
+export const WithStartIconAndTokens: Story = {
+ render: args => {
+ const [value, setValue] = useState([users[0], users[2]]);
+ return (
+ <XDSTokenizer
+ {...args}
+ searchSource={userSource}
+ value={value}
+ onChange={items => setValue(items)}
+ />
+ );
+ },
+ args: {
+ label: 'Team Members',
+ startIcon: MagnifyingGlassIcon,
+ },
+ name: 'With Start Icon and Tokens',
+};
diff --git a/apps/storybook/stories/Typeahead.stories.tsx b/apps/storybook/stories/Typeahead.stories.tsx
index a257a76341..f7f8fd285e 100644
--- a/apps/storybook/stories/Typeahead.stories.tsx
+++ b/apps/storybook/stories/Typeahead.stories.tsx
@@ -2,6 +2,7 @@ import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {XDSTypeahead} from '@xds/core/Typeahead';
import type {XDSSearchableItem, XDSSearchSource} from '@xds/core/Typeahead';
+import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
// Sample data
const fruits: XDSSearchableItem[] = [
@@ -148,3 +149,13 @@ export const LimitedResults: Story = {
},
name: 'Max 3 Results',
};
+
+export const WithStartIcon: Story = {
+ ...Default,
+ args: {
+ ...Default.args,
+ startIcon: MagnifyingGlassIcon,
+ hasEntriesOnFocus: true,
+ },
+ name: 'With Start Icon',
+};
diff --git a/packages/core/src/PowerSearch/XDSPowerSearch.tsx b/packages/core/src/PowerSearch/XDSPowerSearch.tsx
index 21fda73d11..3f2699435f 100644
--- a/packages/core/src/PowerSearch/XDSPowerSearch.tsx
+++ b/packages/core/src/PowerSearch/XDSPowerSearch.tsx
@@ -25,6 +25,7 @@ import {XDSTokenizer, type XDSTokenizerHandle} from '../Tokenizer';
import {XDSTypeaheadItem} from '../Typeahead/XDSTypeaheadItem';
import {XDSToken} from '../Token';
import {XDSIcon} from '../Icon';
+import type {XDSIconType} from '../Icon';
import type {XDSIconName} from '../Icon/globalIconRegistry';
import type {XDSInputStatus} from '../Field';
import {useXDSLayer} from '../Layer';
@@ -319,6 +320,11 @@ export interface XDSPowerSearchProps {
isReadOnly?: boolean;
/** Whether the input is disabled. @default false */
isDisabled?: boolean;
+ /**
+ * Icon to display at the start of the input.
+ * Pass an SVG icon component (e.g. from heroicons, lucide, etc.).
+ */
+ startIcon?: XDSIconType;
/** Focus callback. */
onFocus?: () => void;
/** Blur callback. */
@@ -418,6 +424,7 @@ export function XDSPowerSearch({
hasClear = true,
isReadOnly = false,
isDisabled = false,
+ startIcon,
onFocus,
onBlur,
status,
@@ -709,6 +716,7 @@ export function XDSPowerSearch({
placeholder={filters.length === 0 ? placeholder : ''}
hasAutoFocus={hasAutoFocus}
hasClear={hasClear && !isReadOnly}
+ startIcon={startIcon}
isDisabled={isDisabled}
hasEntriesOnFocus
debounceMs={0}
diff --git a/packages/core/src/Tokenizer/XDSTokenizer.tsx b/packages/core/src/Tokenizer/XDSTokenizer.tsx
index 39d7f119a6..27ec838dc5 100644
--- a/packages/core/src/Tokenizer/XDSTokenizer.tsx
+++ b/packages/core/src/Tokenizer/XDSTokenizer.tsx
@@ -33,6 +33,7 @@ import {
} from '../Field';
import {XDSToken} from '../Token';
import {XDSIcon} from '../Icon';
+import type {XDSIconType} from '../Icon';
import {
colorVars,
spacingVars,
@@ -84,6 +85,11 @@ export interface XDSTokenizerProps<T extends XDSSearchableItem> {
isOptional?: boolean;
/** Validation status. */
status?: XDSInputStatus;
+ /**
+ * Icon to display at the start of the input.
+ * Pass an SVG icon component (e.g. from heroicons, lucide, etc.).
+ */
+ startIcon?: XDSIconType;
/** Label tooltip. */
labelTooltip?: string;
/** Search source providing items. */
@@ -260,6 +266,7 @@ export function XDSTokenizer<T extends XDSSearchableItem>({
isRequired = false,
isOptional = false,
status,
+ startIcon,
labelTooltip,
searchSource,
value,
@@ -455,6 +462,7 @@ export function XDSTokenizer<T extends XDSSearchableItem>({
status && inputStatusHoverShadowStyles[status.type],
status && inputStatusFocusWithinStyles[status.type],
)}>
+ {startIcon && <XDSIcon icon={startIcon} size="sm" color="primary" />}
{tokens}
<XDSBaseTypeahead
ref={inputRef}
diff --git a/packages/core/src/Typeahead/XDSTypeahead.tsx b/packages/core/src/Typeahead/XDSTypeahead.tsx
index a47916fe80..892e03666a 100644
--- a/packages/core/src/Typeahead/XDSTypeahead.tsx
+++ b/packages/core/src/Typeahead/XDSTypeahead.tsx
@@ -30,6 +30,7 @@ import {
} from '../Field';
import {XDSToken} from '../Token';
import {XDSIcon} from '../Icon';
+import type {XDSIconType} from '../Icon';
import {
colorVars,
spacingVars,
@@ -59,6 +60,11 @@ export interface XDSTypeaheadProps<T extends XDSSearchableItem> {
isOptional?: boolean;
/** Validation status. */
status?: XDSInputStatus;
+ /**
+ * Icon to display at the start of the input.
+ * Pass an SVG icon component (e.g. from heroicons, lucide, etc.).
+ */
+ startIcon?: XDSIconType;
/** Label tooltip. */
labelTooltip?: string;
/** Search source providing items. */
@@ -203,6 +209,7 @@ export function XDSTypeahead<T extends XDSSearchableItem>({
isRequired = false,
isOptional = false,
status,
+ startIcon,
labelTooltip,
searchSource,
value,
@@ -377,6 +384,7 @@ export function XDSTypeahead<T extends XDSSearchableItem>({
status && inputStatusFocusWithinStyles[status.type],
isDisabled && inputWrapperStyles.disabled,
)}>
+ {startIcon && <XDSIcon icon={startIcon} size="sm" color="primary" />}
{showToken && (
<XDSToken
ref={tokenRef}