Commit 53244e24 authored by Michael Lange's avatar Michael Lange
Browse files

New accordion component

Follows the same style as the table and pagination components.
parent a022b618
Showing with 116 additions and 0 deletions
+116 -0
import Component from '@ember/component';
import { computed, get } from '@ember/object';
export default Component.extend({
classNames: ['accordion'],
key: 'id',
source: computed(() => []),
decoratedSource: computed('source.[]', function() {
const stateCache = this.get('stateCache');
const key = this.get('key');
const deepKey = `item.${key}`;
const decoratedSource = this.get('source').map(item => {
const cacheItem = stateCache.findBy(deepKey, get(item, key));
return {
item,
isOpen: cacheItem ? !!cacheItem.isOpen : false,
};
});
this.set('stateCache', decoratedSource);
return decoratedSource;
}),
// When source updates come in, the state cache is used to preserve
// open/close state.
stateCache: computed(() => []),
});
import Component from '@ember/component';
export default Component.extend({
tagName: '',
isOpen: false,
});
import Component from '@ember/component';
export default Component.extend({
classNames: ['accordion-head'],
classNameBindings: ['isOpen::is-light', 'isExpandable::is-inactive'],
buttonLabel: 'toggle',
isOpen: false,
isExpandable: true,
item: null,
onClose() {},
onOpen() {},
});
@import './components/accordion';
@import './components/badge'; @import './components/badge';
@import './components/boxed-section'; @import './components/boxed-section';
@import './components/cli-window'; @import './components/cli-window';
......
.accordion {
.accordion-head,
.accordion-body {
border: 1px solid $grey-blue;
border-bottom: none;
padding: 0.75em 1.5em;
&:first-child {
border-top-left-radius: $radius;
border-top-right-radius: $radius;
}
&:last-child {
border-bottom: 1px solid $grey-blue;
border-bottom-left-radius: $radius;
border-bottom-right-radius: $radius;
}
}
.accordion-head {
display: flex;
background: $white-ter;
flex: 1;
&.is-light {
background: $white;
}
&.is-inactive {
color: $grey-light;
}
.accordion-head-content {
width: 100%;
}
.accordion-toggle {
flex-basis: 0;
white-space: nowrap;
}
}
}
{{#each decoratedSource as |item|}}
{{yield (hash
head=(component "list-accordion/accordion-head"
isOpen=item.isOpen
onOpen=(action (mut item.isOpen) true)
onClose=(action (mut item.isOpen) false))
body=(component "list-accordion/accordion-body" isOpen=item.isOpen)
item=item.item
)}}
{{/each}}
{{#if isOpen}}
<div class="accordion-body">
{{yield}}
</div>
{{/if}}
<div class="accordion-head-content">
{{yield}}
</div>
<button
class="button is-light is-compact pull-right accordion-toggle {{unless isExpandable "is-invisible"}}"
onclick={{action (if isOpen onClose onOpen) item}}>
{{buttonLabel}}
</button>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment