Skip to content

Commit

Permalink
Improve data table search bar style
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Mar 29, 2024
1 parent e5c43fc commit 00e2e01
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
38 changes: 38 additions & 0 deletions src/components/ha-outlined-text-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { MdOutlinedTextField } from "@material/web/textfield/outlined-text-field";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-outlined-text-field")
export class HaOutlinedTextField extends MdOutlinedTextField {
static override styles = [
...super.styles,
css`
:host {
--md-sys-color-on-surface: var(--primary-text-color);
--md-sys-color-primary: var(--primary-text-color);
--md-outlined-text-field-input-text-color: var(--primary-text-color);
--md-sys-color-on-surface-variant: var(--secondary-text-color);
--md-outlined-field-outline-color: var(--outline-color);
--md-outlined-field-focus-outline-color: var(--primary-color);
--md-outlined-field-hover-outline-color: var(--outline-hover-color);
}
:host([dense]) {
--md-outlined-field-top-space: 5.5px;
--md-outlined-field-bottom-space: 5.5px;
--md-outlined-field-container-shape-start-start: 10px;
--md-outlined-field-container-shape-start-end: 10px;
--md-outlined-field-container-shape-end-end: 10px;
--md-outlined-field-container-shape-end-start: 10px;
--md-outlined-field-focus-outline-width: 1px;
--mdc-icon-size: var(--md-input-chip-icon-size, 18px);
}
`,
];
}

declare global {
interface HTMLElementTagNameMap {
"ha-outlined-text-field": HaOutlinedTextField;
}
}
42 changes: 13 additions & 29 deletions src/components/search-input-outlined.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "@material/web/textfield/outlined-text-field";
import type { MdOutlinedTextField } from "@material/web/textfield/outlined-text-field";
import { mdiMagnify } from "@mdi/js";
import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit";
import { customElement, property, query } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
import { HomeAssistant } from "../types";
import "./ha-icon-button";
import "./ha-outlined-text-field";
import type { HaOutlinedTextField } from "./ha-outlined-text-field";
import "./ha-svg-icon";

@customElement("search-input-outlined")
Expand All @@ -30,19 +30,22 @@ class SearchInputOutlined extends LitElement {
this._input?.focus();
}

@query("md-outlined-text-field", true) private _input!: MdOutlinedTextField;
@query("ha-outlined-text-field", true) private _input!: HaOutlinedTextField;

protected render(): TemplateResult {
const placeholder =
this.placeholder || this.hass.localize("ui.common.search");

return html`
<md-outlined-text-field
<ha-outlined-text-field
.autofocus=${this.autofocus}
.aria-label=${this.label || this.hass.localize("ui.common.search")}
.placeholder=${this.placeholder ||
this.hass.localize("ui.common.search")}
.placeholder=${placeholder}
.value=${this.filter || ""}
icon
.iconTrailing=${this.filter || this.suffix}
@input=${this._filterInputChanged}
dense
>
<slot name="prefix" slot="leading-icon">
<ha-svg-icon
Expand All @@ -51,7 +54,7 @@ class SearchInputOutlined extends LitElement {
.path=${mdiMagnify}
></ha-svg-icon>
</slot>
</md-outlined-text-field>
</ha-outlined-text-field>
`;
}

Expand All @@ -67,40 +70,21 @@ class SearchInputOutlined extends LitElement {
return css`
:host {
display: inline-flex;
/* For iOS */
z-index: 0;
}
md-outlined-text-field {
ha-outlined-text-field {
display: block;
width: 100%;
--md-sys-color-on-surface: var(--primary-text-color);
--md-sys-color-primary: var(--primary-text-color);
--md-outlined-text-field-input-text-color: var(--primary-text-color);
--md-sys-color-on-surface-variant: var(--secondary-text-color);
--md-outlined-field-top-space: 5.5px;
--md-outlined-field-bottom-space: 5.5px;
--md-outlined-field-outline-color: var(--outline-color);
--md-outlined-field-container-shape-start-start: 10px;
--md-outlined-field-container-shape-start-end: 10px;
--md-outlined-field-container-shape-end-end: 10px;
--md-outlined-field-container-shape-end-start: 10px;
--md-outlined-field-focus-outline-width: 1px;
--md-outlined-field-focus-outline-color: var(--primary-color);
}
ha-svg-icon,
ha-icon-button {
display: flex;
--mdc-icon-size: var(--md-input-chip-icon-size, 18px);
color: var(--primary-text-color);
}
ha-svg-icon {
outline: none;
}
.clear-button {
--mdc-icon-size: 20px;
}
.trailing {
display: flex;
align-items: center;
}
`;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/resources/ha-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const mainStyles = css`
--accent-color: ${unsafeCSS(DEFAULT_ACCENT_COLOR)};
--divider-color: rgba(0, 0, 0, 0.12);
--outline-color: rgba(0, 0, 0, 0.12);
--outline-hover-color: rgba(0, 0, 0, 0.24);
--scrollbar-thumb-color: rgb(194, 194, 194);
Expand Down
1 change: 1 addition & 0 deletions src/resources/styles-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const darkStyles = {
"switch-unchecked-track-color": "#9b9b9b",
"divider-color": "rgba(225, 225, 225, .12)",
"outline-color": "rgba(225, 225, 225, .12)",
"outline-hover-color": "rgba(225, 225, 225, .24)",
"mdc-ripple-color": "#AAAAAA",
"mdc-linear-progress-buffer-color": "rgba(255, 255, 255, 0.1)",

Expand Down

0 comments on commit 00e2e01

Please sign in to comment.