@hh.ru/magritte-ui-chat-marker 1.0.1
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/ChatMarker.d.ts +2 -0
- package/ChatMarker.js +34 -0
- package/ChatMarker.js.map +1 -0
- package/index.css +67 -0
- package/index.d.ts +2 -0
- package/index.js +11 -0
- package/index.js.map +1 -0
- package/index.mock.d.ts +3 -0
- package/index.mock.js +7 -0
- package/index.mock.js.map +1 -0
- package/package.json +38 -0
- package/types.d.ts +19 -0
- package/types.js +3 -0
- package/types.js.map +1 -0
package/ChatMarker.d.ts
ADDED
package/ChatMarker.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef, useRef, useState } from 'react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useResizeObserver } from '@hh.ru/magritte-common-resize';
|
|
6
|
+
import { Divider } from '@hh.ru/magritte-ui-divider';
|
|
7
|
+
import { IconDefaultPropsContext } from '@hh.ru/magritte-ui-icon';
|
|
8
|
+
import { LoaderDefaultPropsContext } from '@hh.ru/magritte-ui-loader';
|
|
9
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
10
|
+
|
|
11
|
+
var styles = {"chat-marker":"magritte-chat-marker___ya9dO_1-0-1","chatMarker":"magritte-chat-marker___ya9dO_1-0-1","line":"magritte-line___0zxh4_1-0-1","icon":"magritte-icon___RUogw_1-0-1","label":"magritte-label___RKh8J_1-0-1","label-outgoing":"magritte-label-outgoing___gqTn0_1-0-1","labelOutgoing":"magritte-label-outgoing___gqTn0_1-0-1","fade-out":"magritte-fade-out___Mog0k_1-0-1","fadeOut":"magritte-fade-out___Mog0k_1-0-1","label-outgoing-centered":"magritte-label-outgoing-centered___GikqE_1-0-1","labelOutgoingCentered":"magritte-label-outgoing-centered___GikqE_1-0-1","label-incoming":"magritte-label-incoming___cq-7a_1-0-1","labelIncoming":"magritte-label-incoming___cq-7a_1-0-1","fade-in":"magritte-fade-in___gDnCc_1-0-1","fadeIn":"magritte-fade-in___gDnCc_1-0-1"};
|
|
12
|
+
|
|
13
|
+
const LABEL_ID = 'label';
|
|
14
|
+
const ChatMarker = forwardRef(({ className, 'data-qa': dataQa = 'chat-marker', divider = false, icon, label, mode = 'secondary', ...props }, ref) => {
|
|
15
|
+
const labelWidth = useRef(0);
|
|
16
|
+
const [transition, setTransition] = useState({ label, outgoing: null });
|
|
17
|
+
const observeLabel = useResizeObserver((elements) => {
|
|
18
|
+
labelWidth.current = elements.get(LABEL_ID)?.getBoundingClientRect().width ?? 0;
|
|
19
|
+
});
|
|
20
|
+
if (transition.label !== label) {
|
|
21
|
+
const width = Math.ceil(labelWidth.current);
|
|
22
|
+
setTransition({ label, outgoing: width > 0 ? { text: transition.label, width } : null });
|
|
23
|
+
}
|
|
24
|
+
const { outgoing } = transition;
|
|
25
|
+
const renderText = (value) => (jsx(Text, { typography: "label-3-regular", style: mode, children: value }));
|
|
26
|
+
const line = divider && (jsx("div", { className: styles.line, "data-qa": "chat-marker-divider", "aria-hidden": true, children: jsx(Divider, {}) }));
|
|
27
|
+
return (jsxs("div", { ...props, className: classnames(className, styles.chatMarker), "data-qa": dataQa, ref: ref, children: [line, icon && (jsx(IconDefaultPropsContext, { props: { initialColor: mode }, children: jsx(LoaderDefaultPropsContext, { props: { size: 16, color: mode }, children: jsx("span", { className: styles.icon, "data-qa": "chat-marker-icon", "aria-hidden": true, children: icon }) }) })), jsxs("div", { ref: observeLabel(LABEL_ID), className: styles.label, "data-qa": "chat-marker-label", children: [jsx("span", { className: classnames({ [styles.labelIncoming]: outgoing !== null }), "data-qa": "chat-marker-label-text", children: renderText(label) }, label), outgoing !== null && (jsx("span", { className: classnames(styles.labelOutgoing, {
|
|
28
|
+
[styles.labelOutgoingCentered]: divider,
|
|
29
|
+
}), style: { width: outgoing.width }, "data-qa": "chat-marker-label-outgoing", onAnimationEnd: () => setTransition({ label, outgoing: null }), "aria-hidden": true, children: renderText(outgoing.text) }, outgoing.text))] }), line] }));
|
|
30
|
+
});
|
|
31
|
+
ChatMarker.displayName = 'ChatMarker';
|
|
32
|
+
|
|
33
|
+
export { ChatMarker };
|
|
34
|
+
//# sourceMappingURL=ChatMarker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatMarker.js","sources":["src/ChatMarker.tsx"],"sourcesContent":["import { forwardRef, useRef, useState } from 'react';\nimport classnames from 'classnames';\n\nimport { useResizeObserver } from '@hh.ru/magritte-common-resize';\nimport { ChatMarkerProps } from '@hh.ru/magritte-ui-chat-marker/types';\nimport { Divider } from '@hh.ru/magritte-ui-divider';\nimport { IconDefaultPropsContext } from '@hh.ru/magritte-ui-icon';\nimport { LoaderDefaultPropsContext } from '@hh.ru/magritte-ui-loader';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './chat-marker.less';\n\nconst LABEL_ID = 'label';\n\nexport const ChatMarker = forwardRef<HTMLDivElement, ChatMarkerProps>(\n (\n { className, 'data-qa': dataQa = 'chat-marker', divider = false, icon, label, mode = 'secondary', ...props },\n ref\n ) => {\n const labelWidth = useRef(0);\n const [transition, setTransition] = useState<{\n label: string;\n outgoing: { text: string; width: number } | null;\n }>({ label, outgoing: null });\n\n const observeLabel = useResizeObserver((elements) => {\n labelWidth.current = elements.get(LABEL_ID)?.getBoundingClientRect().width ?? 0;\n });\n\n if (transition.label !== label) {\n const width = Math.ceil(labelWidth.current);\n setTransition({ label, outgoing: width > 0 ? { text: transition.label, width } : null });\n }\n\n const { outgoing } = transition;\n\n const renderText = (value: string) => (\n <Text typography=\"label-3-regular\" style={mode}>\n {value}\n </Text>\n );\n\n const line = divider && (\n <div className={styles.line} data-qa=\"chat-marker-divider\" aria-hidden>\n <Divider />\n </div>\n );\n\n return (\n <div {...props} className={classnames(className, styles.chatMarker)} data-qa={dataQa} ref={ref}>\n {line}\n {icon && (\n <IconDefaultPropsContext props={{ initialColor: mode }}>\n <LoaderDefaultPropsContext props={{ size: 16, color: mode }}>\n <span className={styles.icon} data-qa=\"chat-marker-icon\" aria-hidden>\n {icon}\n </span>\n </LoaderDefaultPropsContext>\n </IconDefaultPropsContext>\n )}\n <div ref={observeLabel(LABEL_ID)} className={styles.label} data-qa=\"chat-marker-label\">\n <span\n key={label}\n className={classnames({ [styles.labelIncoming]: outgoing !== null })}\n data-qa=\"chat-marker-label-text\"\n >\n {renderText(label)}\n </span>\n {outgoing !== null && (\n <span\n key={outgoing.text}\n className={classnames(styles.labelOutgoing, {\n [styles.labelOutgoingCentered]: divider,\n })}\n style={{ width: outgoing.width }}\n data-qa=\"chat-marker-label-outgoing\"\n onAnimationEnd={() => setTransition({ label, outgoing: null })}\n aria-hidden\n >\n {renderText(outgoing.text)}\n </span>\n )}\n </div>\n {line}\n </div>\n );\n }\n);\n\nChatMarker.displayName = 'ChatMarker';\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;AAYA,MAAM,QAAQ,GAAG,OAAO,CAAC;AAElB,MAAM,UAAU,GAAG,UAAU,CAChC,CACI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,OAAO,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,WAAW,EAAE,GAAG,KAAK,EAAE,EAC5G,GAAG,KACH;AACA,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAC7B,IAAA,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAGzC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAE9B,IAAA,MAAM,YAAY,GAAG,iBAAiB,CAAC,CAAC,QAAQ,KAAI;AAChD,QAAA,UAAU,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,qBAAqB,EAAE,CAAC,KAAK,IAAI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-function-v25-0-1:cubic-bezier(0.4, 0.24, 0, 1);
|
|
4
|
+
}
|
|
5
|
+
.magritte-chat-marker___ya9dO_1-0-1{
|
|
6
|
+
--label-animation-duration:0ms;
|
|
7
|
+
display:flex;
|
|
8
|
+
align-items:flex-start;
|
|
9
|
+
gap:12px;
|
|
10
|
+
}
|
|
11
|
+
@media (prefers-reduced-motion: no-preference){
|
|
12
|
+
.magritte-chat-marker___ya9dO_1-0-1{
|
|
13
|
+
--label-animation-duration:var(--magritte-semantic-animation-time-s-duration-v25-0-1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
.magritte-line___0zxh4_1-0-1,
|
|
17
|
+
.magritte-icon___RUogw_1-0-1{
|
|
18
|
+
display:flex;
|
|
19
|
+
align-items:center;
|
|
20
|
+
height:20px;
|
|
21
|
+
}
|
|
22
|
+
.magritte-line___0zxh4_1-0-1{
|
|
23
|
+
flex:1 1 0;
|
|
24
|
+
}
|
|
25
|
+
.magritte-icon___RUogw_1-0-1{
|
|
26
|
+
flex-shrink:0;
|
|
27
|
+
}
|
|
28
|
+
.magritte-label___RKh8J_1-0-1{
|
|
29
|
+
position:relative;
|
|
30
|
+
flex:0 1 auto;
|
|
31
|
+
min-width:0;
|
|
32
|
+
}
|
|
33
|
+
.magritte-label-outgoing___gqTn0_1-0-1{
|
|
34
|
+
position:absolute;
|
|
35
|
+
top:0;
|
|
36
|
+
left:0;
|
|
37
|
+
animation-name:magritte-fade-out___Mog0k_1-0-1;
|
|
38
|
+
}
|
|
39
|
+
.magritte-label-outgoing-centered___GikqE_1-0-1{
|
|
40
|
+
left:50%;
|
|
41
|
+
transform:translateX(-50%);
|
|
42
|
+
}
|
|
43
|
+
.magritte-label-incoming___cq-7a_1-0-1,
|
|
44
|
+
.magritte-label-outgoing___gqTn0_1-0-1{
|
|
45
|
+
animation-duration:var(--label-animation-duration);
|
|
46
|
+
animation-timing-function:var(--magritte-semantic-animation-ease-base-timing-function-v25-0-1);
|
|
47
|
+
animation-fill-mode:forwards;
|
|
48
|
+
}
|
|
49
|
+
.magritte-label-incoming___cq-7a_1-0-1{
|
|
50
|
+
animation-name:magritte-fade-in___gDnCc_1-0-1;
|
|
51
|
+
}
|
|
52
|
+
@keyframes magritte-fade-in___gDnCc_1-0-1{
|
|
53
|
+
from{
|
|
54
|
+
opacity:0;
|
|
55
|
+
}
|
|
56
|
+
to{
|
|
57
|
+
opacity:1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
@keyframes magritte-fade-out___Mog0k_1-0-1{
|
|
61
|
+
from{
|
|
62
|
+
opacity:1;
|
|
63
|
+
}
|
|
64
|
+
to{
|
|
65
|
+
opacity:0;
|
|
66
|
+
}
|
|
67
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
export { ChatMarker } from './ChatMarker.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'classnames';
|
|
6
|
+
import '@hh.ru/magritte-common-resize';
|
|
7
|
+
import '@hh.ru/magritte-ui-divider';
|
|
8
|
+
import '@hh.ru/magritte-ui-icon';
|
|
9
|
+
import '@hh.ru/magritte-ui-loader';
|
|
10
|
+
import '@hh.ru/magritte-ui-typography';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/index.mock.d.ts
ADDED
package/index.mock.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mock.js","sources":["src/index.mock.ts"],"sourcesContent":["import { ForwardRefExoticComponent } from 'react';\n\nimport { mockComponent } from '@hh.ru/magritte-ui-mock-component';\n\nexport { type ChatMarkerMode, type ChatMarkerProps } from '@hh.ru/magritte-ui-chat-marker/types';\n\nexport const ChatMarker: ForwardRefExoticComponent<Record<string, unknown>> = mockComponent('ChatMarker');\n"],"names":[],"mappings":";;MAMa,UAAU,GAAuD,aAAa,CAAC,YAAY;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hh.ru/magritte-ui-chat-marker",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"index.css"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "yarn root:build $(pwd)",
|
|
11
|
+
"build-test-branch": "yarn root:build-test-branch $(pwd)",
|
|
12
|
+
"prepack": "yarn root:prepack $(pwd)",
|
|
13
|
+
"postpublish": "yarn root:postpublish $(pwd)",
|
|
14
|
+
"stylelint-check": "yarn root:stylelint-check $(pwd)",
|
|
15
|
+
"eslint-check": "yarn root:eslint-check $(pwd)",
|
|
16
|
+
"ts-config": "yarn root:ts-config $(pwd)",
|
|
17
|
+
"ts-check": "yarn root:ts-check $(pwd)",
|
|
18
|
+
"test": "yarn root:test $(pwd)",
|
|
19
|
+
"watch": "yarn root:watch $(pwd)"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@hh.ru/magritte-common-resize": "0.2.2",
|
|
26
|
+
"@hh.ru/magritte-design-tokens": "25.0.1",
|
|
27
|
+
"@hh.ru/magritte-ui-divider": "3.2.8",
|
|
28
|
+
"@hh.ru/magritte-ui-icon": "15.0.3",
|
|
29
|
+
"@hh.ru/magritte-ui-loader": "4.1.0",
|
|
30
|
+
"@hh.ru/magritte-ui-mock-component": "1.1.7",
|
|
31
|
+
"@hh.ru/magritte-ui-typography": "5.3.12"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"classnames": ">=2.3.2",
|
|
35
|
+
"react": ">=18.2.0"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "654e4a7ad4debb3463a3c37b316fbdc7571e9dff"
|
|
38
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ChatMarkerMode = 'secondary' | 'tertiary';
|
|
2
|
+
export interface ChatMarkerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
3
|
+
/** Основной текст маркера */
|
|
4
|
+
label: string;
|
|
5
|
+
/** Слот перед текстом: иконка или лоадер */
|
|
6
|
+
icon?: React.ReactNode;
|
|
7
|
+
/** Горизонтальные разделители с обеих сторон от содержимого
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
divider?: boolean;
|
|
11
|
+
/** Цвет текста и иконки
|
|
12
|
+
* @default secondary
|
|
13
|
+
*/
|
|
14
|
+
mode?: ChatMarkerMode;
|
|
15
|
+
/** Значение data-qa на корневом элементе
|
|
16
|
+
* @default chat-marker
|
|
17
|
+
*/
|
|
18
|
+
'data-qa'?: string;
|
|
19
|
+
}
|
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|