Skip to content

Commit 3d432cc

Browse files
authored
Merge pull request #15 from americanexpress/feature/v2
feat(v2): updates for React 16, external API tests, and removing all JSX
2 parents ba56208 + f486b26 commit 3d432cc

39 files changed

+7294
-10059
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ lib
1111

1212
# Testing
1313
test-results
14+
.jest-cache
1415

1516
# IDE
1617
.idea

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ language: node_js
22
node_js:
33
- "6"
44
- "8"
5-
before_install:
6-
- npm i -g npm
75
after_success:
86
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

README.md

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,57 @@
44
>
55
> \-- _Albus Dumbledore_
66
7-
## What is React [Albus](http://u.kanobu.ru/comments/images/3c682662-4e19-49c6-b85b-539db47ff838.gif)?
8-
React Albus is a React component library for building declarative multi-step flows (also known as Wizards). You are responsible for writing your own steps and configuring their ordering, but React Albus will maintain the flow-related state for you.
7+
## What is React Albus?
8+
React Albus is a React component library used to build declarative multi-step journeys (also known as Wizards). You define your step content and ordering and React Albus will manage the journey-related state for you.
99

10-
React Albus also allows you to create routed flows, conditionally skip steps in your flow, and create custom elements to suit your needs.
10+
React Albus is otherwise unopinionated and allows you to compose funcionality such as routing, animation, and analytics however you see fit.
11+
12+
## Installation
13+
14+
```
15+
npm install react-albus
16+
```
1117

1218
## Example
1319

1420
```jsx
1521
import React from 'react';
16-
import { Wizard, Step, Steps, Navigation } from 'react-albus';
22+
import { Wizard, Steps, Step } from 'react-albus';
1723

18-
const Example = () =>
24+
const Example = () => (
1925
<Wizard>
2026
<Steps>
21-
<Step path="merlin">
22-
<h1>Merlin</h1>
23-
<Navigation
24-
render={({ next }) =>
25-
<button onClick={next}>Next</button>}
26-
/>
27-
</Step>
28-
<Step path="gandalf">
29-
<h1>Gandalf</h1>
30-
<Navigation
31-
render={({ next, previous }) =>
32-
<div>
33-
<button onClick={next}>Next</button>
34-
<button onClick={previous}>Previous</button>
35-
</div>}
36-
/>
37-
</Step>
38-
<Step path="dumbledore">
39-
<h1>Dumbledore</h1>
40-
<Navigation
41-
render={({ previous }) =>
42-
<button onClick={previous}>Previous</button>}
43-
/>
44-
</Step>
27+
<Step
28+
id="merlin"
29+
render={({ next }) => (
30+
<div>
31+
<h1>Merlin</h1>
32+
<button onClick={next}>Next</button>
33+
</div>
34+
)}
35+
/>
36+
<Step
37+
id="gandalf"
38+
render={({ next, previous }) => (
39+
<div>
40+
<h1>Gandalf</h1>
41+
<button onClick={next}>Next</button>
42+
<button onClick={previous}>Previous</button>
43+
</div>
44+
)}
45+
/>
46+
<Step
47+
id="dumbledore"
48+
render={({ previous }) => (
49+
<div>
50+
<h1>Dumbledore</h1>
51+
<button onClick={previous}>Previous</button>
52+
</div>
53+
)}
54+
/>
4555
</Steps>
46-
</Wizard>;
56+
</Wizard>
57+
);
4758

4859
export default Example;
4960
```
@@ -54,89 +65,79 @@ Check out the [demo page](http://americanexpress.io/react-albus)!
5465
## API
5566

5667
- [`<Wizard>`](#wizard)
57-
- [`<Step>`](#step)
5868
- [`<Steps>`](#steps)
59-
- [`<Navigation>`](#navigation)
69+
- [`<Step>`](#step)
6070
- [`withWizard`](#withwizard)
71+
- [`wizardShape`](#wizardShape)
6172
- [`context.wizard`](#contextwizard)
6273

6374
---
6475

6576
### `<Wizard>`
6677

6778
#### Props
68-
##### `onNext(step, steps, push)`: function *(optional)*
69-
A function that will be called by Wizard to determine the next step to proceed to.
79+
##### `onNext(wizard)`: function *(optional)*
80+
A function that will be called by `<Wizard>` to determine the next step to proceed to.
7081

7182
##### Params
72-
* `step`: An object describing the current step with the structure: `{ path: string, name: string }`.
73-
* `steps`: An array of `step` objects in the order they were declared in `<Steps>`.
74-
* `push(path)`: A function that can be called with the `path` of the step that you want to proceed to. Calling this function without arguments will proceed to the next step.
83+
84+
* `wizard` (object): The [`context.wizard`](#contextwizard) object.
7585

7686
If you do not pass an `onNext` prop, `<Wizard>` will proceed directly to the next step.
7787

78-
##### `className`: string *(optional)*
79-
CSS classes to be added to the `<div>` created by `<Wizard>`.
8088
##### `render(wizard)`: function *(optional)*
8189
A function that will be used as the render function of `<Wizard>`.
8290

8391
##### Params
84-
* `wizard`: The [`context.wizard`](#contextwizard) object.
92+
* `wizard` (object): The [`context.wizard`](#contextwizard) object.
8593

8694
---
8795

88-
### `<Step>`
89-
Wraps all the content that will be conditionally shown when the step is active.
96+
### `<Steps>`
97+
Wraps all of the `<Step>` components in your journey. The only direct children of `<Steps>` should be `<Step>` components.
9098

9199
#### Props
92-
##### `path`: string
93-
Unique key for each step.
94-
##### `className`: string *(optional)*
95-
CSS classes to be added to the `<div>` created by `<Step>`.
100+
##### `step`: object ***(optional)***
101+
An object describing the current step with the structure: `{ id: string }`. Defining a `step` prop will make `<Steps>` a [controlled component](https://facebook.github.io/react/docs/forms.html).
96102

97-
In addition to `path` and `className`, any additional props added to `<Step>` will be available on each `step` object. This can be used to add names, descriptions, or other metadata to each step.
103+
------
98104

99-
---
105+
### `<Step>`
100106

101-
### `<Steps>`
102-
Wraps all of the `<Step>` components for your flow. The only direct children of `<Steps>` should be `<Step>` components.
107+
Wraps all the content that will be conditionally shown when the step is active.
103108

104109
#### Props
105-
##### `step`: object ***(optional)***
106-
An object describing the current step with the structure: `{ path: string, name: string }`. Defining this prop will make `<Steps>` a [controlled component](https://facebook.github.io/react/docs/forms.html).
107110

108-
---
111+
##### `id`: string
109112

110-
### `<Navigation>`
111-
Exposes the Wizard navigation functionality for your components to use. Extends its child's props with [`context.wizard`](#contextwizard) and passes [`context.wizard`](#contextwizard) to its render prop.
112-
#### Props
113-
##### `render(wizard)`: function *(optional)*
114-
A function that will be used as the render function of `<Navigation>`.
113+
Unique key for each step.
115114

116-
##### Params
117-
* `wizard`: The [`context.wizard`](#contextwizard) object.
115+
In addition to `id`, any additional props added to `<Step>` will be available on each `step` object. This can be used to add names, descriptions, or other metadata to each step.
116+
117+
`<WithWizard>` is an alias for `<Step>` that can be used to access [`context.wizard`](#contextwizard) anywhere within the `<Wizard>` tree.
118118

119119
---
120120

121121
### `withWizard()`
122-
A higher order component that spreads [`context.wizard`](#contextwizard) across the wrapped component's props.
122+
A higher order component that adds [`context.wizard`](#contextwizard) as a `wizard ` prop on the wrapped component.
123123

124124
---
125125

126126
### `context.wizard`
127-
`<Wizard>` adds this object to context with the following properties:
127+
`<Wizard>` provides an object on context with the following properties:
128128

129-
* `step` (object): Describes the current step with structure: `{ path: string, name: string }`.
129+
* `step` (object): Describes the current step with structure: `{ id: string }`.
130130
* `steps` (array): Array of `step` objects in the order they were declared within `<Steps>`.
131131
* `history` (object): The backing [`history`](https://github.com/ReactTraining/history#properties) object.
132132
* `next()` (function): Moves to the next step in order.
133133
* `previous()` (function): Moves to the previous step in order.
134-
* `go(n)` (function): Moves *n* steps in history.
135-
* `push(path)` (function): Moves to the step with prop `path`.
134+
* `go(n)` (function): Moves `n` steps in history.
135+
* `push(id)` (function): Pushes the step with corresponding `id` onto history.
136+
* `replace(id)` (function): Replaces the current step in history with the step with corresponding `id`.
136137

137138
## Usage with React Router
138139

139-
Internally, React Albus uses [history](https://github.com/ReactTraining/history) to maintain the ordering of steps. This makes integrating with React Router (or any other router) as easy as providing Albus with a `history` object and a `basename` where it is living.
140+
Internally, React Albus uses [history](https://github.com/ReactTraining/history) to maintain the ordering of steps. This makes integrating with React Router (or any other router) as easy as providing `<Wizard>` with `history` and `basename` props.
140141

141142
```jsx
142143
import React from 'react';
Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`withWizard should add the correct props to it's child 1`] = `
4-
<withWizard(ToWrap)>
5-
<ToWrap
6-
hogwarts="rules"
7-
>
8-
<div />
9-
</ToWrap>
10-
</withWizard(ToWrap)>
3+
exports[`withWizard should add wizard prop to wrapped component 1`] = `
4+
<WrappedComponent
5+
wizard={
6+
Object {
7+
"hogwarts": "rules",
8+
}
9+
}
10+
/>
1111
`;
1212

13-
exports[`withWizard should override context with local props 1`] = `
14-
<withWizard(ToWrap)
15-
hogwarts="drools"
16-
>
17-
<ToWrap
18-
hogwarts="drools"
19-
>
20-
<div />
21-
</ToWrap>
22-
</withWizard(ToWrap)>
13+
exports[`withWizard should use component props over context 1`] = `
14+
<WrappedComponent
15+
wizard="hogwarts"
16+
/>
2317
`;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`wizardShape exports the correct shape 1`] = `
4+
Object {
5+
"isRequired": Object {
6+
"go": "squawk",
7+
"history": "squawk",
8+
"next": "squawk",
9+
"previous": "squawk",
10+
"push": "squawk",
11+
"replace": "squawk",
12+
"step": Object {
13+
"id": "squawk",
14+
},
15+
"steps": Object {
16+
"id": "squawk",
17+
},
18+
},
19+
}
20+
`;

__tests__/components/Navigation.spec.jsx

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)