Skip to content

Instantly share code, notes, and snippets.

@Wolfr
Last active April 8, 2021 18:03
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 Wolfr/bc4e11d5efdc25c742972256ffe9b6a3 to your computer and use it in GitHub Desktop.
Save Wolfr/bc4e11d5efdc25c742972256ffe9b6a3 to your computer and use it in GitHub Desktop.
Accordion
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { guidFor } from '@ember/object/internals';
export default class Accordion extends Component {
@tracked isActive = false
accordionId = 'accordion-' + guidFor(this);
@action
toggleAccordion() {
this.isActive = !this.isActive
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
/* ==========================================================================
auk-accordion
========================================================================== */
.auk-accordion__content {
display: none;
transition: max-height 0.3s cubic-bezier(0, 1.05, 0, 1), overflow 0s 0s;
}
.auk-accordion--is-active .auk-accordion__content {
display: block;
}
{{yield}}
<Accordion @label="My Accordion Title">
Content here...!
</Accordion>
<div class="auk-accordion {{if this.isActive "auk-accordion--is-active"}}">
<button
{{on "click" this.toggleAccordion}}
aria-expanded={{if this.isActive "true" "false"}}
aria-controls={{this.accordionId}}
>
{{@label}}
</button>
<div
class="auk-accordion__content"
id={{this.accordionId}}
aria-hidden={{if this.isActive "false" "true"}}
>
{{yield}}
</div>
</div>
{
"version": "0.17.1",
"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.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment