Content-Length: 1552760 | pFad | http://github.com/home-assistant/frontend/pull/25564/files

03 Redesign ha-button by wendevlin · Pull Request #25564 · home-assistant/frontend · GitHub
Skip to content

Redesign ha-button #25564

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

Open
wants to merge 20 commits into
base: dev
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
48 changes: 28 additions & 20 deletions cast/src/launcher/layout/hc-cast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "@material/mwc-button/mwc-button";

import type { ActionDetail } from "@material/mwc-list/mwc-list";
import { mdiCast, mdiCastConnected, mdiViewDashboard } from "@mdi/js";
import type { Auth, Connection } from "home-assistant-js-websocket";
Expand All @@ -20,6 +18,7 @@ import { atLeastVersion } from "../../../../src/common/config/version";
import { toggleAttribute } from "../../../../src/common/dom/toggle_attribute";
import "../../../../src/components/ha-icon";
import "../../../../src/components/ha-list";
import "../../../../src/components/ha-button";
import "../../../../src/components/ha-list-item";
import "../../../../src/components/ha-svg-icon";
import {
Expand Down Expand Up @@ -63,12 +62,20 @@ class HcCast extends LitElement {
<p class="question action-item">
Stay logged in?
<span>
<mwc-button @click=${this._handleSaveTokens}>
<ha-button
appearance="plain"
size="small"
@click=${this._handleSaveTokens}
>
YES
</mwc-button>
<mwc-button @click=${this._handleSkipSaveTokens}>
</ha-button>
<ha-button
appearance="plain"
size="small"
@click=${this._handleSkipSaveTokens}
>
NO
</mwc-button>
</ha-button>
</span>
</p>
`
Expand All @@ -78,10 +85,10 @@ class HcCast extends LitElement {
: !this.castManager.status
? html`
<p class="center-item">
<mwc-button raised @click=${this._handleLaunch}>
<ha-svg-icon .path=${mdiCast}></ha-svg-icon>
<ha-button @click=${this._handleLaunch}>
<ha-svg-icon slot="prefix" .path=${mdiCast}></ha-svg-icon>
Start Casting
</mwc-button>
</ha-button>
</p>
`
: html`
Expand Down Expand Up @@ -121,14 +128,22 @@ class HcCast extends LitElement {
<div class="card-actions">
${this.castManager.status
? html`
<mwc-button @click=${this._handleLaunch}>
<ha-svg-icon .path=${mdiCastConnected}></ha-svg-icon>
<ha-button appearance="plain" @click=${this._handleLaunch}>
<ha-svg-icon
slot="prefix"
.path=${mdiCastConnected}
></ha-svg-icon>
Manage
</mwc-button>
</ha-button>
`
: ""}
<div class="spacer"></div>
<mwc-button @click=${this._handleLogout}>Log out</mwc-button>
<ha-button
variant="danger"
appearance="plain"
@click=${this._handleLogout}
>Log out</ha-button
>
</div>
</hc-layout>
`;
Expand Down Expand Up @@ -245,13 +260,6 @@ class HcCast extends LitElement {
color: var(--secondary-text-color);
}

mwc-button ha-svg-icon {
margin-right: 8px;
margin-inline-end: 8px;
margin-inline-start: initial;
height: 18px;
}

ha-list-item ha-icon,
ha-list-item ha-svg-icon {
padding: 12px;
Expand Down
26 changes: 14 additions & 12 deletions cast/src/launcher/layout/hc-connect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "@material/mwc-button";
import { mdiCastConnected, mdiCast } from "@mdi/js";
import type {
Auth,
Expand Down Expand Up @@ -28,6 +27,7 @@ import "../../../../src/layouts/hass-loading-screen";
import { registerServiceWorker } from "../../../../src/util/register-service-worker";
import "./hc-layout";
import "../../../../src/components/ha-textfield";
import "../../../../src/components/ha-button";

const seeFAQ = (qid) => html`
See <a href="./faq.html${qid ? `#${qid}` : ""}">the FAQ</a> for more
Expand Down Expand Up @@ -83,11 +83,14 @@ export class HcConnect extends LitElement {
Unable to connect to ${tokens!.hassUrl}.
</div>
<div class="card-actions">
<a href="/">
<mwc-button> Retry </mwc-button>
</a>
<ha-button appearance="plain" href="/">Retry</ha-button>
<div class="spacer"></div>
<mwc-button @click=${this._handleLogout}>Log out</mwc-button>
<ha-button
appearance="plain"
variant="danger"
@click=${this._handleLogout}
>Log out</ha-button
>
</div>
</hc-layout>
`;
Expand Down Expand Up @@ -128,16 +131,19 @@ export class HcConnect extends LitElement {
${this.error ? html` <p class="error">${this.error}</p> ` : ""}
</div>
<div class="card-actions">
<mwc-button @click=${this._handleDemo}>
<ha-button appearance="plain" @click=${this._handleDemo}>
Show Demo
<ha-svg-icon
slot="suffix"
.path=${this.castManager.castState === "CONNECTED"
? mdiCastConnected
: mdiCast}
></ha-svg-icon>
</mwc-button>
</ha-button>
<div class="spacer"></div>
<mwc-button @click=${this._handleConnect}>Authorize</mwc-button>
<ha-button appearance="plain" @click=${this._handleConnect}
>Authorize</ha-button
>
</div>
</hc-layout>
`;
Expand Down Expand Up @@ -309,10 +315,6 @@ export class HcConnect extends LitElement {
color: darkred;
}

mwc-button ha-svg-icon {
margin-left: 8px;
}

.spacer {
flex: 1;
}
Expand Down
20 changes: 7 additions & 13 deletions gallery/src/components/demo-black-white-row.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "@material/mwc-button/mwc-button";
import type { Button } from "@material/mwc-button";
import type { TemplateResult } from "lit";
import { html, LitElement, css, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { applyThemesOnElement } from "../../../src/common/dom/apply_themes_on_element";
import { fireEvent } from "../../../src/common/dom/fire_event";
import "../../../src/components/ha-card";
import "../../../src/components/ha-button";
import type { HaButton } from "../../../src/components/ha-button";

@customElement("demo-black-white-row")
class DemoBlackWhiteRow extends LitElement {
Expand All @@ -25,12 +25,9 @@ class DemoBlackWhiteRow extends LitElement {
<slot name="light"></slot>
</div>
<div class="card-actions">
<mwc-button
.disabled=${this.disabled}
@click=${this.handleSubmit}
>
<ha-button .disabled=${this.disabled} @click=${this.handleSubmit}>
Submit
</mwc-button>
</ha-button>
</div>
</ha-card>
</div>
Expand All @@ -40,12 +37,9 @@ class DemoBlackWhiteRow extends LitElement {
<slot name="dark"></slot>
</div>
<div class="card-actions">
<mwc-button
.disabled=${this.disabled}
@click=${this.handleSubmit}
>
<ha-button .disabled=${this.disabled} @click=${this.handleSubmit}>
Submit
</mwc-button>
</ha-button>
</div>
</ha-card>
${this.value
Expand Down Expand Up @@ -74,7 +68,7 @@ class DemoBlackWhiteRow extends LitElement {
}

handleSubmit(ev) {
const content = (ev.target as Button).closest(".content")!;
const content = (ev.target as HaButton).closest(".content")!;
fireEvent(this, "submitted" as any, {
slot: content.classList.contains("light") ? "light" : "dark",
});
Expand Down
4 changes: 2 additions & 2 deletions gallery/src/pages/components/ha-alert.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ The `title ` option should not be used without a description.

<ha-alert alert-type="success">
This is a success alert — check it out!
<mwc-button slot="action" label="Undo"></mwc-button>
<ha-button slot="action" label="Undo"></ha-button>
</ha-alert>

```html
<ha-alert alert-type="success">
This is a success alert — check it out!
<mwc-button slot="action" label="Undo"></mwc-button>
<ha-button slot="action" label="Undo"></ha-button>
</ha-alert>
```

Expand Down
20 changes: 14 additions & 6 deletions gallery/src/pages/components/ha-alert.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "@material/mwc-button/mwc-button";
import type { TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement } from "lit/decorators";
import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element";
import "../../../../src/components/ha-alert";
import "../../../../src/components/ha-card";
import "../../../../src/components/ha-button";
import "../../../../src/components/ha-logo-svg";

const alerts: {
Expand Down Expand Up @@ -78,13 +78,21 @@ const alerts: {
title: "Error with action",
description: "This is a test error alert with action",
type: "error",
actionSlot: html`<mwc-button slot="action" label="restart"></mwc-button>`,
actionSlot: html`<ha-button
size="small"
slot="action"
label="restart"
></ha-button>`,
},
{
title: "Unsaved data",
description: "You have unsaved data",
type: "warning",
actionSlot: html`<mwc-button slot="action" label="save"></mwc-button>`,
actionSlot: html`<ha-button
size="small"
slot="action"
label="save"
></ha-button>`,
},
{
title: "Slotted icon",
Expand All @@ -108,7 +116,7 @@ const alerts: {
title: "Slotted action",
description: "Alert with slotted action",
type: "info",
actionSlot: html`<mwc-button slot="action" label="action"></mwc-button>`,
actionSlot: html`<ha-button slot="action" label="action"></ha-button>`,
},
{
description: "Dismissable information (RTL)",
Expand All @@ -120,7 +128,7 @@ const alerts: {
title: "Error with action",
description: "This is a test error alert with action (RTL)",
type: "error",
actionSlot: html`<mwc-button slot="action" label="restart"></mwc-button>`,
actionSlot: html`<ha-button slot="action" label="restart"></ha-button>`,
rtl: true,
},
{
Expand Down Expand Up @@ -211,7 +219,7 @@ export class DemoHaAlert extends LitElement {
max-height: 24px;
width: 24px;
}
mwc-button {
ha-button {
--mdc-theme-primary: var(--primary-text-color);
}
`;
Expand Down
98 changes: 98 additions & 0 deletions gallery/src/pages/components/ha-button.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: Button
---

<style>
.wrapper {
display: flex;
gap: 24px;
}
</style>

# Button `<ha-button>`

## Implementation

### Example Usage

<div class="wrapper">
<ha-button>
simple button
</ha-button>
<ha-button appearance="plain">
plain button
</ha-button>
<ha-button appearance="filled">
filled button
</ha-button>

<ha-button size="small">
small
</ha-button>
</div>

```html
<ha-button> simple button </ha-button>

<ha-button size="small"> small </ha-button>
```

### API

This component is based on the shoelace button component.
Check the [shoelace documentation](https://shoelace.style/components/button) for more details.

**Slots**

- default slot: Label of the button
` - no default
- `prefix`: The prefix container (usually for icons).
` - no default
- `suffix`: The suffix container (usually for icons).
` - no default

**Properties/Attributes**

| Name | Type | Default | Description |
| ----------- | ------------------------------------------------ | --------- | ---------------------------------------------------- |
| appearance | "accent"/"filled"/"plain" | "accent" | Sets the button appearance. |
| variants | "primary"/"danger"/"neutral"/"warning"/"success" | "primary" | Sets the button color variant. "primary" is default. |
| size | "small"/"medium" | "medium" | Sets the button size. |
| hideContent | Boolean | false | Hides the button content (for overlays) |

**CSS Custom Properties**

- `--ha-button-font-family` - Font family for the button text.
- `--ha-button-font-weight` - buttons font weight.
- `--ha-button-font-size` - Font weight for the button text.
- `--ha-button-height` - Height of the button.
- `--ha-button-padding-inline-start` - padding for the button text on the left side.
- `--ha-button-padding-inline-end` - padding for the button text on the right side.
- `--ha-button-border-radius` - Border radius for the button.
- `--ha-button-border-width` - Border width for the button.
- `--ha-button-theme-color` - Main color for the button.
- `--ha-button-theme-dark-color` - Dark variant of the main color.
- `--ha-button-theme-darker-color` - Dark variant of the main color.
- `--ha-button-theme-light-color` - Light variant of the main color.
- `--ha-button-text-color` - Text color for the button.
- `--ha-button-focus-ring-color` - Focus ring color for the button.
- `--ha-button-primary-color` - Main color for the primary variant.
- `--ha-button-primary-light-color` - Light color for the primary variant.
- `--ha-button-primary-dark-color` - Dark color for the primary variant.
- `--ha-button-primary-darker-color` - Darker color for the primary variant.
- `--ha-button-error-color` - Main color for the error variant.
- `--ha-button-error-light-color` - Light color for the error variant.
- `--ha-button-error-dark-color` - Dark color for the error variant.
- `--ha-button-error-darker-color` - Darker color for the error variant.
- `--ha-button-neutral-color` - Main color for the neutral variant.
- `--ha-button-neutral-light-color` - Light color for the neutral variant.
- `--ha-button-neutral-dark-color` - Dark color for the neutral variant.
- `--ha-button-neutral-darker-color` - Darker color for the neutral variant.
- `--ha-button-warning-color` - Main color for the warning variant.
- `--ha-button-warning-light-color` - Light color for the warning variant.
- `--ha-button-warning-dark-color` - Dark color for the warning variant.
- `--ha-button-warning-darker-color` - Darker color for the warning variant.
- `--ha-button-success-color` - Main color for the success variant.
- `--ha-button-success-light-color` - Light color for the success variant.
- `--ha-button-success-dark-color` - Dark color for the success variant.
- `--ha-button-success-darker-color` - Darker color for the success variant.
Loading
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/home-assistant/frontend/pull/25564/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy