Skip to content

Commit 32806fe

Browse files
committed
add filter menu
1 parent 7185fd7 commit 32806fe

File tree

6 files changed

+61
-64
lines changed

6 files changed

+61
-64
lines changed

packages/code-editor/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
"@leafygreen-ui/a11y": "workspace:^",
4949
"@leafygreen-ui/badge": "workspace:^",
5050
"@leafygreen-ui/button": "workspace:^",
51+
"@leafygreen-ui/checkbox": "workspace:^",
5152
"@leafygreen-ui/emotion": "workspace:^",
5253
"@leafygreen-ui/hooks": "workspace:^",
5354
"@leafygreen-ui/icon": "workspace:^",
5455
"@leafygreen-ui/icon-button": "workspace:^",
56+
"@leafygreen-ui/input-option": "workspace:^",
5557
"@leafygreen-ui/leafygreen-provider": "workspace:^",
5658
"@leafygreen-ui/lib": "workspace:^",
5759
"@leafygreen-ui/menu": "workspace:^",

packages/code-editor/src/SearchPanel/SearchPanel.spec.tsx

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/code-editor/src/SearchPanel/SearchPanel.stories.tsx

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/code-editor/src/SearchPanel/SearchPanel.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ import {
1818
} from '@codemirror/search';
1919

2020
import { Button } from '@leafygreen-ui/button';
21+
import { Checkbox } from '@leafygreen-ui/checkbox';
2122
import { IconButton } from '@leafygreen-ui/icon-button';
23+
import { InputOption } from '@leafygreen-ui/input-option';
2224
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
25+
import { Menu, MenuVariant } from '@leafygreen-ui/menu';
2326
import { TextInput } from '@leafygreen-ui/text-input';
2427
import { Body, useUpdatedBaseFontSize } from '@leafygreen-ui/typography';
2528

@@ -67,6 +70,15 @@ export function SearchPanel({
6770
const baseFontSize = useUpdatedBaseFontSize();
6871
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
6972

73+
const findOptions = {
74+
isCaseSensitive: 'Match case',
75+
isRegex: 'Regexp',
76+
isWholeWord: 'By word',
77+
} as const;
78+
const [highlightedOption, setHighlightedOption] = useState<string | null>(
79+
null,
80+
);
81+
7082
const updateSelectedIndex = useCallback(() => {
7183
const cursor = query.getCursor(view.state.doc);
7284
const selection = view.state.selection.main;
@@ -246,9 +258,41 @@ export function SearchPanel({
246258
{selectedIndex ?? '?'}/{findCount}
247259
</Body>
248260
)}
249-
<IconButton aria-label="filter button">
250-
<Icon glyph="Filter" />
251-
</IconButton>
261+
<Menu
262+
trigger={
263+
<IconButton aria-label="filter button">
264+
<Icon glyph="Filter" />
265+
</IconButton>
266+
}
267+
renderDarkMenu={false}
268+
variant={MenuVariant.Compact}
269+
>
270+
{Object.entries(findOptions).map(([key, value]) => (
271+
<InputOption
272+
key={key}
273+
as="li"
274+
highlighted={highlightedOption === key}
275+
>
276+
<Checkbox
277+
label={value}
278+
onChange={() => {
279+
switch (key) {
280+
case 'isCaseSensitive':
281+
setIsCaseSensitive(!isCaseSensitive);
282+
break;
283+
case 'isRegex':
284+
setIsRegex(!isRegex);
285+
break;
286+
case 'isWholeWord':
287+
setIsWholeWord(!isWholeWord);
288+
break;
289+
}
290+
setHighlightedOption(key);
291+
}}
292+
/>
293+
</InputOption>
294+
))}
295+
</Menu>
252296
</div>
253297
</div>
254298
<IconButton

packages/code-editor/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
{
1919
"path": "../button"
2020
},
21+
{
22+
"path": "../checkbox"
23+
},
2124
{
2225
"path": "../emotion"
2326
},
2427
{
2528
"path": "../hooks"
2629
},
30+
{
31+
"path": "../input-option"
32+
},
2733
{
2834
"path": "../lib"
2935
},

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)