Skip to content

Commit e4a235b

Browse files
authored
Merge pull request #2247 from oasisprotocol/mz/uil-tableSearch
Replace MUI dependencies in TableSearchBar with Oasis UI Library
2 parents fd7b079 + f6536ec commit e4a235b

5 files changed

Lines changed: 15 additions & 140 deletions

File tree

.changelog/2247.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace MUI dependencies in TableSearchBar with Oasis UI Library
Lines changed: 13 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,28 @@
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'
122
import { useTranslation } from 'react-i18next'
13-
import MuiButton from '@mui/material/Button'
3+
import { Button } from '@oasisprotocol/ui-library/src/components/ui/button'
144
import { 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

197
export 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

4117
export 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

16948
export 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
}

src/app/pages/ProposalDetailsPage/ProposalVotesCard.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import Box from '@mui/material/Box'
1717
import { NoMatchingDataMaybeClearFilters, TableSearchBar } from '../../components/Search/TableSearchBar'
1818
import { CardEmptyState } from '../../components/CardEmptyState'
1919
import { WithHighlightPattern } from '../../components/PatternHighlightingContext'
20-
import { useScreenSize } from '../../hooks/useScreensize'
2120

2221
type ProposalVotesProps = {
2322
isLoading: boolean
@@ -120,7 +119,6 @@ export const ProposalVotesView: FC = () => {
120119

121120
export const ProposalVotesCard: FC = () => {
122121
const { t } = useTranslation()
123-
const { isTablet } = useScreenSize()
124122

125123
const { wantedType, setWantedType, wantedNameInput, setWantedNameInput, nameError } = useVoteFiltering()
126124

@@ -138,8 +136,6 @@ export const ProposalVotesCard: FC = () => {
138136
onChange={setWantedNameInput}
139137
placeholder={t('networkProposal.searchForVoter')}
140138
warning={nameError}
141-
size={'small'}
142-
fullWidth={isTablet}
143139
/>
144140
</div>
145141
</div>

src/app/pages/RoflAppsPage/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export const RoflAppsPage: FC = () => {
8383
onChange={setWantedNameInput}
8484
placeholder={t('rofl.searchByNameOrKeyword')}
8585
warning={nameError}
86-
fullWidth={isMobile}
8786
autoFocus={!isMobile}
8887
onEnter={jumpToSingleResult}
8988
/>

0 commit comments

Comments
 (0)