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

Use Sortable to move entities in entities editor #6810

Merged
merged 9 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
122 changes: 60 additions & 62 deletions src/components/ha-sidebar-sort-styles.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,75 @@
import { html } from "lit-element";
import { css } from "lit-element";

export const sortStyles = html`
<style>
#sortable a:nth-of-type(2n) paper-icon-item {
animation-name: keyframes1;
animation-iteration-count: infinite;
transform-origin: 50% 10%;
animation-delay: -0.75s;
animation-duration: 0.25s;
}
export const sortableStyles = css`
#sortable a:nth-of-type(2n) paper-icon-item {
animation-name: keyframes1;
animation-iteration-count: infinite;
transform-origin: 50% 10%;
animation-delay: -0.75s;
animation-duration: 0.25s;
}

#sortable a:nth-of-type(2n-1) paper-icon-item {
animation-name: keyframes2;
animation-iteration-count: infinite;
animation-direction: alternate;
transform-origin: 30% 5%;
animation-delay: -0.5s;
animation-duration: 0.33s;
}
#sortable a:nth-of-type(2n-1) paper-icon-item {
animation-name: keyframes2;
animation-iteration-count: infinite;
animation-direction: alternate;
transform-origin: 30% 5%;
animation-delay: -0.5s;
animation-duration: 0.33s;
}

#sortable {
outline: none;
display: flex;
flex-direction: column;
}

.sortable-ghost {
opacity: 0.4;
}
#sortable {
outline: none;
display: flex;
flex-direction: column;
}

.sortable-fallback {
opacity: 0;
}
.sortable-ghost {
opacity: 0.4;
}

@keyframes keyframes1 {
0% {
transform: rotate(-1deg);
animation-timing-function: ease-in;
}
.sortable-fallback {
opacity: 0;
}

50% {
transform: rotate(1.5deg);
animation-timing-function: ease-out;
}
@keyframes keyframes1 {
0% {
transform: rotate(-1deg);
animation-timing-function: ease-in;
}

@keyframes keyframes2 {
0% {
transform: rotate(1deg);
animation-timing-function: ease-in;
}

50% {
transform: rotate(-1.5deg);
animation-timing-function: ease-out;
}
50% {
transform: rotate(1.5deg);
animation-timing-function: ease-out;
}
}

.hide-panel {
display: none;
position: absolute;
right: 8px;
@keyframes keyframes2 {
0% {
transform: rotate(1deg);
animation-timing-function: ease-in;
}

:host([expanded]) .hide-panel {
display: inline-flex;
50% {
transform: rotate(-1.5deg);
animation-timing-function: ease-out;
}
}

paper-icon-item.hidden-panel,
paper-icon-item.hidden-panel span,
paper-icon-item.hidden-panel ha-icon[slot="item-icon"] {
color: var(--secondary-text-color);
cursor: pointer;
}
</style>
.hide-panel {
display: none;
position: absolute;
right: 8px;
}

:host([expanded]) .hide-panel {
display: inline-flex;
}

paper-icon-item.hidden-panel,
paper-icon-item.hidden-panel span,
paper-icon-item.hidden-panel ha-icon[slot="item-icon"] {
color: var(--secondary-text-color);
cursor: pointer;
}
`;
14 changes: 9 additions & 5 deletions src/components/ha-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
LitElement,
property,
PropertyValues,
TemplateResult,
unsafeCSS,
} from "lit-element";
import { classMap } from "lit-html/directives/class-map";
import { guard } from "lit-html/directives/guard";
Expand Down Expand Up @@ -160,7 +160,7 @@ const computePanels = memoizeOne(

let Sortable;

let sortStyles: TemplateResult;
let sortStyles: CSSResult;

@customElement("ha-sidebar")
class HaSidebar extends LitElement {
Expand Down Expand Up @@ -228,7 +228,9 @@ class HaSidebar extends LitElement {
}

return html`
${this._editMode ? sortStyles : ""}
<style>
${sortStyles?.cssText}
</style>
zsarnett marked this conversation as resolved.
Show resolved Hide resolved
<div class="menu">
${!this.narrow
? html`
Expand Down Expand Up @@ -483,7 +485,7 @@ class HaSidebar extends LitElement {
import("./ha-sidebar-sort-styles"),
]);

sortStyles = sortStylesImport.sortStyles;
sortStyles = sortStylesImport.sortableStyles;

Sortable = sortableImport.Sortable;
Sortable.mount(sortableImport.OnSpill);
Expand Down Expand Up @@ -686,7 +688,7 @@ class HaSidebar extends LitElement {
}

static get styles(): CSSResult[] {
return [
const styles = [
haStyleScrollbar,
css`
:host {
Expand Down Expand Up @@ -962,6 +964,8 @@ class HaSidebar extends LitElement {
}
`,
];

return styles;
}
}

Expand Down
34 changes: 18 additions & 16 deletions src/panels/lovelace/components/hui-entity-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Sortable, {
import { fireEvent } from "../../../common/dom/fire_event";
import "../../../components/entity/ha-entity-picker";
import "../../../components/ha-icon-button";
import { sortStyles } from "../../../components/ha-sidebar-sort-styles";
import { sortableStyles } from "../../../components/ha-sidebar-sort-styles";
import { HomeAssistant } from "../../../types";
import { EditorTarget } from "../editor/types";
import { EntityConfig } from "../entity-rows/types";
Expand Down Expand Up @@ -52,7 +52,6 @@ export class HuiEntityEditor extends LitElement {
}

return html`
${sortStyles}
<h3>
${this.label ||
this.hass!.localize("ui.panel.lovelace.editor.card.generic.entities") +
Expand Down Expand Up @@ -167,20 +166,23 @@ export class HuiEntityEditor extends LitElement {
fireEvent(this, "entities-changed", { entities: newConfigEntities });
}

static get styles(): CSSResult {
return css`
.entity {
display: flex;
align-items: center;
}
.entity ha-svg-icon {
padding-right: 8px;
cursor: move;
}
.entity ha-entity-picker {
flex-grow: 1;
}
`;
static get styles(): CSSResult[] {
return [
sortableStyles,
css`
.entity {
display: flex;
align-items: center;
}
.entity ha-svg-icon {
padding-right: 8px;
cursor: move;
}
.entity ha-entity-picker {
flex-grow: 1;
}
`,
];
}
}

Expand Down