@snack-uikit/stepper 0.2.19-preview-85c5f47b.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 (55) hide show
  1. package/CHANGELOG.md +288 -0
  2. package/LICENSE +201 -0
  3. package/README.md +55 -0
  4. package/dist/StepperContext/StepperContext.d.ts +4 -0
  5. package/dist/StepperContext/StepperContext.js +15 -0
  6. package/dist/StepperContext/index.d.ts +1 -0
  7. package/dist/StepperContext/index.js +1 -0
  8. package/dist/components/Stepper/Stepper.d.ts +29 -0
  9. package/dist/components/Stepper/Stepper.js +103 -0
  10. package/dist/components/Stepper/index.d.ts +1 -0
  11. package/dist/components/Stepper/index.js +1 -0
  12. package/dist/components/Stepper/styles.module.css +4 -0
  13. package/dist/components/index.d.ts +1 -0
  14. package/dist/components/index.js +1 -0
  15. package/dist/constants.d.ts +11 -0
  16. package/dist/constants.js +13 -0
  17. package/dist/helperComponents/Icon/Icon.d.ts +7 -0
  18. package/dist/helperComponents/Icon/Icon.js +24 -0
  19. package/dist/helperComponents/Icon/index.d.ts +1 -0
  20. package/dist/helperComponents/Icon/index.js +1 -0
  21. package/dist/helperComponents/Icon/styles.module.css +38 -0
  22. package/dist/helperComponents/Step/Step.d.ts +8 -0
  23. package/dist/helperComponents/Step/Step.js +26 -0
  24. package/dist/helperComponents/Step/index.d.ts +1 -0
  25. package/dist/helperComponents/Step/index.js +1 -0
  26. package/dist/helperComponents/Step/styles.module.css +65 -0
  27. package/dist/helperComponents/index.d.ts +2 -0
  28. package/dist/helperComponents/index.js +2 -0
  29. package/dist/hooks.d.ts +1 -0
  30. package/dist/hooks.js +3 -0
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +2 -0
  33. package/dist/types.d.ts +18 -0
  34. package/dist/types.js +1 -0
  35. package/dist/utils.d.ts +1 -0
  36. package/dist/utils.js +1 -0
  37. package/package.json +43 -0
  38. package/src/StepperContext/StepperContext.ts +20 -0
  39. package/src/StepperContext/index.ts +1 -0
  40. package/src/components/Stepper/Stepper.tsx +167 -0
  41. package/src/components/Stepper/index.ts +1 -0
  42. package/src/components/Stepper/styles.module.scss +4 -0
  43. package/src/components/index.ts +1 -0
  44. package/src/constants.ts +12 -0
  45. package/src/helperComponents/Icon/Icon.tsx +38 -0
  46. package/src/helperComponents/Icon/index.ts +1 -0
  47. package/src/helperComponents/Icon/styles.module.scss +45 -0
  48. package/src/helperComponents/Step/Step.tsx +54 -0
  49. package/src/helperComponents/Step/index.ts +1 -0
  50. package/src/helperComponents/Step/styles.module.scss +76 -0
  51. package/src/helperComponents/index.ts +2 -0
  52. package/src/hooks.ts +5 -0
  53. package/src/index.ts +2 -0
  54. package/src/types.ts +21 -0
  55. package/src/utils.ts +2 -0
@@ -0,0 +1,38 @@
1
+ import cn from 'classnames';
2
+ import { useMemo } from 'react';
3
+
4
+ import { CheckSVG, CrossSVG } from '@snack-uikit/icons';
5
+ import { Sun } from '@snack-uikit/loaders';
6
+ import { Typography } from '@snack-uikit/typography';
7
+
8
+ import { StepState } from '../../constants';
9
+ import styles from './styles.module.scss';
10
+
11
+ export type IconProps = {
12
+ state: StepState;
13
+ number: number;
14
+ className?: string;
15
+ };
16
+
17
+ function getContent(state: StepState, number: number) {
18
+ switch (state) {
19
+ case StepState.Completed:
20
+ return <CheckSVG />;
21
+ case StepState.Rejected:
22
+ return <CrossSVG />;
23
+ case StepState.Loading:
24
+ return <Sun size={Sun.sizes.S} />;
25
+ default:
26
+ return number;
27
+ }
28
+ }
29
+
30
+ export function Icon({ state, number, className }: IconProps) {
31
+ const content = useMemo(() => getContent(state, number), [number, state]);
32
+
33
+ return (
34
+ <div data-state={state} className={cn(styles.icon, className)}>
35
+ {typeof content === 'number' ? <Typography.SansLabelL>{content}</Typography.SansLabelL> : content}
36
+ </div>
37
+ );
38
+ }
@@ -0,0 +1 @@
1
+ export * from './Icon';
@@ -0,0 +1,45 @@
1
+ @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-stepper';
2
+ @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
3
+
4
+ .icon {
5
+ @include composite-var($stepper-step-status-container);
6
+
7
+ overflow: hidden;
8
+ display: inline-flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+
12
+ svg {
13
+ width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
14
+ height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
15
+ }
16
+
17
+ &[data-state='completed'] {
18
+ color: $sys-primary-accent-default;
19
+ background-color: $sys-primary-decor-default;
20
+ }
21
+
22
+ &[data-state='current'] {
23
+ color: $sys-primary-on-accent;
24
+ background-color: $sys-primary-accent-default;
25
+ }
26
+
27
+ &[data-state='waiting'] {
28
+ box-sizing: border-box;
29
+ color: $sys-neutral-text-support;
30
+ border-color: $sys-neutral-decor-default;
31
+ border-style: solid;
32
+ }
33
+
34
+ &[data-state='loading'] {
35
+ box-sizing: border-box;
36
+ color: $sys-neutral-accent-default;
37
+ border-color: $sys-neutral-decor-default;
38
+ border-style: solid;
39
+ }
40
+
41
+ &[data-state='rejected'] {
42
+ color: $sys-red-on-accent;
43
+ background-color: $sys-red-accent-default;
44
+ }
45
+ }
@@ -0,0 +1,54 @@
1
+ import cn from 'classnames';
2
+
3
+ import { TruncateString } from '@snack-uikit/truncate-string';
4
+ import { Typography } from '@snack-uikit/typography';
5
+ import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
6
+
7
+ import { StepState } from '../../constants';
8
+ import { StepViewData } from '../../types';
9
+ import { getTestIdBuilder } from '../../utils';
10
+ import { Icon } from '../Icon';
11
+ import styles from './styles.module.scss';
12
+
13
+ export type StepProps = WithSupportProps<{
14
+ step: StepViewData;
15
+ className?: string;
16
+ isLast: boolean;
17
+ }>;
18
+
19
+ const getTailTestId = getTestIdBuilder('_element-tail');
20
+ const getStepTestId = getTestIdBuilder('_element-step');
21
+
22
+ export function Step({ step, className, isLast, 'data-test-id': testId, ...props }: StepProps) {
23
+ return (
24
+ <div className={cn(styles.step, className)} data-state={step.state} {...extractSupportProps(props)}>
25
+ <button
26
+ className={styles.content}
27
+ onClick={step.onClick}
28
+ disabled={!step.onClick}
29
+ data-test-id={getStepTestId(testId)}
30
+ data-state={step.state}
31
+ >
32
+ <Icon {...step} className={styles.icon} />
33
+ <Typography
34
+ className={styles.title}
35
+ tag={Typography.tags.div}
36
+ family={Typography.families.Sans}
37
+ role={Typography.roles.Body}
38
+ size={Typography.sizes.M}
39
+ >
40
+ <TruncateString text={step.title} />
41
+ </Typography>
42
+ </button>
43
+ {!isLast && (
44
+ <div
45
+ className={styles.tail}
46
+ data-completed={step.state === StepState.Completed || undefined}
47
+ data-test-id={getTailTestId(testId)}
48
+ >
49
+ <div className={styles.tailLine} />
50
+ </div>
51
+ )}
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +1 @@
1
+ export * from './Step';
@@ -0,0 +1,76 @@
1
+ @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-stepper';
2
+ @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
3
+
4
+ .tailLine {
5
+ @include composite-var($stepper-step-track-line);
6
+
7
+ flex-grow: 1;
8
+ background-color: $sys-neutral-decor-default;
9
+ }
10
+
11
+ .tail {
12
+ @include composite-var($stepper-step-track-container);
13
+
14
+ display: flex;
15
+ flex-grow: 1;
16
+ flex-shrink: 1;
17
+ align-items: center;
18
+
19
+ min-width: $dimension-2m;
20
+
21
+ &[data-completed] .tailLine {
22
+ background-color: $sys-primary-accent-default;
23
+ }
24
+ }
25
+
26
+ .title {
27
+ overflow: hidden;
28
+ }
29
+
30
+ .step {
31
+ display: flex;
32
+ flex: 1;
33
+ align-items: center;
34
+ justify-content: center;
35
+
36
+ min-width: 0;
37
+
38
+ &:last-child {
39
+ max-width: max-content;
40
+ }
41
+ }
42
+
43
+ .content {
44
+ @include composite-var($stepper-step-container-content);
45
+
46
+ overflow: hidden;
47
+ display: flex;
48
+ flex-shrink: 1;
49
+ align-items: center;
50
+
51
+ margin: 0;
52
+ padding: 0;
53
+
54
+ color: $sys-neutral-text-main;
55
+
56
+ background-color: transparent;
57
+ border: none;
58
+
59
+ &:focus-visible {
60
+ @include outline-var($container-focused-s);
61
+
62
+ outline-color: $sys-available-complementary;
63
+ outline-offset: $spacing-state-focus-offset;
64
+ }
65
+
66
+ &:not([disabled]) {
67
+ cursor: pointer;
68
+ &:focus-visible, &:hover {
69
+ color: $sys-neutral-text-light;
70
+ }
71
+ }
72
+ }
73
+
74
+ .icon {
75
+ flex-shrink: 0;
76
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Step';
2
+ export * from './Icon';
package/src/hooks.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { useContext } from 'react';
2
+
3
+ import { StepperContext } from './StepperContext';
4
+
5
+ export const useStepperApi = () => useContext(StepperContext);
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export * from './hooks';
package/src/types.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { StepState, StepValidationResult } from './constants';
2
+
3
+ export type StepData = {
4
+ title: string;
5
+ validation?(): Promise<StepValidationResult>;
6
+ };
7
+
8
+ export type StepViewData = StepData & {
9
+ onClick?(): void;
10
+ state: StepState;
11
+ number: number;
12
+ };
13
+
14
+ export type StepperApi = {
15
+ goNext(): void;
16
+ goPrev(): void;
17
+ resetValidation(): void;
18
+ isCompleted: boolean;
19
+ currentStepIndex: number;
20
+ stepCount: number;
21
+ };
package/src/utils.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const getTestIdBuilder = (postfix?: string) => (testId?: string) =>
2
+ postfix && testId ? `${testId}${postfix}` : undefined;