Created
February 18, 2020 12:04
-
-
Save ganapathyHf/746a204624f3fbd0b6b8aea6b52bf68b to your computer and use it in GitHub Desktop.
Collapse panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
export default Component.extend({ | |
classNames: ['panel-body'], | |
classNameBindings: ['isOpen:is-open'] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
import { inject as service } from '@ember/service'; | |
export default Component.extend({ | |
panelActionsService: service('panel-actions'), | |
group: null, | |
disabled: false, | |
classNames: ['panel-header'], | |
toggleAllPanels: false, | |
actions: { | |
expandAllPanels() { | |
if (this.get("disabled")) { | |
return; | |
} | |
this.get('panelActionsService').openAllPanels(this.get('group')); | |
}, | |
collapseAllPanels() { | |
if (this.get("disabled")) { | |
return; | |
} | |
this.get('panelActionsService').closeAllPanels(this.get('group')); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
export default Component.extend({ | |
classNames: ['panel-toggle', 'u-cursor-pointer'], | |
classNameBindings: ['isOpen:is-open'], | |
click(e) { | |
e.preventDefault(); | |
this.get('onClick')(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EmberObject, { computed } from '@ember/object'; | |
import { reads, not } from '@ember/object/computed'; | |
import Component from '@ember/component'; | |
import { inject as service } from '@ember/service'; | |
import { run } from '@ember/runloop'; | |
export default Component.extend({ | |
classNames: ['panel'], | |
classNameBindings: ['isOpen:is-open:is-closed', 'disabled:is-disabled'], | |
panelActionsService: service('panel-actions'), | |
panelId: null, | |
disabled: false, | |
panelState: computed('panelActionsService.panels.[]', 'panelId', { | |
get() { | |
let panelActionsService = this.get('panelActionsService'); | |
let currentPanel = panelActionsService.getPanelById(this.get('panelId')); | |
return currentPanel; | |
} | |
}), | |
isOpen: reads('panelState.isOpen'), | |
isClosed: not('isOpen'), | |
init() { | |
this._super(...arguments); | |
run.next(() => { | |
let panels = this.get('panelActionsService.panels'); | |
panels.addObject(EmberObject.create({ | |
id: this.get('panelId'), | |
isOpen: true, | |
group: this.get('group') | |
})); | |
}); | |
}, | |
actions: { | |
toggleIsOpen() { | |
if (this.get("disabled")) { | |
return; | |
} | |
this.get('panelActionsService').togglePanel(this.get('panelId')); | |
} | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
import { computed } from '@ember/object'; | |
import { inject as service } from '@ember/service'; | |
export default Component.extend({ | |
panelActionsService: service('panel-actions'), | |
classNames: ['panels'], | |
group: null, | |
canExpandAllPanels:computed('[email protected]', { | |
get() { | |
return this.get('panelActionsService.panels').isEvery('isOpen', false); | |
} | |
}) | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
reports: [{ | |
"id": 1, | |
"name": "Report 1", | |
"pages":[{ | |
"id": "11", | |
"name": "Page 1" | |
}, { | |
"id": "12", | |
"name": "Page 2" | |
}] | |
}, { | |
"id": 2, | |
"name": "Report 2", | |
"pages":[{ | |
"id": "13", | |
"name": "Page 3 - Report 2" | |
}] | |
}] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Service from '@ember/service'; | |
import { A } from '@ember/array'; | |
export default Service.extend({ | |
panels: A(), | |
getPanelById(panelId) { | |
return this.get('panels').findBy('id', panelId); | |
}, | |
getPanelsForGroup(group) { | |
return this.get('panels').filterBy('group', group); | |
}, | |
togglePanel(panelId) { | |
let panel = this.getPanelById(panelId); | |
panel.toggleProperty('isOpen'); | |
}, | |
openAllPanels(group) { | |
let panels = this.getPanelsForGroup(group); | |
panels.forEach((panel) => { | |
panel.set('isOpen', true); | |
}); | |
}, | |
closeAllPanels(group) { | |
let panels = this.getPanelsForGroup(group); | |
panels.forEach((panel) => { | |
panel.set('isOpen', false); | |
}); | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.panel { | |
margin-bottom: 5px; | |
} | |
.panel-toggle { | |
.u-vertically-centered-container; | |
width: 100%; | |
padding: 5px; | |
border-radius: 4px; | |
background-color: green; | |
font-size: 14px; | |
font-weight: bold; | |
&::before { | |
content: ''; | |
background-image: url(svgs/chevron-right.svg); | |
width: 17px; | |
height: 17px; | |
background-size: 17px 17px; | |
} | |
} | |
.panel-toggle.is-open { | |
&::before { | |
background-image: url(svgs/chevron-down.svg); | |
} | |
} | |
.panel-body { | |
&.is-open { | |
padding: 10px 5px 5px; | |
} | |
.field:last-of-type { | |
margin-bottom: 0px; | |
} | |
} | |
.navigation-pane_reports_panel { | |
margin-right: 20px; | |
.panel { | |
margin-bottom: 10px; | |
} | |
.panel.is-open { | |
margin-bottom: 0; | |
} | |
.panel-toggle { | |
padding: 0 0 0 5px; | |
} | |
.panel-body.is-open { | |
padding: 5px 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment