Skip to content

Commit

Permalink
[Suggest component] Allow adding icon to Suggest (#19801)
Browse files Browse the repository at this point in the history
## Summary & Motivation
as titled

## How I Tested These Changes
storybook
<img width="309" alt="Screenshot 2024-02-14 at 2 48 29 PM"
src="https://github.com/dagster-io/dagster/assets/2286579/e99822a9-d6ef-492a-b6de-473d68e8083b">
<img width="337" alt="Screenshot 2024-02-14 at 2 48 25 PM"
src="https://github.com/dagster-io/dagster/assets/2286579/9e22011c-5c6e-4bcb-ab2f-2100493a0869">
  • Loading branch information
salazarm authored Feb 14, 2024
1 parent 41cd16b commit 85d7587
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {Suggest as BlueprintSuggest, SuggestProps, isCreateNewItem} from '@bluep
import deepmerge from 'deepmerge';
import * as React from 'react';
import {List as _List} from 'react-virtualized';
import {createGlobalStyle} from 'styled-components';
import styled, {createGlobalStyle} from 'styled-components';

import {Box} from './Box';
import {Colors} from './Color';
import {IconWrapper} from './Icon';
import {Icon, IconName, IconWrapper} from './Icon';
import {TextInputContainerStyles, TextInputStyles} from './TextInput';

// todo: react-virtualized needs updated types to work with React 18. For now lets any type.
Expand Down Expand Up @@ -57,6 +57,7 @@ const VISIBLE_ITEMS = 7.5;
interface Props<T> extends React.PropsWithChildren<SuggestProps<T>> {
itemHeight?: number;
menuWidth?: number;
icon?: IconName;
}

export const Suggest = <T,>(props: Props<T>) => {
Expand All @@ -65,6 +66,7 @@ export const Suggest = <T,>(props: Props<T>) => {
itemHeight = MENU_ITEM_HEIGHT,
menuWidth = MENU_WIDTH,
noResults,
icon,
...rest
} = props;

Expand All @@ -80,7 +82,7 @@ export const Suggest = <T,>(props: Props<T>) => {
className: 'dagster-suggest-input',
};

return (
const suggest = (
<BlueprintSuggest<T>
{...rest}
inputProps={inputProps as any}
Expand Down Expand Up @@ -122,4 +124,33 @@ export const Suggest = <T,>(props: Props<T>) => {
popoverProps={allPopoverProps}
/>
);

if (icon) {
return (
<SuggestWithIconWrapper>
<div>
<Icon name={icon} />
</div>
{suggest}
</SuggestWithIconWrapper>
);
}
return suggest;
};

const SuggestWithIconWrapper = styled.div`
position: relative;
> :first-child {
position: absolute;
left: 8px;
z-index: 1;
top: 0;
bottom: 0;
display: flex;
align-items: center;
}
&&& input {
padding-left: 28px;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const Default = () => {
placeholder: 'Type the name of a US state…',
style: {width: '250px'},
}}
icon="search"
items={US_STATES}
inputValueRenderer={(item) => item}
itemPredicate={(query, item) => item.toLocaleLowerCase().includes(query.toLocaleLowerCase())}
Expand Down

1 comment on commit 85d7587

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagit-storybook ready!

✅ Preview
https://dagit-storybook-5szz6284r-elementl.vercel.app

Built with commit 85d7587.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.