Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wave8] Search Input component #32439

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import {GestureResponderEvent, StyleProp, View, ViewStyle} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import {PressableWithFeedback} from './Pressable';
import Text from './Text';
import Tooltip from './Tooltip';

type SearchProps = {
// Callback fired when component is pressed
onPress: (event?: GestureResponderEvent | KeyboardEvent) => void;

// Text explaining what the user can search for
placeholder?: string;

// Text showing up in a tooltip when component is hovered
tooltip?: string;

// Styles to apply on the outer element
style?: StyleProp<ViewStyle>;
};

function Search({onPress, placeholder, tooltip, style}: SearchProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

return (
<Tooltip text={tooltip ?? translate('common.search')}>
<PressableWithFeedback
Copy link
Contributor

Choose a reason for hiding this comment

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

no background color when press/long press on mobile. Is it expected?

ios.hover.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @aimane-chnaif . If you change the sidebar background color from sidebar: colors.productDark200, to sidebar: colors.productDark100, you will see the touchable feedback in action. It's visible on onPress. There's no style change when onPress becomes onLongPress.

@dannymcclain @shawnborton LMK if this looks good.

Screen.Recording.2023-12-13.at.16.07.48.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah a couple of things here:

  • At some point we need to change this entire sidebar to use the same color100 (appBG) color. Not sure when or where we plan to do that.
  • The search input should technically be using color300 (same as rowHover) as the background color. I don't think we've decided anything for the search inputs :hover or :active but I suppose it could be color400 for hover and color500 for active/press?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same concern on light theme. There's no visual feedback on background color on press/long press. (not blocker)

light.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

Asked Maciej to address this in the follow up PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, the color of the search input from figma (#07271F) seems to be gone from the repo after recent changes in the theme. So I'll do 300/400/500 @shawnborton. Although our app now suggests something like that:

    componentBG: colors.productDark100,
    hoverComponentBG: colors.productDark200,
    activeComponentBG: colors.productDark400,

But I know it can change as currently we have the wrong background color in the sidebar, while ideal-nav will have bg200 if I remember correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While on the buttons currently we have:

    buttonDefaultBG: colors.productDark400,
    buttonHoveredBG: colors.productDark500,
    buttonPressedBG: colors.productDark600,

Copy link
Contributor Author

@MaciejSWM MaciejSWM Dec 15, 2023

Choose a reason for hiding this comment

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

@shawnborton

300/400/500:

Screen.Recording.2023-12-15.at.17.20.54.mov
Screen.Recording.2023-12-15.at.17.24.20.mov

accessibilityLabel={tooltip ?? translate('common.search')}
role={CONST.ROLE.BUTTON}
onPress={onPress}
style={styles.searchPressable}
>
{({hovered}) => (
<View style={[styles.searchContainer, hovered && styles.searchContainerHovered, style]}>
<Icon
src={Expensicons.MagnifyingGlass}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
/>
<Text
style={styles.searchInputStyle}
numberOfLines={1}
>
{placeholder ?? translate('common.searchWithThreeDots')}
</Text>
</View>
)}
</PressableWithFeedback>
</Tooltip>
);
}

Search.displayName = 'Search';

export type {SearchProps};
export default Search;
3 changes: 2 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default {
optional: 'Optional',
new: 'New',
search: 'Search',
searchWithThreeDots: 'Search...',
next: 'Next',
previous: 'Previous',
goBack: 'Go back',
Expand Down Expand Up @@ -497,7 +498,7 @@ export default {
},
},
sidebarScreen: {
buttonSearch: 'Search',
buttonSearch: 'Search for something...',
buttonMySettings: 'My settings',
fabNewChat: 'Start chat',
fabNewChatExplained: 'Start chat (Floating action)',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default {
optional: 'Opcional',
new: 'Nuevo',
search: 'Buscar',
searchWithThreeDots: 'Buscar...',
next: 'Siguiente',
previous: 'Anterior',
goBack: 'Volver',
Expand Down Expand Up @@ -490,7 +491,7 @@ export default {
},
},
sidebarScreen: {
buttonSearch: 'Buscar',
buttonSearch: 'Busca algo...',
buttonMySettings: 'Mi configuración',
fabNewChat: 'Iniciar chat',
fabNewChatExplained: 'Iniciar chat (Acción flotante)',
Expand Down
42 changes: 42 additions & 0 deletions src/stories/Search.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import Search, {SearchProps} from '@components/Search';

/**
* We use the Component Story Format for writing stories. Follow the docs here:
*
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format
*/
const story = {
title: 'Components/Search',
component: Search,
};

type StoryType = typeof Template & {args?: Partial<SearchProps>};

function Template(args: SearchProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <Search {...args} />;
}

// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Default: StoryType = Template.bind({});
Default.args = {
onPress: () => alert('Pressed'),
};

const CustomPlaceholderAndTooltip: StoryType = Template.bind({});
CustomPlaceholderAndTooltip.args = {
placeholder: 'Search for a specific thing...',
tooltip: 'Custom tooltip text',
onPress: () => alert('This component has custom placeholder text. Also custom tooltip text when hovered.'),
};

const CustomBackground: StoryType = Template.bind({});
CustomBackground.args = {
onPress: () => alert('This component has custom styles applied'),
style: {backgroundColor: 'darkgreen'},
};

export default story;
export {Default, CustomPlaceholderAndTooltip, CustomBackground};
25 changes: 25 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,31 @@ const styles = (theme: ThemeColors) =>
flex: 1,
},

searchPressable: {
height: 40,
},

searchContainer: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
gap: 8,
paddingHorizontal: 24,
backgroundColor: theme.highlightBG,
borderRadius: variables.componentBorderRadiusRounded,
},

searchContainerHovered: {
backgroundColor: theme.border,
},

searchInputStyle: {
color: colors.productDark800,
fontSize: 13,
lineHeight: 16,
width: '100%',
},

threeDotsPopoverOffset: (windowWidth: number) =>
({
...getPopOverVerticalOffset(60),
Expand Down
Loading