@snack-uikit/code-editor 0.6.5-preview-580e8472.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.7.0 (2025-05-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PDS-2227:** add copy button for code editor ([6891964](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/commits/6891964be3dffecab54a3a226f250f6d303da7e9))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.6.4 (2025-05-16)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -15,7 +15,8 @@
15
15
  | jsonSchema* | `JsonSchema` | - | Схема для валидации |
16
16
  | themeName | `string` | - | Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей. |
17
17
  | hasBackground | `boolean` | true | Включение/отключение псевдобекграунда |
18
- | onCopyClick | `MouseEventHandler<HTMLElement>` | - | Клик по кнопке копирования |
18
+ | hasHeader | `boolean` | - | Включение/отключение шапки |
19
+ | onCopyClick | `() => void` | - | Клик по кнопке копирования |
19
20
  | defaultValue | `string` | - | Default value of the current model |
20
21
  | defaultLanguage | `string` | - | Default language of the current model |
21
22
  | defaultPath | `string` | - | Default path of the current model Will be passed as the third argument to `.createModel` method `monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))` |
@@ -1,4 +1,3 @@
1
- import { ButtonFunctionProps } from '@snack-uikit/button';
2
1
  import { WithSupportProps } from '@snack-uikit/utils';
3
2
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
4
3
  export type CodeEditorProps = WithSupportProps<{
@@ -10,9 +9,13 @@ export type CodeEditorProps = WithSupportProps<{
10
9
  * Включение/отключение псевдобекграунда
11
10
  */
12
11
  hasBackground?: boolean;
12
+ /**
13
+ * Включение/отключение шапки
14
+ */
15
+ hasHeader?: boolean;
13
16
  /**
14
17
  * Клик по кнопке копирования
15
18
  */
16
- onCopyClick?: ButtonFunctionProps['onClick'];
19
+ onCopyClick?(): void;
17
20
  }> & (EditorBaseProps | EditorWithJsonSchemaProps);
18
- export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, hasHeader, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -22,7 +22,6 @@ const react_1 = require("@monaco-editor/react");
22
22
  const classnames_1 = __importDefault(require("classnames"));
23
23
  const react_2 = require("react");
24
24
  const loaders_1 = require("@snack-uikit/loaders");
25
- const locale_1 = require("@snack-uikit/locale");
26
25
  const typography_1 = require("@snack-uikit/typography");
27
26
  const utils_1 = require("@snack-uikit/utils");
28
27
  const constants_1 = require("./constants");
@@ -40,14 +39,12 @@ function CodeEditor(_a) {
40
39
  hasBackground = true,
41
40
  onMount,
42
41
  language,
43
- onCopyClick
42
+ onCopyClick,
43
+ hasHeader
44
44
  } = _a,
45
- props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick"]);
45
+ props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick", "hasHeader"]);
46
46
  const monaco = (0, react_1.useMonaco)();
47
47
  const [wrapperElement, setWrapperElement] = (0, react_2.useState)(null);
48
- const {
49
- t
50
- } = (0, locale_1.useLocale)();
51
48
  const {
52
49
  jsonSchemaProps,
53
50
  jsonSchemaOptions
@@ -122,10 +119,10 @@ function CodeEditor(_a) {
122
119
  className: className
123
120
  }, (0, utils_1.extractSupportProps)(props), {
124
121
  ref: setWrapperElement,
125
- children: [(0, jsx_runtime_1.jsxs)("div", {
122
+ children: [hasHeader && (0, jsx_runtime_1.jsxs)("div", {
126
123
  className: styles_module_scss_1.default.headline,
127
- children: [(0, jsx_runtime_1.jsx)(typography_1.Typography.SansLabelS, {
128
- children: t('Markdown.codeEditorTitle')
124
+ children: [language && (0, jsx_runtime_1.jsx)(typography_1.Typography.SansLabelS, {
125
+ children: (0, utils_2.uppercaseFirstLetter)(language)
129
126
  }), (0, jsx_runtime_1.jsx)(CopyButton_1.CopyButton, {
130
127
  valueToCopy: props.value || '',
131
128
  size: 's',
@@ -4,6 +4,6 @@ export type CopyButtonProps = WithSupportProps<{
4
4
  valueToCopy: string | number;
5
5
  size?: ButtonFunctionProps['size'];
6
6
  className?: string;
7
- onClick?: ButtonFunctionProps['onClick'];
7
+ onClick?(): void;
8
8
  }>;
9
9
  export declare function CopyButton({ valueToCopy, size, className, onClick, ...rest }: CopyButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "__esModule", {
19
19
  exports.CopyButton = CopyButton;
20
20
  const jsx_runtime_1 = require("react/jsx-runtime");
21
21
  const react_1 = require("react");
22
- const frontend_tools_copy_to_clipboard_1 = require("@cloud-ru/frontend-tools-copy-to-clipboard");
22
+ const ft_copy_to_clipboard_1 = require("@cloud-ru/ft-copy-to-clipboard");
23
23
  const button_1 = require("@snack-uikit/button");
24
24
  const icons_1 = require("@snack-uikit/icons");
25
25
  const locale_1 = require("@snack-uikit/locale");
@@ -43,18 +43,18 @@ function CopyButton(_a) {
43
43
  const closeChecked = () => setIsCheckedOpen(false);
44
44
  const handleClick = event => {
45
45
  event.stopPropagation();
46
- valueToCopy && (0, frontend_tools_copy_to_clipboard_1.copyToClipboard)(String(valueToCopy));
46
+ valueToCopy && (0, ft_copy_to_clipboard_1.copyToClipboard)(String(valueToCopy));
47
47
  openChecked();
48
48
  clearTimeout(timerId.current);
49
49
  timerId.current = setTimeout(closeChecked, 1000);
50
- onClick === null || onClick === void 0 ? void 0 : onClick(event);
50
+ onClick === null || onClick === void 0 ? void 0 : onClick();
51
51
  };
52
52
  (0, react_1.useEffect)(() => () => {
53
53
  closeChecked();
54
54
  clearTimeout(timerId.current);
55
55
  }, []);
56
56
  return (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, {
57
- tip: t('Markdown.copyButtonToolTip'),
57
+ tip: t('CodeEditor.copyButtonToolTip'),
58
58
  children: (0, jsx_runtime_1.jsx)(button_1.ButtonFunction, Object.assign({}, (0, utils_1.extractSupportProps)(rest), {
59
59
  onClick: handleClick,
60
60
  className: className,
@@ -13,9 +13,9 @@
13
13
  }
14
14
 
15
15
  .headline{
16
- min-height:var(--size-markdown-code-editor-headline-min-height, 36px);
17
- padding-left:var(--space-markdown-code-editor-headline-horizontal-padding, 12px);
18
- padding-right:var(--space-markdown-code-editor-headline-horizontal-padding, 12px);
16
+ min-height:var(--size-code-editor-headline-min-height, 36px);
17
+ padding-left:var(--space-code-editor-headline-horizontal-padding, 12px);
18
+ padding-right:var(--space-code-editor-headline-horizontal-padding, 12px);
19
19
  display:flex;
20
20
  align-items:center;
21
21
  justify-content:space-between;
@@ -3,3 +3,4 @@ import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(HTMLcolor: string): number[];
4
4
  export declare function isDark(color: string): boolean;
5
5
  export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
6
+ export declare function uppercaseFirstLetter(value: string): string;
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", {
11
11
  exports.getJsonSchema = void 0;
12
12
  exports.rgb2hsl = rgb2hsl;
13
13
  exports.isDark = isDark;
14
+ exports.uppercaseFirstLetter = uppercaseFirstLetter;
14
15
  const chroma_js_1 = __importDefault(require("chroma-js"));
15
16
  const constants_1 = require("./constants");
16
17
  function rgb2hsl(HTMLcolor) {
@@ -50,4 +51,11 @@ const getJsonSchema = jsonSchema => jsonSchema && Object.assign(Object.assign({}
50
51
  uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || constants_1.DEFAULT_SCHEMA_URI,
51
52
  fileMatch: [jsonSchema.fileMatch]
52
53
  });
53
- exports.getJsonSchema = getJsonSchema;
54
+ exports.getJsonSchema = getJsonSchema;
55
+ function uppercaseFirstLetter(value) {
56
+ const trimmedValue = value.trim();
57
+ if (trimmedValue.length === 0) {
58
+ return value;
59
+ }
60
+ return trimmedValue[0].toUpperCase() + trimmedValue.slice(1);
61
+ }
@@ -1,4 +1,3 @@
1
- import { ButtonFunctionProps } from '@snack-uikit/button';
2
1
  import { WithSupportProps } from '@snack-uikit/utils';
3
2
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
4
3
  export type CodeEditorProps = WithSupportProps<{
@@ -10,9 +9,13 @@ export type CodeEditorProps = WithSupportProps<{
10
9
  * Включение/отключение псевдобекграунда
11
10
  */
12
11
  hasBackground?: boolean;
12
+ /**
13
+ * Включение/отключение шапки
14
+ */
15
+ hasHeader?: boolean;
13
16
  /**
14
17
  * Клик по кнопке копирования
15
18
  */
16
- onCopyClick?: ButtonFunctionProps['onClick'];
19
+ onCopyClick?(): void;
17
20
  }> & (EditorBaseProps | EditorWithJsonSchemaProps);
18
- export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, hasHeader, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -14,19 +14,17 @@ import { Editor, useMonaco } from '@monaco-editor/react';
14
14
  import cn from 'classnames';
15
15
  import { useCallback, useMemo, useState } from 'react';
16
16
  import { Spinner } from '@snack-uikit/loaders';
17
- import { useLocale } from '@snack-uikit/locale';
18
17
  import { Typography } from '@snack-uikit/typography';
19
18
  import { extractSupportProps, isBrowser } from '@snack-uikit/utils';
20
19
  import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
21
20
  import { CopyButton } from './CopyButton';
22
21
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
23
22
  import styles from './styles.module.css';
24
- import { isDark } from './utils';
23
+ import { isDark, uppercaseFirstLetter } from './utils';
25
24
  export function CodeEditor(_a) {
26
- var { themeName, className, theme, options, loading, hasBackground = true, onMount, language, onCopyClick } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick"]);
25
+ var { themeName, className, theme, options, loading, hasBackground = true, onMount, language, onCopyClick, hasHeader } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick", "hasHeader"]);
27
26
  const monaco = useMonaco();
28
27
  const [wrapperElement, setWrapperElement] = useState(null);
29
- const { t } = useLocale();
30
28
  const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(language, 'jsonSchema' in props ? props.jsonSchema : undefined);
31
29
  const onEditorMount = useCallback((editor, monaco) => {
32
30
  var _a;
@@ -91,5 +89,5 @@ export function CodeEditor(_a) {
91
89
  fontFamily: themeValues.mono.body.s['font-family'],
92
90
  }
93
91
  : DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono, jsonSchemaOptions]);
94
- return (_jsxs("div", Object.assign({ className: className }, extractSupportProps(props), { ref: setWrapperElement, children: [_jsxs("div", { className: styles.headline, children: [_jsx(Typography.SansLabelS, { children: t('Markdown.codeEditorTitle') }), _jsx(CopyButton, { valueToCopy: props.value || '', size: 's', onClick: onCopyClick })] }), _jsx(Editor, Object.assign({}, jsonSchemaProps, props, { theme: theme !== null && theme !== void 0 ? theme : (dark ? 'snackDark' : 'snack'), className: cn({ [styles.editor]: hasBackground }), loading: loading !== null && loading !== void 0 ? loading : _jsx(Spinner, {}), options: mergedOptions, onMount: onEditorMount, language: language }))] })));
92
+ return (_jsxs("div", Object.assign({ className: className }, extractSupportProps(props), { ref: setWrapperElement, children: [hasHeader && (_jsxs("div", { className: styles.headline, children: [language && _jsx(Typography.SansLabelS, { children: uppercaseFirstLetter(language) }), _jsx(CopyButton, { valueToCopy: props.value || '', size: 's', onClick: onCopyClick })] })), _jsx(Editor, Object.assign({}, jsonSchemaProps, props, { theme: theme !== null && theme !== void 0 ? theme : (dark ? 'snackDark' : 'snack'), className: cn({ [styles.editor]: hasBackground }), loading: loading !== null && loading !== void 0 ? loading : _jsx(Spinner, {}), options: mergedOptions, onMount: onEditorMount, language: language }))] })));
95
93
  }
@@ -4,6 +4,6 @@ export type CopyButtonProps = WithSupportProps<{
4
4
  valueToCopy: string | number;
5
5
  size?: ButtonFunctionProps['size'];
6
6
  className?: string;
7
- onClick?: ButtonFunctionProps['onClick'];
7
+ onClick?(): void;
8
8
  }>;
9
9
  export declare function CopyButton({ valueToCopy, size, className, onClick, ...rest }: CopyButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { useEffect, useRef, useState } from 'react';
14
- import { copyToClipboard } from '@cloud-ru/frontend-tools-copy-to-clipboard';
14
+ import { copyToClipboard } from '@cloud-ru/ft-copy-to-clipboard';
15
15
  import { ButtonFunction } from '@snack-uikit/button';
16
16
  import { CheckSVG, CopySVG } from '@snack-uikit/icons';
17
17
  import { useLocale } from '@snack-uikit/locale';
@@ -31,11 +31,11 @@ export function CopyButton(_a) {
31
31
  openChecked();
32
32
  clearTimeout(timerId.current);
33
33
  timerId.current = setTimeout(closeChecked, 1000);
34
- onClick === null || onClick === void 0 ? void 0 : onClick(event);
34
+ onClick === null || onClick === void 0 ? void 0 : onClick();
35
35
  };
36
36
  useEffect(() => () => {
37
37
  closeChecked();
38
38
  clearTimeout(timerId.current);
39
39
  }, []);
40
- return (_jsx(Tooltip, { tip: t('Markdown.copyButtonToolTip'), children: _jsx(ButtonFunction, Object.assign({}, extractSupportProps(rest), { onClick: handleClick, className: className, "data-test-id": 'button-copy-value', type: 'button', icon: isChecked ? _jsx(CheckSVG, { className: styles.checkIcon }) : _jsx(CopySVG, {}), size: size })) }));
40
+ return (_jsx(Tooltip, { tip: t('CodeEditor.copyButtonToolTip'), children: _jsx(ButtonFunction, Object.assign({}, extractSupportProps(rest), { onClick: handleClick, className: className, "data-test-id": 'button-copy-value', type: 'button', icon: isChecked ? _jsx(CheckSVG, { className: styles.checkIcon }) : _jsx(CopySVG, {}), size: size })) }));
41
41
  }
@@ -13,9 +13,9 @@
13
13
  }
14
14
 
15
15
  .headline{
16
- min-height:var(--size-markdown-code-editor-headline-min-height, 36px);
17
- padding-left:var(--space-markdown-code-editor-headline-horizontal-padding, 12px);
18
- padding-right:var(--space-markdown-code-editor-headline-horizontal-padding, 12px);
16
+ min-height:var(--size-code-editor-headline-min-height, 36px);
17
+ padding-left:var(--space-code-editor-headline-horizontal-padding, 12px);
18
+ padding-right:var(--space-code-editor-headline-horizontal-padding, 12px);
19
19
  display:flex;
20
20
  align-items:center;
21
21
  justify-content:space-between;
@@ -3,3 +3,4 @@ import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(HTMLcolor: string): number[];
4
4
  export declare function isDark(color: string): boolean;
5
5
  export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
6
+ export declare function uppercaseFirstLetter(value: string): string;
@@ -38,3 +38,10 @@ export function isDark(color) {
38
38
  return (h < 0.55 && l >= 0.5) || (h >= 0.55 && l >= 0.75);
39
39
  }
40
40
  export const getJsonSchema = (jsonSchema) => jsonSchema && Object.assign(Object.assign({}, jsonSchema), { uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] });
41
+ export function uppercaseFirstLetter(value) {
42
+ const trimmedValue = value.trim();
43
+ if (trimmedValue.length === 0) {
44
+ return value;
45
+ }
46
+ return trimmedValue[0].toUpperCase() + trimmedValue.slice(1);
47
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.5-preview-580e8472.0",
7
+ "version": "0.7.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -36,12 +36,11 @@
36
36
  "license": "Apache-2.0",
37
37
  "scripts": {},
38
38
  "dependencies": {
39
- "@cloud-ru/frontend-tools-copy-to-clipboard": "0.0.1-preview-8188049.0",
39
+ "@cloud-ru/ft-copy-to-clipboard": "0.1.0",
40
40
  "@monaco-editor/react": "4.6.0",
41
41
  "@snack-uikit/button": "0.19.11",
42
42
  "@snack-uikit/icons": "0.26.3",
43
43
  "@snack-uikit/loaders": "0.9.5",
44
- "@snack-uikit/locale": "0.14.1-preview-580e8472.0",
45
44
  "@snack-uikit/tooltip": "0.17.2",
46
45
  "@snack-uikit/typography": "0.8.7",
47
46
  "@snack-uikit/utils": "3.8.2",
@@ -49,8 +48,11 @@
49
48
  "classnames": "2.5.1",
50
49
  "monaco-yaml": "5.2.3"
51
50
  },
51
+ "peerDependencies": {
52
+ "@snack-uikit/locale": "*"
53
+ },
52
54
  "devDependencies": {
53
55
  "@types/chroma-js": "2.4.4"
54
56
  },
55
- "gitHead": "83474111057d185ee911d5bb4489288c89f1490f"
57
+ "gitHead": "bfec8dd0ba3b8e294440db45599d9770216e602f"
56
58
  }
@@ -2,9 +2,7 @@ import { Editor, OnMount, useMonaco } from '@monaco-editor/react';
2
2
  import cn from 'classnames';
3
3
  import { useCallback, useMemo, useState } from 'react';
4
4
 
5
- import { ButtonFunctionProps } from '@snack-uikit/button';
6
5
  import { Spinner } from '@snack-uikit/loaders';
7
- import { useLocale } from '@snack-uikit/locale';
8
6
  import { Typography } from '@snack-uikit/typography';
9
7
  import { extractSupportProps, isBrowser, WithSupportProps } from '@snack-uikit/utils';
10
8
 
@@ -13,7 +11,7 @@ import { CopyButton } from './CopyButton';
13
11
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
14
12
  import styles from './styles.module.scss';
15
13
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
16
- import { isDark } from './utils';
14
+ import { isDark, uppercaseFirstLetter } from './utils';
17
15
 
18
16
  export type CodeEditorProps = WithSupportProps<{
19
17
  /**
@@ -24,10 +22,14 @@ export type CodeEditorProps = WithSupportProps<{
24
22
  * Включение/отключение псевдобекграунда
25
23
  */
26
24
  hasBackground?: boolean;
25
+ /**
26
+ * Включение/отключение шапки
27
+ */
28
+ hasHeader?: boolean;
27
29
  /**
28
30
  * Клик по кнопке копирования
29
31
  */
30
- onCopyClick?: ButtonFunctionProps['onClick'];
32
+ onCopyClick?(): void;
31
33
  }> &
32
34
  (EditorBaseProps | EditorWithJsonSchemaProps);
33
35
 
@@ -41,13 +43,12 @@ export function CodeEditor({
41
43
  onMount,
42
44
  language,
43
45
  onCopyClick,
46
+ hasHeader,
44
47
  ...props
45
48
  }: CodeEditorProps) {
46
49
  const monaco = useMonaco();
47
50
  const [wrapperElement, setWrapperElement] = useState<HTMLDivElement | null>(null);
48
51
 
49
- const { t } = useLocale();
50
-
51
52
  const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(
52
53
  language,
53
54
  'jsonSchema' in props ? props.jsonSchema : undefined,
@@ -143,10 +144,12 @@ export function CodeEditor({
143
144
 
144
145
  return (
145
146
  <div className={className} {...extractSupportProps(props)} ref={setWrapperElement}>
146
- <div className={styles.headline}>
147
- <Typography.SansLabelS>{t('Markdown.codeEditorTitle')}</Typography.SansLabelS>
148
- <CopyButton valueToCopy={props.value || ''} size={'s'} onClick={onCopyClick} />
149
- </div>
147
+ {hasHeader && (
148
+ <div className={styles.headline}>
149
+ {language && <Typography.SansLabelS>{uppercaseFirstLetter(language)}</Typography.SansLabelS>}
150
+ <CopyButton valueToCopy={props.value || ''} size={'s'} onClick={onCopyClick} />
151
+ </div>
152
+ )}
150
153
  <Editor
151
154
  {...jsonSchemaProps}
152
155
  {...props}
@@ -1,6 +1,6 @@
1
1
  import { MouseEventHandler, useEffect, useRef, useState } from 'react';
2
2
 
3
- import { copyToClipboard } from '@cloud-ru/frontend-tools-copy-to-clipboard';
3
+ import { copyToClipboard } from '@cloud-ru/ft-copy-to-clipboard';
4
4
  import { ButtonFunction, ButtonFunctionProps } from '@snack-uikit/button';
5
5
  import { CheckSVG, CopySVG } from '@snack-uikit/icons';
6
6
  import { useLocale } from '@snack-uikit/locale';
@@ -13,7 +13,7 @@ export type CopyButtonProps = WithSupportProps<{
13
13
  valueToCopy: string | number;
14
14
  size?: ButtonFunctionProps['size'];
15
15
  className?: string;
16
- onClick?: ButtonFunctionProps['onClick'];
16
+ onClick?(): void;
17
17
  }>;
18
18
 
19
19
  export function CopyButton({ valueToCopy, size = 's', className, onClick, ...rest }: CopyButtonProps) {
@@ -29,7 +29,7 @@ export function CopyButton({ valueToCopy, size = 's', className, onClick, ...res
29
29
  openChecked();
30
30
  clearTimeout(timerId.current);
31
31
  timerId.current = setTimeout(closeChecked, 1000);
32
- onClick?.(event);
32
+ onClick?.();
33
33
  };
34
34
 
35
35
  useEffect(
@@ -41,7 +41,7 @@ export function CopyButton({ valueToCopy, size = 's', className, onClick, ...res
41
41
  );
42
42
 
43
43
  return (
44
- <Tooltip tip={t('Markdown.copyButtonToolTip')}>
44
+ <Tooltip tip={t('CodeEditor.copyButtonToolTip')}>
45
45
  <ButtonFunction
46
46
  {...extractSupportProps(rest)}
47
47
  onClick={handleClick}
@@ -1,6 +1,6 @@
1
- @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
1
+ @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables' as ste;
2
2
 
3
3
 
4
4
  .checkIcon {
5
- fill: styles-theme-variables.$sys-green-accent-default
5
+ fill: ste.$sys-green-accent-default
6
6
  }
@@ -1,5 +1,6 @@
1
- @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
2
- @use '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-markdown';
1
+ @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables' as var;
2
+ @use '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-codeEditor' as stc;
3
+
3
4
 
4
5
 
5
6
  .editor {
@@ -15,19 +16,18 @@
15
16
 
16
17
  width: 100%;
17
18
 
18
- opacity: styles-theme-variables.$opacity-a004;
19
- background-color: styles-theme-variables.$sys-neutral-accent-default;
19
+ opacity: var.$opacity-a004;
20
+ background-color: var.$sys-neutral-accent-default;
20
21
  }
21
22
  }
22
23
 
23
24
  .headline {
24
- @include styles-tokens-markdown.composite-var(styles-tokens-markdown.$markdown-syntax-code-editor-headline);
25
+ @include stc.composite-var(stc.$code-editor-headline);
25
26
 
26
27
  display: flex;
27
28
  align-items: center;
28
29
  justify-content: space-between;
29
30
 
30
- background-color: styles-tokens-markdown.$sys-neutral-background;
31
- border-color: styles-tokens-markdown.$sys-neutral-decor-default;
32
-
31
+ background-color: stc.$sys-neutral-background;
32
+ border-color: stc.$sys-neutral-decor-default;
33
33
  }
@@ -56,3 +56,13 @@ export function isDark(color: string) {
56
56
 
57
57
  export const getJsonSchema = (jsonSchema?: JsonSchema): SchemasSettings | undefined =>
58
58
  jsonSchema && { ...jsonSchema, uri: jsonSchema?.uri || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] };
59
+
60
+ export function uppercaseFirstLetter(value: string) {
61
+ const trimmedValue = value.trim();
62
+
63
+ if (trimmedValue.length === 0) {
64
+ return value;
65
+ }
66
+
67
+ return trimmedValue[0].toUpperCase() + trimmedValue.slice(1);
68
+ }