-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4883f2f
commit dcf72a3
Showing
39 changed files
with
374 additions
and
382 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
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
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
16 changes: 0 additions & 16 deletions
16
packages/components/src/FilterToolbar/FilterDropdown/styles.css.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,33 +1,49 @@ | ||
import React from 'react'; | ||
import React, { ChangeEvent, SyntheticEvent, useState } from 'react'; | ||
import classnames from 'clsx'; | ||
import { escapeRegExp, ComboBox, ComboBoxProps, SelectionChangeHandler } from '@salt-ds/lab'; | ||
import { ComboBox, Option, ComboBoxProps } from '@salt-ds/core'; | ||
import { Icon } from '../../Icon'; | ||
|
||
import { useToolbarDispatch } from '../ToolbarProvider'; | ||
import styles from '../SortDropdown/styles.css'; | ||
import styles from './styles.css'; | ||
|
||
export interface FilterSearchProps extends ComboBoxProps<string, 'deselectable'> {} | ||
const regExp = /[.*+?^${}()|[\]\\]/g; | ||
|
||
function escapeRegExp(string: string): string { | ||
return string.replace(regExp, '\\$&'); | ||
} | ||
|
||
export interface FilterSearchProps extends ComboBoxProps { | ||
source: string[]; | ||
} | ||
|
||
export function FilterSearch({ className, source = [], ...rest }: FilterSearchProps) { | ||
const dispatch = useToolbarDispatch(); | ||
const [value, setValue] = useState(''); | ||
|
||
// TODO convert to multiselect once Salt supports Multiselect from a ComboBox | ||
const handleSelect: SelectionChangeHandler<string, 'deselectable'> = (_e, item) => { | ||
const value = item === null ? [] : [item]; | ||
dispatch({ type: 'setFilters', value }); | ||
const handleSelect = (_e: SyntheticEvent, newSelected: string[]) => { | ||
dispatch({ type: 'setFilters', value: newSelected }); | ||
}; | ||
|
||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
setValue(event.target.value); | ||
}; | ||
const getFilterRegex: (text: string) => RegExp = value => | ||
new RegExp(`\\b(${escapeRegExp(value)})`, 'gi'); | ||
|
||
return ( | ||
<ComboBox | ||
InputProps={{ startAdornment: <Icon name="filter" /> }} | ||
startAdornment={<Icon name="filter" />} | ||
className={classnames(className, styles.root)} | ||
getFilterRegex={getFilterRegex} | ||
onSelectionChange={handleSelect} | ||
source={source} | ||
width={200} | ||
value={value} | ||
onChange={handleChange} | ||
style={{ width: 200 }} | ||
{...rest} | ||
/> | ||
> | ||
{source | ||
.filter(item => item.match(new RegExp(`\\b(${escapeRegExp(value)})`, 'gi'))) | ||
.map(item => ( | ||
<Option value={item} key={item} /> | ||
))} | ||
</ComboBox> | ||
); | ||
} |
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
15 changes: 0 additions & 15 deletions
15
packages/components/src/FilterToolbar/SortDropdown/styles.css.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.