Skip to content

Commit 299698d

Browse files
authored
Merge pull request #15 from devrnt/docs/improve-readme
Docs/improve readme
2 parents e81c69a + 46cde06 commit 299698d

File tree

8 files changed

+114
-53
lines changed

8 files changed

+114
-53
lines changed

README.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
## Features
1414

15-
- Hooks
15+
- Simplicity
1616
- Focused on logic
1717
- No UI restrictions
1818
- Written in TypeScript
19-
- Documented, self explaining methods
2019

2120
## Installation
2221

@@ -72,25 +71,26 @@ const Step1 = () => {
7271

7372
### Wizard
7473

75-
`Wizard` is used to wrap your steps. Each child component will be treated as an individual step. You can pass a shared `footer` and `header` component that should always be in your steps.
74+
`Wizard` is used to wrap your steps. Each child component will be treated as an individual step. You can pass a shared `footer` and `header` component that should always be in your steps.
7675

7776
Example: pass a footer component that contains a "previous" and "next" button to the wizard.
7877

7978
#### Props
8079

81-
| name | type | description | required | default |
82-
| ---------- | --------------- | ------------------------------------------------------------- | -------- | ------- |
83-
| startIndex | number | Indicate the wizard to start at the given step || 0 |
84-
| header | React.ReactNode | Header that is shown above the active step || |
85-
| footer | React.ReactNode | Footer that is shown below the active stepstep || |
86-
| children | React.ReactNode | Each child component will be treated as an individual step | ✔️ |
80+
| name | type | description | required | default |
81+
| ---------- | --------------- | ---------------------------------------------------------- | -------- | ------- |
82+
| startIndex | number | Indicate the wizard to start at the given step || 0 |
83+
| header | React.ReactNode | Header that is shown above the active step || |
84+
| footer | React.ReactNode | Footer that is shown below the active stepstep || |
85+
| children | React.ReactNode | Each child component will be treated as an individual step | ✔️ |
8786

8887
#### Example
8988

9089
```javascript
91-
// Example: show the active step in this component
90+
// Example: show the active step in the header
9291
const Header = () => <p>I am the header component</p>;
9392

93+
// Example: show the "previous" and "next" buttons in the footer
9494
const Footer = () => <p>I am the footer component</p>;
9595

9696
const App = () => {
@@ -106,22 +106,24 @@ const App = () => {
106106

107107
### useWizard
108108

109-
Used to retrieve all methods and properties related to your wizard. Make sure `Wizard` is wrapped around your component when calling `useWizard`.
109+
Used to retrieve all methods and properties related to your wizard. Make sure `Wizard` is wrapped around your component when calling `useWizard`.
110+
111+
`handleStep` is used to attach a handler to the step, can either be `async` or a `sync` function. This function will be invoked when calling `nextStep`.
110112

111113
**Remark** - You can't use `useWizard` in the same component where `Wizard` is used.
112114

113115
#### Methods
114116

115-
| name | type | description |
116-
| ----------------------------------------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------- |
117-
| nextStep | () => Promise<void> | Go to the next step |
118-
| previousStep | () => void | Go to the previous step |
119-
| handleStep | (handler: Handler) => void | Attach a callback that will be called when calling `nextStep`. `handler` can be either sync or async |
120-
| isLoading | boolean | \* Will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected |
121-
| activeStep | number | The current active step of the wizard |
122-
| isFirstStep | boolean | Indicate if the current step is the first step (aka no previous step) |
123-
| isLastStep | boolean | Indicate if the current step is the last step (aka no next step) |
124-
| |
117+
| name | type | description |
118+
| ------------ | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
119+
| nextStep | () => Promise<void> | Go to the next step |
120+
| previousStep | () => void | Go to the previous step |
121+
| handleStep | (handler: Handler) => void | Attach a callback that will be called when calling `nextStep`. `handler` can be either sync or async |
122+
| isLoading | boolean | \* Will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected |
123+
| activeStep | number | The current active step of the wizard |
124+
| isFirstStep | boolean | Indicate if the current step is the first step (aka no previous step) |
125+
| isLastStep | boolean | Indicate if the current step is the last step (aka no next step) |
126+
| |
125127

126128
#### Example
127129

@@ -149,6 +151,7 @@ const Step1 = () => {
149151
handleStep,
150152
} = useWizard();
151153

154+
// This handler is optional
152155
handleStep(() => {
153156
alert('Going to step 2');
154157
});
@@ -173,6 +176,7 @@ const Step1 = () => {
173176
It's recommended to pass the shared components to the `header` or `footer` in the `Wizard` to avoid duplication.
174177

175178
## Examples
179+
176180
Go to [examples](https://github.com/devrnt/react-use-wiard/tree/master/examples) to check see some examples
177181

178182
## Async
@@ -200,14 +204,17 @@ const Step1 = () => {
200204
```
201205

202206
### Errors
207+
203208
If no errors are thrown then the wizard will go to the next step, so no need to call `nextStep` by yourself.
204209

205-
If an error is thrown in the conencted function the wizard will just stay at the same step and will rethrow the error. (So you can try-catch in your attached function).
210+
If an error is thrown in the attached function the wizard will just stay at the same step and will rethrow the error. (So you can try-catch in your attached function).
206211

207212
### IsLoading
213+
208214
If an async function is attached to `handleStep` the `isLoading` property will indicate the loading state of the function. In general `isLoading` will reflect the handler promise state: will be `true` if the handler promise is pending and `false` when the handler is either fulfilled or rejected.
209215

210216
## Animation
211-
Since `react-use-wizard` is focused to manage the logic of a wizard it doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest [framer-motion](https://www.framer.com/motion/) to add your animations.
212217

213-
Checkout this [example](https://github.com/devrnt/react-use-wizard/blob/docs/readme/example/components/animatedStep.tsx) to see how a step can be animated with framer motion.
218+
Since `react-use-wizard` is focused to manage the logic of a wizard it doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest [framer-motion](https://www.framer.com/motion/) to add your animations.
219+
220+
Checkout this [example](https://github.com/devrnt/react-use-wizard/blob/docs/readme/example/components/animatedStep.tsx) to see how a step can be animated with framer motion.

playground/components/asyncStep.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Container = styled('div')`
3232
`;
3333

3434
const P = styled('p')`
35-
color: white;
35+
color: var(--text);
3636
`;
3737

3838
const AsyncStep: React.FC<Props> = React.memo(({ number }) => {

playground/components/footer.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,31 @@ import { useWizard } from '../../dist';
55
import { Button } from '../modules/common';
66

77
const Actions = styled('div')`
8-
display: grid;
8+
display: flex;
99
justify-content: center;
1010
margin: 1rem 0;
11-
grid-template-columns: min-content min-content;
1211
gap: 1rem;
12+
flex-direction: row;
1313
`;
1414

1515
const Info = styled('div')`
1616
display: flex;
1717
justify-content: center;
18-
gap: 1rem;
18+
flex-direction: column;
19+
gap: 0;
20+
21+
& > p {
22+
margin: 0.25rem 0;
23+
}
24+
25+
@media screen and (min-width: 600px) {
26+
flex-direction: row;
27+
gap: 1rem;
28+
29+
& > p {
30+
margin: initial;
31+
}
32+
}
1933
`;
2034

2135
const Footer: React.FC = React.memo(() => {

playground/components/step.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const Container = styled('div')`
2121
`;
2222

2323
const P = styled('p')`
24-
color: white;
24+
color: var(--text);
2525
`;
2626

2727
const Step: React.FC<Props> = React.memo(({ number, withCallback = true }) => {

playground/modules/common/button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Container = styled('button')`
1212
border: 1px solid var(--purple);
1313
padding: 0.7rem 1.75rem;
1414
border-radius: 6px;
15-
color: white;
15+
color: var(--text);
1616
font-size: 1.1rem;
1717
font-weight: 700;
1818
background-color: var(--dark);
@@ -27,6 +27,7 @@ const Container = styled('button')`
2727
&:disabled {
2828
opacity: 0.4;
2929
background-image: initial;
30+
cursor: initial;
3031
}
3132
`;
3233

playground/modules/common/page.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Container = styled('main')`
1414
display: flex;
1515
justify-content: center;
1616
background: var(--dark);
17+
overflow: hidden;
1718
`;
1819

1920
const Wrapper = styled('div')`
@@ -27,29 +28,35 @@ const Body = styled('div')`
2728
const Description = styled('div')`
2829
font-size: 1.1rem;
2930
font-weight: 200;
31+
line-height: 1.5rem;
3032
`;
3133

3234
const Divider = styled('div')`
3335
height: 2px;
34-
width: 7%;
36+
width: 15%;
3537
background-image: linear-gradient(48.66deg, var(--purple), var(--blue));
36-
margin: 2.5rem 0;
38+
margin: 2.5rem auto;
3739
display: flex;
40+
41+
@media screen and (min-width: 800px) {
42+
max-width: 7%;
43+
}
3844
`;
3945

4046
const TopBar = styled('header')`
4147
position: sticky;
4248
top: 0;
4349
left: 0;
4450
right: 0;
45-
padding: 1.5rem 1.75rem;
51+
padding: 1.75rem 0;
4652
display: flex;
4753
justify-content: space-between;
4854
align-items: center;
49-
margin-bottom: 4rem;
55+
margin-bottom: 5rem;
5056
background-color: var(--nav);
5157
backdrop-filter: blur(20px);
5258
z-index: 1000;
59+
width: 100%;
5360
`;
5461

5562
const Logo = styled('img')`
@@ -62,11 +69,19 @@ const GithubLogo = styled('img')`
6269
`;
6370

6471
const MaxWidth = styled('div')`
65-
max-width: 53rem;
72+
width: 100%;
6673
padding: 0 2rem;
6774
margin: 0 auto;
6875
justify-content: space-between;
69-
width: 100%;
76+
77+
@media screen and (min-width: 800px) {
78+
max-width: 53rem;
79+
padding: 0 2rem;
80+
}
81+
`;
82+
83+
const H1 = styled('h1')`
84+
font-size: 2.25rem;
7085
`;
7186

7287
const Page = ({ title, description, children }: Props) => {
@@ -77,6 +92,7 @@ const Page = ({ title, description, children }: Props) => {
7792
<MaxWidth
7893
style={{
7994
display: 'flex',
95+
alignItems: 'center',
8096
}}
8197
>
8298
<Logo src={logoPath} />
@@ -90,7 +106,7 @@ const Page = ({ title, description, children }: Props) => {
90106
</MaxWidth>
91107
</TopBar>
92108
<MaxWidth>
93-
<h1>{title}</h1>
109+
<H1>{title}</H1>
94110
<Description>{description}</Description>
95111
<Divider />
96112
<Body>{children}</Body>

playground/modules/common/style.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const GlobalStyle = createGlobalStyles`
1111
--blue: #08D8F4;
1212
--code:#260949;
1313
--step:#170231;
14+
--text: #cccccc;
15+
}
16+
17+
* {
18+
box-sizing: border-box;
1419
}
1520
1621
html {
@@ -31,7 +36,7 @@ const GlobalStyle = createGlobalStyles`
3136
body {
3237
font-family: 'Inter', Helvetica, sans-serif;
3338
text-rendering: optimizeLegibility;
34-
color: white;
39+
color: var(--text);
3540
}
3641
3742
i {
@@ -44,7 +49,7 @@ const GlobalStyle = createGlobalStyles`
4449
border-radius: 2px;
4550
font-family: 'Fira Code', monospace;
4651
font-size: 0.95rem;
47-
padding: 0.75rem 0.35rem;
52+
padding: 0.75rem 1rem;
4853
}
4954
`;
5055

playground/modules/wizard/wizard.tsx

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { styled } from 'goober';
1+
import { css, styled } from 'goober';
22
import * as React from 'react';
33

44
import { Wizard } from '../../../dist';
55
import { AnimatedStep, AsyncStep, Footer, Step } from '../../components';
66

7-
const Grid = styled('section')`
8-
display: grid;
9-
grid-template-columns: repeat(1, 1fr);
7+
const Container = styled('section')`
8+
display: flex;
9+
flex-direction: column;
1010
width: 100%;
1111
`;
1212

@@ -21,27 +21,45 @@ const Title = styled('h2')`
2121
}
2222
`;
2323

24-
const Item = styled('div')`
25-
display: grid;
26-
grid-template-rows: min-content;
24+
const Item = styled('div')<{ showDivider: boolean }>`
25+
display: flex;
26+
flex-direction: column;
2727
2828
&::after {
29-
content: '';
3029
margin: 3rem 0 2rem;
30+
content: '';
3131
background-image: linear-gradient(48.66deg, var(--purple), var(--blue));
3232
width: 100%;
3333
position: relative;
34-
height: 1px;
34+
height: ${({ showDivider }) => (showDivider ? '1px' : 0)};
3535
}
36+
37+
${({ showDivider }) =>
38+
showDivider
39+
? `
40+
&::after {
41+
margin: 3rem 0 2rem;
42+
content: '';
43+
background-image: linear-gradient(
44+
48.66deg,
45+
var(--purple),
46+
var(--blue)
47+
);
48+
width: 100%;
49+
position: relative;
50+
height: 1px;
51+
}
52+
`
53+
: ''}
3654
`;
3755

3856
const WizardModule = () => {
3957
return (
40-
<Grid>
58+
<Container>
4159
<Title>
4260
Simple wizard <span>mix of async and sync steps</span>
4361
</Title>
44-
<Item>
62+
<Item showDivider>
4563
<Wizard footer={<Footer />}>
4664
<AsyncStep number={1} />
4765
<Step number={2} />
@@ -51,9 +69,9 @@ const WizardModule = () => {
5169
</Item>
5270

5371
<Title>
54-
Animated wizard <span>animations by framer motion</span>
72+
Animated wizard <span>animation by framer motion</span>
5573
</Title>
56-
<Item>
74+
<Item showDivider={false}>
5775
<Wizard footer={<Footer />}>
5876
<AnimatedStep>
5977
<Step number={1} withCallback={false} />
@@ -69,7 +87,7 @@ const WizardModule = () => {
6987
</AnimatedStep>
7088
</Wizard>
7189
</Item>
72-
</Grid>
90+
</Container>
7391
);
7492
};
7593

0 commit comments

Comments
 (0)