1
- React Off-Canvas
2
- =====
1
+ # React Off-Canvas
3
2
4
3
Off-canvas menus for React.
5
4
6
5
## Installation
7
6
8
- ```` bash
7
+ ``` bash
9
8
$ npm install --save react-offcanvas
10
- ````
9
+ ```
11
10
12
11
## Usage
13
12
14
13
### Basic Usage
15
14
16
- ```` jsx
17
- < OffCanvas width= {300 } transitionDuration= {300 } isMenuOpened= {false } position= {" left" }>
18
- < OffCanvasBody className= {" my-body-class" } style= {{fontSize: ' 18px' }}>
15
+ ``` jsx
16
+ < OffCanvas
17
+ width= {300 }
18
+ transitionDuration= {300 }
19
+ isMenuOpened= {false }
20
+ position= {" left" }
21
+ >
22
+ < OffCanvasBody className= {" my-body-class" } style= {{ fontSize: " 18px" }}>
19
23
This is the canvas body.
20
24
< / OffCanvasBody>
21
- < OffCanvasMenu className= {" my-menu-class" } style= {{fontWeight: ' bold' }}>
25
+ < OffCanvasMenu className= {" my-menu-class" } style= {{ fontWeight: " bold" }}>
22
26
This is the canvas menu.
23
27
< / OffCanvasMenu>
24
28
< / OffCanvas>
25
- ````
29
+ ```
26
30
27
31
### Within An Application
28
32
29
33
You'll need to hook up your application to handle the state for toggling the menu. Check out the basic example below:
30
34
31
- ```` js
32
- ' use strict' ;
35
+ ``` js
36
+ " use strict" ;
33
37
34
- import React , { Component } from ' react' ;
35
- import { OffCanvas , OffCanvasMenu , OffCanvasBody } from ' react-offcanvas' ;
38
+ import React , { Component } from " react" ;
39
+ import { OffCanvas , OffCanvasMenu , OffCanvasBody } from " react-offcanvas" ;
36
40
37
41
export default class App extends Component {
38
-
39
42
componentWillMount () {
40
43
// sets the initial state
41
44
this .setState ({
42
45
isMenuOpened: false
43
- })
46
+ });
44
47
}
45
48
46
49
render () {
47
50
return (
48
- < OffCanvas width= {300 } transitionDuration= {300 } isMenuOpened= {this .state .isMenuOpened } position= {" right" }>
49
- < OffCanvasBody className= {styles .bodyClass } style= {{fontSize: ' 30px' }}>
51
+ < OffCanvas
52
+ width= {300 }
53
+ transitionDuration= {300 }
54
+ effect= {" parallax" }
55
+ isMenuOpened= {this .state .isMenuOpened }
56
+ position= {" right" }
57
+ >
58
+ < OffCanvasBody
59
+ className= {styles .bodyClass }
60
+ style= {{ fontSize: " 30px" }}
61
+ >
50
62
< p> This is the main body container.< / p>
51
- < p>< a href= " #" onClick= {this .handleClick .bind (this )}> Click here< / a> to toggle the menu.< / p>
63
+ < p>
64
+ < a href= " #" onClick= {this .handleClick .bind (this )}>
65
+ Click here
66
+ < / a> {" " }
67
+ to toggle the menu.
68
+ < / p>
52
69
< / OffCanvasBody>
53
70
< OffCanvasMenu className= {styles .menuClass }>
54
71
< p> Placeholder content.< / p>
@@ -58,7 +75,11 @@ export default class App extends Component {
58
75
< li> Link 3 < / li>
59
76
< li> Link 4 < / li>
60
77
< li> Link 5 < / li>
61
- < li>< a href= " #" onClick= {this .handleClick .bind (this )}> Toggle Menu< / a>< / li>
78
+ < li>
79
+ < a href= " #" onClick= {this .handleClick .bind (this )}>
80
+ Toggle Menu
81
+ < / a>
82
+ < / li>
62
83
< / ul>
63
84
< / OffCanvasMenu>
64
85
< / OffCanvas>
@@ -69,41 +90,41 @@ export default class App extends Component {
69
90
// toggles the menu opened state
70
91
this .setState ({ isMenuOpened: ! this .state .isMenuOpened });
71
92
}
72
-
73
93
}
74
- ````
94
+ ```
75
95
76
96
## Components
77
97
78
98
### ` OffCanvas `
79
99
80
100
This is the main component you will be using to compose your body and menu.
81
101
82
- | Prop | Type | Default | Description |
83
- | :--- | :--- | :--- | :--- |
84
- | ` width ` | ` number ` | 250 | The width of the menu and off-canvas transition. |
85
- | ` transitionDuration ` | ` number ` | 250 | The time in ms for the transition. |
86
- | ` isMenuOpened ` | ` bool ` | false | Is the menu opened or not. |
87
- | ` position ` | ` string ` | "left" | Position the menu to the "left" or "right". |
102
+ | Prop | Type | Default | Description |
103
+ | :------------------- | :------- | :------ | :-------------------------------------------------------- |
104
+ | ` width ` | ` number ` | 250 | The width of the menu and off-canvas transition. |
105
+ | ` transitionDuration ` | ` number ` | 250 | The time in ms for the transition. |
106
+ | ` isMenuOpened ` | ` bool ` | false | Is the menu opened or not. |
107
+ | ` position ` | ` string ` | "left" | Position the menu to the "left" or "right". |
108
+ | ` effect ` | ` string ` | "push" | Position the menu to the "push", "overlay" or "parallax". |
88
109
89
110
### ` OffCanvasBody `
90
111
91
- | Prop | Type | Default | Description |
92
- | :--- | :--- | :--- | :--- |
93
- | ` width ` | ` number ` | 250 | The width of the menu and off-canvas transition. |
94
- | ` transitionDuration ` | ` number ` | 250 | The time in ms for the transition. |
95
- | ` isMenuOpened ` | ` bool ` | false | Is the menu opened or not. |
96
- | ` position ` | ` string ` | "left" | Position the menu to the "left" or "right". |
97
- | ` className ` | ` string ` | | Custom className for the element. |
98
- | ` style ` | ` object ` | | CSS style object for the element. |
112
+ | Prop | Type | Default | Description |
113
+ | :------------------- | :------- | :------ | :-------------------------------------------- --- |
114
+ | ` width ` | ` number ` | 250 | The width of the menu and off-canvas transition. |
115
+ | ` transitionDuration ` | ` number ` | 250 | The time in ms for the transition. |
116
+ | ` isMenuOpened ` | ` bool ` | false | Is the menu opened or not. |
117
+ | ` position ` | ` string ` | "left" | Position the menu to the "left" or "right". |
118
+ | ` className ` | ` string ` | | Custom className for the element. |
119
+ | ` style ` | ` object ` | | CSS style object for the element. |
99
120
100
121
### ` OffCanvasMenu `
101
122
102
- | Prop | Type | Default | Description |
103
- | :--- | :--- | :--- | :--- |
104
- | ` width ` | ` number ` | 250 | The width of the menu and off-canvas transition. |
105
- | ` transitionDuration ` | ` number ` | 250 | The time in ms for the transition. |
106
- | ` isMenuOpened ` | ` bool ` | false | Is the menu opened or not. |
107
- | ` position ` | ` string ` | "left" | Position the menu to the "left" or "right". |
108
- | ` className ` | ` string ` | | Custom className for the element. |
109
- | ` style ` | ` object ` | | CSS style object for the element. |
123
+ | Prop | Type | Default | Description |
124
+ | :------------------- | :------- | :------ | :-------------------------------------------- --- |
125
+ | ` width ` | ` number ` | 250 | The width of the menu and off-canvas transition. |
126
+ | ` transitionDuration ` | ` number ` | 250 | The time in ms for the transition. |
127
+ | ` isMenuOpened ` | ` bool ` | false | Is the menu opened or not. |
128
+ | ` position ` | ` string ` | "left" | Position the menu to the "left" or "right". |
129
+ | ` className ` | ` string ` | | Custom className for the element. |
130
+ | ` style ` | ` object ` | | CSS style object for the element. |
0 commit comments