-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] add contextual components support
Contextual components provide a nice syntax for encapsulating components that would not be much use elsewhere. `x-option` is such a component; it is not so useful without `x-select`. Indeed, we even assert if there is no parent `x-select` component. Because we want to provide a great experience for our users who don't yet have the time to upgrade Ember, I implemented this using ember-cli's `treeForAddonTemplates` hook. If the consuming app has a version of ember that is less than `2.3.0`, the original template is provided to the app tree. Otherwise, we can take advantage of contextual components and provide a template that yields a hash with `x-option` for users to use. I stole this from Ember CLI Version Checker's ["Real World Example"](https://github.com/rwjblue/ember-cli-version-checker/blob/0040430d799c783731301773aeeb32b76f936585/README.md#real-world-example) in their README.
- Loading branch information
Stanley Stuart
committed
Mar 10, 2016
1 parent
c923be9
commit c6f02d1
Showing
11 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{yield | ||
(hash | ||
option=(component "x-option" parentXSelect=this) | ||
) | ||
}} |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'emberx-select/templates/components/x-select'; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"predef": [ | ||
"expect", | ||
"document", | ||
"window", | ||
"location", | ||
|
26 changes: 26 additions & 0 deletions
26
tests/integration/with-contextual-components/contextual-component-test.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { it, describeComponent } from 'ember-mocha'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import Ember from 'ember'; | ||
|
||
const integration = true; | ||
|
||
function hasContextualComponents() { | ||
return !Ember.VERSION.match(/^2\.[0-3]/) && !Ember.VERSION.match(/^1/); | ||
} | ||
|
||
describeComponent('x-select', 'X-Select - Contextual Component', {integration}, function() { | ||
|
||
if (hasContextualComponents()) { | ||
it('yields a hash with the option component', function() { | ||
this.render(hbs` | ||
{{#x-select value=status as |xs|}} | ||
{{#xs.option value="in the office"}}In the Office{{/xs.option}} | ||
{{#xs.option value="out of office"}}Out of Office{{/xs.option}} | ||
{{/x-select}} | ||
`); | ||
|
||
expect(this.$('option').length).to.equal(2); | ||
}); | ||
} | ||
}); | ||
|