@cloud-ru/ds-uikit-product-copy 1.0.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 +8 -0
- package/LICENSE +201 -0
- package/README.md +253 -0
- package/dist/cjs/components/CopyButton/CopyButton.d.ts +16 -0
- package/dist/cjs/components/CopyButton/CopyButton.js +17 -0
- package/dist/cjs/components/CopyButton/index.d.ts +1 -0
- package/dist/cjs/components/CopyButton/index.js +17 -0
- package/dist/cjs/components/CopyLine/CopyLine.d.ts +16 -0
- package/dist/cjs/components/CopyLine/CopyLine.js +32 -0
- package/dist/cjs/components/CopyLine/constants.d.ts +4 -0
- package/dist/cjs/components/CopyLine/constants.js +7 -0
- package/dist/cjs/components/CopyLine/index.d.ts +3 -0
- package/dist/cjs/components/CopyLine/index.js +19 -0
- package/dist/cjs/components/CopyLine/styles.module.css +36 -0
- package/dist/cjs/components/CopyLine/types.d.ts +3 -0
- package/dist/cjs/components/CopyLine/types.js +2 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/constants.d.ts +9 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +36 -0
- package/dist/cjs/utils.d.ts +2 -0
- package/dist/cjs/utils.js +6 -0
- package/dist/esm/components/CopyButton/CopyButton.d.ts +16 -0
- package/dist/esm/components/CopyButton/CopyButton.js +14 -0
- package/dist/esm/components/CopyButton/index.d.ts +1 -0
- package/dist/esm/components/CopyButton/index.js +1 -0
- package/dist/esm/components/CopyLine/CopyLine.d.ts +16 -0
- package/dist/esm/components/CopyLine/CopyLine.js +26 -0
- package/dist/esm/components/CopyLine/constants.d.ts +4 -0
- package/dist/esm/components/CopyLine/constants.js +4 -0
- package/dist/esm/components/CopyLine/index.d.ts +3 -0
- package/dist/esm/components/CopyLine/index.js +3 -0
- package/dist/esm/components/CopyLine/styles.module.css +36 -0
- package/dist/esm/components/CopyLine/types.d.ts +3 -0
- package/dist/esm/components/CopyLine/types.js +1 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/constants.d.ts +9 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/style.css +36 -0
- package/dist/esm/utils.d.ts +2 -0
- package/dist/esm/utils.js +3 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/src/components/CopyButton/CopyButton.tsx +43 -0
- package/src/components/CopyButton/index.ts +1 -0
- package/src/components/CopyLine/CopyLine.tsx +73 -0
- package/src/components/CopyLine/constants.ts +4 -0
- package/src/components/CopyLine/index.ts +3 -0
- package/src/components/CopyLine/styles.module.scss +43 -0
- package/src/components/CopyLine/types.ts +5 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +9 -0
- package/src/index.ts +2 -0
- package/src/utils.ts +5 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CopyLine"), exports);
|
|
18
|
+
__exportStar(require("./CopyButton"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEST_IDS = void 0;
|
|
4
|
+
exports.TEST_IDS = {
|
|
5
|
+
copyButton: {
|
|
6
|
+
root: 'copy-button',
|
|
7
|
+
},
|
|
8
|
+
copyLine: {
|
|
9
|
+
root: 'copy-line',
|
|
10
|
+
copyButton: 'copy-line__copy-button',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./components"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.copyButton{
|
|
2
|
+
flex-shrink:0;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.content{
|
|
6
|
+
font-family:var(--sn-regular-body-m-fontFamily, var(--sn-brand-font-fontFamily-regular-body, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
|
|
7
|
+
font-weight:var(--sn-regular-body-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-m, var(--sn-brand-font-fontWeight-light-regular-body-m, var(--sn-primitive-font-fontWeightValue-400, 400))));
|
|
8
|
+
line-height:var(--sn-regular-body-m-lineHeight, var(--sn-density-typography-roleBody-lineHeightM, var(--sn-primitive-font-lineHeight-by16, 24px)));
|
|
9
|
+
font-size:var(--sn-regular-body-m-fontSize, var(--sn-density-typography-roleBody-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px)));
|
|
10
|
+
letter-spacing:var(--sn-regular-body-m-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
|
|
11
|
+
paragraph-spacing:var(--sn-regular-body-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize14, 7px));
|
|
12
|
+
overflow:hidden;
|
|
13
|
+
flex:0 1 auto;
|
|
14
|
+
min-width:0;
|
|
15
|
+
color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
|
|
16
|
+
text-overflow:ellipsis;
|
|
17
|
+
white-space:nowrap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.copyLine{
|
|
21
|
+
cursor:pointer;
|
|
22
|
+
display:inline-flex;
|
|
23
|
+
flex-shrink:0;
|
|
24
|
+
gap:var(--sn-primitive-dimension-4, 4px);
|
|
25
|
+
align-items:center;
|
|
26
|
+
box-sizing:border-box;
|
|
27
|
+
min-width:0;
|
|
28
|
+
max-width:100%;
|
|
29
|
+
min-height:var(--sn-primitive-dimension-24, 24px);
|
|
30
|
+
}
|
|
31
|
+
.copyLine[data-copy-button-hide-strategy=hover] .copyButton{
|
|
32
|
+
display:none;
|
|
33
|
+
}
|
|
34
|
+
.copyLine[data-copy-button-hide-strategy=hover]:hover .copyButton, .copyLine[data-copy-button-hide-strategy=hover]:focus-within .copyButton{
|
|
35
|
+
display:inline-flex;
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ButtonProps } from '@cloud-ru/ds-button';
|
|
2
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
import { MouseEventHandler } from 'react';
|
|
4
|
+
export type CopyButtonProps = WithSupportProps<{
|
|
5
|
+
/** Значение для копирования в буфер. */
|
|
6
|
+
valueToCopy: string | number;
|
|
7
|
+
/** Размер кнопки (s / m / l). По-умолчанию s. */
|
|
8
|
+
size?: ButtonProps['size'];
|
|
9
|
+
/** Текст рядом с иконкой. Если не задан — кнопка отображается только с иконкой. */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Дополнительный класс. */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Доп. обработчик клика. */
|
|
14
|
+
onClick?: MouseEventHandler<HTMLButtonElement>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function CopyButton({ valueToCopy, size, label, className, onClick, ...rest }: CopyButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
3
|
+
import { CheckSVG, CopySVG } from '@cloud-ru/ds-icons/interface/system';
|
|
4
|
+
import { extractSupportProps, useCopyToClipboard } from '@cloud-ru/ds-utils';
|
|
5
|
+
export function CopyButton({ valueToCopy, size = 's', label, className, onClick, ...rest }) {
|
|
6
|
+
const { isChecked, copy } = useCopyToClipboard();
|
|
7
|
+
const handleClick = event => {
|
|
8
|
+
event.stopPropagation();
|
|
9
|
+
if (valueToCopy)
|
|
10
|
+
copy(String(valueToCopy));
|
|
11
|
+
onClick?.(event);
|
|
12
|
+
};
|
|
13
|
+
return (_jsx(Button, { ...extractSupportProps(rest), className: className, view: 'function', appearance: 'neutral', size: size, type: 'button', "aria-label": label ? undefined : 'Copy', label: label, icon: isChecked ? _jsx(CheckSVG, {}) : _jsx(CopySVG, {}), iconPosition: 'after', onClick: handleClick }));
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CopyButton.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CopyButton.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
2
|
+
import { MouseEventHandler, ReactNode } from 'react';
|
|
3
|
+
import { CopyButtonHideStrategy } from './types.js';
|
|
4
|
+
export type CopyLineProps = WithSupportProps<{
|
|
5
|
+
/** Отображаемое содержимое. Если это строка/число — автоматически truncated и используется как значение для копирования по-умолчанию. */
|
|
6
|
+
content: ReactNode;
|
|
7
|
+
/** Значение, которое попадёт в буфер при клике. По-умолчанию равно content, если он string/number. */
|
|
8
|
+
valueToCopy?: string | number;
|
|
9
|
+
/** Дополнительный класс корневого элемента. */
|
|
10
|
+
className?: string;
|
|
11
|
+
/** Обработчик клика по строке. */
|
|
12
|
+
onClick?: MouseEventHandler<HTMLDivElement>;
|
|
13
|
+
/** Стратегия показа кнопки копирования: hover — только по наведению, never — всегда. */
|
|
14
|
+
copyButtonHideStrategy?: CopyButtonHideStrategy;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function CopyLine({ content, className, valueToCopy: valueToCopyProp, onClick, copyButtonHideStrategy, ...rest }: CopyLineProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
3
|
+
import { CheckSVG, CopySVG } from '@cloud-ru/ds-icons/interface/system';
|
|
4
|
+
import { TruncateString } from '@cloud-ru/ds-truncate-string';
|
|
5
|
+
import { extractSupportProps, useCopyToClipboard } from '@cloud-ru/ds-utils';
|
|
6
|
+
import cn from 'classnames';
|
|
7
|
+
import { TEST_IDS } from '../../constants.js';
|
|
8
|
+
import { isStringOrNumber } from '../../utils.js';
|
|
9
|
+
import { COPY_BUTTON_HIDE_STRATEGY } from './constants.js';
|
|
10
|
+
import styles from './styles.module.css';
|
|
11
|
+
const ICON_SIZE = 16;
|
|
12
|
+
export function CopyLine({ content, className, valueToCopy: valueToCopyProp, onClick, copyButtonHideStrategy = COPY_BUTTON_HIDE_STRATEGY.Hover, ...rest }) {
|
|
13
|
+
const valueToCopy = valueToCopyProp ?? (isStringOrNumber(content) ? String(content) : '');
|
|
14
|
+
const { isChecked, copy } = useCopyToClipboard();
|
|
15
|
+
const handleClick = event => {
|
|
16
|
+
event.stopPropagation();
|
|
17
|
+
if (valueToCopy)
|
|
18
|
+
copy(String(valueToCopy));
|
|
19
|
+
onClick?.(event);
|
|
20
|
+
};
|
|
21
|
+
return (_jsxs("div", { className: cn(styles.copyLine, className), onClick: handleClick, role: 'presentation', "data-copy-button-hide-strategy": copyButtonHideStrategy, ...extractSupportProps(rest), children: [_jsx("span", { className: styles.content, children: isStringOrNumber(content) ? _jsx(TruncateString, { text: String(content), maxLines: 1 }) : content }), _jsx(Button, { className: styles.copyButton, view: 'function', appearance: 'neutral', size: 's', type: 'button', "aria-label": 'Copy', "data-test-id": TEST_IDS.copyLine.copyButton, icon: isChecked ? _jsx(CheckSVG, { size: ICON_SIZE }) : _jsx(CopySVG, { size: ICON_SIZE }), onClick: (e) => {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
if (valueToCopy)
|
|
24
|
+
copy(String(valueToCopy));
|
|
25
|
+
} })] }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.copyButton{
|
|
2
|
+
flex-shrink:0;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.content{
|
|
6
|
+
font-family:var(--sn-regular-body-m-fontFamily, var(--sn-brand-font-fontFamily-regular-body, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
|
|
7
|
+
font-weight:var(--sn-regular-body-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-m, var(--sn-brand-font-fontWeight-light-regular-body-m, var(--sn-primitive-font-fontWeightValue-400, 400))));
|
|
8
|
+
line-height:var(--sn-regular-body-m-lineHeight, var(--sn-density-typography-roleBody-lineHeightM, var(--sn-primitive-font-lineHeight-by16, 24px)));
|
|
9
|
+
font-size:var(--sn-regular-body-m-fontSize, var(--sn-density-typography-roleBody-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px)));
|
|
10
|
+
letter-spacing:var(--sn-regular-body-m-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
|
|
11
|
+
paragraph-spacing:var(--sn-regular-body-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize14, 7px));
|
|
12
|
+
overflow:hidden;
|
|
13
|
+
flex:0 1 auto;
|
|
14
|
+
min-width:0;
|
|
15
|
+
color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
|
|
16
|
+
text-overflow:ellipsis;
|
|
17
|
+
white-space:nowrap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.copyLine{
|
|
21
|
+
cursor:pointer;
|
|
22
|
+
display:inline-flex;
|
|
23
|
+
flex-shrink:0;
|
|
24
|
+
gap:var(--sn-primitive-dimension-4, 4px);
|
|
25
|
+
align-items:center;
|
|
26
|
+
box-sizing:border-box;
|
|
27
|
+
min-width:0;
|
|
28
|
+
max-width:100%;
|
|
29
|
+
min-height:var(--sn-primitive-dimension-24, 24px);
|
|
30
|
+
}
|
|
31
|
+
.copyLine[data-copy-button-hide-strategy=hover] .copyButton{
|
|
32
|
+
display:none;
|
|
33
|
+
}
|
|
34
|
+
.copyLine[data-copy-button-hide-strategy=hover]:hover .copyButton, .copyLine[data-copy-button-hide-strategy=hover]:focus-within .copyButton{
|
|
35
|
+
display:inline-flex;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.copyButton{
|
|
2
|
+
flex-shrink:0;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.content{
|
|
6
|
+
font-family:var(--sn-regular-body-m-fontFamily, var(--sn-brand-font-fontFamily-regular-body, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
|
|
7
|
+
font-weight:var(--sn-regular-body-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-m, var(--sn-brand-font-fontWeight-light-regular-body-m, var(--sn-primitive-font-fontWeightValue-400, 400))));
|
|
8
|
+
line-height:var(--sn-regular-body-m-lineHeight, var(--sn-density-typography-roleBody-lineHeightM, var(--sn-primitive-font-lineHeight-by16, 24px)));
|
|
9
|
+
font-size:var(--sn-regular-body-m-fontSize, var(--sn-density-typography-roleBody-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px)));
|
|
10
|
+
letter-spacing:var(--sn-regular-body-m-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
|
|
11
|
+
paragraph-spacing:var(--sn-regular-body-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize14, 7px));
|
|
12
|
+
overflow:hidden;
|
|
13
|
+
flex:0 1 auto;
|
|
14
|
+
min-width:0;
|
|
15
|
+
color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
|
|
16
|
+
text-overflow:ellipsis;
|
|
17
|
+
white-space:nowrap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.copyLine{
|
|
21
|
+
cursor:pointer;
|
|
22
|
+
display:inline-flex;
|
|
23
|
+
flex-shrink:0;
|
|
24
|
+
gap:var(--sn-primitive-dimension-4, 4px);
|
|
25
|
+
align-items:center;
|
|
26
|
+
box-sizing:border-box;
|
|
27
|
+
min-width:0;
|
|
28
|
+
max-width:100%;
|
|
29
|
+
min-height:var(--sn-primitive-dimension-24, 24px);
|
|
30
|
+
}
|
|
31
|
+
.copyLine[data-copy-button-hide-strategy=hover] .copyButton{
|
|
32
|
+
display:none;
|
|
33
|
+
}
|
|
34
|
+
.copyLine[data-copy-button-hide-strategy=hover]:hover .copyButton, .copyLine[data-copy-button-hide-strategy=hover]:focus-within .copyButton{
|
|
35
|
+
display:inline-flex;
|
|
36
|
+
}
|