Skip to content

Commit

Permalink
using classList.addOrRemove method
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 10, 2021
1 parent 03eadab commit b2da3f4
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 48 deletions.
12 changes: 2 additions & 10 deletions src/editor-view/actions/actions-toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,10 @@ export class ActionsToolbar extends Widget {
this.orientationTemplates.interactable = value === true;
break;
case 'leftPanelVisible':
if (value === true) {
this.leftPanelToggle.classList.remove('is-hidden');
} else {
this.leftPanelToggle.classList.add('is-hidden');
}
this.leftPanelToggle.classList.addOrRemove('is-hidden', value !== true);
break;
case 'rightPanelVisible':
if (value === true) {
this.rightPanelToggle.classList.remove('is-hidden');
} else {
this.rightPanelToggle.classList.add('is-hidden');
}
this.rightPanelToggle.classList.addOrRemove('is-hidden', value !== true);
break;
case 'referenceImageEnabled':
this.referenceImageGroup.classList
Expand Down
11 changes: 2 additions & 9 deletions src/editor-view/actions/button/action-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ export class ActionButton extends HTMLElement {
private action: Action;

public set interactable(value: boolean) {
if (value) {
this.classList.remove('disabled');
return;
}
if (!this.classList.contains('disabled')) {
this.classList.add('disabled');
}
this.classList.addOrRemove('disabled', !value);
}

public setAction(action: Action) {
Expand Down Expand Up @@ -55,8 +49,7 @@ export class ActionButton extends HTMLElement {
}

public updateState() {
if (this.action.state?.()) this.classList.add('selected');
else this.classList.remove('selected');
this.classList.addOrRemove('selected', this.action.state?.());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ export class SizeTemplatesPanel extends HTMLElement {
public static readonly tagName = 'phred-size-templates-panel';

public set interactable(value: boolean) {
if (value) {
this.classList.remove('disabled');
return;
}
if (!this.classList.contains('disabled')) {
this.classList.add('disabled');
}
this.classList.addOrRemove('disabled', !value);
}

public init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ export class ObjectTreeInspector extends Inspector {
}

private filterContent(filter: string) {
if (filter) this.classList.add('filtering');
else this.classList.remove('filtering');
this.classList.addOrRemove('filtering', !!filter);
this.model.filter(filter);
}

Expand Down
9 changes: 4 additions & 5 deletions src/editor-view/object-tree/model/object-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ export class ObjectTreeModel {
Object.keys(objects).forEach(k => {
const o = objects[k] as ObjectTreeNodeModel;
if (!o.node) return;
if (o.node.title.toLowerCase().indexOf(filter) >= 0) {
o.node.classList.remove('invisible');
} else {
o.node.classList.add('invisible');
}
o.node.classList.addOrRemove(
'invisible',
o.node.title.toLowerCase().indexOf(filter) < 0
);
});
}
}
3 changes: 1 addition & 2 deletions src/editor-view/object-tree/tree-node/object-tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export class ObjectTreeNode extends HTMLElement {
public get title() { return this.label.textContent; }

public updateObjectVisibility(value: boolean) {
if (value) this.classList.remove('object-invisible');
else this.classList.add('object-invisible');
this.classList.addOrRemove('object-invisible', !value);
}

public setContent(model: ObjectTreeNodeModel) {
Expand Down
6 changes: 1 addition & 5 deletions src/editor-view/panel/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ export class Panel extends Widget {
private visiblePrefKey: PreferenceKey;

public set visible(value: boolean) {
if (value) {
this.classList.remove('hidden');
} else if (!this.classList.contains('hidden')) {
this.classList.add('hidden');
}
this.classList.addOrRemove('hidden', !value);
}

public setSide(value: PanelSide) {
Expand Down
4 changes: 1 addition & 3 deletions src/scene-view/game-container/game-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export class GameContainer extends HTMLElement {

private setResponsive(responsive: boolean) {
if (responsive) {
if (!this.classList.contains('responsive')) {
this.classList.add('responsive');
}
this.classList.add('responsive');
this.gameParent.setResponsiveSize(Editor.prefs.get('responsiveSize') as Size);
} else {
this.classList.remove('responsive');
Expand Down
6 changes: 1 addition & 5 deletions src/scene-view/game-parent/game-parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ export class GameParent extends HTMLElement {
}

public responsiveSizeTemplateChanged(index: number) {
if (!index) {
this.classList.add('resizable');
} else {
this.classList.remove('resizable');
}
this.classList.addOrRemove('resizable', index === 0);
}

private onGameResized(width: number, height: number) {
Expand Down

0 comments on commit b2da3f4

Please sign in to comment.