Skip to content

Commit b717e1d

Browse files
committed
fix darkmode and font size
1 parent 9bfa487 commit b717e1d

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ const BaseCodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(
289289
createRoot(dom).render(
290290
React.createElement(SearchPanel, {
291291
view,
292+
darkMode: props.darkMode,
292293
}),
293294
);
294295
return { dom, top: true };

packages/code-editor/src/SearchPanel/SearchPanel.styles.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { css, cx } from '@leafygreen-ui/emotion';
22
import { Theme } from '@leafygreen-ui/lib';
33
import {
4+
BaseFontSize,
45
borderRadius,
56
InteractionState,
67
shadow,
@@ -15,10 +16,14 @@ const SECTION_HEIGHT = 52;
1516
const INPUT_WIDTH = 240;
1617
const INPUT_MIN_WIDTH = 120;
1718

18-
const getBaseContainerStyles = (theme: Theme) => css`
19+
const getBaseContainerStyles = (
20+
theme: Theme,
21+
baseFontSize: BaseFontSize,
22+
) => css`
1923
background-color: ${color[theme].background[Variant.Secondary][
2024
InteractionState.Default
2125
]};
26+
font-size: ${baseFontSize}px;
2227
border-bottom-left-radius: ${borderRadius[150]}px;
2328
border-bottom-right-radius: ${borderRadius[150]}px;
2429
width: 100%;
@@ -62,11 +67,13 @@ const openContainerStyles = css`
6267
export const getContainerStyles = ({
6368
theme,
6469
isOpen,
70+
baseFontSize,
6571
}: {
6672
theme: Theme;
6773
isOpen: boolean;
74+
baseFontSize: BaseFontSize;
6875
}) =>
69-
cx(getBaseContainerStyles(theme), {
76+
cx(getBaseContainerStyles(theme, baseFontSize), {
7077
[openContainerStyles]: isOpen,
7178
});
7279

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Button from '@leafygreen-ui/button';
2121
import IconButton from '@leafygreen-ui/icon-button';
2222
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
2323
import TextInput from '@leafygreen-ui/text-input';
24-
import { Body } from '@leafygreen-ui/typography';
24+
import { Body, useUpdatedBaseFontSize } from '@leafygreen-ui/typography';
2525

2626
import { Icon } from '../../../icon/src/Icon';
2727

@@ -42,7 +42,11 @@ import {
4242
} from './SearchPanel.styles';
4343
import { SearchPanelProps } from './SearchPanel.types';
4444

45-
export function SearchPanel({ view }: SearchPanelProps) {
45+
export function SearchPanel({
46+
view,
47+
darkMode,
48+
baseFontSize: baseFontSizeProp,
49+
}: SearchPanelProps) {
4650
const [isOpen, setIsOpen] = useState(false);
4751
const [searchString, setSearchString] = useState('');
4852
const [replaceString, setReplaceString] = useState('');
@@ -59,7 +63,8 @@ export function SearchPanel({ view }: SearchPanelProps) {
5963
}),
6064
);
6165
const [findCount, setFindCount] = useState(0);
62-
const { theme } = useDarkMode();
66+
const { theme } = useDarkMode(darkMode);
67+
const baseFontSize = useUpdatedBaseFontSize();
6368
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
6469

6570
const updateSelectedIndex = useCallback(() => {
@@ -204,7 +209,11 @@ export function SearchPanel({ view }: SearchPanelProps) {
204209

205210
return (
206211
<div
207-
className={getContainerStyles({ theme, isOpen })}
212+
className={getContainerStyles({
213+
theme,
214+
isOpen,
215+
baseFontSize: baseFontSizeProp || baseFontSize,
216+
})}
208217
data-no-context-menu="true"
209218
>
210219
<div className={findSectionStyles}>
@@ -226,6 +235,8 @@ export function SearchPanel({ view }: SearchPanelProps) {
226235
// eslint-disable-next-line jsx-a11y/no-autofocus
227236
autoFocus
228237
value={searchString}
238+
baseFontSize={baseFontSizeProp || baseFontSize}
239+
darkMode={darkMode}
229240
/>
230241
<div className={findOptionsContainerStyles}>
231242
{searchString && (
@@ -259,6 +270,8 @@ export function SearchPanel({ view }: SearchPanelProps) {
259270
selectMatches(view);
260271
setSelectedIndex(null);
261272
}}
273+
baseFontSize={baseFontSizeProp || baseFontSize}
274+
darkMode={darkMode}
262275
>
263276
All
264277
</Button>
@@ -284,18 +297,24 @@ export function SearchPanel({ view }: SearchPanelProps) {
284297
value={replaceString}
285298
onChange={handleReplaceQueryChange}
286299
onKeyDown={handleReplaceInputKeyDown}
300+
baseFontSize={baseFontSizeProp || baseFontSize}
301+
darkMode={darkMode}
287302
/>
288303
<Button
289304
aria-label="replace button"
290305
className={replaceButtonStyles}
291306
onClick={handleReplace}
307+
baseFontSize={baseFontSizeProp || baseFontSize}
308+
darkMode={darkMode}
292309
>
293310
Replace
294311
</Button>
295312
<Button
296313
aria-label="replace all button"
297314
className={replaceButtonStyles}
298315
onClick={handleReplaceAll}
316+
baseFontSize={baseFontSizeProp || baseFontSize}
317+
darkMode={darkMode}
299318
>
300319
Replace All
301320
</Button>
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
import { DarkModeProps } from '@leafygreen-ui/lib';
2+
import { type BaseFontSize } from '@leafygreen-ui/tokens';
3+
14
import { CodeMirrorView } from '../CodeEditor';
25

3-
export interface SearchPanelProps {
6+
export interface SearchPanelProps extends DarkModeProps {
7+
/**
8+
* Font size of text in the editor.
9+
*
10+
* @default 13
11+
*/
12+
baseFontSize?: BaseFontSize;
13+
14+
/**
15+
* The CodeMirror view instance.
16+
*/
417
view: CodeMirrorView;
518
}

0 commit comments

Comments
 (0)