Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: animate list expansion with css instead of jQuery #537

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@

.fxmaster-groups-list__collapsible,
.fxmaster-list__collapsible {
display: grid;
grid-template-rows: 1fr;
transition: grid-template-rows 250ms;
}

.fxmaster-groups-list__collapsible > *,
.fxmaster-list__collapsible > * {
margin: 0;
overflow: hidden;
padding: 0;
margin: 0;
}

.fxmaster-groups-list__collapsible--collapsed,
.fxmaster-list__collapsible--collapsed {
display: none;
.fxmaster-groups-list__collapsible[aria-hidden="true"],
.fxmaster-list__collapsible[aria-hidden="true"] {
grid-template-rows: 0fr;
}

.fxmaster-list__icon {
Expand Down
21 changes: 8 additions & 13 deletions src/base-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,25 @@ export class FXMasterBaseForm extends FormApplication {
const parentItem = $(event.currentTarget).parents(`.${parentClass}`);
const collapsible = parentItem.children(`.${collapsibleClass}`);
const icon = iconClass !== undefined ? parentItem.find(`.${iconClass}`) : undefined;
this._collapse(collapsible, icon, `${collapsibleClass}--collapsed`);
this._collapse(collapsible[0], icon);
}

/**
* Toggle the collapsed state of an element.
* @param {JQuery} collapsible The element to collapse
* @param {HTMLElement} collapsible The element to collapse
* @param {JQuery|null} [icon] An up/down arrow icon to be toggled
* @param {string} [collapsedClass="collaped"] The CSS clas to use to mark the element as collapsed
* @param {number} [speed=250] The speed for sliding the element in and out, in milliseconds
* @private
*/
_collapse(collapsible, icon, collapsedClass = "collapsed", speed = 250) {
const shouldCollapse = !collapsible.hasClass(collapsedClass);
_collapse(collapsible, icon) {
const shouldCollapse = collapsible.getAttribute("aria-hidden") !== "true";

if (shouldCollapse) {
collapsible.slideUp(speed, () => {
collapsible.addClass(collapsedClass);
icon?.removeClass("fa-angle-down").addClass("fa-angle-up");
});
collapsible.setAttribute("aria-hidden", "true");
icon?.removeClass("fa-angle-down").addClass("fa-angle-up");
} else {
collapsible.slideDown(speed, () => {
collapsible.removeClass(collapsedClass);
icon?.removeClass("fa-angle-up").addClass("fa-angle-down");
});
collapsible.removeAttribute("aria-hidden");
icon?.removeClass("fa-angle-up").addClass("fa-angle-down");
}
}

Expand Down
20 changes: 11 additions & 9 deletions templates/filter-effects-management.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
class="fxmaster-list__collapse-icon fa fa-angle-{{#if (lookup @root.activeFilters type)}}down{{else}}up{{/if}}"></i></label>
<input type="checkbox" name="{{type}}" {{checked (lookup @root.activeFilters type)}} />
</header>
<ul
class="fxmaster-list__collapsible{{#unless (lookup @root.activeFilters type)}} fxmaster-list__collapsible--collapsed{{/unless}}">
{{#each filter.parameters as |parameterConfig parameterName|}}
<li class="flexrow">
<span>{{localize parameterConfig.label}}</span>
{{{fxmasterParameter filter parameterConfig parameterName (lookup @root.activeFilters type)}}}
</li>
{{/each}}
</ul>
<div class="fxmaster-list__collapsible" {{#unless (lookup @root.activeFilters type)}} aria-hidden="true"
{{/unless}}>
<ul>
{{#each filter.parameters as |parameterConfig parameterName|}}
<li class="flexrow">
<span>{{localize parameterConfig.label}}</span>
{{{fxmasterParameter filter parameterConfig parameterName (lookup @root.activeFilters type)}}}
</li>
{{/each}}
</ul>
</div>
</li>
{{/each}}
</ol>
Expand Down
47 changes: 25 additions & 22 deletions templates/particle-effects-management.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@
<label class="fxmaster-groups-list__collapse">{{localize group.label}} <i
class="fxmaster-groups-list__collapse-icon fa fa-angle-{{#if group.expanded}}down{{else}}up{{/if}}"></i></label>
</header>
<ol
class="fxmaster-groups-list__collapsible{{#unless group.expanded}} fxmaster-groups-list__collapsible--collapsed{{/unless}} fxmaster-list">
{{#each group.effects as |effect type|}}
<li class="fxmaster-list__item">
<header class="fxmaster-list__item-header">
{{#if effect.icon}}<img class="fxmaster-list__icon" width="24" height="24" src="{{effect.icon}}">{{/if}}
<label class="fxmaster-list__collapse">{{localize effect.label}} <i
class="fxmaster-list__collapse-icon fa fa-angle-{{#if (lookup @root.activeEffects type)}}down{{else}}up{{/if}}"></i></label>
<input type="checkbox" name="{{type}}" {{checked (lookup @root.activeEffects type)}} />
</header>
<ul
class="fxmaster-list__collapsible{{#unless (lookup @root.activeEffects type)}} fxmaster-list__collapsible--collapsed{{/unless}}">
{{#each effect.parameters as |parameterConfig parameterName|}}
<li class="flexrow">
<span>{{localize parameterConfig.label}}</span>
{{{fxmasterParameter effect parameterConfig parameterName (lookup @root.activeEffects type)}}}
</li>
{{/each}}
</ul>
</li>
{{/each}}
</ol>
<div class="fxmaster-groups-list__collapsible" {{#unless group.expanded}} aria-hidden="true" {{/unless}}>
<ol class="fxmaster-list">
{{#each group.effects as |effect type|}}
<li class="fxmaster-list__item">
<header class="fxmaster-list__item-header">
{{#if effect.icon}}<img class="fxmaster-list__icon" width="24" height="24" src="{{effect.icon}}">{{/if}}
<label class="fxmaster-list__collapse">{{localize effect.label}} <i
class="fxmaster-list__collapse-icon fa fa-angle-{{#if (lookup @root.activeEffects type)}}down{{else}}up{{/if}}"></i></label>
<input type="checkbox" name="{{type}}" {{checked (lookup @root.activeEffects type)}} />
</header>
<div class="fxmaster-list__collapsible" {{#unless (lookup @root.activeEffects type)}} aria-hidden="true"
{{/unless}}>
<ul>
{{#each effect.parameters as |parameterConfig parameterName|}}
<li class="flexrow">
<span>{{localize parameterConfig.label}}</span>
{{{fxmasterParameter effect parameterConfig parameterName (lookup @root.activeEffects type)}}}
</li>
{{/each}}
</ul>
</div>
</li>
{{/each}}
</ol>
</div>
</li>
{{/each}}
</ol>
Expand Down