Skip to content

Commit

Permalink
Adding in a clearable input for the filter of collections (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
travjenkins authored Nov 21, 2023
1 parent 06af395 commit 83956f9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/collection/Selector/List/Header/Name.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TextField } from '@mui/material';
import ClearInput from 'components/shared/Input/Clear';
import { useIntl } from 'react-intl';

interface Props {
Expand Down Expand Up @@ -30,6 +31,14 @@ function CollectionSelectorHeaderName({
size="small"
variant="outlined"
value={inputValue}
InputProps={{
endAdornment: (
<ClearInput
show={Boolean(!disabled && inputValue)}
onClear={onChange}
/>
),
}}
onChange={(event) => {
onChange(event.target.value);
}}
Expand Down
39 changes: 39 additions & 0 deletions src/components/shared/Input/Clear.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Close } from '@mui/icons-material';
import { IconButton, InputAdornment } from '@mui/material';
import { useIntl } from 'react-intl';

interface Props {
onClear: (emptyValue: string) => void;
show?: boolean;
}

function ClearInput({ onClear, show }: Props) {
const intl = useIntl();

return (
<InputAdornment
position="end"
style={{
display: show ? 'flex' : 'none',
position: 'absolute',
right: 0,
}}
>
<IconButton
aria-label={intl.formatMessage({
id: 'jsonForms.clearInput',
})}
onClick={() => onClear('')}
size="large"
>
<Close
style={{
borderRadius: '50%',
}}
/>
</IconButton>
</InputAdornment>
);
}

export default ClearInput;
5 changes: 5 additions & 0 deletions src/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,10 @@ const Notifications: ResolvedIntlConfig['messages'] = {
'notifications.paymentMethods.missing.trialPast.instructions': `Please {cta} to continue using Estuary Flow.`,
};

const JsonForms: ResolvedIntlConfig['messages'] = {
'jsonForms.clearInput': `Clear input field`,
};

const enUSMessages: ResolvedIntlConfig['messages'] = {
...CommonMessages,
...CTAs,
Expand Down Expand Up @@ -1361,6 +1365,7 @@ const enUSMessages: ResolvedIntlConfig['messages'] = {
...NotBeforeNotAfter,
...Notifications,
...Fetchers,
...JsonForms,
};

export default enUSMessages;

0 comments on commit 83956f9

Please sign in to comment.