Skip to content

Commit 90f4666

Browse files
committed
allow th use of custom drawer
Drawer does not necessarily have to be the in built one. Developers can have more control
1 parent 33dd1e4 commit 90f4666

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/nav/index.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ class NavCard {
6262
useBackdrop: false,
6363
backdrop: null,
6464
dest: null,
65+
scrollableContainer: null,
6566
maxStartArea: 25,
6667
threshold: 1 / 2,
67-
unit: 'px'
68+
unit: 'px',
69+
CustomDrawer: null
6870
}
6971

7072
static SERVICES = {
@@ -134,13 +136,15 @@ class NavCard {
134136
MAX_WIDTH: maxWidth,
135137
DIRECTION: opts.direction,
136138
maxStartArea: opts.maxStartArea,
137-
threshold: opts.threshold
139+
threshold: opts.threshold,
140+
scrollableContainer: opts.scrollableContainer,
141+
CustomDrawer: opts.CustomDrawer
138142
}
139143
const hashOptions = {
140144
INIT_ELEM: defaultOptions.INIT_ELEM
141145
}
142146

143-
return new NavMountWorker({
147+
return new NavMountWorker(this, {
144148
defaultOptions,
145149
drawerOptions,
146150
hashOptions
@@ -174,7 +178,10 @@ class NavCard {
174178
}
175179

176180
_drawerAPI(options) {
177-
this.Drawer = new NavDrawer(options, this.State)
181+
const {
182+
CustomDrawer: Drawer
183+
} = options
184+
this.Drawer = Drawer && typeof Drawer === 'object' ? new Drawer(options, this.State) : new NavDrawer(options, this.State)
178185
return {
179186
activate: () => this.Drawer.activate(),
180187
deactivate: () => this.Drawer.deactivate()
@@ -198,29 +205,29 @@ class NavCard {
198205
}
199206
}
200207

201-
class NavMountWorker extends NavCard {
202-
constructor(options) {
203-
super()
208+
class NavMountWorker {
209+
constructor(borrowedContext, options) {
210+
this.$this = borrowedContext
204211
this.options = options
205212
}
206213

207214
mount() {
208-
const DEFAULT_ACTIVE = !this._defaultAPI(this.options.defaultOptions).activate()
209-
const DRAWER_ACTIVE = !this._drawerAPI(this.options.drawerOptions).activate()
210-
const HASH_ACTIVE = !this._hashAPI(this.options.hashOptions).activate()
215+
const DEFAULT_ACTIVE = !this.$this._defaultAPI(this.options.defaultOptions).activate()
216+
const DRAWER_ACTIVE = !this.$this._drawerAPI(this.options.drawerOptions).activate()
217+
const HASH_ACTIVE = !this.$this._hashAPI(this.options.hashOptions).activate()
211218
return new Promise((resolve, reject) => {
212219
if (!(DEFAULT_ACTIVE && DRAWER_ACTIVE && HASH_ACTIVE)) {
213220
reject(new Error('one or more services could not activate'))
214221
return
215222
}
216-
resolve(new NavStateEvent(this.State))
223+
resolve(new NavStateEvent(this.$this, this.$this.State))
217224
})
218225
}
219226

220227
unmount() {
221-
this.SheetService.forceDeactivate()
222-
this.Drawer.deactivate()
223-
this.PopService.deactivate()
228+
this.$this.SheetService.forceDeactivate()
229+
this.$this.Drawer.deactivate()
230+
this.$this.PopService.deactivate()
224231
}
225232

226233
toString() {
@@ -230,14 +237,15 @@ class NavMountWorker extends NavCard {
230237

231238
class NavStateEvent {
232239
events = [NAVSTATE_EVENTS.show, NAVSTATE_EVENTS.hide]
233-
constructor(state) {
240+
constructor($this, state) {
241+
this.$this = $this
234242
this._State = state
235243
}
236-
on(event, handle) {
244+
on(event, handle = () => false) {
237245
if (!(this.events.indexOf(event) + 1)) {
238246
throw new Error(`unknown event '${event}'`)
239247
}
240-
this._State[`on${event}`] = handle
248+
this._State[`on${event}`] = handle.bind(this.$this)
241249
}
242250
off(event) {
243251
if (!(this.events.indexOf(event) + 1)) {

0 commit comments

Comments
 (0)