1- import { FC , KeyboardEventHandler , useCallback , useEffect , useState } from 'react'
2- import TextField from '@mui/material/TextField'
3- import SearchIcon from '@mui/icons-material/Search'
4- import HighlightOffIcon from '@mui/icons-material/HighlightOff'
5- import InputAdornment from '@mui/material/InputAdornment'
6- import { COLORS } from '../../../styles/theme/colors'
7- import { Button } from '@oasisprotocol/ui-library/src/components/ui/button'
8- import { useScreenSize } from '../../hooks/useScreensize'
9- import WarningIcon from '@mui/icons-material/WarningAmber'
10- import { typingDelay } from '../../../styles/theme'
11- import Typography from '@mui/material/Typography'
1+ import { FC , KeyboardEventHandler , useCallback } from 'react'
122import { useTranslation } from 'react-i18next'
13- import MuiButton from '@mui/material/Button '
3+ import { Button } from '@oasisprotocol/ui-library/src/components/ui/button '
144import { CardEmptyState } from '../CardEmptyState'
15- import { inputBaseClasses } from '@mui/material/InputBase'
16-
17- type SearchBarSize = 'small' | 'medium' | 'large'
5+ import { SearchInput } from '@oasisprotocol/ui-library/src/components/input'
186
197export interface TableSearchBarProps {
8+ className ?: string
209 placeholder : string
2110 warning ?: string
2211 value : string
23- /**
24- * Should we go 100% width?
25- */
26- fullWidth ?: boolean
27-
28- /**
29- * Width of the whole component
30- *
31- * Note: fullWidth overrides this.
32- */
33- width ?: string | number
34-
3512 onChange : ( value : string ) => void
3613 onEnter ?: ( ) => void
37- size ?: SearchBarSize
3814 autoFocus ?: boolean
3915}
4016
4117export const TableSearchBar : FC < TableSearchBarProps > = ( {
18+ className,
4219 value,
4320 onChange,
4421 placeholder,
4522 warning,
46- fullWidth,
4723 autoFocus,
4824 onEnter,
49- width = 190 ,
5025} ) => {
51- const { isTablet } = useScreenSize ( )
52-
53- const [ isWarningFresh , setIsWarningFresh ] = useState ( false )
54-
55- useEffect ( ( ) => {
56- if ( warning ) {
57- const timeout = setTimeout ( ( ) => {
58- setIsWarningFresh ( false )
59- } , typingDelay )
60- return ( ) => clearTimeout ( timeout )
61- } else {
62- setIsWarningFresh ( true )
63- }
64- } , [ warning ] )
65-
6626 const handleKeyPress : KeyboardEventHandler < HTMLInputElement > = useCallback (
6727 event => {
6828 if ( event . key === 'Enter' ) {
@@ -72,106 +32,25 @@ export const TableSearchBar: FC<TableSearchBarProps> = ({
7232 [ onEnter ] ,
7333 )
7434
75- const startAdornment = (
76- < InputAdornment
77- position = "start"
78- disablePointerEvents // Pass clicks through, so it focuses the input
79- >
80- < SearchIcon sx = { { color : COLORS . grayDark , ml : - 3 } } />
81- </ InputAdornment >
82- )
83-
84- const onClearValue = ( ) => onChange ( '' )
85-
86- const endAdornment = (
87- < InputAdornment position = "end" >
88- { value ? (
89- < Button
90- variant = "ghost"
91- size = "icon"
92- onClick = { onClearValue }
93- className = "hover:bg-black/[0.04] rounded-full -my-2 -ml-0.5"
94- >
95- < HighlightOffIcon />
96- </ Button >
97- ) : (
98- < span style = { { width : '38px' } } />
99- ) }
100- </ InputAdornment >
101- )
102-
103- const helperText = isWarningFresh ? undefined : (
104- < Typography
105- component = "span"
106- sx = { {
107- display : 'inline-flex' ,
108- color : COLORS . warningColor ,
109- fontSize : 12 ,
110- lineHeight : 2 ,
111- alignItems : 'center' ,
112- verticalAlign : 'middle' ,
113- mt : 3 ,
114- mb : 4 ,
115- width : fullWidth ? '100%' : isTablet ? '160px' : undefined ,
116- } }
117- >
118- < WarningIcon sx = { { mr : 3 } } />
119- { warning }
120- </ Typography >
121- )
122-
12335 return (
124- < TextField
125- sx = { {
126- backgroundColor : COLORS . white ,
127- '&:focus-within' : {
128- boxShadow : '3px 3px 3px 3px rgb(0, 0, 98, 0.125) !important' ,
129- } ,
130- [ `.${ inputBaseClasses . root } ` ] : {
131- border : '1px solid' ,
132- borderColor : COLORS . inactiveStroke ,
133- } ,
134- ...( helperText
135- ? {
136- border : '1px solid' ,
137- borderColor : COLORS . inactiveStroke ,
138- marginBottom : isTablet ? '-99px' : '-50px' ,
139- }
140- : { } ) ,
141- zIndex : 10 ,
142- ...( fullWidth ? { width : '100%' } : { } ) ,
143- } }
144- variant = { 'outlined' }
145- value = { value }
146- onChange = { e => onChange ( e . target . value ) }
36+ < SearchInput
37+ className = { className }
38+ autoFocus = { autoFocus }
39+ hint = { warning }
40+ onChange = { onChange }
14741 onKeyDown = { handleKeyPress }
148- InputProps = { {
149- inputProps : {
150- sx : {
151- p : 2 ,
152- width : fullWidth ? '100%' : width ,
153- margin : 2 ,
154- marginLeft : 0 ,
155- paddingLeft : 0 ,
156- fontSize : '14px' ,
157- } ,
158- autoFocus,
159- } ,
160- startAdornment,
161- endAdornment,
162- } }
16342 placeholder = { placeholder }
164- helperText = { helperText }
43+ value = { value }
16544 />
16645 )
16746}
16847
16948export const NoMatchingDataMaybeClearFilters : FC < { clearFilters : ( ) => void } > = ( { clearFilters } ) => {
17049 const { t } = useTranslation ( )
17150 const clearButton = (
172- < MuiButton variant = { 'text' } onClick = { ( ) => clearFilters ( ) } >
51+ < Button size = "sm" variant = "link" onClick = { ( ) => clearFilters ( ) } >
17352 { t ( 'tableSearch.clearFilters' ) }
174- </ MuiButton >
53+ </ Button >
17554 )
17655 return < CardEmptyState label = { t ( 'tableSearch.noMatchingResults' ) } action = { clearButton } />
17756}
0 commit comments