@semcore/wizard 2.43.1 → 2.44.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 (56) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/cjs/Wizard.js +201 -47
  3. package/lib/cjs/Wizard.js.map +1 -1
  4. package/lib/cjs/index.d.js.map +1 -1
  5. package/lib/cjs/style/wizard.shadow.css +4 -0
  6. package/lib/cjs/translations/de.json +3 -1
  7. package/lib/cjs/translations/en.json +3 -1
  8. package/lib/cjs/translations/es.json +3 -1
  9. package/lib/cjs/translations/fr.json +3 -1
  10. package/lib/cjs/translations/it.json +3 -1
  11. package/lib/cjs/translations/ja.json +3 -1
  12. package/lib/cjs/translations/ko.json +3 -1
  13. package/lib/cjs/translations/nl.json +3 -1
  14. package/lib/cjs/translations/pl.json +3 -1
  15. package/lib/cjs/translations/pt.json +3 -1
  16. package/lib/cjs/translations/sv.json +3 -1
  17. package/lib/cjs/translations/tr.json +3 -1
  18. package/lib/cjs/translations/vi.json +3 -1
  19. package/lib/cjs/translations/zh.json +3 -1
  20. package/lib/es6/Wizard.js +203 -47
  21. package/lib/es6/Wizard.js.map +1 -1
  22. package/lib/es6/index.d.js.map +1 -1
  23. package/lib/es6/style/wizard.shadow.css +4 -0
  24. package/lib/es6/translations/de.json +3 -1
  25. package/lib/es6/translations/en.json +3 -1
  26. package/lib/es6/translations/es.json +3 -1
  27. package/lib/es6/translations/fr.json +3 -1
  28. package/lib/es6/translations/it.json +3 -1
  29. package/lib/es6/translations/ja.json +3 -1
  30. package/lib/es6/translations/ko.json +3 -1
  31. package/lib/es6/translations/nl.json +3 -1
  32. package/lib/es6/translations/pl.json +3 -1
  33. package/lib/es6/translations/pt.json +3 -1
  34. package/lib/es6/translations/sv.json +3 -1
  35. package/lib/es6/translations/tr.json +3 -1
  36. package/lib/es6/translations/vi.json +3 -1
  37. package/lib/es6/translations/zh.json +3 -1
  38. package/lib/types/index.d.ts +17 -0
  39. package/package.json +5 -5
  40. package/src/Wizard.jsx +162 -21
  41. package/src/index.d.ts +17 -0
  42. package/src/style/wizard.shadow.css +4 -0
  43. package/src/translations/de.json +3 -1
  44. package/src/translations/en.json +3 -1
  45. package/src/translations/es.json +3 -1
  46. package/src/translations/fr.json +3 -1
  47. package/src/translations/it.json +3 -1
  48. package/src/translations/ja.json +3 -1
  49. package/src/translations/ko.json +3 -1
  50. package/src/translations/nl.json +3 -1
  51. package/src/translations/pl.json +3 -1
  52. package/src/translations/pt.json +3 -1
  53. package/src/translations/sv.json +3 -1
  54. package/src/translations/tr.json +3 -1
  55. package/src/translations/vi.json +3 -1
  56. package/src/translations/zh.json +3 -1
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { UnknownProperties, Intergalactic } from '@semcore/core';
3
3
  import { Box, BoxProps } from '@semcore/flex-box';
4
+ import { ButtonProps } from '@semcore/button';
4
5
  import { ModalProps } from '@semcore/modal';
5
6
 
6
7
  export type WizardStep = string | number | boolean;
@@ -12,6 +13,7 @@ export type WizardProps = ModalProps & {
12
13
  * Active step value
13
14
  */
14
15
  step: WizardStep;
16
+ locale?: string;
15
17
  };
16
18
 
17
19
  /** @deprecated */
@@ -62,6 +64,19 @@ export type WizardStepperProps<T extends WizardStep = WizardStep> = BoxProps & {
62
64
  disabled?: boolean;
63
65
  };
64
66
 
67
+ export type WizardStepBackProps<T extends WizardStep = WizardStep> = ButtonProps & {
68
+ onActive?:
69
+ | ((step: T, e: React.SyntheticEvent<HTMLElement>) => void)
70
+ | React.Dispatch<React.SetStateAction<T>>;
71
+ stepName?: string;
72
+ };
73
+ export type WizardStepNextProps<T extends WizardStep = WizardStep> = ButtonProps & {
74
+ onActive?:
75
+ | ((step: T, e: React.SyntheticEvent<HTMLElement>) => void)
76
+ | React.Dispatch<React.SetStateAction<T>>;
77
+ stepName?: string;
78
+ };
79
+
65
80
  type IntergalacticWizardStepperComponent<PropsExtending = {}> = (<
66
81
  Value extends WizardStep,
67
82
  Tag extends Intergalactic.Tag = 'div',
@@ -76,6 +91,8 @@ declare const Wizard: Intergalactic.Component<'div', WizardProps> & {
76
91
  Step: Intergalactic.Component<'div', WizardStepProps>;
77
92
  Stepper: IntergalacticWizardStepperComponent;
78
93
  Content: typeof Box;
94
+ StepBack: Intergalactic.Component<'button', WizardStepBackProps>;
95
+ StepNext: Intergalactic.Component<'button', WizardStepNextProps>;
79
96
  };
80
97
 
81
98
  declare const wrapWizardStepper: <PropsExtending extends {}>(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/wizard",
3
3
  "description": "Semrush Wizard Component",
4
- "version": "2.43.1",
4
+ "version": "2.44.0",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
@@ -9,10 +9,10 @@
9
9
  "author": "UI-kit team <ui-kit-team@semrush.com>",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@semcore/utils": "4.35.0",
13
- "@semcore/flex-box": "5.32.0",
14
- "@semcore/icon": "4.44.1",
15
- "@semcore/modal": "4.44.1"
12
+ "@semcore/utils": "4.36.0",
13
+ "@semcore/flex-box": "5.33.0",
14
+ "@semcore/icon": "4.45.0",
15
+ "@semcore/modal": "4.45.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@semcore/core": "^2.17.5",
package/src/Wizard.jsx CHANGED
@@ -8,13 +8,17 @@ import i18nEnhance from '@semcore/utils/lib/enhances/i18nEnhance';
8
8
  import { localizedMessages } from './translations/__intergalactic-dynamic-locales';
9
9
  import { ScreenReaderOnly } from '@semcore/utils/lib/ScreenReaderOnly';
10
10
  import { setFocus } from '@semcore/utils/lib/use/useFocusLock';
11
+ import uniqueIDEnhancement from '@semcore/utils/lib/uniqueID';
12
+ import Button from '@semcore/button';
13
+ import ArrowRight from '@semcore/icon/ArrowRight/m';
14
+ import ArrowLeft from '@semcore/icon/ArrowLeft/m';
11
15
 
12
16
  import style from './style/wizard.shadow.css';
13
17
 
14
18
  class WizardRoot extends Component {
15
19
  static displayName = 'Wizard';
16
20
  static style = style;
17
- static enhance = [i18nEnhance(localizedMessages)];
21
+ static enhance = [i18nEnhance(localizedMessages), uniqueIDEnhancement()];
18
22
  static defaultProps = {
19
23
  step: null,
20
24
  i18n: localizedMessages,
@@ -23,14 +27,60 @@ class WizardRoot extends Component {
23
27
 
24
28
  _steps = new Map();
25
29
  modalRef = React.createRef();
30
+ contentRef = React.createRef();
31
+ state = { highlighted: null };
26
32
 
27
33
  getStepProps(props) {
28
34
  return {
29
35
  steps: this._steps,
30
36
  active: props.step === this.asProps.step,
37
+ id: `${this.asProps.uid}-step-${props.step}`,
31
38
  };
32
39
  }
33
40
 
41
+ getSidebarProps() {
42
+ return {
43
+ uid: this.asProps.uid,
44
+ };
45
+ }
46
+ getContentProps() {
47
+ return {
48
+ uid: this.asProps.uid,
49
+ step: this.asProps.step,
50
+ ref: this.contentRef,
51
+ };
52
+ }
53
+ getStepBackProps() {
54
+ return {
55
+ getI18nText: this.asProps.getI18nText,
56
+ step: this.asProps.step,
57
+ };
58
+ }
59
+ getStepNextProps() {
60
+ return {
61
+ getI18nText: this.asProps.getI18nText,
62
+ step: this.asProps.step,
63
+ };
64
+ }
65
+
66
+ stepperRefs = [];
67
+ stepperFocusPrev = (i) => () => {
68
+ const prevStep = this._steps.get(this.asProps.step);
69
+ if (!prevStep) return;
70
+ this.setState({ highlighted: prevStep?.step });
71
+ setTimeout(() => {
72
+ this.stepperRefs[i - 1]?.focus();
73
+ }, 0);
74
+ };
75
+ stepperFocusNext = (i) => () => {
76
+ const nextStep = this._steps.get(this.asProps.step + 2);
77
+ if (!nextStep) return;
78
+ this.setState({ highlighted: nextStep?.step });
79
+ setTimeout(() => {
80
+ this.stepperRefs[i + 1]?.focus();
81
+ }, 0);
82
+ };
83
+
34
84
  getStepperProps(props, i) {
35
85
  let number = i + 1;
36
86
  if (this._steps.has(props.step)) {
@@ -39,32 +89,45 @@ class WizardRoot extends Component {
39
89
  } else {
40
90
  this._steps.set(props.step, { number, ...props });
41
91
  }
92
+ const active = props.step === this.asProps.step;
93
+ const highlighted =
94
+ this.state.highlighted === props.step || (this.state.highlighted === null && i === 0);
42
95
  return {
43
- active: props.step === this.asProps.step,
96
+ active,
97
+ tabIndex: highlighted ? 0 : -1,
44
98
  number,
45
99
  getI18nText: this.asProps.getI18nText,
100
+ uid: this.asProps.uid,
101
+ ref: (node) => {
102
+ this.stepperRefs[i] = node;
103
+ },
104
+ focusNext: this.stepperFocusNext(i),
105
+ focusPrev: this.stepperFocusPrev(i),
46
106
  };
47
107
  }
48
108
 
49
109
  componentDidUpdate(prevProps) {
50
110
  if (prevProps.step === this.asProps.step) return;
111
+ this.setState({ highlighted: this.asProps.step || null });
51
112
  setTimeout(() => {
52
113
  if (prevProps.step === this.asProps.step) return;
53
- if (document.activeElement !== document.body) return;
54
- if (!this.asProps.visible) return;
55
- if (!this.modalRef.current) return;
56
- setFocus(this.modalRef.current, document.body);
114
+ setFocus(this.contentRef.current);
57
115
  }, 1);
58
116
  }
59
117
 
60
118
  render() {
61
119
  const SWizard = this.Root;
62
- const { Children, styles } = this.asProps;
120
+ const { Children, styles, uid } = this.asProps;
63
121
 
64
122
  this._steps.clear();
65
123
 
66
124
  return sstyled(styles)(
67
- <SWizard render={Modal} ref={this.modalRef}>
125
+ <SWizard
126
+ render={Modal}
127
+ aria-label={undefined}
128
+ ref={this.modalRef}
129
+ aria-labelledby={`${uid}-title`}
130
+ >
68
131
  <Children />
69
132
  </SWizard>,
70
133
  );
@@ -72,13 +135,19 @@ class WizardRoot extends Component {
72
135
  }
73
136
 
74
137
  function Sidebar(props) {
75
- const { Children, styles, title } = props;
138
+ const { Children, styles, title, uid } = props;
76
139
  const SSidebar = Root;
77
140
  const SSidebarHeader = 'h2';
141
+ const SSidebarMenu = 'div';
142
+
143
+ const handleKeyDown = React.useCallback((e) => {}, []);
144
+
78
145
  return sstyled(styles)(
79
- <SSidebar render={Box} role='menu'>
80
- {title && <SSidebarHeader>{title}</SSidebarHeader>}
81
- <Children />
146
+ <SSidebar render={Box} __excludeProps={['title']}>
147
+ {title && <SSidebarHeader id={`${uid}-title`}>{title}</SSidebarHeader>}
148
+ <SSidebarMenu role='tablist' aria-orientation='vertical'>
149
+ <Children />
150
+ </SSidebarMenu>
82
151
  </SSidebar>,
83
152
  );
84
153
  }
@@ -88,7 +157,7 @@ function Step(props) {
88
157
  const { Children, styles, active } = props;
89
158
  if (active) {
90
159
  return sstyled(styles)(
91
- <SStep render={Box} tag={Box}>
160
+ <SStep render={Box}>
92
161
  <Children />
93
162
  </SStep>,
94
163
  );
@@ -97,8 +166,20 @@ function Step(props) {
97
166
  }
98
167
 
99
168
  function Stepper(props) {
100
- const { Children, styles, step, active, onActive, completed, disabled, number, getI18nText } =
101
- props;
169
+ const {
170
+ Children,
171
+ styles,
172
+ step,
173
+ active,
174
+ onActive,
175
+ completed,
176
+ disabled,
177
+ number,
178
+ getI18nText,
179
+ uid,
180
+ focusNext,
181
+ focusPrev,
182
+ } = props;
102
183
  const SStepper = Root;
103
184
  const SStepNumber = 'span';
104
185
  const SStepDescription = 'span';
@@ -117,16 +198,26 @@ function Stepper(props) {
117
198
  e.preventDefault();
118
199
  onActive(step, e);
119
200
  }
201
+ if (e.key === 'ArrowUp') {
202
+ focusPrev();
203
+ e.stopPropagation();
204
+ }
205
+ if (e.key === 'ArrowDown') {
206
+ focusNext();
207
+ e.stopPropagation();
208
+ }
120
209
  },
121
- [step, onActive],
210
+ [step, onActive, focusPrev, focusNext],
122
211
  );
123
212
 
124
213
  return sstyled(styles)(
125
214
  <SStepper
126
215
  render={Box}
127
- role='menuitem'
216
+ role='tab'
217
+ id={`${uid}-stepper-${step}`}
218
+ aria-controls={active ? `${uid}-content-${step}` : undefined}
128
219
  aria-disabled={disabled}
129
- aria-current={active}
220
+ aria-selected={active}
130
221
  onClick={handlerClick}
131
222
  onKeyDown={handlerKeyDown}
132
223
  >
@@ -142,20 +233,70 @@ function Stepper(props) {
142
233
  Stepper.enhance = [keyboardFocusEnhance()];
143
234
 
144
235
  function Content(props) {
145
- const { Children, styles } = props;
236
+ const { Children, children: hasChildren, styles, uid, step } = props;
146
237
  const SContent = Root;
147
238
  return sstyled(styles)(
148
- <SContent render={Box}>
149
- <Children />
239
+ <SContent
240
+ render={Box}
241
+ role='tabpanel'
242
+ aria-labelledby={`${uid}-stepper-${step}`}
243
+ id={`${uid}-content-${step}`}
244
+ >
245
+ {hasChildren ? <Children /> : stepName}
150
246
  </SContent>,
151
247
  );
152
248
  }
153
249
 
250
+ function StepBack(props) {
251
+ const SStepBack = Root;
252
+ const { Children, children: hasChildren, styles, getI18nText, stepName } = props;
253
+ const handleClick = React.useCallback(() => {
254
+ props.onActive?.(props.step - 1);
255
+ }, [props.step]);
256
+ return sstyled(styles)(
257
+ <SStepBack
258
+ render={Button}
259
+ use='tertiary'
260
+ size='l'
261
+ onClick={handleClick}
262
+ aria-label={getI18nText('backButton', { buttonName: stepName })}
263
+ >
264
+ <Button.Addon>
265
+ <ArrowLeft />
266
+ </Button.Addon>
267
+ <Button.Text>{hasChildren ? <Children /> : stepName}</Button.Text>
268
+ </SStepBack>,
269
+ );
270
+ }
271
+ function StepNext(props) {
272
+ const SStepNext = Root;
273
+ const { Children, children: hasChildren, styles, getI18nText, stepName } = props;
274
+ const handleClick = React.useCallback(() => {
275
+ props.onActive?.(props.step + 1);
276
+ }, [props.step]);
277
+ return sstyled(styles)(
278
+ <SStepNext
279
+ render={Button}
280
+ use='tertiary'
281
+ size='l'
282
+ onClick={handleClick}
283
+ aria-label={getI18nText('nextButton', { buttonName: stepName })}
284
+ >
285
+ <Button.Text>{hasChildren ? <Children /> : stepName}</Button.Text>
286
+ <Button.Addon>
287
+ <ArrowRight />
288
+ </Button.Addon>
289
+ </SStepNext>,
290
+ );
291
+ }
292
+
154
293
  const Wizard = createComponent(WizardRoot, {
155
294
  Sidebar,
156
295
  Content,
157
296
  Step,
158
297
  Stepper,
298
+ StepBack,
299
+ StepNext,
159
300
  });
160
301
 
161
302
  export const wrapWizardStepper = (wrapper) => wrapper;
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { UnknownProperties, Intergalactic } from '@semcore/core';
3
3
  import { Box, BoxProps } from '@semcore/flex-box';
4
+ import { ButtonProps } from '@semcore/button';
4
5
  import { ModalProps } from '@semcore/modal';
5
6
 
6
7
  export type WizardStep = string | number | boolean;
@@ -12,6 +13,7 @@ export type WizardProps = ModalProps & {
12
13
  * Active step value
13
14
  */
14
15
  step: WizardStep;
16
+ locale?: string;
15
17
  };
16
18
 
17
19
  /** @deprecated */
@@ -62,6 +64,19 @@ export type WizardStepperProps<T extends WizardStep = WizardStep> = BoxProps & {
62
64
  disabled?: boolean;
63
65
  };
64
66
 
67
+ export type WizardStepBackProps<T extends WizardStep = WizardStep> = ButtonProps & {
68
+ onActive?:
69
+ | ((step: T, e: React.SyntheticEvent<HTMLElement>) => void)
70
+ | React.Dispatch<React.SetStateAction<T>>;
71
+ stepName?: string;
72
+ };
73
+ export type WizardStepNextProps<T extends WizardStep = WizardStep> = ButtonProps & {
74
+ onActive?:
75
+ | ((step: T, e: React.SyntheticEvent<HTMLElement>) => void)
76
+ | React.Dispatch<React.SetStateAction<T>>;
77
+ stepName?: string;
78
+ };
79
+
65
80
  type IntergalacticWizardStepperComponent<PropsExtending = {}> = (<
66
81
  Value extends WizardStep,
67
82
  Tag extends Intergalactic.Tag = 'div',
@@ -76,6 +91,8 @@ declare const Wizard: Intergalactic.Component<'div', WizardProps> & {
76
91
  Step: Intergalactic.Component<'div', WizardStepProps>;
77
92
  Stepper: IntergalacticWizardStepperComponent;
78
93
  Content: typeof Box;
94
+ StepBack: Intergalactic.Component<'button', WizardStepBackProps>;
95
+ StepNext: Intergalactic.Component<'button', WizardStepNextProps>;
79
96
  };
80
97
 
81
98
  declare const wrapWizardStepper: <PropsExtending extends {}>(
@@ -97,3 +97,7 @@ SContent {
97
97
  0;
98
98
  background: var(--intergalactic-bg-primary-neutral, #ffffff);
99
99
  }
100
+
101
+ SSidebarMenu {
102
+ display: contents;
103
+ }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Abgeschlossener Schritt"
2
+ "completedStep": "Abgeschlossener Schritt",
3
+ "backButton": "Zurück zu {buttonName}",
4
+ "nextButton": "Weiter zu {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Completed step"
2
+ "completedStep": "Completed step",
3
+ "backButton": "Back to {buttonName}",
4
+ "nextButton": "Go to {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Paso completado"
2
+ "completedStep": "Paso completado",
3
+ "backButton": "Volver a {buttonName}",
4
+ "nextButton": "Continuar a {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Étape terminée"
2
+ "completedStep": "Étape terminée",
3
+ "backButton": "Retour à {buttonName}",
4
+ "nextButton": "Continuer vers {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Fase completata"
2
+ "completedStep": "Fase completata",
3
+ "backButton": "Torna a {buttonName}",
4
+ "nextButton": "Continua a {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "完成したステップ"
2
+ "completedStep": "完成したステップ",
3
+ "backButton": "{buttonName}に戻る",
4
+ "nextButton": "{buttonName} に移動"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "단계 완료됨"
2
+ "completedStep": "단계 완료됨",
3
+ "backButton": "{buttonName} 단계로 돌아가기",
4
+ "nextButton": "{buttonName}로 계속"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Voltooide stap"
2
+ "completedStep": "Voltooide stap",
3
+ "backButton": "Terug naar {buttonName}",
4
+ "nextButton": "Door naar {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Ukończony krok"
2
+ "completedStep": "Ukończony krok",
3
+ "backButton": "Wróć do: {buttonName}",
4
+ "nextButton": "Dalej do: {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Etapa concluída"
2
+ "completedStep": "Etapa concluída",
3
+ "backButton": "Voltar para {buttonName}",
4
+ "nextButton": "Continuar para {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Genomfört steg"
2
+ "completedStep": "Genomfört steg",
3
+ "backButton": "Tillbaka till {buttonName}",
4
+ "nextButton": "Fortsätt till {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Tamamlanan adım"
2
+ "completedStep": "Tamamlanan adım",
3
+ "backButton": "Geri dön{buttonName}",
4
+ "nextButton": "{buttonName} adresine devam edin"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "Bước đã hoàn thành"
2
+ "completedStep": "Bước đã hoàn thành",
3
+ "backButton": "Quay lại {buttonName}",
4
+ "nextButton": "Tiếp tục đến {buttonName}"
3
5
  }
@@ -1,3 +1,5 @@
1
1
  {
2
- "completedStep": "已完成的步骤"
2
+ "completedStep": "已完成的步骤",
3
+ "backButton": "返回到{buttonName}",
4
+ "nextButton": "继续到 {buttonName}"
3
5
  }