-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Introduce ha-dropdown #27417
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
base: dev
Are you sure you want to change the base?
Introduce ha-dropdown #27417
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Dropdown | ||
--- | ||
|
||
# Dropdown `<ha-dropdown>` | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { | ||
mdiContentCopy, | ||
mdiContentCut, | ||
mdiContentPaste, | ||
mdiDelete, | ||
} from "@mdi/js"; | ||
import type { TemplateResult } from "lit"; | ||
import { css, html, LitElement } from "lit"; | ||
import { customElement } from "lit/decorators"; | ||
import "../../../../src/components/ha-button"; | ||
import "../../../../src/components/ha-card"; | ||
import "../../../../src/components/ha-svg-icon"; | ||
import "../../../../src/components/ha-dropdown-item"; | ||
import "@home-assistant/webawesome/dist/components/icon/icon"; | ||
import "@home-assistant/webawesome/dist/components/button/button"; | ||
import "@home-assistant/webawesome/dist/components/dropdown/dropdown"; | ||
import "../../../../src/components/ha-dropdown"; | ||
import "@home-assistant/webawesome/dist/components/popup/popup"; | ||
import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element"; | ||
import "../../../../src/components/ha-icon-button"; | ||
|
||
@customElement("demo-components-ha-dropdown") | ||
export class DemoHaDropdown extends LitElement { | ||
protected render(): TemplateResult { | ||
return html` | ||
${["light", "dark"].map( | ||
(mode) => html` | ||
<div class=${mode}> | ||
<ha-card header="ha-button in ${mode}"> | ||
<div class="card-content"> | ||
<ha-dropdown open> | ||
timmo001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ha-button slot="trigger" with-caret>Dropdown</ha-button> | ||
<ha-dropdown-item> | ||
<ha-svg-icon | ||
.path=${mdiContentCut} | ||
slot="icon" | ||
></ha-svg-icon> | ||
Cut | ||
</ha-dropdown-item> | ||
<ha-dropdown-item> | ||
<ha-svg-icon | ||
.path=${mdiContentCopy} | ||
slot="icon" | ||
></ha-svg-icon> | ||
Copy | ||
</ha-dropdown-item> | ||
<ha-dropdown-item disabled> | ||
<ha-svg-icon | ||
.path=${mdiContentPaste} | ||
slot="icon" | ||
></ha-svg-icon> | ||
Paste | ||
</ha-dropdown-item> | ||
<ha-dropdown-item> | ||
Show images | ||
<ha-dropdown-item slot="submenu" value="show-all-images" | ||
>Show All Images</ha-dropdown-item | ||
> | ||
<ha-dropdown-item slot="submenu" value="show-thumbnails" | ||
>Show Thumbnails</ha-dropdown-item | ||
> | ||
</ha-dropdown-item> | ||
<ha-dropdown-item type="checkbox" checked | ||
>Emoji Shortcuts</ha-dropdown-item | ||
> | ||
<ha-dropdown-item type="checkbox" checked | ||
>Word Wrap</ha-dropdown-item | ||
> | ||
<ha-dropdown-item variant="danger"> | ||
<ha-svg-icon .path=${mdiDelete} slot="icon"></ha-svg-icon> | ||
Delete | ||
</ha-dropdown-item> | ||
</ha-dropdown> | ||
</div> | ||
</ha-card> | ||
</div> | ||
` | ||
)} | ||
`; | ||
} | ||
|
||
firstUpdated(changedProps) { | ||
super.firstUpdated(changedProps); | ||
applyThemesOnElement( | ||
this.shadowRoot!.querySelector(".dark"), | ||
{ | ||
default_theme: "default", | ||
default_dark_theme: "default", | ||
themes: {}, | ||
darkMode: true, | ||
theme: "default", | ||
}, | ||
undefined, | ||
undefined, | ||
true | ||
); | ||
} | ||
|
||
static styles = css` | ||
:host { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
.dark, | ||
.light { | ||
display: block; | ||
background-color: var(--primary-background-color); | ||
padding: 0 50px; | ||
} | ||
.button { | ||
padding: unset; | ||
} | ||
ha-card { | ||
margin: 24px auto; | ||
} | ||
.card-content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 24px; | ||
} | ||
.card-content div { | ||
display: flex; | ||
gap: 8px; | ||
} | ||
`; | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"demo-components-ha-dropdown": DemoHaDropdown; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import DropdownItem from "@home-assistant/webawesome/dist/components/dropdown-item/dropdown-item"; | ||
import { css, type CSSResultGroup } from "lit"; | ||
import { customElement } from "lit/decorators"; | ||
|
||
@customElement("ha-dropdown-item") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add js docs with reference to WA |
||
export class HaDropdownItem extends DropdownItem { | ||
static get styles(): CSSResultGroup { | ||
return [ | ||
DropdownItem.styles, | ||
css` | ||
:host { | ||
min-height: 40px; | ||
} | ||
`, | ||
]; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-dropdown-item": HaDropdownItem; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Dropdown from "@home-assistant/webawesome/dist/components/dropdown/dropdown"; | ||
import { css, type CSSResultGroup } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
|
||
@customElement("ha-dropdown") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add js docs with reference to WA |
||
export class HaDropdown extends Dropdown { | ||
@property({ attribute: false }) dropdownTag = "ha-dropdown"; | ||
|
||
@property({ attribute: false }) dropdownItemTag = "ha-dropdown-item"; | ||
|
||
static get styles(): CSSResultGroup { | ||
return [ | ||
Dropdown.styles, | ||
css` | ||
:host { | ||
--wa-color-surface-border: var(--ha-color-border-normal); | ||
--wa-color-surface-raised: var( | ||
--card-background-color, | ||
var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff)), | ||
); | ||
} | ||
#menu { | ||
--wa-shadow-m: 0px 4px 8px 0px var(--ha-color-shadow); | ||
} | ||
`, | ||
]; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-dropdown": HaDropdown; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -52,6 +52,11 @@ export const waColorStyles = css` | |||||
--wa-color-danger-on-normal: var(--ha-color-on-danger-normal); | ||||||
--wa-color-danger-on-quiet: var(--ha-color-on-danger-quiet); | ||||||
|
||||||
--wa-color-text-normal: var(--ha-color-text-primary); | ||||||
--wa-color-surface-default: var(--card-background-color); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--wa-color-surface-raised: var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use a semantic color here, but I am not sure which one. Where is this color used? |
||||||
--wa-color-surface-border: var(--ha-color-border-normal); | ||||||
|
||||||
--wa-focus-ring-color: var(--ha-color-neutral-60); | ||||||
} | ||||||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more docs please. When to use it and reference to WA docs