Skip to content

Commit e4d9818

Browse files
authored
feat: add configuration for monaco (#314)
1 parent f9598d8 commit e4d9818

File tree

14 files changed

+207
-48
lines changed

14 files changed

+207
-48
lines changed

docs/spec.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,15 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
145145

146146
#### MonacoParams
147147

148-
| Property | Type | Required | Description |
149-
| :------- | :------- | :------: | :--------------------------- |
150-
| language | `string` | yes | Syntax highlighting language |
151-
| fontSize | `string` | | Font size |
148+
| Property | Type | Required | Description |
149+
| :--------------------- | :------- | :------: | :--------------------------- |
150+
| language | `string` | yes | Syntax highlighting language |
151+
| fontSize | `string` | | Font size |
152+
| headerIconSize | `number` | | Size of the header icon |
153+
| headerIconIndent | `number` | | Indent of the header icon |
154+
| headerTitleVariant | `string` | | Variant of the header title |
155+
| headerDialogButtonSize | `string` | | Size of the dialog button |
156+
| headerDialogIconSize | `number` | | Size of the dialog icon |
152157

153158
#### OneOfParams
154159

docs/styles.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,14 @@ Variables for the Checkbox Group View component:
393393

394394
Variables for the Monaco Input View component:
395395

396-
| Variable | Default Value | Description |
397-
| :--------------------------------------- | :-----------: | :----------------------------- |
398-
| `--df-monaco-base-view-width` | `550px` | Width of the Monaco input view |
399-
| `--df-monaco-view-dialog-footer-padding` | `16px` | Padding of the dialog footer |
400-
| `--df-monaco-view-dialog-header-height` | `48px` | Height of the dialog header |
396+
| Variable | Default Value | Description |
397+
| :--------------------------------------- | :-----------: | :------------------------------- |
398+
| `--df-monaco-base-view-width` | `550px` | Width of the Monaco input view |
399+
| `--df-monaco-base-view-height` | `354px` | Height of the Monaco base view |
400+
| `--df-monaco-view-dialog-footer-padding` | `16px` | Padding of the dialog footer |
401+
| `--df-monaco-view-dialog-header-height` | `48px` | Height of the dialog header |
402+
| `--df-monaco-view-dialog-width` | `966px` | Width of the Monaco view dialog |
403+
| `--df-monaco-view-dialog-height` | `804px` | Height of the Monaco view dialog |
401404

402405
---
403406

src/lib/core/types/specs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {AlertProps, LabelProps} from '@gravity-ui/uikit';
1+
import type {AlertProps, ButtonSize, LabelProps, TextProps} from '@gravity-ui/uikit';
22
import type {ColorTextBaseProps} from '@gravity-ui/uikit/build/esm/components/Text/colorText/colorText';
33

44
import type {ReadAsMethod, SpecTypes} from '../constants';
@@ -164,6 +164,11 @@ export interface StringSpec<
164164
monacoParams?: {
165165
language?: string;
166166
fontSize?: number;
167+
headerIconSize?: number;
168+
headerIconIndent?: number;
169+
headerTitleVariant?: TextProps['variant'];
170+
headerDialogButtonSize?: ButtonSize;
171+
headerDialogIconSize?: number;
167172
};
168173
hideValues?: string[];
169174
placeholder?: string;

src/lib/kit/components/Inputs/MonacoInput/MonacoHeader.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
align-items: center;
99
background-color: var(--g-color-base-float-hover);
1010
box-sizing: border-box;
11+
12+
&__title {
13+
display: flex;
14+
align-items: center;
15+
}
1116
}
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import {File} from '@gravity-ui/icons';
4-
import {Icon, Text} from '@gravity-ui/uikit';
4+
import {Icon, Text, type TextProps} from '@gravity-ui/uikit';
55

66
import {block} from '../../../utils';
77

@@ -10,16 +10,27 @@ import './MonacoHeader.scss';
1010
const b = block('monaco-header');
1111

1212
interface MonacoHeaderProps {
13-
language?: string;
14-
editButton?: React.ReactNode;
13+
language: string;
14+
dialogButton?: React.ReactNode;
15+
headerIconSize: number;
16+
headerIconIndent: number;
17+
headerTitleVariant: TextProps['variant'];
1518
}
1619

17-
export const MonacoHeader: React.FC<MonacoHeaderProps> = ({language, editButton}) => (
20+
export const MonacoHeader: React.FC<MonacoHeaderProps> = ({
21+
language,
22+
dialogButton,
23+
headerIconSize,
24+
headerIconIndent,
25+
headerTitleVariant,
26+
}) => (
1827
<div className={b()}>
19-
<div>
20-
<Icon data={File} size={18} />
21-
<Text variant="body-3">{language}</Text>
28+
<div className={b('title')}>
29+
<div style={{marginRight: `${headerIconIndent}px`}}>
30+
<Icon data={File} size={headerIconSize} />
31+
</div>
32+
<Text variant={headerTitleVariant}>{language}</Text>
2233
</div>
23-
{editButton ?? null}
34+
{dialogButton ?? null}
2435
</div>
2536
);

src/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
height: var(--df-monaco-input-height, 354px);
66

77
&__container {
8-
height: 100%;
8+
height: calc(100% - 2px);
99
display: flex;
1010
flex-direction: column;
1111
border: 1px solid var(--g-color-line-generic);
12+
box-sizing: content-box;
1213
}
1314

1415
&__editor {

src/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ export const MonacoInputBase: React.FC<MonacoInputBaseProps> = ({
3434

3535
const {monacoParams, disabled, layoutTitle} = spec.viewSpec;
3636

37-
const {language, fontSize} = monacoParams ?? {language: 'plaintext', fontSize: 11};
37+
const {
38+
language = 'plaintext',
39+
fontSize = 11,
40+
headerIconSize = 18,
41+
headerIconIndent = 5,
42+
headerTitleVariant = 'body-2',
43+
headerDialogButtonSize = 'm',
44+
headerDialogIconSize = 16,
45+
} = monacoParams || {};
3846

3947
const [monacoEditorDialog, setMonacoEditorDialog] = React.useState<boolean>(false);
4048

@@ -45,14 +53,18 @@ export const MonacoInputBase: React.FC<MonacoInputBaseProps> = ({
4553
const dialogButton = React.useMemo(() => {
4654
if (!withoutDialog) {
4755
return (
48-
<Button onClick={() => setMonacoEditorDialog(true)} qa={`${name}-open-dialog`}>
49-
<Icon data={ChevronsExpandUpRight} size={16} />
56+
<Button
57+
size={headerDialogButtonSize}
58+
onClick={() => setMonacoEditorDialog(true)}
59+
qa={`${name}-open-dialog`}
60+
>
61+
<Icon data={ChevronsExpandUpRight} size={headerDialogIconSize} />
5062
</Button>
5163
);
5264
}
5365

5466
return;
55-
}, [withoutDialog, setMonacoEditorDialog, name]);
67+
}, [withoutDialog, setMonacoEditorDialog, name, headerDialogButtonSize, headerDialogIconSize]);
5668

5769
React.useEffect(() => onChange(monacoValue), [monacoValue]);
5870

@@ -65,7 +77,13 @@ export const MonacoInputBase: React.FC<MonacoInputBaseProps> = ({
6577
return (
6678
<div className={b()}>
6779
<div className={b('container')} data-qa={name}>
68-
<MonacoHeader language={language} editButton={dialogButton} />
80+
<MonacoHeader
81+
language={language}
82+
dialogButton={dialogButton}
83+
headerIconSize={headerIconSize}
84+
headerIconIndent={headerIconIndent}
85+
headerTitleVariant={headerTitleVariant}
86+
/>
6987
<div className={b('editor')}>
7088
<MonacoEditor
7189
language={language}
@@ -86,6 +104,9 @@ export const MonacoInputBase: React.FC<MonacoInputBaseProps> = ({
86104
onChange={onChange}
87105
onClose={handleMonacoEditorDialogClose}
88106
MonacoComponent={MonacoComponent}
107+
headerIconSize={headerIconSize}
108+
headerIconIndent={headerIconIndent}
109+
headerTitleVariant={headerTitleVariant}
89110
/>
90111
</div>
91112
);

src/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
}
1313

1414
&__container {
15-
height: 100%;
15+
height: calc(100% - 2px);
1616
display: flex;
1717
flex-direction: column;
1818
border: 1px solid var(--g-color-line-generic);
19+
box-sizing: content-box;
1920
}
2021

2122
&__editor {

src/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import {Dialog} from '@gravity-ui/uikit';
3+
import {Dialog, type TextProps} from '@gravity-ui/uikit';
44
import type {MonacoEditorProps} from 'react-monaco-editor/lib/types';
55

66
import {useMonaco} from '../../../../core/components/Form/hooks';
@@ -18,13 +18,16 @@ interface MonacoInputDialogProps {
1818
name: string;
1919
visible: boolean;
2020
value: string;
21-
language?: string;
21+
language: string;
2222
title: string | undefined;
2323
fontSize: number | undefined;
2424
onChange: (value: string) => void;
2525
onClose: () => void;
2626
changeMonacoValue: (value: string) => void;
2727
MonacoComponent?: React.ComponentType<MonacoEditorProps>;
28+
headerIconSize: number;
29+
headerIconIndent: number;
30+
headerTitleVariant: TextProps['variant'];
2831
}
2932

3033
export const MonacoInputDialog: React.FC<MonacoInputDialogProps> = ({
@@ -38,6 +41,9 @@ export const MonacoInputDialog: React.FC<MonacoInputDialogProps> = ({
3841
changeMonacoValue,
3942
fontSize,
4043
MonacoComponent,
44+
headerIconSize,
45+
headerIconIndent,
46+
headerTitleVariant,
4147
}) => {
4248
const MonacoEditor = useMonaco() || MonacoComponent;
4349

@@ -57,7 +63,12 @@ export const MonacoInputDialog: React.FC<MonacoInputDialogProps> = ({
5763
<Dialog.Header caption={title} className={b('dialog-header')} />
5864
<Dialog.Body>
5965
<div className={b('container')} data-qa={`${name}-dialog`}>
60-
<MonacoHeader language={language} />
66+
<MonacoHeader
67+
language={language}
68+
headerIconSize={headerIconSize}
69+
headerIconIndent={headerIconIndent}
70+
headerTitleVariant={headerTitleVariant}
71+
/>
6172
<div className={b('editor')}>
6273
<MonacoEditor
6374
language={language}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
@import '../../../styles/variables.scss';
22

33
.#{$ns}monaco-base-view {
4-
border: 1px solid var(--g-color-line-generic);
54
width: var(--df-monaco-base-view-width, 550px);
5+
height: var(--df-monaco-base-view-height, 354px);
6+
7+
&__container {
8+
height: calc(100% - 2px);
9+
display: flex;
10+
flex-direction: column;
11+
border: 1px solid var(--g-color-line-generic);
12+
box-sizing: content-box;
13+
}
14+
15+
&__editor {
16+
flex: 1;
17+
}
618
}

0 commit comments

Comments
 (0)