forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#32439 from software-mansion-labs/wave8/t…
…op-bar-search-no-usage [Wave8] Search Input component
- Loading branch information
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters