mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Migrate search bar to mwc (#11637)
This commit is contained in:
parent
b0b3222b33
commit
467a5169c0
@ -1,17 +1,10 @@
|
|||||||
import { mdiClose, mdiMagnify } from "@mdi/js";
|
import { mdiClose, mdiMagnify } from "@mdi/js";
|
||||||
import "@polymer/paper-input/paper-input";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import type { PaperInputElement } from "@polymer/paper-input/paper-input";
|
|
||||||
import {
|
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
|
||||||
html,
|
|
||||||
LitElement,
|
|
||||||
PropertyValues,
|
|
||||||
TemplateResult,
|
|
||||||
} from "lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import "../../components/ha-icon-button";
|
import "../../components/ha-icon-button";
|
||||||
import "../../components/ha-svg-icon";
|
import "../../components/ha-svg-icon";
|
||||||
|
import "../../components/ha-textfield";
|
||||||
|
import type { HaTextField } from "../../components/ha-textfield";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { fireEvent } from "../dom/fire_event";
|
import { fireEvent } from "../dom/fire_event";
|
||||||
|
|
||||||
@ -21,12 +14,6 @@ class SearchInput extends LitElement {
|
|||||||
|
|
||||||
@property() public filter?: string;
|
@property() public filter?: string;
|
||||||
|
|
||||||
@property({ type: Boolean, attribute: "no-label-float" })
|
|
||||||
public noLabelFloat? = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean, attribute: "no-underline" })
|
|
||||||
public noUnderline = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean })
|
@property({ type: Boolean })
|
||||||
public autofocus = false;
|
public autofocus = false;
|
||||||
|
|
||||||
@ -34,49 +21,42 @@ class SearchInput extends LitElement {
|
|||||||
public label?: string;
|
public label?: string;
|
||||||
|
|
||||||
public focus() {
|
public focus() {
|
||||||
this.shadowRoot!.querySelector("paper-input")!.focus();
|
this._input?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@query("paper-input", true) private _input!: PaperInputElement;
|
@query("ha-textfield", true) private _input!: HaTextField;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<paper-input
|
<ha-textfield
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label || "Search"}
|
.label=${this.label || "Search"}
|
||||||
.value=${this.filter}
|
.value=${this.filter || ""}
|
||||||
@value-changed=${this._filterInputChanged}
|
.icon=${true}
|
||||||
.noLabelFloat=${this.noLabelFloat}
|
.iconTrailing=${this.filter}
|
||||||
|
@input=${this._filterInputChanged}
|
||||||
>
|
>
|
||||||
<slot name="prefix" slot="prefix">
|
<slot name="prefix" slot="leadingIcon">
|
||||||
<ha-svg-icon class="prefix" .path=${mdiMagnify}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
|
tabindex="-1"
|
||||||
|
class="prefix"
|
||||||
|
.path=${mdiMagnify}
|
||||||
|
></ha-svg-icon>
|
||||||
</slot>
|
</slot>
|
||||||
${this.filter &&
|
${this.filter &&
|
||||||
html`
|
html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="suffix"
|
slot="trailingIcon"
|
||||||
@click=${this._clearSearch}
|
@click=${this._clearSearch}
|
||||||
.label=${this.hass.localize("ui.common.clear")}
|
.label=${this.hass.localize("ui.common.clear")}
|
||||||
.path=${mdiClose}
|
.path=${mdiClose}
|
||||||
|
class="clear-button"
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
`}
|
`}
|
||||||
</paper-input>
|
</ha-textfield>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
|
||||||
if (
|
|
||||||
changedProps.has("noUnderline") &&
|
|
||||||
(this.noUnderline || changedProps.get("noUnderline") !== undefined)
|
|
||||||
) {
|
|
||||||
(
|
|
||||||
this._input.inputElement!.parentElement!.shadowRoot!.querySelector(
|
|
||||||
"div.unfocused-line"
|
|
||||||
) as HTMLElement
|
|
||||||
).style.display = this.noUnderline ? "none" : "block";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _filterChanged(value: string) {
|
private async _filterChanged(value: string) {
|
||||||
fireEvent(this, "value-changed", { value: String(value) });
|
fireEvent(this, "value-changed", { value: String(value) });
|
||||||
}
|
}
|
||||||
@ -91,15 +71,24 @@ class SearchInput extends LitElement {
|
|||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
|
:host {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
ha-svg-icon,
|
ha-svg-icon,
|
||||||
ha-icon-button {
|
ha-icon-button {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
}
|
}
|
||||||
|
ha-svg-icon {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
ha-icon-button {
|
ha-icon-button {
|
||||||
--mdc-icon-button-size: 24px;
|
--mdc-icon-button-size: 24px;
|
||||||
}
|
}
|
||||||
ha-svg-icon.prefix {
|
.clear-button {
|
||||||
margin: 8px;
|
--mdc-icon-size: 20px;
|
||||||
|
}
|
||||||
|
ha-textfield {
|
||||||
|
display: inherit;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -928,11 +928,10 @@ export class HaDataTable extends LitElement {
|
|||||||
}
|
}
|
||||||
.table-header {
|
.table-header {
|
||||||
border-bottom: 1px solid var(--divider-color);
|
border-bottom: 1px solid var(--divider-color);
|
||||||
padding: 0 16px;
|
|
||||||
}
|
}
|
||||||
search-input {
|
search-input {
|
||||||
position: relative;
|
display: block;
|
||||||
top: 2px;
|
flex: 1;
|
||||||
}
|
}
|
||||||
slot[name="header"] {
|
slot[name="header"] {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -24,7 +24,6 @@ import { computeDomain } from "../../common/entity/compute_domain";
|
|||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { domainIcon } from "../../common/entity/domain_icon";
|
import { domainIcon } from "../../common/entity/domain_icon";
|
||||||
import { navigate } from "../../common/navigate";
|
import { navigate } from "../../common/navigate";
|
||||||
import "../../common/search/search-input";
|
|
||||||
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||||
import {
|
import {
|
||||||
fuzzyFilterSort,
|
fuzzyFilterSort,
|
||||||
|
@ -159,14 +159,13 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
const headerToolbar = html`<search-input
|
const headerToolbar = html`<search-input
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.filter=${this.filter}
|
.filter=${this.filter}
|
||||||
no-label-float
|
|
||||||
no-underline
|
|
||||||
@value-changed=${this._handleSearchChange}
|
@value-changed=${this._handleSearchChange}
|
||||||
.label=${this.searchLabel ||
|
.label=${this.searchLabel ||
|
||||||
this.hass.localize("ui.components.data-table.search")}
|
this.hass.localize("ui.components.data-table.search")}
|
||||||
>
|
>
|
||||||
</search-input
|
</search-input>
|
||||||
>${filterInfo
|
<div class="filters">
|
||||||
|
${filterInfo
|
||||||
? html`<div class="active-filters">
|
? html`<div class="active-filters">
|
||||||
${this.narrow
|
${this.narrow
|
||||||
? html`<div>
|
? html`<div>
|
||||||
@ -180,7 +179,8 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
${this.hass.localize("ui.components.data-table.clear")}
|
${this.hass.localize("ui.components.data-table.clear")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
</div>`
|
</div>`
|
||||||
: ""}<slot name="filter-menu"></slot>`;
|
: ""}<slot name="filter-menu"></slot>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-tabs-subpage
|
||||||
@ -257,23 +257,35 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
.table-header {
|
.table-header {
|
||||||
border-bottom: 1px solid rgba(var(--rgb-primary-text-color), 0.12);
|
|
||||||
padding: 0 16px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
--mdc-shape-small: 0;
|
||||||
|
height: 56px;
|
||||||
}
|
}
|
||||||
.search-toolbar {
|
.search-toolbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
search-input {
|
.table-header search-input {
|
||||||
position: relative;
|
display: block;
|
||||||
top: 2px;
|
position: absolute;
|
||||||
flex-grow: 1;
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
left: 0;
|
||||||
}
|
}
|
||||||
search-input.header {
|
.search-toolbar search-input {
|
||||||
left: -8px;
|
display: block;
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
--mdc-text-field-fill-color: transparant;
|
||||||
|
--mdc-text-field-idle-line-color: var(--divider-color);
|
||||||
|
--mdc-ripple-color: transparant;
|
||||||
|
}
|
||||||
|
.filters {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
width: 100%;
|
||||||
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
.active-filters {
|
.active-filters {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
|
@ -521,7 +521,7 @@ export class HaConfigDeviceDashboard extends LitElement {
|
|||||||
return [
|
return [
|
||||||
css`
|
css`
|
||||||
ha-button-menu {
|
ha-button-menu {
|
||||||
margin: 0 -8px 0 8px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
haStyle,
|
haStyle,
|
||||||
|
@ -20,7 +20,6 @@ import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
|||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
import "../../../common/search/search-input";
|
|
||||||
import { LocalizeFunc } from "../../../common/translations/localize";
|
import { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||||
import type {
|
import type {
|
||||||
@ -863,8 +862,11 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 58px;
|
height: 56px;
|
||||||
border-bottom: 1px solid rgba(var(--rgb-primary-text-color), 0.12);
|
background-color: var(--mdc-text-field-fill-color, whitesmoke);
|
||||||
|
border-bottom: 1px solid
|
||||||
|
var(--mdc-text-field-idle-line-color, rgba(0, 0, 0, 0.42));
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.header-toolbar {
|
.header-toolbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -892,7 +894,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
margin: 8px;
|
margin: 8px;
|
||||||
}
|
}
|
||||||
ha-button-menu {
|
ha-button-menu {
|
||||||
margin: 0 -8px 0 8px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
|
@ -6,7 +6,6 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||||
import { domainIcon } from "../../../common/entity/domain_icon";
|
import { domainIcon } from "../../../common/entity/domain_icon";
|
||||||
import "../../../common/search/search-input";
|
|
||||||
import {
|
import {
|
||||||
DataTableColumnContainer,
|
DataTableColumnContainer,
|
||||||
RowClickedEvent,
|
RowClickedEvent,
|
||||||
|
@ -663,7 +663,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
haStyle,
|
haStyle,
|
||||||
css`
|
css`
|
||||||
ha-button-menu {
|
ha-button-menu {
|
||||||
margin: 0 -8px 0 8px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
display: grid;
|
display: grid;
|
||||||
@ -686,31 +686,36 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
search-input.header {
|
search-input.header {
|
||||||
display: block;
|
display: block;
|
||||||
position: relative;
|
|
||||||
left: -8px;
|
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
margin-left: 16px;
|
margin-left: 8px;
|
||||||
|
--mdc-text-field-fill-color: transparant;
|
||||||
|
--mdc-text-field-idle-line-color: var(--divider-color);
|
||||||
|
--mdc-ripple-color: transparant;
|
||||||
}
|
}
|
||||||
.search {
|
.search {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
width: 100%;
|
||||||
|
margin-right: 8px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 16px;
|
height: 56px;
|
||||||
background: var(--sidebar-background-color);
|
position: sticky;
|
||||||
border-bottom: 1px solid var(--divider-color);
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
}
|
}
|
||||||
.search search-input {
|
.search search-input {
|
||||||
flex: 1;
|
display: block;
|
||||||
position: relative;
|
position: absolute;
|
||||||
top: 2px;
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.active-filters {
|
.active-filters {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 2px 2px 2px 8px;
|
padding: 2px 2px 2px 8px;
|
||||||
margin-left: 4px;
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
.active-filters mwc-button {
|
.active-filters mwc-button {
|
||||||
|
@ -98,18 +98,19 @@ export class HaConfigLogs extends LitElement {
|
|||||||
-webkit-user-select: initial;
|
-webkit-user-select: initial;
|
||||||
-moz-user-select: initial;
|
-moz-user-select: initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search {
|
.search {
|
||||||
padding: 0 16px;
|
position: sticky;
|
||||||
background: var(--sidebar-background-color);
|
top: 0;
|
||||||
border-bottom: 1px solid var(--divider-color);
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
search-input {
|
||||||
.search search-input {
|
display: block;
|
||||||
position: relative;
|
}
|
||||||
top: 2px;
|
search-input.header {
|
||||||
|
--mdc-text-field-fill-color: transparant;
|
||||||
|
--mdc-text-field-idle-line-color: var(--divider-color);
|
||||||
|
--mdc-ripple-color: transparant;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
direction: ltr;
|
direction: ltr;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,6 @@ export class HuiCardPicker extends LitElement {
|
|||||||
<search-input
|
<search-input
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.filter=${this._filter}
|
.filter=${this._filter}
|
||||||
no-label-float
|
|
||||||
@value-changed=${this._handleSearchChange}
|
@value-changed=${this._handleSearchChange}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.lovelace.editor.edit_card.search_cards"
|
"ui.panel.lovelace.editor.edit_card.search_cards"
|
||||||
@ -337,7 +336,8 @@ export class HuiCardPicker extends LitElement {
|
|||||||
css`
|
css`
|
||||||
search-input {
|
search-input {
|
||||||
display: block;
|
display: block;
|
||||||
margin: 0 -8px;
|
--mdc-shape-small: var(--card-picker-search-shape);
|
||||||
|
margin: var(--card-picker-search-margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cards-container {
|
.cards-container {
|
||||||
|
@ -195,9 +195,14 @@ export class HuiCreateDialogCard
|
|||||||
var(--mdc-dialog-scroll-divider-color, rgba(0, 0, 0, 0.12));
|
var(--mdc-dialog-scroll-divider-color, rgba(0, 0, 0, 0.12));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hui-card-picker {
|
||||||
|
--card-picker-search-shape: 0;
|
||||||
|
--card-picker-search-margin: -2px -24px 0;
|
||||||
|
}
|
||||||
hui-entity-picker-table {
|
hui-entity-picker-table {
|
||||||
display: block;
|
display: block;
|
||||||
height: calc(100vh - 198px);
|
height: calc(100vh - 198px);
|
||||||
|
--mdc-shape-small: 0;
|
||||||
}
|
}
|
||||||
@media all and (max-width: 450px), all and (max-height: 500px) {
|
@media all and (max-width: 450px), all and (max-height: 500px) {
|
||||||
hui-entity-picker-table {
|
hui-entity-picker-table {
|
||||||
|
@ -168,7 +168,6 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
}
|
}
|
||||||
hui-entity-picker-table {
|
hui-entity-picker-table {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
margin-top: -20px;
|
|
||||||
}
|
}
|
||||||
.fab {
|
.fab {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user