@availity/mui-stepper 0.1.2 → 0.1.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.1.4](https://github.com/Availity/element/compare/@availity/mui-stepper@0.1.3...@availity/mui-stepper@0.1.4) (2024-09-09)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * resolve accessibility issues in stories ([7e22419](https://github.com/Availity/element/commit/7e2241913f8ad10f467493b605fc0234e6eab5e2))
11
+
12
+ ## [0.1.3](https://github.com/Availity/element/compare/@availity/mui-stepper@0.1.2...@availity/mui-stepper@0.1.3) (2024-08-08)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **mui-stepper:** add background to stories ([627fd5d](https://github.com/Availity/element/commit/627fd5da3f571ca2d95ffdc6c2e270878929cc2d))
18
+
5
19
  ## [0.1.2](https://github.com/Availity/element/compare/@availity/mui-stepper@0.1.1...@availity/mui-stepper@0.1.2) (2024-08-08)
6
20
 
7
21
  ### Dependency Updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-stepper",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Availity MUI Stepper Component - part of the @availity/element design system",
5
5
  "keywords": [
6
6
  "react",
@@ -37,6 +37,7 @@
37
37
  "devDependencies": {
38
38
  "@availity/mui-button": "^0.6.10",
39
39
  "@availity/mui-layout": "^0.1.6",
40
+ "@availity/mui-paper": "^0.1.9",
40
41
  "@availity/mui-typography": "^0.2.0",
41
42
  "@mui/material": "^5.15.15",
42
43
  "react": "18.2.0",
@@ -1,9 +1,10 @@
1
1
  // Each exported component in the package should have its own stories file
2
- import { useState } from 'react';
2
+ import { useState, useEffect } from 'react';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
4
  import { Button } from '@availity/mui-button';
5
5
  import { Typography } from '@availity/mui-typography';
6
6
  import { Box } from '@availity/mui-layout';
7
+ import { Paper } from '@availity/mui-paper';
7
8
 
8
9
  import { Stepper, StepperProps } from './Stepper';
9
10
  import { Step } from './Step';
@@ -22,6 +23,30 @@ const meta: Meta<typeof Stepper> = {
22
23
 
23
24
  export default meta;
24
25
 
26
+ // credit: https://stackoverflow.com/questions/36862334/get-viewport-window-height-in-reactjs
27
+ function getWindowDimensions() {
28
+ const { innerWidth: width, innerHeight: height } = window;
29
+ return {
30
+ width,
31
+ height,
32
+ };
33
+ }
34
+
35
+ function useWindowDimensions() {
36
+ const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
37
+
38
+ useEffect(() => {
39
+ function handleResize() {
40
+ setWindowDimensions(getWindowDimensions());
41
+ }
42
+
43
+ window.addEventListener('resize', handleResize);
44
+ return () => window.removeEventListener('resize', handleResize);
45
+ }, []);
46
+
47
+ return windowDimensions;
48
+ }
49
+
25
50
  const steps = ['Select', 'Another Step', 'Form Data', 'Create a new one'];
26
51
 
27
52
  export const _Stepper: StoryObj<typeof Stepper> = {
@@ -29,6 +54,8 @@ export const _Stepper: StoryObj<typeof Stepper> = {
29
54
  const [activeStep, setActiveStep] = useState(0);
30
55
  const [skipped, setSkipped] = useState(new Set<number>());
31
56
 
57
+ const { width } = useWindowDimensions();
58
+
32
59
  const isStepOptional = (step: number) => {
33
60
  return step > 1;
34
61
  };
@@ -81,63 +108,65 @@ export const _Stepper: StoryObj<typeof Stepper> = {
81
108
 
82
109
  return (
83
110
  <Box maxWidth="75vw" marginX="auto">
84
- <Stepper activeStep={activeStep} {...args}>
85
- {steps.map((label, index) => {
86
- const stepProps: { completed?: boolean } = {};
87
- const labelProps: { optional?: React.ReactNode; error?: boolean; warning?: boolean } = {};
88
-
89
- if (isStepOptional(index)) {
90
- labelProps.optional = <Typography variant="caption">Optional</Typography>;
91
- }
92
-
93
- if (isStepSkipped(index)) {
94
- stepProps.completed = false;
95
- }
96
-
97
- if (isStepError(index)) {
98
- labelProps.error = true;
99
- }
100
-
101
- if (isStepWarning(index)) {
102
- labelProps.warning = true;
103
- }
104
-
105
- return (
106
- <Step key={label} {...stepProps}>
107
- <StepLabel {...labelProps}>{label}</StepLabel>
108
- </Step>
109
- );
110
- })}
111
- </Stepper>
112
- {activeStep === steps.length ? (
113
- <>
114
- <Typography sx={{ mt: 2, mb: 1 }}>All steps completed - you&apos;re finished</Typography>
115
- <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
116
- <Box sx={{ flex: '1 1 auto' }} />
117
- <Button color="tertiary" onClick={handleReset}>
118
- Reset
119
- </Button>
120
- </Box>
121
- </>
122
- ) : (
123
- <>
124
- <Typography sx={{ mt: 2, mb: 1 }}>Step {activeStep + 1}</Typography>
125
- <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
126
- <Button color="secondary" disabled={activeStep === 0} onClick={handleBack} sx={{ mr: 1 }}>
127
- Back
128
- </Button>
129
- <Box sx={{ flex: '1 1 auto' }} />
130
- {isStepOptional(activeStep) && (
131
- <Button color="secondary" onClick={handleSkip} sx={{ mr: 1 }}>
132
- Skip
111
+ <Paper sx={{ padding: '2rem' }}>
112
+ <Stepper activeStep={activeStep} {...args} orientation={width < 600 ? 'vertical' : args.orientation}>
113
+ {steps.map((label, index) => {
114
+ const stepProps: { completed?: boolean } = {};
115
+ const labelProps: { optional?: React.ReactNode; error?: boolean; warning?: boolean } = {};
116
+
117
+ if (isStepOptional(index)) {
118
+ labelProps.optional = <Typography variant="caption">Optional</Typography>;
119
+ }
120
+
121
+ if (isStepSkipped(index)) {
122
+ stepProps.completed = false;
123
+ }
124
+
125
+ if (isStepError(index)) {
126
+ labelProps.error = true;
127
+ }
128
+
129
+ if (isStepWarning(index)) {
130
+ labelProps.warning = true;
131
+ }
132
+
133
+ return (
134
+ <Step key={label} {...stepProps}>
135
+ <StepLabel {...labelProps}>{label}</StepLabel>
136
+ </Step>
137
+ );
138
+ })}
139
+ </Stepper>
140
+ {activeStep === steps.length ? (
141
+ <>
142
+ <Typography sx={{ mt: 2, mb: 1 }}>All steps completed - you&apos;re finished</Typography>
143
+ <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
144
+ <Box sx={{ flex: '1 1 auto' }} />
145
+ <Button color="tertiary" onClick={handleReset}>
146
+ Reset
147
+ </Button>
148
+ </Box>
149
+ </>
150
+ ) : (
151
+ <>
152
+ <Typography sx={{ mt: 2, mb: 1 }}>Step {activeStep + 1}</Typography>
153
+ <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
154
+ <Button color="secondary" disabled={activeStep === 0} onClick={handleBack} sx={{ mr: 1 }}>
155
+ Back
133
156
  </Button>
134
- )}
135
- <Button color={activeStep === steps.length - 1 ? 'primary' : 'secondary'} onClick={handleNext}>
136
- {activeStep === steps.length - 1 ? 'Finish' : 'Next'}
137
- </Button>
138
- </Box>
139
- </>
140
- )}
157
+ <Box sx={{ flex: '1 1 auto' }} />
158
+ {isStepOptional(activeStep) && (
159
+ <Button color="secondary" onClick={handleSkip} sx={{ mr: 1 }}>
160
+ Skip
161
+ </Button>
162
+ )}
163
+ <Button color={activeStep === steps.length - 1 ? 'primary' : 'secondary'} onClick={handleNext}>
164
+ {activeStep === steps.length - 1 ? 'Finish' : 'Next'}
165
+ </Button>
166
+ </Box>
167
+ </>
168
+ )}
169
+ </Paper>
141
170
  </Box>
142
171
  );
143
172
  },
@@ -153,10 +182,14 @@ export const _StepLabel: StoryObj<typeof StepLabel> = {
153
182
 
154
183
  export const _Step: StoryObj<typeof Step> = {
155
184
  render: (args) => (
156
- <Stepper>
157
- <Step {...args}>
158
- <StepLabel>Label</StepLabel>
159
- </Step>
160
- </Stepper>
185
+ <Box>
186
+ <Paper sx={{ padding: '2rem' }}>
187
+ <Stepper>
188
+ <Step {...args}>
189
+ <StepLabel>Label</StepLabel>
190
+ </Step>
191
+ </Stepper>
192
+ </Paper>
193
+ </Box>
161
194
  ),
162
195
  };