@gravity-ui/aikit 3.6.1-beta.dba49d670e4787f06259ebac420e8816e02d2ecb.0 → 3.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/build/cjs/components/internal/RunActivityWaitingContext.d.ts +2 -0
- package/build/cjs/components/internal/RunActivityWaitingContext.js +7 -0
- package/build/cjs/components/internal/RunActivityWaitingContext.js.map +1 -0
- package/build/cjs/components/organisms/AskUserQuestion/AskUserQuestion.css +217 -0
- package/build/cjs/components/organisms/AskUserQuestion/AskUserQuestion.d.ts +3 -0
- package/build/cjs/components/organisms/AskUserQuestion/AskUserQuestion.js +187 -0
- package/build/cjs/components/organisms/AskUserQuestion/AskUserQuestion.js.map +1 -0
- package/build/cjs/components/organisms/AskUserQuestion/i18n/en.json +12 -0
- package/build/cjs/components/organisms/AskUserQuestion/i18n/index.d.ts +13 -0
- package/build/cjs/components/organisms/AskUserQuestion/i18n/index.js +9 -0
- package/build/cjs/components/organisms/AskUserQuestion/i18n/index.js.map +1 -0
- package/build/cjs/components/organisms/AskUserQuestion/i18n/ru.json +12 -0
- package/build/cjs/components/organisms/AskUserQuestion/index.d.ts +2 -0
- package/build/cjs/components/organisms/AskUserQuestion/index.js +6 -0
- package/build/cjs/components/organisms/AskUserQuestion/index.js.map +1 -0
- package/build/cjs/components/organisms/AskUserQuestion/types.d.ts +41 -0
- package/build/cjs/components/organisms/AskUserQuestion/types.js +3 -0
- package/build/cjs/components/organisms/AskUserQuestion/types.js.map +1 -0
- package/build/cjs/components/organisms/AskUserQuestion/useQuestionTransition.d.ts +3 -0
- package/build/cjs/components/organisms/AskUserQuestion/useQuestionTransition.js +57 -0
- package/build/cjs/components/organisms/AskUserQuestion/useQuestionTransition.js.map +1 -0
- package/build/cjs/components/organisms/RunActivity/index.js +3 -2
- package/build/cjs/components/organisms/RunActivity/index.js.map +1 -1
- package/build/cjs/components/organisms/ToolMessage/index.js +5 -2
- package/build/cjs/components/organisms/ToolMessage/index.js.map +1 -1
- package/build/cjs/components/organisms/index.d.ts +1 -0
- package/build/cjs/components/organisms/index.js +1 -0
- package/build/cjs/components/organisms/index.js.map +1 -1
- package/build/cjs/package.json +1 -1
- package/build/docs/INDEX.md +1 -0
- package/build/docs/components/organisms/AskUserQuestion.md +241 -0
- package/build/docs/components/organisms/RunActivity.md +7 -0
- package/build/docs/components/pages/AgentChat.md +42 -0
- package/build/docs/guides/COMPONENTS.md +2 -1
- package/build/docs/guides/PROJECT_STRUCTURE.md +2 -1
- package/build/esm/components/internal/RunActivityWaitingContext.d.ts +2 -0
- package/build/esm/components/internal/RunActivityWaitingContext.js +4 -0
- package/build/esm/components/internal/RunActivityWaitingContext.js.map +1 -0
- package/build/esm/components/organisms/AskUserQuestion/AskUserQuestion.css +217 -0
- package/build/esm/components/organisms/AskUserQuestion/AskUserQuestion.d.ts +3 -0
- package/build/esm/components/organisms/AskUserQuestion/AskUserQuestion.js +184 -0
- package/build/esm/components/organisms/AskUserQuestion/AskUserQuestion.js.map +1 -0
- package/build/esm/components/organisms/AskUserQuestion/i18n/en.json +12 -0
- package/build/esm/components/organisms/AskUserQuestion/i18n/index.d.ts +13 -0
- package/build/esm/components/organisms/AskUserQuestion/i18n/index.js +5 -0
- package/build/esm/components/organisms/AskUserQuestion/i18n/index.js.map +1 -0
- package/build/esm/components/organisms/AskUserQuestion/i18n/ru.json +12 -0
- package/build/esm/components/organisms/AskUserQuestion/index.d.ts +2 -0
- package/build/esm/components/organisms/AskUserQuestion/index.js +2 -0
- package/build/esm/components/organisms/AskUserQuestion/index.js.map +1 -0
- package/build/esm/components/organisms/AskUserQuestion/types.d.ts +41 -0
- package/build/esm/components/organisms/AskUserQuestion/types.js +2 -0
- package/build/esm/components/organisms/AskUserQuestion/types.js.map +1 -0
- package/build/esm/components/organisms/AskUserQuestion/useQuestionTransition.d.ts +3 -0
- package/build/esm/components/organisms/AskUserQuestion/useQuestionTransition.js +54 -0
- package/build/esm/components/organisms/AskUserQuestion/useQuestionTransition.js.map +1 -0
- package/build/esm/components/organisms/RunActivity/index.js +3 -2
- package/build/esm/components/organisms/RunActivity/index.js.map +1 -1
- package/build/esm/components/organisms/ToolMessage/index.js +5 -2
- package/build/esm/components/organisms/ToolMessage/index.js.map +1 -1
- package/build/esm/components/organisms/index.d.ts +1 -0
- package/build/esm/components/organisms/index.js +1 -0
- package/build/esm/components/organisms/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/docs/COMPONENTS.md +2 -1
- package/docs/PROJECT_STRUCTURE.md +2 -1
- package/llms-full.txt +4 -2
- package/llms.txt +2 -0
- package/package.json +11 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunActivityWaitingContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/** An enclosing run already presents the waiting status in its summary. */
|
|
6
|
+
exports.RunActivityWaitingContext = (0, react_1.createContext)(false);
|
|
7
|
+
//# sourceMappingURL=RunActivityWaitingContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RunActivityWaitingContext.js","sourceRoot":"../../../../src","sources":["components/internal/RunActivityWaitingContext.ts"],"names":[],"mappings":";;;AAAA,iCAAoC;AAEpC,2EAA2E;AAC9D,QAAA,yBAAyB,GAAG,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC","sourcesContent":["import {createContext} from 'react';\n\n/** An enclosing run already presents the waiting status in its summary. */\nexport const RunActivityWaitingContext = createContext(false);\n"]}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
.g-aikit-ask-user-question {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
width: var(--g-aikit-ask-user-question-width, 480px);
|
|
6
|
+
max-width: 100%;
|
|
7
|
+
padding: var(--g-spacing-1);
|
|
8
|
+
border: 1px solid var(--g-color-text-utility);
|
|
9
|
+
border-radius: var(--g-border-radius-xl);
|
|
10
|
+
background: var(--g-color-base-background);
|
|
11
|
+
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.0509803922), 1px 3px 13px rgba(0, 0, 0, 0.0509803922);
|
|
12
|
+
color: var(--g-color-text-primary);
|
|
13
|
+
font-family: var(--g-text-body-font-family);
|
|
14
|
+
font-size: var(--g-text-body-1-font-size);
|
|
15
|
+
line-height: var(--g-text-body-1-line-height);
|
|
16
|
+
}
|
|
17
|
+
.g-aikit-ask-user-question:focus-visible {
|
|
18
|
+
outline: 2px solid var(--g-color-line-focus);
|
|
19
|
+
outline-offset: 2px;
|
|
20
|
+
}
|
|
21
|
+
.g-aikit-ask-user-question__body {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex: none;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
gap: var(--g-spacing-1);
|
|
26
|
+
min-width: 0;
|
|
27
|
+
}
|
|
28
|
+
.g-aikit-ask-user-question__header {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
align-items: stretch;
|
|
32
|
+
gap: var(--g-spacing-2);
|
|
33
|
+
padding: var(--g-spacing-2);
|
|
34
|
+
}
|
|
35
|
+
.g-aikit-ask-user-question__question {
|
|
36
|
+
font-size: var(--g-text-subheader-2-font-size);
|
|
37
|
+
line-height: var(--g-text-subheader-2-line-height);
|
|
38
|
+
flex: 1;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
font-family: var(--g-text-subheader-font-family);
|
|
41
|
+
font-weight: var(--g-text-subheader-font-weight);
|
|
42
|
+
overflow-wrap: anywhere;
|
|
43
|
+
}
|
|
44
|
+
.g-aikit-ask-user-question__actions, .g-aikit-ask-user-question__navigation {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-shrink: 0;
|
|
47
|
+
align-items: center;
|
|
48
|
+
}
|
|
49
|
+
.g-aikit-ask-user-question__actions {
|
|
50
|
+
align-items: flex-start;
|
|
51
|
+
order: -1;
|
|
52
|
+
align-self: stretch;
|
|
53
|
+
gap: var(--g-spacing-2);
|
|
54
|
+
}
|
|
55
|
+
.g-aikit-ask-user-question__tool-label {
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
gap: var(--g-spacing-2);
|
|
59
|
+
margin-inline-end: auto;
|
|
60
|
+
color: var(--g-color-text-secondary);
|
|
61
|
+
}
|
|
62
|
+
.g-aikit-ask-user-question__skip {
|
|
63
|
+
align-items: center;
|
|
64
|
+
line-height: var(--g-text-body-1-line-height);
|
|
65
|
+
}
|
|
66
|
+
.g-aikit-ask-user-question__navigation {
|
|
67
|
+
gap: var(--g-spacing-1);
|
|
68
|
+
}
|
|
69
|
+
.g-aikit-ask-user-question__progress-track {
|
|
70
|
+
display: flex;
|
|
71
|
+
gap: var(--g-spacing-1);
|
|
72
|
+
margin: var(--g-spacing-1) var(--g-spacing-2) var(--g-spacing-2);
|
|
73
|
+
}
|
|
74
|
+
.g-aikit-ask-user-question__progress-segment {
|
|
75
|
+
flex: 1;
|
|
76
|
+
height: var(--g-spacing-1);
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
border-radius: var(--g-border-radius-xs);
|
|
79
|
+
background: var(--g-color-line-generic);
|
|
80
|
+
}
|
|
81
|
+
.g-aikit-ask-user-question__progress-fill {
|
|
82
|
+
display: block;
|
|
83
|
+
height: 100%;
|
|
84
|
+
background: var(--g-color-base-info-heavy);
|
|
85
|
+
transform: scaleX(0);
|
|
86
|
+
transform-origin: left;
|
|
87
|
+
transition: transform 220ms cubic-bezier(0.2, 0, 0, 1);
|
|
88
|
+
}
|
|
89
|
+
.g-aikit-ask-user-question__progress-segment_answered .g-aikit-ask-user-question__progress-fill {
|
|
90
|
+
transform: scaleX(1);
|
|
91
|
+
}
|
|
92
|
+
@media (prefers-reduced-motion: reduce) {
|
|
93
|
+
.g-aikit-ask-user-question__progress-fill {
|
|
94
|
+
transition: none;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
.g-aikit-ask-user-question__progress {
|
|
98
|
+
color: var(--g-color-text-secondary);
|
|
99
|
+
white-space: nowrap;
|
|
100
|
+
}
|
|
101
|
+
.g-aikit-ask-user-question_keyboard-focus .g-aikit-ask-user-question__option:focus, .g-aikit-ask-user-question_keyboard-focus .g-aikit-ask-user-question__custom:focus {
|
|
102
|
+
outline: 2px solid var(--g-color-line-focus);
|
|
103
|
+
outline-offset: -2px;
|
|
104
|
+
}
|
|
105
|
+
.g-aikit-ask-user-question_keyboard-focus .g-aikit-ask-user-question__option:focus {
|
|
106
|
+
background: var(--g-color-base-simple-hover);
|
|
107
|
+
}
|
|
108
|
+
.g-aikit-ask-user-question__answers {
|
|
109
|
+
display: flex;
|
|
110
|
+
flex-direction: column;
|
|
111
|
+
gap: var(--g-spacing-1);
|
|
112
|
+
}
|
|
113
|
+
.g-aikit-ask-user-question__option, .g-aikit-ask-user-question__custom {
|
|
114
|
+
box-sizing: border-box;
|
|
115
|
+
display: flex;
|
|
116
|
+
align-items: flex-start;
|
|
117
|
+
gap: var(--g-spacing-3);
|
|
118
|
+
width: 100%;
|
|
119
|
+
padding: var(--g-spacing-1) var(--g-spacing-2);
|
|
120
|
+
border: 0;
|
|
121
|
+
border-radius: var(--g-border-radius-m);
|
|
122
|
+
background: transparent;
|
|
123
|
+
color: inherit;
|
|
124
|
+
font: inherit;
|
|
125
|
+
text-align: start;
|
|
126
|
+
}
|
|
127
|
+
.g-aikit-ask-user-question__option {
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
}
|
|
130
|
+
.g-aikit-ask-user-question__option:hover, .g-aikit-ask-user-question__option:focus-visible {
|
|
131
|
+
background: var(--g-color-base-simple-hover);
|
|
132
|
+
}
|
|
133
|
+
.g-aikit-ask-user-question__option:focus-visible {
|
|
134
|
+
outline: 2px solid var(--g-color-line-focus);
|
|
135
|
+
outline-offset: -2px;
|
|
136
|
+
}
|
|
137
|
+
.g-aikit-ask-user-question__option_selected, .g-aikit-ask-user-question__option_selected:hover, .g-aikit-ask-user-question__option_selected:focus-visible, .g-aikit-ask-user-question_keyboard-focus .g-aikit-ask-user-question__option_selected:focus, .g-aikit-ask-user-question__custom_selected {
|
|
138
|
+
background: var(--g-color-base-selection);
|
|
139
|
+
}
|
|
140
|
+
.g-aikit-ask-user-question__shortcut {
|
|
141
|
+
display: flex;
|
|
142
|
+
flex-shrink: 0;
|
|
143
|
+
align-items: flex-start;
|
|
144
|
+
padding-top: var(--g-spacing-1);
|
|
145
|
+
}
|
|
146
|
+
.g-aikit-ask-user-question__hotkey {
|
|
147
|
+
box-sizing: border-box;
|
|
148
|
+
display: inline-flex;
|
|
149
|
+
justify-content: center;
|
|
150
|
+
align-items: center;
|
|
151
|
+
min-width: 20px;
|
|
152
|
+
height: 20px;
|
|
153
|
+
padding: 0 4px;
|
|
154
|
+
border: 1px solid var(--g-color-line-generic);
|
|
155
|
+
background: var(--g-color-base-background);
|
|
156
|
+
}
|
|
157
|
+
.g-aikit-ask-user-question__content {
|
|
158
|
+
display: flex;
|
|
159
|
+
flex: 1;
|
|
160
|
+
flex-direction: column;
|
|
161
|
+
gap: var(--g-spacing-1);
|
|
162
|
+
min-width: 0;
|
|
163
|
+
}
|
|
164
|
+
.g-aikit-ask-user-question__title {
|
|
165
|
+
display: flex;
|
|
166
|
+
flex-wrap: wrap;
|
|
167
|
+
align-items: center;
|
|
168
|
+
gap: var(--g-spacing-2);
|
|
169
|
+
font-family: var(--g-text-subheader-font-family);
|
|
170
|
+
font-weight: var(--g-text-subheader-font-weight);
|
|
171
|
+
}
|
|
172
|
+
.g-aikit-ask-user-question__description {
|
|
173
|
+
color: var(--g-color-text-secondary);
|
|
174
|
+
overflow-wrap: anywhere;
|
|
175
|
+
}
|
|
176
|
+
.g-aikit-ask-user-question__trailing {
|
|
177
|
+
display: flex;
|
|
178
|
+
flex-shrink: 0;
|
|
179
|
+
align-items: center;
|
|
180
|
+
align-self: stretch;
|
|
181
|
+
box-sizing: border-box;
|
|
182
|
+
width: 22px;
|
|
183
|
+
padding-inline-end: 6px;
|
|
184
|
+
transform: translateX(var(--g-spacing-1));
|
|
185
|
+
color: var(--g-color-text-secondary);
|
|
186
|
+
visibility: hidden;
|
|
187
|
+
}
|
|
188
|
+
.g-aikit-ask-user-question__option:hover .g-aikit-ask-user-question__trailing, .g-aikit-ask-user-question__option:focus-visible .g-aikit-ask-user-question__trailing {
|
|
189
|
+
visibility: visible;
|
|
190
|
+
}
|
|
191
|
+
.g-aikit-ask-user-question__custom {
|
|
192
|
+
align-items: center;
|
|
193
|
+
min-height: 38px;
|
|
194
|
+
padding-inline-end: var(--g-spacing-1);
|
|
195
|
+
border: 1px solid transparent;
|
|
196
|
+
}
|
|
197
|
+
.g-aikit-ask-user-question__custom:hover:not(.g-aikit-ask-user-question__custom_filled, :focus-within) {
|
|
198
|
+
border-color: var(--g-color-line-generic-hover);
|
|
199
|
+
}
|
|
200
|
+
.g-aikit-ask-user-question__custom:focus-visible {
|
|
201
|
+
outline: 2px solid var(--g-color-line-focus);
|
|
202
|
+
outline-offset: -2px;
|
|
203
|
+
}
|
|
204
|
+
.g-aikit-ask-user-question__custom:focus-within, .g-aikit-ask-user-question__custom_filled {
|
|
205
|
+
border-color: var(--g-color-line-generic-active);
|
|
206
|
+
}
|
|
207
|
+
.g-aikit-ask-user-question__custom .g-aikit-ask-user-question__shortcut {
|
|
208
|
+
padding-top: 0;
|
|
209
|
+
}
|
|
210
|
+
.g-aikit-ask-user-question__footer {
|
|
211
|
+
padding: var(--g-spacing-2);
|
|
212
|
+
}
|
|
213
|
+
.g-aikit-ask-user-question__input {
|
|
214
|
+
flex: 1;
|
|
215
|
+
min-width: 0;
|
|
216
|
+
--g-text-input-text-indent: 0;
|
|
217
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AskUserQuestionProps } from "./types.js";
|
|
2
|
+
import "./AskUserQuestion.css";
|
|
3
|
+
export declare function AskUserQuestion({ question, options, onAnswer, selectedAnswer, questionIndex, questionCount, answeredQuestionIndices, onProgressComplete, onQuestionChange, onClose, allowCustomAnswer, customAnswer, onCustomAnswerChange, customAnswerPlaceholder, showShortcuts, footer, className, qa, }: AskUserQuestionProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AskUserQuestion = AskUserQuestion;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const icons_1 = require("@gravity-ui/icons");
|
|
7
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
8
|
+
const cn_1 = require("../../../utils/cn.js");
|
|
9
|
+
const ActionButton_1 = require("../../atoms/ActionButton/index.js");
|
|
10
|
+
const i18n_1 = require("./i18n/index.js");
|
|
11
|
+
const useQuestionTransition_1 = require("./useQuestionTransition.js");
|
|
12
|
+
require("./AskUserQuestion.css");
|
|
13
|
+
const b = (0, cn_1.block)('ask-user-question');
|
|
14
|
+
function AskUserQuestion({ question, options, onAnswer, selectedAnswer, questionIndex = 0, questionCount = 1, answeredQuestionIndices, onProgressComplete, onQuestionChange, onClose, allowCustomAnswer = true, customAnswer, onCustomAnswerChange, customAnswerPlaceholder, showShortcuts = true, footer, className, qa, }) {
|
|
15
|
+
const { t } = i18n_1.i18n.useTranslation();
|
|
16
|
+
const titleId = (0, react_1.useId)();
|
|
17
|
+
const answered = new Set(answeredQuestionIndices === null || answeredQuestionIndices === void 0 ? void 0 : answeredQuestionIndices.filter((index) => Number.isInteger(index) && index >= 0 && index < questionCount));
|
|
18
|
+
const progressRef = (0, react_1.useRef)(null);
|
|
19
|
+
const progressCompleteCallback = (0, react_1.useRef)(onProgressComplete);
|
|
20
|
+
progressCompleteCallback.current = onProgressComplete;
|
|
21
|
+
const progressComplete = Boolean(answeredQuestionIndices) && questionCount > 1 && answered.size === questionCount;
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (!progressComplete) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
let cancelled = false;
|
|
28
|
+
const animations = (_b = (_a = progressRef.current) === null || _a === void 0 ? void 0 : _a.getAnimations({ subtree: true })) !== null && _b !== void 0 ? _b : [];
|
|
29
|
+
Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {
|
|
30
|
+
var _a;
|
|
31
|
+
if (!cancelled) {
|
|
32
|
+
(_a = progressCompleteCallback.current) === null || _a === void 0 ? void 0 : _a.call(progressCompleteCallback);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
cancelled = true;
|
|
37
|
+
};
|
|
38
|
+
}, [progressComplete]);
|
|
39
|
+
const contentRef = (0, react_1.useRef)(null);
|
|
40
|
+
const rootRef = (0, react_1.useRef)(null);
|
|
41
|
+
(0, useQuestionTransition_1.useQuestionTransition)(rootRef, contentRef);
|
|
42
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
43
|
+
const customRowRef = (0, react_1.useRef)(null);
|
|
44
|
+
const selectedOptions = (0, react_1.useRef)(new Map());
|
|
45
|
+
const questionKey = `${questionIndex}:${question}`;
|
|
46
|
+
const selectedAnswerRef = (0, react_1.useRef)(selectedAnswer);
|
|
47
|
+
selectedAnswerRef.current = selectedAnswer;
|
|
48
|
+
const [keyboardFocus, setKeyboardFocus] = (0, react_1.useState)(true);
|
|
49
|
+
const answerOption = (0, react_1.useCallback)((optionId) => {
|
|
50
|
+
selectedOptions.current.set(questionKey, { type: 'option', optionId });
|
|
51
|
+
onAnswer({ type: 'option', optionId });
|
|
52
|
+
}, [onAnswer, questionKey]);
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
const root = rootRef.current;
|
|
56
|
+
if (!root || root.closest('[inert]')) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const active = root.ownerDocument.activeElement;
|
|
60
|
+
if (active &&
|
|
61
|
+
!root.contains(active) &&
|
|
62
|
+
active.matches('input, textarea, select, [contenteditable]:not([contenteditable="false"])') &&
|
|
63
|
+
!(active instanceof HTMLTextAreaElement && !active.value.trim())) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if ((active === null || active === void 0 ? void 0 : active.closest('[data-question-shortcuts]')) && !root.contains(active)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setKeyboardFocus(true);
|
|
70
|
+
const answers = Array.from(root.querySelectorAll('[data-question-answer]'));
|
|
71
|
+
const saved = (_a = selectedAnswerRef.current) !== null && _a !== void 0 ? _a : selectedOptions.current.get(questionKey);
|
|
72
|
+
const target = (_b = ((saved === null || saved === void 0 ? void 0 : saved.type) === 'custom'
|
|
73
|
+
? customRowRef.current
|
|
74
|
+
: answers.find((item) => item.dataset.questionAnswer === (saved === null || saved === void 0 ? void 0 : saved.optionId)))) !== null && _b !== void 0 ? _b : answers[0];
|
|
75
|
+
target === null || target === void 0 ? void 0 : target.focus({ preventScroll: true });
|
|
76
|
+
}, [questionKey]);
|
|
77
|
+
const [draft, setDraft] = (0, react_1.useState)({ questionKey, value: '' });
|
|
78
|
+
const value = customAnswer !== null && customAnswer !== void 0 ? customAnswer : (draft.questionKey === questionKey ? draft.value : '');
|
|
79
|
+
const hasValue = Boolean(value.trim());
|
|
80
|
+
const submitCustom = () => {
|
|
81
|
+
if (hasValue) {
|
|
82
|
+
selectedOptions.current.set(questionKey, { type: 'custom', value: value.trim() });
|
|
83
|
+
onAnswer({ type: 'custom', value: value.trim() });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
(0, react_1.useEffect)(() => {
|
|
87
|
+
var _a;
|
|
88
|
+
const handleKeyDown = (event) => {
|
|
89
|
+
var _a;
|
|
90
|
+
if (event.defaultPrevented || event.repeat || event.isComposing) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const root = rootRef.current;
|
|
94
|
+
const target = event.target;
|
|
95
|
+
if (!root || !target.closest) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const focusedCard = target.closest('[data-question-shortcuts]');
|
|
99
|
+
const firstCard = Array.from(root.ownerDocument.querySelectorAll('[data-question-shortcuts="true"]')).find((card) => !card.closest('[inert]') && card.getClientRects().length > 0);
|
|
100
|
+
if (focusedCard ? focusedCard !== root : firstCard !== root) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (event.key === 'Escape' && onClose && root.contains(target)) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
onClose();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!showShortcuts ||
|
|
110
|
+
[event.altKey, event.ctrlKey, event.metaKey].some(Boolean) ||
|
|
111
|
+
target.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])')) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const index = Number(event.key) - 1;
|
|
115
|
+
if (!/^[1-9]$/.test(event.key)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const option = options[index];
|
|
119
|
+
if (option) {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
answerOption(option.id);
|
|
122
|
+
}
|
|
123
|
+
else if (allowCustomAnswer && index === options.length) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const doc = (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
129
|
+
doc === null || doc === void 0 ? void 0 : doc.addEventListener('keydown', handleKeyDown);
|
|
130
|
+
return () => doc === null || doc === void 0 ? void 0 : doc.removeEventListener('keydown', handleKeyDown);
|
|
131
|
+
}, [allowCustomAnswer, answerOption, onClose, options, showShortcuts]);
|
|
132
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: b({ 'keyboard-focus': keyboardFocus }, className), "data-qa": qa, role: "group", "aria-labelledby": titleId, ref: rootRef, "data-question-shortcuts": showShortcuts, tabIndex: 0, onPointerDown: () => setKeyboardFocus(false), onKeyDown: (event) => {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
setKeyboardFocus(true);
|
|
135
|
+
if (event.altKey ||
|
|
136
|
+
event.ctrlKey ||
|
|
137
|
+
event.metaKey ||
|
|
138
|
+
event.nativeEvent.isComposing) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const target = event.target;
|
|
142
|
+
if (target.closest('input, textarea, select, [contenteditable="true"]')) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const answers = Array.from(event.currentTarget.querySelectorAll('[data-question-answer]'));
|
|
146
|
+
const currentAnswer = target.closest('[data-question-answer]');
|
|
147
|
+
const current = currentAnswer ? answers.indexOf(currentAnswer) : -1;
|
|
148
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
const next = current < 0
|
|
151
|
+
? 0
|
|
152
|
+
: (current + (event.key === 'ArrowDown' ? 1 : -1) + answers.length) %
|
|
153
|
+
answers.length;
|
|
154
|
+
(_a = answers[next]) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
155
|
+
}
|
|
156
|
+
else if (event.key === 'Enter' && target === customRowRef.current) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
(_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
159
|
+
}
|
|
160
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", { ref: contentRef, className: b('body'), children: [(0, jsx_runtime_1.jsxs)("div", { className: b('header'), children: [(0, jsx_runtime_1.jsx)("div", { id: titleId, className: b('question'), children: question }), (0, jsx_runtime_1.jsxs)("div", { className: b('actions'), children: [(0, jsx_runtime_1.jsxs)("span", { className: b('tool-label'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleQuestion, size: 16 }), t('tool-name')] }), questionCount > 1 && ((0, jsx_runtime_1.jsxs)("div", { className: b('navigation'), children: [(0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, { view: "flat", size: "m", "aria-label": t('previous'), tooltipTitle: t('previous'), tooltipPlacement: "top", disabled: !onQuestionChange || questionIndex <= 0, onClick: () => onQuestionChange === null || onQuestionChange === void 0 ? void 0 : onQuestionChange(questionIndex - 1), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.ChevronLeft, size: 16 }) }), (0, jsx_runtime_1.jsx)("span", { className: b('progress'), "aria-live": "polite", children: t('progress', {
|
|
161
|
+
current: questionIndex + 1,
|
|
162
|
+
total: questionCount,
|
|
163
|
+
}) }), (0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, { view: "flat", size: "m", "aria-label": t('next'), tooltipTitle: t('next'), tooltipPlacement: "top", disabled: !onQuestionChange || questionIndex >= questionCount - 1, onClick: () => onQuestionChange === null || onQuestionChange === void 0 ? void 0 : onQuestionChange(questionIndex + 1), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.ChevronRight, size: 16 }) })] })), onClose && ((0, jsx_runtime_1.jsx)(uikit_1.Button, { className: b('skip'), view: "normal", size: "m", onClick: onClose, children: t('skip') }))] })] }), (0, jsx_runtime_1.jsxs)("div", { className: b('answers'), children: [options.map((option, index) => ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: b('option', {
|
|
164
|
+
selected: (selectedAnswer === null || selectedAnswer === void 0 ? void 0 : selectedAnswer.type) === 'option' &&
|
|
165
|
+
selectedAnswer.optionId === option.id,
|
|
166
|
+
}), "aria-pressed": (selectedAnswer === null || selectedAnswer === void 0 ? void 0 : selectedAnswer.type) === 'option' &&
|
|
167
|
+
selectedAnswer.optionId === option.id, "data-question-answer": option.id, onClick: () => answerOption(option.id), children: [showShortcuts && index < 9 && ((0, jsx_runtime_1.jsx)("span", { className: b('shortcut'), "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(uikit_1.Hotkey, { className: b('hotkey'), value: String(index + 1) }) })), (0, jsx_runtime_1.jsxs)("span", { className: b('content'), children: [(0, jsx_runtime_1.jsxs)("span", { className: b('title'), children: [(0, jsx_runtime_1.jsx)("span", { children: option.title }), option.recommended && ((0, jsx_runtime_1.jsx)(uikit_1.Label, { size: "2xs", theme: "success", children: t('recommended') }))] }), option.description && ((0, jsx_runtime_1.jsx)("span", { className: b('description'), children: option.description }))] }), (0, jsx_runtime_1.jsx)("span", { className: b('trailing'), "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.ChevronRight, size: 16 }) })] }, option.id))), allowCustomAnswer && ((0, jsx_runtime_1.jsxs)("div", { className: b('custom', {
|
|
168
|
+
filled: hasValue,
|
|
169
|
+
selected: (selectedAnswer === null || selectedAnswer === void 0 ? void 0 : selectedAnswer.type) === 'custom',
|
|
170
|
+
}), ref: customRowRef, "data-question-answer": "custom", role: "group", "aria-label": customAnswerPlaceholder !== null && customAnswerPlaceholder !== void 0 ? customAnswerPlaceholder : t('placeholder'), tabIndex: -1, children: [showShortcuts && options.length < 9 && ((0, jsx_runtime_1.jsx)("span", { className: b('shortcut'), "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(uikit_1.Hotkey, { className: b('hotkey'), value: String(options.length + 1) }) })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, { controlRef: inputRef, view: "clear", size: "m", className: b('input'), value: value, placeholder: customAnswerPlaceholder !== null && customAnswerPlaceholder !== void 0 ? customAnswerPlaceholder : t('placeholder'), controlProps: {
|
|
171
|
+
'aria-label': customAnswerPlaceholder !== null && customAnswerPlaceholder !== void 0 ? customAnswerPlaceholder : t('placeholder'),
|
|
172
|
+
}, onUpdate: (nextValue) => {
|
|
173
|
+
setDraft({ questionKey, value: nextValue });
|
|
174
|
+
onCustomAnswerChange === null || onCustomAnswerChange === void 0 ? void 0 : onCustomAnswerChange(nextValue);
|
|
175
|
+
}, onKeyDown: (event) => {
|
|
176
|
+
if (event.key === 'Enter' && !event.nativeEvent.isComposing) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
submitCustom();
|
|
179
|
+
}
|
|
180
|
+
} }), hasValue && ((0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "normal", size: "m", onClick: submitCustom, children: t('confirm') }))] }))] }), footer && (0, jsx_runtime_1.jsx)("div", { className: b('footer'), children: footer }), answeredQuestionIndices && questionCount > 1 && ((0, jsx_runtime_1.jsx)("div", { className: b('progress-track'), ref: progressRef, role: "progressbar", "aria-label": t('answered-progress'), "aria-valuemin": 0, "aria-valuemax": questionCount, "aria-valuenow": answered.size, "aria-valuetext": t('answered-count', {
|
|
181
|
+
count: answered.size,
|
|
182
|
+
total: questionCount,
|
|
183
|
+
}), children: Array.from({ length: questionCount }, (_, index) => ((0, jsx_runtime_1.jsx)("span", { className: b('progress-segment', {
|
|
184
|
+
answered: answered.has(index),
|
|
185
|
+
}), children: (0, jsx_runtime_1.jsx)("span", { className: b('progress-fill') }) }, index))) }))] }) }));
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=AskUserQuestion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskUserQuestion.js","sourceRoot":"../../../../../src","sources":["components/organisms/AskUserQuestion/AskUserQuestion.tsx"],"names":[],"mappings":";;AAgBA,0CAkXC;;AAlYD,iCAAsE;AAEtE,6CAA4E;AAC5E,6CAAyE;AAEzE,6CAAwC;AACxC,oEAAsD;AAEtD,0CAA4B;AAE5B,sEAA8D;AAE9D,iCAAgC;AAEhC,MAAM,CAAC,GAAG,IAAA,UAAK,EAAC,mBAAmB,CAAC,CAAC;AAErC,SAAgB,eAAe,CAAC,EAC5B,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,cAAc,EACd,aAAa,GAAG,CAAC,EACjB,aAAa,GAAG,CAAC,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,OAA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AAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAC/C,iCAEI,SAAS,EAAE,CAAC,CAAC,kBAAkB,EAAE;4BAC7B,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;yBAChC,CAAC,YAEF,iCAAM,SAAS,EAAE,CAAC,CAAC,eAAe,CAAC,GAAI,IALlC,KAAK,CAMP,CACV,CAAC,GACA,CACT,IACC,GACJ,CACT,CAAC;AACN,CAAC","sourcesContent":["import {useCallback, useEffect, useId, useRef, useState} from 'react';\n\nimport {ChevronLeft, ChevronRight, CircleQuestion} from '@gravity-ui/icons';\nimport {Button, Hotkey, Icon, Label, TextInput} from '@gravity-ui/uikit';\n\nimport {block} from '../../../utils/cn';\nimport {ActionButton} from '../../atoms/ActionButton';\n\nimport {i18n} from './i18n';\nimport type {AskUserQuestionAnswer, AskUserQuestionProps} from './types';\nimport {useQuestionTransition} from './useQuestionTransition';\n\nimport './AskUserQuestion.scss';\n\nconst b = block('ask-user-question');\n\nexport function AskUserQuestion({\n question,\n options,\n onAnswer,\n selectedAnswer,\n questionIndex = 0,\n questionCount = 1,\n answeredQuestionIndices,\n onProgressComplete,\n onQuestionChange,\n onClose,\n allowCustomAnswer = true,\n customAnswer,\n onCustomAnswerChange,\n customAnswerPlaceholder,\n showShortcuts = true,\n footer,\n className,\n qa,\n}: AskUserQuestionProps) {\n const {t} = i18n.useTranslation();\n const titleId = useId();\n const answered = new Set(\n answeredQuestionIndices?.filter(\n (index) => Number.isInteger(index) && index >= 0 && index < questionCount,\n ),\n );\n const progressRef = useRef<HTMLDivElement>(null);\n const progressCompleteCallback = useRef(onProgressComplete);\n progressCompleteCallback.current = onProgressComplete;\n const progressComplete =\n Boolean(answeredQuestionIndices) && questionCount > 1 && answered.size === questionCount;\n useEffect(() => {\n if (!progressComplete) {\n return undefined;\n }\n let cancelled = false;\n const animations = progressRef.current?.getAnimations({subtree: true}) ?? [];\n Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {\n if (!cancelled) {\n progressCompleteCallback.current?.();\n }\n });\n return () => {\n cancelled = true;\n };\n }, [progressComplete]);\n const contentRef = useRef<HTMLDivElement>(null);\n const rootRef = useRef<HTMLDivElement>(null);\n useQuestionTransition(rootRef, contentRef);\n const inputRef = useRef<HTMLInputElement>(null);\n const customRowRef = useRef<HTMLDivElement>(null);\n const selectedOptions = useRef(new Map<string, AskUserQuestionAnswer>());\n const questionKey = `${questionIndex}:${question}`;\n const selectedAnswerRef = useRef(selectedAnswer);\n selectedAnswerRef.current = selectedAnswer;\n const [keyboardFocus, setKeyboardFocus] = useState(true);\n const answerOption = useCallback(\n (optionId: string) => {\n selectedOptions.current.set(questionKey, {type: 'option', optionId});\n onAnswer({type: 'option', optionId});\n },\n [onAnswer, questionKey],\n );\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root || root.closest('[inert]')) {\n return;\n }\n const active = root.ownerDocument.activeElement;\n if (\n active &&\n !root.contains(active) &&\n active.matches(\n 'input, textarea, select, [contenteditable]:not([contenteditable=\"false\"])',\n ) &&\n !(active instanceof HTMLTextAreaElement && !active.value.trim())\n ) {\n return;\n }\n if (active?.closest('[data-question-shortcuts]') && !root.contains(active)) {\n return;\n }\n setKeyboardFocus(true);\n const answers = Array.from(root.querySelectorAll<HTMLElement>('[data-question-answer]'));\n const saved = selectedAnswerRef.current ?? selectedOptions.current.get(questionKey);\n const target =\n (saved?.type === 'custom'\n ? customRowRef.current\n : answers.find((item) => item.dataset.questionAnswer === saved?.optionId)) ??\n answers[0];\n target?.focus({preventScroll: true});\n }, [questionKey]);\n const [draft, setDraft] = useState({questionKey, value: ''});\n const value = customAnswer ?? (draft.questionKey === questionKey ? draft.value : '');\n const hasValue = Boolean(value.trim());\n\n const submitCustom = () => {\n if (hasValue) {\n selectedOptions.current.set(questionKey, {type: 'custom', value: value.trim()});\n onAnswer({type: 'custom', value: value.trim()});\n }\n };\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.defaultPrevented || event.repeat || event.isComposing) {\n return;\n }\n const root = rootRef.current;\n const target = event.target as HTMLElement;\n if (!root || !target.closest) {\n return;\n }\n const focusedCard = target.closest('[data-question-shortcuts]');\n const firstCard = Array.from(\n root.ownerDocument.querySelectorAll<HTMLElement>(\n '[data-question-shortcuts=\"true\"]',\n ),\n ).find((card) => !card.closest('[inert]') && card.getClientRects().length > 0);\n if (focusedCard ? focusedCard !== root : firstCard !== root) {\n return;\n }\n if (event.key === 'Escape' && onClose && root.contains(target)) {\n event.preventDefault();\n event.stopPropagation();\n onClose();\n return;\n }\n if (\n !showShortcuts ||\n [event.altKey, event.ctrlKey, event.metaKey].some(Boolean) ||\n target.closest(\n 'input, textarea, select, [contenteditable]:not([contenteditable=\"false\"])',\n )\n ) {\n return;\n }\n const index = Number(event.key) - 1;\n if (!/^[1-9]$/.test(event.key)) {\n return;\n }\n const option = options[index];\n if (option) {\n event.preventDefault();\n answerOption(option.id);\n } else if (allowCustomAnswer && index === options.length) {\n event.preventDefault();\n inputRef.current?.focus();\n }\n };\n const doc = rootRef.current?.ownerDocument;\n doc?.addEventListener('keydown', handleKeyDown);\n return () => doc?.removeEventListener('keydown', handleKeyDown);\n }, [allowCustomAnswer, answerOption, onClose, options, showShortcuts]);\n\n return (\n <div\n className={b({'keyboard-focus': keyboardFocus}, className)}\n data-qa={qa}\n role=\"group\"\n aria-labelledby={titleId}\n ref={rootRef}\n data-question-shortcuts={showShortcuts}\n tabIndex={0}\n onPointerDown={() => setKeyboardFocus(false)}\n onKeyDown={(event) => {\n setKeyboardFocus(true);\n if (\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.nativeEvent.isComposing\n ) {\n return;\n }\n const target = event.target as HTMLElement;\n if (target.closest('input, textarea, select, [contenteditable=\"true\"]')) {\n return;\n }\n const answers = Array.from(\n event.currentTarget.querySelectorAll<HTMLElement>('[data-question-answer]'),\n );\n const currentAnswer = target.closest<HTMLElement>('[data-question-answer]');\n const current = currentAnswer ? answers.indexOf(currentAnswer) : -1;\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault();\n const next =\n current < 0\n ? 0\n : (current + (event.key === 'ArrowDown' ? 1 : -1) + answers.length) %\n answers.length;\n answers[next]?.focus({preventScroll: true});\n } else if (event.key === 'Enter' && target === customRowRef.current) {\n event.preventDefault();\n inputRef.current?.focus();\n }\n }}\n >\n <div ref={contentRef} className={b('body')}>\n <div className={b('header')}>\n <div id={titleId} className={b('question')}>\n {question}\n </div>\n <div className={b('actions')}>\n <span className={b('tool-label')}>\n <Icon data={CircleQuestion} size={16} />\n {t('tool-name')}\n </span>\n {questionCount > 1 && (\n <div className={b('navigation')}>\n <ActionButton\n view=\"flat\"\n size=\"m\"\n aria-label={t('previous')}\n tooltipTitle={t('previous')}\n tooltipPlacement=\"top\"\n disabled={!onQuestionChange || questionIndex <= 0}\n onClick={() => onQuestionChange?.(questionIndex - 1)}\n >\n <Icon data={ChevronLeft} size={16} />\n </ActionButton>\n <span className={b('progress')} aria-live=\"polite\">\n {t('progress', {\n current: questionIndex + 1,\n total: questionCount,\n })}\n </span>\n <ActionButton\n view=\"flat\"\n size=\"m\"\n aria-label={t('next')}\n tooltipTitle={t('next')}\n tooltipPlacement=\"top\"\n disabled={\n !onQuestionChange || questionIndex >= questionCount - 1\n }\n onClick={() => onQuestionChange?.(questionIndex + 1)}\n >\n <Icon data={ChevronRight} size={16} />\n </ActionButton>\n </div>\n )}\n {onClose && (\n <Button className={b('skip')} view=\"normal\" size=\"m\" onClick={onClose}>\n {t('skip')}\n </Button>\n )}\n </div>\n </div>\n <div className={b('answers')}>\n {options.map((option, index) => (\n <button\n key={option.id}\n type=\"button\"\n className={b('option', {\n selected:\n selectedAnswer?.type === 'option' &&\n selectedAnswer.optionId === option.id,\n })}\n aria-pressed={\n selectedAnswer?.type === 'option' &&\n selectedAnswer.optionId === option.id\n }\n data-question-answer={option.id}\n onClick={() => answerOption(option.id)}\n >\n {showShortcuts && index < 9 && (\n <span className={b('shortcut')} aria-hidden=\"true\">\n <Hotkey className={b('hotkey')} value={String(index + 1)} />\n </span>\n )}\n <span className={b('content')}>\n <span className={b('title')}>\n <span>{option.title}</span>\n {option.recommended && (\n <Label size=\"2xs\" theme=\"success\">\n {t('recommended')}\n </Label>\n )}\n </span>\n {option.description && (\n <span className={b('description')}>{option.description}</span>\n )}\n </span>\n <span className={b('trailing')} aria-hidden=\"true\">\n <Icon data={ChevronRight} size={16} />\n </span>\n </button>\n ))}\n {allowCustomAnswer && (\n <div\n className={b('custom', {\n filled: hasValue,\n selected: selectedAnswer?.type === 'custom',\n })}\n ref={customRowRef}\n data-question-answer=\"custom\"\n role=\"group\"\n aria-label={customAnswerPlaceholder ?? t('placeholder')}\n tabIndex={-1}\n >\n {showShortcuts && options.length < 9 && (\n <span className={b('shortcut')} aria-hidden=\"true\">\n <Hotkey\n className={b('hotkey')}\n value={String(options.length + 1)}\n />\n </span>\n )}\n <TextInput\n controlRef={inputRef}\n view=\"clear\"\n size=\"m\"\n className={b('input')}\n value={value}\n placeholder={customAnswerPlaceholder ?? t('placeholder')}\n controlProps={{\n 'aria-label': customAnswerPlaceholder ?? t('placeholder'),\n }}\n onUpdate={(nextValue) => {\n setDraft({questionKey, value: nextValue});\n onCustomAnswerChange?.(nextValue);\n }}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && !event.nativeEvent.isComposing) {\n event.preventDefault();\n submitCustom();\n }\n }}\n />\n {hasValue && (\n <Button view=\"normal\" size=\"m\" onClick={submitCustom}>\n {t('confirm')}\n </Button>\n )}\n </div>\n )}\n </div>\n {footer && <div className={b('footer')}>{footer}</div>}\n {answeredQuestionIndices && questionCount > 1 && (\n <div\n className={b('progress-track')}\n ref={progressRef}\n role=\"progressbar\"\n aria-label={t('answered-progress')}\n aria-valuemin={0}\n aria-valuemax={questionCount}\n aria-valuenow={answered.size}\n aria-valuetext={t('answered-count', {\n count: answered.size,\n total: questionCount,\n })}\n >\n {Array.from({length: questionCount}, (_, index) => (\n <span\n key={index}\n className={b('progress-segment', {\n answered: answered.has(index),\n })}\n >\n <span className={b('progress-fill')} />\n </span>\n ))}\n </div>\n )}\n </div>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"previous": "Previous question",
|
|
3
|
+
"next": "Next question",
|
|
4
|
+
"skip": "Skip",
|
|
5
|
+
"answered-progress": "Answered questions",
|
|
6
|
+
"answered-count": "{{count}} of {{total}} answered",
|
|
7
|
+
"progress": "{{current}} of {{total}}",
|
|
8
|
+
"recommended": "Recommended",
|
|
9
|
+
"placeholder": "Write your own response",
|
|
10
|
+
"confirm": "Confirm",
|
|
11
|
+
"tool-name": "Question"
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const i18n: ((key: "progress" | "next" | "previous" | "placeholder" | "skip" | "answered-progress" | "answered-count" | "recommended" | "confirm" | "tool-name", params?: import("@gravity-ui/i18n").Params) => string) & {
|
|
2
|
+
Translation: import("react").ComponentType<{
|
|
3
|
+
children: (props: {
|
|
4
|
+
t: (key: "progress" | "next" | "previous" | "placeholder" | "skip" | "answered-progress" | "answered-count" | "recommended" | "confirm" | "tool-name", params?: import("@gravity-ui/i18n").Params) => string;
|
|
5
|
+
}) => React.ReactNode;
|
|
6
|
+
}>;
|
|
7
|
+
useTranslation: () => {
|
|
8
|
+
t: (key: "progress" | "next" | "previous" | "placeholder" | "skip" | "answered-progress" | "answered-count" | "recommended" | "confirm" | "tool-name", params?: import("@gravity-ui/i18n").Params) => string;
|
|
9
|
+
};
|
|
10
|
+
keysetData: {
|
|
11
|
+
"g-aikit.AskUserQuestion": Record<"progress" | "next" | "previous" | "placeholder" | "skip" | "answered-progress" | "answered-count" | "recommended" | "confirm" | "tool-name", import("@gravity-ui/i18n").KeyData>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.i18n = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const i18n_1 = require("@gravity-ui/uikit/i18n");
|
|
6
|
+
const en_json_1 = tslib_1.__importDefault(require("./en.json"));
|
|
7
|
+
const ru_json_1 = tslib_1.__importDefault(require("./ru.json"));
|
|
8
|
+
exports.i18n = (0, i18n_1.addComponentKeysets)({ en: en_json_1.default, ru: ru_json_1.default }, 'g-aikit.AskUserQuestion');
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["components/organisms/AskUserQuestion/i18n/index.ts"],"names":[],"mappings":";;;;AAAA,iDAA2D;AAE3D,gEAA2B;AAC3B,gEAA2B;AAEd,QAAA,IAAI,GAAG,IAAA,0BAAmB,EAAC,EAAC,EAAE,EAAF,iBAAE,EAAE,EAAE,EAAF,iBAAE,EAAC,EAAE,yBAAyB,CAAC,CAAC","sourcesContent":["import {addComponentKeysets} from '@gravity-ui/uikit/i18n';\n\nimport en from './en.json';\nimport ru from './ru.json';\n\nexport const i18n = addComponentKeysets({en, ru}, 'g-aikit.AskUserQuestion');\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"previous": "Предыдущий вопрос",
|
|
3
|
+
"next": "Следующий вопрос",
|
|
4
|
+
"skip": "Пропустить",
|
|
5
|
+
"answered-progress": "Отвеченные вопросы",
|
|
6
|
+
"answered-count": "Отвечено на {{count}} из {{total}}",
|
|
7
|
+
"progress": "{{current}} из {{total}}",
|
|
8
|
+
"recommended": "Рекомендуется",
|
|
9
|
+
"placeholder": "Напишите свой ответ",
|
|
10
|
+
"confirm": "Подтвердить",
|
|
11
|
+
"tool-name": "Вопрос"
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AskUserQuestion = void 0;
|
|
4
|
+
var AskUserQuestion_1 = require("./AskUserQuestion.js");
|
|
5
|
+
Object.defineProperty(exports, "AskUserQuestion", { enumerable: true, get: function () { return AskUserQuestion_1.AskUserQuestion; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../../../../../src","sources":["components/organisms/AskUserQuestion/index.ts"],"names":[],"mappings":";;;AAAA,wDAAkD;AAA1C,kHAAA,eAAe,OAAA","sourcesContent":["export {AskUserQuestion} from './AskUserQuestion';\nexport type {AskUserQuestionProps, AskUserQuestionOption, AskUserQuestionAnswer} from './types';\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface AskUserQuestionOption {
|
|
3
|
+
id: string;
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
recommended?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type AskUserQuestionAnswer = {
|
|
9
|
+
type: 'option';
|
|
10
|
+
optionId: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'custom';
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
export interface AskUserQuestionProps {
|
|
16
|
+
question: string;
|
|
17
|
+
options: AskUserQuestionOption[];
|
|
18
|
+
/** Emits one answer. The host saves it and resumes the run once all required answers are collected. */
|
|
19
|
+
onAnswer: (answer: AskUserQuestionAnswer) => void;
|
|
20
|
+
/** Saved answer for the current question, controlled by the host. */
|
|
21
|
+
selectedAnswer?: AskUserQuestionAnswer;
|
|
22
|
+
/** Zero-based question index. Navigation is controlled by the host. */
|
|
23
|
+
questionIndex?: number;
|
|
24
|
+
questionCount?: number;
|
|
25
|
+
/** Optional segmented progress. Zero-based indices of answered questions; skips are excluded. */
|
|
26
|
+
answeredQuestionIndices?: readonly number[];
|
|
27
|
+
/** All progress segments are filled and their animations have finished. Not emitted without multi-question progress. */
|
|
28
|
+
onProgressComplete?: () => void;
|
|
29
|
+
onQuestionChange?: (index: number) => void;
|
|
30
|
+
/** Close/skip notification only; does not submit an answer or select a default. */
|
|
31
|
+
onClose?: () => void;
|
|
32
|
+
allowCustomAnswer?: boolean;
|
|
33
|
+
customAnswer?: string;
|
|
34
|
+
onCustomAnswerChange?: (value: string) => void;
|
|
35
|
+
customAnswerPlaceholder?: string;
|
|
36
|
+
showShortcuts?: boolean;
|
|
37
|
+
/** Optional additional host-provided footer content. */
|
|
38
|
+
footer?: ReactNode;
|
|
39
|
+
className?: string;
|
|
40
|
+
qa?: string;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../../../../../src","sources":["components/organisms/AskUserQuestion/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {ReactNode} from 'react';\n\nexport interface AskUserQuestionOption {\n id: string;\n title: ReactNode;\n description?: ReactNode;\n recommended?: boolean;\n}\n\nexport type AskUserQuestionAnswer =\n | {type: 'option'; optionId: string}\n | {type: 'custom'; value: string};\n\nexport interface AskUserQuestionProps {\n question: string;\n options: AskUserQuestionOption[];\n /** Emits one answer. The host saves it and resumes the run once all required answers are collected. */\n onAnswer: (answer: AskUserQuestionAnswer) => void;\n /** Saved answer for the current question, controlled by the host. */\n selectedAnswer?: AskUserQuestionAnswer;\n /** Zero-based question index. Navigation is controlled by the host. */\n questionIndex?: number;\n questionCount?: number;\n /** Optional segmented progress. Zero-based indices of answered questions; skips are excluded. */\n answeredQuestionIndices?: readonly number[];\n /** All progress segments are filled and their animations have finished. Not emitted without multi-question progress. */\n onProgressComplete?: () => void;\n onQuestionChange?: (index: number) => void;\n /** Close/skip notification only; does not submit an answer or select a default. */\n onClose?: () => void;\n allowCustomAnswer?: boolean;\n customAnswer?: string;\n onCustomAnswerChange?: (value: string) => void;\n customAnswerPlaceholder?: string;\n showShortcuts?: boolean;\n /** Optional additional host-provided footer content. */\n footer?: ReactNode;\n className?: string;\n qa?: string;\n}\n"]}
|