|
25 | 25 |
|
26 | 26 | ### Create a canal |
27 | 27 |
|
28 | | -In order to create a canal, use the `createCanal` function. Pass it your screens in the business order. |
| 28 | +In order to create a canal, use the `Canal` and `Screen` components. Your screens order is important: the order is the elevation order. If two or more screens are visible, last visible in the array is shown. |
29 | 29 |
|
30 | 30 | ```ts |
31 | 31 | import React from 'react'; |
32 | | -import { createCanal } from 'react-gondola'; |
| 32 | +import { Canal, Screen } from 'react-gondola'; |
33 | 33 | import { FirstName } from './FirstName'; |
34 | 34 | import { LastName } from './LastName'; |
35 | 35 |
|
36 | | -const SignInCanal = createCanal([ |
37 | | - { name: 'firstName', Component: FirstName }, |
38 | | - { name: 'lastName', Component: LastName }, |
39 | | -]); |
40 | | -``` |
41 | | - |
42 | | -Then, use the canal wherever you want in your app. Specify whether to show/hide a screen by using the screen's name as a prop: |
43 | | - |
44 | | -```ts |
45 | | -import React, { Component } from 'react'; |
46 | | -import { SignInCanal } from './canals/SignIn'; |
47 | | - |
48 | | -export default class App extends Component { |
49 | | - render() { |
50 | | - return <SignInCanal firstName={true} lastName={false} />; |
51 | | - } |
52 | | -} |
| 36 | +const SignInCanal = () => ( |
| 37 | + <Canal> |
| 38 | + <Screen name="firstname" Component={FirstName} visible /> |
| 39 | + <Screen name="lastname" Component={LastName} visible={false} /> |
| 40 | + </Canal> |
| 41 | +); |
53 | 42 | ``` |
54 | 43 |
|
55 | 44 | That's all ! |
56 | 45 |
|
57 | 46 | ### Add a full screen page |
58 | 47 |
|
59 | | -If you want to add full screen page, pass the `isFullScreen` flag to the right page when creating a canal. In the following example, `confirm` is a full screen page. |
| 48 | +If you want to add full screen page, pass the `isFullScreen` flag prop to your `Screen` when creating a canal. In the following example, `lastname` is a full screen page. |
60 | 49 |
|
61 | 50 | ```ts |
62 | 51 | import React from 'react'; |
63 | | -import { createCanal } from 'react-gondola'; |
| 52 | +import { Canal, Screen } from 'react-gondola'; |
64 | 53 | import { FirstName } from './FirstName'; |
65 | 54 | import { LastName } from './LastName'; |
66 | 55 |
|
67 | | -const SignInCanal = createCanal([ |
68 | | - { name: 'firstName', Component: FirstName }, |
69 | | - { name: 'lastName', Component: LastName }, |
70 | | - { name: 'confirm', Component: Confirm, isFullScreen: true }, |
71 | | -]); |
| 56 | +const SignInCanal = () => ( |
| 57 | + <Canal> |
| 58 | + <Screen name="firstname" Component={FirstName} visible /> |
| 59 | + <Screen name="lastname" Component={LastName} visible={false} isFullScreen /> |
| 60 | + </Canal> |
| 61 | +); |
72 | 62 | ``` |
73 | 63 |
|
74 | | -In order to render the full screen page at the top level in your app, add the `FullScreenPortal` at the top level in your rendering tree. |
| 64 | +In order to render the full screen page, add the `FullScreenPortal` at the top level in your rendering tree. |
75 | 65 |
|
76 | 66 | ```ts |
77 | 67 | import React, { Component } from 'react'; |
78 | | -import { SignInCanal } from './canals/SignIn'; |
| 68 | +import { MyCanal } from './canals/MyCanal'; |
79 | 69 | import { FullScreenPortal } from 'react-gondola'; |
80 | 70 |
|
81 | 71 | export default class App extends Component { |
82 | 72 | render() { |
83 | 73 | return ( |
84 | 74 | <FullScreenPortal> |
85 | | - <SignInCanal firstName lastName confirm /> |
| 75 | + <MyCanal /> |
86 | 76 | </FullScreenPortal> |
87 | 77 | ); |
88 | 78 | } |
89 | 79 | } |
90 | 80 | ``` |
91 | 81 |
|
| 82 | +### Go Back |
| 83 | + |
| 84 | +Back events are also managed in a declarative way. Use the `onBack` callback prop on your screen. |
| 85 | + |
| 86 | +```ts |
| 87 | +import React from 'react'; |
| 88 | +import { Canal, Screen } from 'react-gondola'; |
| 89 | +import { FirstName } from './FirstName'; |
| 90 | +import { LastName } from './LastName'; |
| 91 | + |
| 92 | +const SignInCanal = () => ( |
| 93 | + <Canal> |
| 94 | + <Screen name="firstname" Component={FirstName} visible /> |
| 95 | + <Screen |
| 96 | + name="lastname" |
| 97 | + Component={LastName} |
| 98 | + visible={false} |
| 99 | + onBack={() => { |
| 100 | + doSomething(); |
| 101 | + }} |
| 102 | + /> |
| 103 | + </Canal> |
| 104 | +); |
| 105 | +``` |
| 106 | + |
| 107 | +import { Info } from 'components/Info'; |
| 108 | +import { Warning } from 'components/Warning'; |
| 109 | + |
| 110 | +<Warning> |
| 111 | + You should use a state machine in order to make your canal a controlled component. In fact, your |
| 112 | + `onBack` callbacks should modify your state in a way it affects the visibility of your screens. |
| 113 | + See the example in the repo. |
| 114 | +</Warning> |
| 115 | +<Info> |
| 116 | + If you have nested or multiple canals, here is the priority of `onBack` callbacks: |
| 117 | + <br/> |
| 118 | + - Last visible full-screen screen. |
| 119 | + <br/> |
| 120 | + - Deepest visible screen. |
| 121 | +</Info> |
| 122 | + |
92 | 123 | You are ready to use React-Gondola 🎸. |
0 commit comments