Forked from fpalluel/components.power-select-custom-group.js
Created
April 20, 2017 14:15
-
-
Save cibernox/9e0bb0fbff5283856661066d87deb043 to your computer and use it in GitHub Desktop.
EPS submenu
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.Component.extend({ | |
disabled: Ember.computed.reads('group.disabled'), | |
groupName: Ember.computed.reads('group.groupName'), | |
cancelClose: false, | |
// Hooks | |
didReceiveAttrs() { | |
this._super(...arguments); | |
Ember.run.scheduleOnce('actions', this, this.checkIfSubItemIsHighlighted); | |
}, | |
// Methods | |
calculatePosition(trigger, content) { | |
let { top, left, width, height } = trigger.getBoundingClientRect(); | |
let { width: contentWidth,height: contentHeight } = content.getBoundingClientRect(); | |
let style = { | |
left: left - contentWidth, | |
top: top + window.pageYOffset + (height / 2) - (contentHeight / 2) + 25 | |
}; | |
return { style }; | |
}, | |
checkIfSubItemIsHighlighted(){ | |
let highlightedOpt = this.get('select.highlighted'); | |
let options = this.get('group.options'); | |
let highlightedIsInThisGroup = options.indexOf(highlightedOpt) > -1; | |
if (highlightedIsInThisGroup && !this._oldHighlightedIsInThisGroup) { | |
this.get('dropdown').actions.open(); | |
} else if (!highlightedIsInThisGroup && this._oldHighlightedIsInThisGroup) { | |
this.get('dropdown').actions.close(); | |
} | |
this._oldHighlightedIsInThisGroup = highlightedIsInThisGroup; | |
}, | |
// Actions | |
actions: { | |
onTriggerMouseEnter(trigger) { | |
this.set('cancelClose', false); | |
trigger.actions.open(); | |
}, | |
onContentMouseEnter(trigger) { | |
this.set('cancelClose', true); | |
}, | |
onContentMouseLeave(trigger) { | |
trigger.actions.close(); | |
}, | |
onTriggerMouseLeave(trigger) { | |
Ember.run.later((id) => { | |
if(this.get('_state') !== "destroying") { | |
if(!this.get('cancelClose')) { | |
trigger.actions.close(); | |
} | |
this.set('cancelClose', false); | |
} | |
},trigger, 100); | |
}, | |
onClose(trigger) { | |
}, | |
onOpen(trigger) { | |
// Highlight first submenu item | |
this.get('select').actions.highlight(this.get('group.options.firstObject')); | |
} | |
} | |
}); |
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', | |
options: [ | |
'Item One', | |
'Item Two', | |
{groupName: 'Group One', options: [ | |
'G1 - Sub Item One', | |
'G1 - Sub Item Two', | |
'G1 - Sub Item Three', | |
] | |
}, | |
{groupName: 'Group Two', options: [ | |
'G2 - Sub Item One', | |
'G2 - Sub Item Two', | |
'G2 - Sub Item Three', | |
] | |
}, | |
'Item Three', | |
'Item Four', | |
'Item Five', | |
{groupName: 'Group Three', options: [ | |
'G3 - Sub Item One', | |
'G3 - Sub Item Two', | |
'G3 - Sub Item Three', | |
] | |
}, | |
] | |
}); |
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; | |
} | |
.power-wrapper { | |
width: 15em; | |
display: block; | |
float: right; | |
} | |
.ember-power-select-group { | |
background-color: #e8f0ff; | |
} | |
.content-bootstrap-feel { | |
background-color: #fff; | |
border: 1px solid rgba(0,0,0,.15); | |
border-radius: 4px; | |
box-shadow: 0 6px 12px rgba(0,0,0,.175); | |
padding: 5px; | |
margin: 2px 0 0; | |
} | |
.arrow-right-content { | |
margin-left: 10px; | |
background: #fff; | |
border: 1px solid rgba(0, 0, 0, 0.15); | |
} | |
.arrow-right-content:after, .arrow-right-content:before { | |
left: 100%; | |
top: 50%; | |
border: solid transparent; | |
content: " "; | |
height: 0; | |
width: 0; | |
position: absolute; | |
pointer-events: none; | |
} | |
.arrow-right-content:after { | |
border-color: rgba(255, 255, 255, 0); | |
border-left-color: #fff; | |
border-width: 10px; | |
margin-top: -10px; | |
} | |
.arrow-right-content:before { | |
border-color: rgba(0, 0, 0, 0); | |
border-left-color: rgba(0, 0, 0, 0.15); | |
border-width: 11px; | |
margin-top: -11px; | |
} |
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.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-power-select": "1.7.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment