Skip to content

Instantly share code, notes, and snippets.

@nightire
Last active April 8, 2020 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightire/fef86bc426193e399166f82d62589e93 to your computer and use it in GitHub Desktop.
Save nightire/fef86bc426193e399166f82d62589e93 to your computer and use it in GitHub Desktop.
limited-items
import Component from '@glimmer/component';
export default class extends Component {
get shouldLimit() {
return this.args.items.length > this.args.showMax;
}
get items() {
if (this.shouldLimit) {
const [...items] = this.args.items;
return items.splice(0, items.length - (this.args.showMax - 1));
} else {
return this.args.items;
}
}
get remaining() {
return this.args.items.length - this.args.showMax;
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
options = [
{ name: 'A' },
{ name: 'B' },
{ name: 'C' },
{ name: 'D' },
{ name: 'E' },
]
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<LimitedItems @items={{this.options}} @showMax={{3}} as |item|>
{{item.name}}
</LimitedItems>
<br>
{{outlet}}
<br>
<br>
{{#each this.items as |item|}}
{{yield item}}
{{/each}}
{{#if this.shouldLimit}}
<button type="button">+{{this.remaining}}</button>
{{/if}}
{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.17.0",
"ember-template-compiler": "3.17.0",
"ember-testing": "3.17.0"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment