@snack-uikit/stepper 0.6.13 → 0.6.15-preview-1f246c4a.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/StepperContext/StepperContext.js +28 -0
  3. package/dist/cjs/StepperContext/index.js +25 -0
  4. package/dist/cjs/components/Stepper/Stepper.js +183 -0
  5. package/dist/cjs/components/Stepper/index.js +25 -0
  6. package/dist/cjs/components/index.js +25 -0
  7. package/dist/cjs/constants.js +13 -0
  8. package/dist/cjs/helperComponents/Icon/Icon.js +48 -0
  9. package/dist/cjs/helperComponents/Icon/index.js +25 -0
  10. package/dist/cjs/helperComponents/Step/Step.js +81 -0
  11. package/dist/cjs/helperComponents/Step/index.js +25 -0
  12. package/dist/cjs/helperComponents/index.js +26 -0
  13. package/dist/cjs/index.js +33 -0
  14. package/dist/cjs/types.js +5 -0
  15. package/dist/cjs/utils.js +8 -0
  16. package/dist/esm/StepperContext/StepperContext.d.ts +4 -0
  17. package/dist/esm/StepperContext/index.js +1 -0
  18. package/dist/esm/components/Stepper/Stepper.d.ts +27 -0
  19. package/dist/esm/components/index.d.ts +1 -0
  20. package/dist/esm/components/index.js +1 -0
  21. package/dist/esm/constants.d.ts +7 -0
  22. package/dist/esm/helperComponents/Icon/Icon.d.ts +7 -0
  23. package/dist/esm/helperComponents/Icon/index.js +1 -0
  24. package/dist/esm/helperComponents/Step/Step.d.ts +8 -0
  25. package/dist/esm/helperComponents/Step/index.js +1 -0
  26. package/dist/esm/helperComponents/index.js +2 -0
  27. package/dist/esm/index.js +2 -0
  28. package/dist/esm/types.d.ts +24 -0
  29. package/dist/esm/utils.d.ts +1 -0
  30. package/package.json +12 -10
  31. package/dist/components/Stepper/styles.module.css +0 -5
  32. package/dist/helperComponents/Icon/styles.module.css +0 -38
  33. package/dist/helperComponents/Step/styles.module.css +0 -83
  34. /package/dist/{StepperContext → cjs/StepperContext}/StepperContext.d.ts +0 -0
  35. /package/dist/{StepperContext → cjs/StepperContext}/index.d.ts +0 -0
  36. /package/dist/{components → cjs/components}/Stepper/Stepper.d.ts +0 -0
  37. /package/dist/{components → cjs/components}/Stepper/index.d.ts +0 -0
  38. /package/dist/{components → cjs/components}/index.d.ts +0 -0
  39. /package/dist/{constants.d.ts → cjs/constants.d.ts} +0 -0
  40. /package/dist/{helperComponents → cjs/helperComponents}/Icon/Icon.d.ts +0 -0
  41. /package/dist/{helperComponents → cjs/helperComponents}/Icon/index.d.ts +0 -0
  42. /package/dist/{helperComponents → cjs/helperComponents}/Step/Step.d.ts +0 -0
  43. /package/dist/{helperComponents → cjs/helperComponents}/Step/index.d.ts +0 -0
  44. /package/dist/{helperComponents → cjs/helperComponents}/index.d.ts +0 -0
  45. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  46. /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
  47. /package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
  48. /package/dist/{StepperContext → esm/StepperContext}/StepperContext.js +0 -0
  49. /package/dist/{StepperContext/index.js → esm/StepperContext/index.d.ts} +0 -0
  50. /package/dist/{components → esm/components}/Stepper/Stepper.js +0 -0
  51. /package/dist/{components/Stepper/index.js → esm/components/Stepper/index.d.ts} +0 -0
  52. /package/dist/{components → esm/components/Stepper}/index.js +0 -0
  53. /package/dist/{constants.js → esm/constants.js} +0 -0
  54. /package/dist/{helperComponents → esm/helperComponents}/Icon/Icon.js +0 -0
  55. /package/dist/{helperComponents/Icon/index.js → esm/helperComponents/Icon/index.d.ts} +0 -0
  56. /package/dist/{helperComponents → esm/helperComponents}/Step/Step.js +0 -0
  57. /package/dist/{helperComponents/Step/index.js → esm/helperComponents/Step/index.d.ts} +0 -0
  58. /package/dist/{helperComponents/index.js → esm/helperComponents/index.d.ts} +0 -0
  59. /package/dist/{index.js → esm/index.d.ts} +0 -0
  60. /package/dist/{types.js → esm/types.js} +0 -0
  61. /package/dist/{utils.js → esm/utils.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
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.6.14 (2024-09-26)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/truncate-string@0.4.24](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/truncate-string/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
6
15
  ## 0.6.13 (2024-09-24)
7
16
 
8
17
  ### Only dependencies have been changed
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useStepperApi = exports.StepperContext = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("react");
9
+ exports.StepperContext = (0, react_1.createContext)({
10
+ stepper: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}),
11
+ stepCount: 0,
12
+ isCompleted: false,
13
+ currentStepIndex: 0,
14
+ goNext() {
15
+ /* stub */
16
+ },
17
+ goPrev() {
18
+ /* stub */
19
+ },
20
+ resetValidation() {
21
+ /* stub */
22
+ },
23
+ setValidator() {
24
+ /* stub */
25
+ }
26
+ });
27
+ const useStepperApi = () => (0, react_1.useContext)(exports.StepperContext);
28
+ exports.useStepperApi = useStepperApi;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./StepperContext"), exports);
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P ? value : new P(function (resolve) {
6
+ resolve(value);
7
+ });
8
+ }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) {
11
+ try {
12
+ step(generator.next(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ }
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+ function step(result) {
25
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
26
+ }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
31
+ var t = {};
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
33
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
34
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
35
+ }
36
+ return t;
37
+ };
38
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
39
+ return mod && mod.__esModule ? mod : {
40
+ "default": mod
41
+ };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", {
44
+ value: true
45
+ });
46
+ exports.Stepper = Stepper;
47
+ const jsx_runtime_1 = require("react/jsx-runtime");
48
+ const classnames_1 = __importDefault(require("classnames"));
49
+ const react_1 = require("react");
50
+ const utils_1 = require("@snack-uikit/utils");
51
+ const constants_1 = require("../../constants");
52
+ const helperComponents_1 = require("../../helperComponents");
53
+ const StepperContext_1 = require("../../StepperContext");
54
+ const styles_module_scss_1 = __importDefault({});
55
+ const DEFAULT_VALIDATOR = () => __awaiter(void 0, void 0, void 0, function* () {
56
+ return true;
57
+ });
58
+ function Stepper(_a) {
59
+ var {
60
+ children,
61
+ steps,
62
+ className,
63
+ onChangeCurrentStep,
64
+ onCompleteChange,
65
+ defaultCurrentStepIndex = 0,
66
+ validator: validatorProp = DEFAULT_VALIDATOR
67
+ } = _a,
68
+ props = __rest(_a, ["children", "steps", "className", "onChangeCurrentStep", "onCompleteChange", "defaultCurrentStepIndex", "validator"]);
69
+ const isCompletedByDefault = defaultCurrentStepIndex === steps.length - 1;
70
+ const [currentStepState, setCurrentStepState] = (0, react_1.useState)(isCompletedByDefault ? constants_1.STEP_STATE.Completed : constants_1.STEP_STATE.Current);
71
+ const [currentStepIndex, setCurrentStepIndexValue] = (0, react_1.useState)(defaultCurrentStepIndex);
72
+ const [isCompleted, setIsCompleted] = (0, react_1.useState)(isCompletedByDefault);
73
+ const [stepsValidator, setStepsValidator] = (0, react_1.useState)();
74
+ (0, react_1.useEffect)(() => {
75
+ onCompleteChange === null || onCompleteChange === void 0 ? void 0 : onCompleteChange(isCompleted);
76
+ }, [isCompleted, onCompleteChange]);
77
+ const setCurrentStepIndex = (0, react_1.useCallback)(newValue => {
78
+ setCurrentStepIndexValue(prevValue => {
79
+ if (prevValue !== newValue) {
80
+ onChangeCurrentStep === null || onChangeCurrentStep === void 0 ? void 0 : onChangeCurrentStep(newValue, prevValue);
81
+ }
82
+ return newValue;
83
+ });
84
+ }, [onChangeCurrentStep]);
85
+ const goNext = (0, react_1.useCallback)(function () {
86
+ let newStepIndexUnsafety = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : currentStepIndex + 1;
87
+ if (currentStepIndex >= steps.length || isCompleted || newStepIndexUnsafety <= currentStepIndex) {
88
+ return;
89
+ }
90
+ const newStepIndex = Math.min(steps.length - 1, newStepIndexUnsafety);
91
+ setCurrentStepState(constants_1.STEP_STATE.Loading);
92
+ const validator = (stepsValidator === null || stepsValidator === void 0 ? void 0 : stepsValidator.value) || validatorProp;
93
+ validator(currentStepIndex, newStepIndex).catch(() => false).then(isValid => {
94
+ if (!isValid) {
95
+ setCurrentStepState(constants_1.STEP_STATE.Rejected);
96
+ return;
97
+ }
98
+ if (currentStepIndex === steps.length - 1) {
99
+ // завершился последний шаг
100
+ setCurrentStepState(constants_1.STEP_STATE.Completed);
101
+ setIsCompleted(true);
102
+ } else {
103
+ setCurrentStepIndex(newStepIndex);
104
+ setCurrentStepState(constants_1.STEP_STATE.Current);
105
+ }
106
+ });
107
+ }, [currentStepIndex, isCompleted, setCurrentStepIndex, steps.length, stepsValidator === null || stepsValidator === void 0 ? void 0 : stepsValidator.value, validatorProp]);
108
+ const goPrev = (0, react_1.useCallback)(function () {
109
+ let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : currentStepIndex - 1;
110
+ if (currentStepIndex === 0 || index < 0 || index > currentStepIndex) {
111
+ return;
112
+ }
113
+ if (index === currentStepIndex && !isCompleted) {
114
+ return;
115
+ }
116
+ if (isCompleted) {
117
+ setIsCompleted(false);
118
+ }
119
+ setCurrentStepIndex(index);
120
+ setCurrentStepState(constants_1.STEP_STATE.Current);
121
+ }, [currentStepIndex, isCompleted, setCurrentStepIndex]);
122
+ const stepsView = (0, react_1.useMemo)(() => steps.map((step, index) => {
123
+ const number = index + 1;
124
+ if (index < currentStepIndex) {
125
+ return Object.assign(Object.assign({}, step), {
126
+ number,
127
+ state: constants_1.STEP_STATE.Completed,
128
+ onClick: () => goPrev(index)
129
+ });
130
+ }
131
+ if (index === currentStepIndex) {
132
+ return Object.assign(Object.assign({}, step), {
133
+ number,
134
+ state: currentStepState,
135
+ onClick: isCompleted ? () => goPrev(index) : undefined
136
+ });
137
+ }
138
+ if (index - 1 === currentStepIndex) {
139
+ return Object.assign(Object.assign({}, step), {
140
+ number,
141
+ state: constants_1.STEP_STATE.Waiting,
142
+ onClick: () => goNext()
143
+ });
144
+ }
145
+ return Object.assign(Object.assign({}, step), {
146
+ number,
147
+ state: constants_1.STEP_STATE.Waiting
148
+ });
149
+ }), [steps, currentStepIndex, goPrev, currentStepState, isCompleted, goNext]);
150
+ const resetValidation = (0, react_1.useCallback)(() => {
151
+ if (currentStepState === constants_1.STEP_STATE.Rejected) {
152
+ setCurrentStepState(constants_1.STEP_STATE.Current);
153
+ }
154
+ }, [currentStepState]);
155
+ const setValidator = (0, react_1.useCallback)(validator => {
156
+ setStepsValidator({
157
+ value: validator
158
+ });
159
+ }, []);
160
+ const stepper = (0, jsx_runtime_1.jsx)("div", Object.assign({
161
+ className: (0, classnames_1.default)(styles_module_scss_1.default.stepper, className)
162
+ }, (0, utils_1.extractSupportProps)(props), {
163
+ children: stepsView.map((step, index) => (0, jsx_runtime_1.jsx)(helperComponents_1.Step, {
164
+ step: step,
165
+ "data-test-id": props['data-test-id'],
166
+ hideTailLine: index === steps.length - 1
167
+ }, step.title + index))
168
+ }));
169
+ const stepperApi = {
170
+ goNext,
171
+ goPrev,
172
+ currentStepIndex,
173
+ isCompleted,
174
+ resetValidation,
175
+ stepCount: steps.length,
176
+ stepper,
177
+ setValidator
178
+ };
179
+ return (0, jsx_runtime_1.jsx)(StepperContext_1.StepperContext.Provider, {
180
+ value: stepperApi,
181
+ children: children(stepperApi)
182
+ });
183
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./Stepper"), exports);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./Stepper"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.STEP_STATE = void 0;
7
+ exports.STEP_STATE = {
8
+ Completed: 'completed',
9
+ Current: 'current',
10
+ Loading: 'loading',
11
+ Waiting: 'waiting',
12
+ Rejected: 'rejected'
13
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
4
+ return mod && mod.__esModule ? mod : {
5
+ "default": mod
6
+ };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.Icon = Icon;
12
+ const jsx_runtime_1 = require("react/jsx-runtime");
13
+ const classnames_1 = __importDefault(require("classnames"));
14
+ const react_1 = require("react");
15
+ const icons_1 = require("@snack-uikit/icons");
16
+ const loaders_1 = require("@snack-uikit/loaders");
17
+ const typography_1 = require("@snack-uikit/typography");
18
+ const constants_1 = require("../../constants");
19
+ const styles_module_scss_1 = __importDefault({});
20
+ function getContent(state, number) {
21
+ switch (state) {
22
+ case constants_1.STEP_STATE.Completed:
23
+ return (0, jsx_runtime_1.jsx)(icons_1.CheckSVG, {});
24
+ case constants_1.STEP_STATE.Rejected:
25
+ return (0, jsx_runtime_1.jsx)(icons_1.CrossSVG, {});
26
+ case constants_1.STEP_STATE.Loading:
27
+ return (0, jsx_runtime_1.jsx)(loaders_1.Sun, {
28
+ size: 's'
29
+ });
30
+ default:
31
+ return number;
32
+ }
33
+ }
34
+ function Icon(_ref) {
35
+ let {
36
+ state,
37
+ number,
38
+ className
39
+ } = _ref;
40
+ const content = (0, react_1.useMemo)(() => getContent(state, number), [number, state]);
41
+ return (0, jsx_runtime_1.jsx)("div", {
42
+ "data-state": state,
43
+ className: (0, classnames_1.default)(styles_module_scss_1.default.icon, className),
44
+ children: typeof content === 'number' ? (0, jsx_runtime_1.jsx)(typography_1.Typography.SansLabelL, {
45
+ children: content
46
+ }) : content
47
+ });
48
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./Icon"), exports);
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8
+ }
9
+ return t;
10
+ };
11
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
12
+ return mod && mod.__esModule ? mod : {
13
+ "default": mod
14
+ };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+ exports.Step = Step;
20
+ const jsx_runtime_1 = require("react/jsx-runtime");
21
+ const classnames_1 = __importDefault(require("classnames"));
22
+ const truncate_string_1 = require("@snack-uikit/truncate-string");
23
+ const typography_1 = require("@snack-uikit/typography");
24
+ const utils_1 = require("@snack-uikit/utils");
25
+ const constants_1 = require("../../constants");
26
+ const utils_2 = require("../../utils");
27
+ const Icon_1 = require("../Icon");
28
+ const styles_module_scss_1 = __importDefault({});
29
+ const getTailTestId = (0, utils_2.getTestIdBuilder)('_element-tail');
30
+ const getStepTestId = (0, utils_2.getTestIdBuilder)('_element-step');
31
+ function Step(_a) {
32
+ var {
33
+ step,
34
+ className,
35
+ 'data-test-id': testId,
36
+ hideTailLine
37
+ } = _a,
38
+ props = __rest(_a, ["step", "className", 'data-test-id', "hideTailLine"]);
39
+ return (0, jsx_runtime_1.jsxs)("div", Object.assign({
40
+ className: (0, classnames_1.default)(styles_module_scss_1.default.step, className),
41
+ "data-state": step.state
42
+ }, (0, utils_1.extractSupportProps)(props), {
43
+ children: [(0, jsx_runtime_1.jsxs)("div", {
44
+ className: styles_module_scss_1.default.track,
45
+ children: [(0, jsx_runtime_1.jsx)("button", {
46
+ type: 'button',
47
+ className: styles_module_scss_1.default.statusContainer,
48
+ onClick: step.onClick,
49
+ disabled: !step.onClick,
50
+ "data-test-id": getStepTestId(testId),
51
+ "data-state": step.state,
52
+ children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, Object.assign({}, step, {
53
+ className: styles_module_scss_1.default.icon
54
+ }))
55
+ }), !hideTailLine && (0, jsx_runtime_1.jsx)("div", {
56
+ className: styles_module_scss_1.default.tail,
57
+ "data-completed": step.state === constants_1.STEP_STATE.Completed || undefined,
58
+ "data-test-id": getTailTestId(testId),
59
+ children: (0, jsx_runtime_1.jsx)("div", {
60
+ className: styles_module_scss_1.default.tailLine
61
+ })
62
+ })]
63
+ }), (0, jsx_runtime_1.jsxs)("div", {
64
+ className: styles_module_scss_1.default.content,
65
+ children: [(0, jsx_runtime_1.jsx)(typography_1.Typography.SansBodyM, {
66
+ className: styles_module_scss_1.default.title,
67
+ tag: 'div',
68
+ children: (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
69
+ text: step.title
70
+ })
71
+ }), step.description && (0, jsx_runtime_1.jsx)(typography_1.Typography.SansBodyS, {
72
+ className: styles_module_scss_1.default.description,
73
+ tag: 'div',
74
+ children: (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
75
+ text: step.description,
76
+ maxLines: 2
77
+ })
78
+ })]
79
+ })]
80
+ }));
81
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./Step"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./Step"), exports);
26
+ __exportStar(require("./Icon"), exports);
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ exports.useStepperApi = void 0;
26
+ __exportStar(require("./components"), exports);
27
+ var StepperContext_1 = require("./StepperContext");
28
+ Object.defineProperty(exports, "useStepperApi", {
29
+ enumerable: true,
30
+ get: function () {
31
+ return StepperContext_1.useStepperApi;
32
+ }
33
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTestIdBuilder = void 0;
7
+ const getTestIdBuilder = postfix => testId => postfix && testId ? `${testId}${postfix}` : undefined;
8
+ exports.getTestIdBuilder = getTestIdBuilder;
@@ -0,0 +1,4 @@
1
+ import { StepperApi } from '../types';
2
+ export type StepperContextValue = StepperApi;
3
+ export declare const StepperContext: import("react").Context<StepperApi>;
4
+ export declare const useStepperApi: () => StepperApi;
@@ -0,0 +1 @@
1
+ export * from './StepperContext';
@@ -0,0 +1,27 @@
1
+ import { ReactElement } from 'react';
2
+ import { WithSupportProps } from '@snack-uikit/utils';
3
+ import { StepData, StepperApi, StepsValidator } from '../../types';
4
+ export type StepperState = StepperApi & {
5
+ stepper: ReactElement;
6
+ };
7
+ export type StepperProps = WithSupportProps<{
8
+ /** Массив шагов */
9
+ steps: StepData[];
10
+ /** Индекс текущего шага по-дефолту */
11
+ defaultCurrentStepIndex: number;
12
+ /** Валидатор шагов. Выполняется при смене шага. Принимает первым аргументом индекс текущего, вторым - индекс нового шага. */
13
+ validator?: StepsValidator;
14
+ /** CSS-класс */
15
+ className?: string;
16
+ /**
17
+ * Render function. Принимает аргументы: `stepper` - JSX-элемент степпера,
18
+ * `goNext(stepIndex?: number)` - перейти на след. шаг, `goPrev(stepIndex?: number)` - перейти на пред. шаг, `resetValidation` - сбросить состояние валидации для текущего шага, `setValidator` переопределяет функцию-валидатор, которая принимает в параметры индекс текущего шага и индекс нового, `isCompleted` - окончен ли процесс, `currentStepIndex` - индекс текущего шага, `stepCount` - кол-во шагов.
19
+ * @type ({stepper, ...api}) => ReactElement
20
+ */
21
+ children: (params: StepperState) => ReactElement;
22
+ /** Колбек смены текущего степа */
23
+ onChangeCurrentStep?: (newValue: number, prevValue: number) => void;
24
+ /** Колбек изменения завершенности */
25
+ onCompleteChange?: (isCompleted: boolean) => void;
26
+ }>;
27
+ export declare function Stepper({ children, steps, className, onChangeCurrentStep, onCompleteChange, defaultCurrentStepIndex, validator: validatorProp, ...props }: StepperProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './Stepper';
@@ -0,0 +1 @@
1
+ export * from './Stepper';
@@ -0,0 +1,7 @@
1
+ export declare const STEP_STATE: {
2
+ readonly Completed: "completed";
3
+ readonly Current: "current";
4
+ readonly Loading: "loading";
5
+ readonly Waiting: "waiting";
6
+ readonly Rejected: "rejected";
7
+ };
@@ -0,0 +1,7 @@
1
+ import { StepState } from '../../types';
2
+ export type IconProps = {
3
+ state: StepState;
4
+ number: number;
5
+ className?: string;
6
+ };
7
+ export declare function Icon({ state, number, className }: IconProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './Icon';
@@ -0,0 +1,8 @@
1
+ import { WithSupportProps } from '@snack-uikit/utils';
2
+ import { StepViewData } from '../../types';
3
+ export type StepProps = WithSupportProps<{
4
+ hideTailLine?: boolean;
5
+ step: StepViewData;
6
+ className?: string;
7
+ }>;
8
+ export declare function Step({ step, className, 'data-test-id': testId, hideTailLine, ...props }: StepProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './Step';
@@ -0,0 +1,2 @@
1
+ export * from './Step';
2
+ export * from './Icon';
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export { useStepperApi } from './StepperContext';
@@ -0,0 +1,24 @@
1
+ import { JSX } from 'react';
2
+ import { ValueOf } from '@snack-uikit/utils';
3
+ import { STEP_STATE } from './constants';
4
+ export type StepState = ValueOf<typeof STEP_STATE>;
5
+ export type StepsValidator = (prevStepIndex: number, newStepIndex: number) => Promise<boolean>;
6
+ export type StepData = {
7
+ title: string;
8
+ description?: string;
9
+ };
10
+ export type StepViewData = StepData & {
11
+ onClick?(): void;
12
+ state: StepState;
13
+ number: number;
14
+ };
15
+ export type StepperApi = {
16
+ stepper: JSX.Element;
17
+ goNext(stepIndex?: number): void;
18
+ goPrev(stepIndex?: number): void;
19
+ resetValidation(): void;
20
+ setValidator(validator: StepsValidator): void;
21
+ isCompleted: boolean;
22
+ currentStepIndex: number;
23
+ stepCount: number;
24
+ };
@@ -0,0 +1 @@
1
+ export declare const getTestIdBuilder: (postfix?: string) => (testId?: string) => string | undefined;
package/package.json CHANGED
@@ -4,15 +4,16 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Stepper",
7
- "version": "0.6.13",
7
+ "version": "0.6.15-preview-1f246c4a.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
11
11
  "*.woff2"
12
12
  ],
13
13
  "description": "",
14
- "main": "./dist/index.js",
15
- "module": "./dist/index.js",
14
+ "types": "./dist/esm/index.d.ts",
15
+ "main": "./dist/cjs/index.js",
16
+ "module": "./dist/esm/index.js",
16
17
  "homepage": "https://github.com/cloud-ru-tech/snack-uikit/tree/master/packages/stepper",
17
18
  "repository": {
18
19
  "type": "git",
@@ -24,7 +25,8 @@
24
25
  "Сергей Хлупин <svhlupin@cloud.ru>"
25
26
  ],
26
27
  "files": [
27
- "dist",
28
+ "dist/cjs",
29
+ "dist/esm",
28
30
  "src",
29
31
  "./CHANGELOG.md",
30
32
  "./LICENSE"
@@ -32,12 +34,12 @@
32
34
  "license": "Apache-2.0",
33
35
  "scripts": {},
34
36
  "dependencies": {
35
- "@snack-uikit/icons": "0.22.1",
36
- "@snack-uikit/loaders": "0.5.3",
37
- "@snack-uikit/truncate-string": "0.4.23",
38
- "@snack-uikit/typography": "0.6.3",
39
- "@snack-uikit/utils": "3.4.0",
37
+ "@snack-uikit/icons": "0.22.2-preview-1f246c4a.0",
38
+ "@snack-uikit/loaders": "0.5.4-preview-1f246c4a.0",
39
+ "@snack-uikit/truncate-string": "0.4.25-preview-1f246c4a.0",
40
+ "@snack-uikit/typography": "0.6.4-preview-1f246c4a.0",
41
+ "@snack-uikit/utils": "3.4.1-preview-1f246c4a.0",
40
42
  "classnames": "2.3.2"
41
43
  },
42
- "gitHead": "fc6a22e54444112c7ded3349a79da17bb777fd0e"
44
+ "gitHead": "a185a55c0722b19f70dd168cf299e6f53a0fd93f"
43
45
  }
@@ -1,5 +0,0 @@
1
- .stepper{
2
- display:flex;
3
- flex-direction:row;
4
- align-items:start;
5
- }
@@ -1,38 +0,0 @@
1
- .icon{
2
- width:var(--size-stepper-step-status, 32px);
3
- height:var(--size-stepper-step-status, 32px);
4
- border-radius:var(--radius-stepper-step-status, 24px);
5
- border-width:var(--border-width-stepper-step-status, 2px);
6
- overflow:hidden;
7
- display:inline-flex;
8
- align-items:center;
9
- justify-content:center;
10
- }
11
- .icon svg{
12
- width:var(--size-icon-container-s, 24px) !important;
13
- height:var(--size-icon-container-s, 24px) !important;
14
- }
15
- .icon[data-state=completed]{
16
- color:var(--sys-primary-accent-default, #794ed3);
17
- background-color:var(--sys-primary-decor-default, #ebdefd);
18
- }
19
- .icon[data-state=current]{
20
- color:var(--sys-primary-on-accent, #fdfbff);
21
- background-color:var(--sys-primary-accent-default, #794ed3);
22
- }
23
- .icon[data-state=waiting]{
24
- box-sizing:border-box;
25
- color:var(--sys-neutral-text-support, #6d707f);
26
- border-color:var(--sys-neutral-decor-default, #dde0ea);
27
- border-style:solid;
28
- }
29
- .icon[data-state=loading]{
30
- box-sizing:border-box;
31
- color:var(--sys-neutral-accent-default, #787b8a);
32
- border-color:var(--sys-neutral-decor-default, #dde0ea);
33
- border-style:solid;
34
- }
35
- .icon[data-state=rejected]{
36
- color:var(--sys-red-on-accent, #fffbf9);
37
- background-color:var(--sys-red-accent-default, #cb3f3e);
38
- }
@@ -1,83 +0,0 @@
1
- .tailLine{
2
- height:var(--size-stepper-step-track-line, 2px);
3
- border-radius:var(--radius-stepper-step-track-line, 2px);
4
- flex-grow:1;
5
- background-color:var(--sys-neutral-decor-default, #dde0ea);
6
- }
7
-
8
- .tail{
9
- display:flex;
10
- flex-grow:1;
11
- flex-shrink:1;
12
- align-items:center;
13
- min-width:var(--dimension-2m, 16px);
14
- }
15
- .tail[data-completed] .tailLine{
16
- background-color:var(--sys-primary-accent-default, #794ed3);
17
- }
18
-
19
- .title{
20
- overflow:hidden;
21
- color:var(--sys-neutral-text-main, #41424e);
22
- }
23
-
24
- .description{
25
- overflow:hidden;
26
- color:var(--sys-neutral-text-light, #8b8e9b);
27
- }
28
-
29
- .step{
30
- gap:var(--space-stepper-step-container-gap, 4px);
31
- padding-right:var(--space-stepper-step-container-padding-right, 8px);
32
- display:flex;
33
- flex:1;
34
- flex-direction:column;
35
- align-items:center;
36
- justify-content:center;
37
- min-width:0;
38
- }
39
-
40
- .track{
41
- gap:var(--space-stepper-step-track-gap, 8px);
42
- display:flex;
43
- width:100%;
44
- }
45
-
46
- .statusContainer{
47
- width:var(--size-stepper-step-status, 32px);
48
- height:var(--size-stepper-step-status, 32px);
49
- border-radius:var(--radius-stepper-step-status, 24px);
50
- border-width:var(--border-width-stepper-step-status, 2px);
51
- overflow:hidden;
52
- display:flex;
53
- flex-shrink:1;
54
- align-items:center;
55
- margin:0;
56
- padding:0;
57
- color:var(--sys-neutral-text-main, #41424e);
58
- background-color:transparent;
59
- border:none;
60
- }
61
- .statusContainer:focus-visible{
62
- outline-width:var(--border-state-focus-s-border-width, 2px);
63
- outline-style:var(--border-state-focus-s-border-style, solid);
64
- outline-color:var(--border-state-focus-s-border-color, );
65
- outline-color:var(--sys-available-complementary, #1c1c24);
66
- outline-offset:var(--spacing-state-focus-offset, 2px);
67
- }
68
- .statusContainer:not([disabled]){
69
- cursor:pointer;
70
- }
71
- .statusContainer:not([disabled]):focus-visible, .statusContainer:not([disabled]):hover{
72
- color:var(--sys-neutral-text-light, #8b8e9b);
73
- }
74
-
75
- .content{
76
- display:flex;
77
- flex-direction:column;
78
- width:100%;
79
- }
80
-
81
- .icon{
82
- flex-shrink:0;
83
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes