-
Notifications
You must be signed in to change notification settings - Fork 3k
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
New component: ha-expansion-panel #6789
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f9768eb
init
Misiu 0df0314
class name and span
Misiu 40e3f23
events
Misiu 5d09075
use ha-svg-icon, style adjustments
Misiu 0b2e843
remove duration overrite
Misiu 05039bc
use dot notation for svg path
Misiu 7a01561
classMap
Misiu 2c9ba24
simplify css
Misiu f37e676
slots + css tweaks
Misiu f0cc152
remove title property
Misiu 26d151b
added outlined property
Misiu 1ca2a2e
animate max-height instead of height
Misiu a73d55a
remove header height animation, simplify css
Misiu ef24251
Update src/components/ha-expansion-panel.ts
Misiu 96b0aaf
fix after event rename
Misiu bc32c5a
remove slot name
Misiu 338c80b
remove div around icon + css fixes
Misiu c169acd
remove not needed css
Misiu 0ea20a2
remove extra div
Misiu 1cfe7e6
js animation
Misiu 08ddb2b
address comments
Misiu 981270a
remove type
Misiu 890b7bb
fixed animation duration
Misiu 228ff6b
use @query for container
Misiu 484c49e
simplify transition logic
Misiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { | ||
css, | ||
CSSResult, | ||
customElement, | ||
html, | ||
LitElement, | ||
property, | ||
query, | ||
TemplateResult, | ||
} from "lit-element"; | ||
import { fireEvent } from "../common/dom/fire_event"; | ||
import "./ha-svg-icon"; | ||
import { mdiChevronDown } from "@mdi/js"; | ||
import { classMap } from "lit-html/directives/class-map"; | ||
|
||
@customElement("ha-expansion-panel") | ||
class HaExpansionPanel extends LitElement { | ||
@property({ type: Boolean, reflect: true }) expanded = false; | ||
|
||
@property({ type: Boolean, reflect: true }) outlined = false; | ||
|
||
@query(".container") private _container!: HTMLDivElement; | ||
|
||
protected render(): TemplateResult { | ||
return html` | ||
<div class="summary" @click=${this._toggleContainer}> | ||
<slot name="title"></slot> | ||
<ha-svg-icon | ||
.path=${mdiChevronDown} | ||
class="summary-icon ${classMap({ expanded: this.expanded })}" | ||
></ha-svg-icon> | ||
</div> | ||
<div | ||
class="container ${classMap({ expanded: this.expanded })}" | ||
@transitionend=${this._handleTransitionEnd} | ||
> | ||
<slot></slot> | ||
</div> | ||
`; | ||
} | ||
|
||
private _handleTransitionEnd() { | ||
this._container.style.removeProperty("height"); | ||
} | ||
|
||
private _toggleContainer(): void { | ||
const scrollHeight = this._container.scrollHeight; | ||
this._container.style.height = `${scrollHeight}px`; | ||
|
||
if (this.expanded) { | ||
setTimeout(() => { | ||
this._container.style.height = "0px"; | ||
}, 0); | ||
} | ||
|
||
this.expanded = !this.expanded; | ||
Misiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fireEvent(this, "expanded-changed", { expanded: this.expanded }); | ||
} | ||
|
||
static get styles(): CSSResult { | ||
return css` | ||
:host { | ||
display: block; | ||
} | ||
|
||
:host([outlined]) { | ||
box-shadow: none; | ||
border-width: 1px; | ||
border-style: solid; | ||
border-color: var( | ||
--ha-card-border-color, | ||
var(--divider-color, #e0e0e0) | ||
); | ||
border-radius: var(--ha-card-border-radius, 4px); | ||
} | ||
|
||
.summary { | ||
display: flex; | ||
padding: 0px 16px; | ||
min-height: 48px; | ||
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. actually its this that is too large that is making it not close enough to the content |
||
align-items: center; | ||
cursor: pointer; | ||
overflow: hidden; | ||
} | ||
|
||
.summary-icon { | ||
transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1); | ||
margin-left: auto; | ||
} | ||
|
||
.summary-icon.expanded { | ||
transform: rotate(180deg); | ||
} | ||
|
||
.container { | ||
overflow: hidden; | ||
transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1); | ||
height: 0px; | ||
} | ||
|
||
.container.expanded { | ||
height: auto; | ||
} | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-expansion-panel": HaExpansionPanel; | ||
} | ||
|
||
// for fire event | ||
interface HASSDomEvents { | ||
"expanded-changed": { | ||
expanded: boolean; | ||
}; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this so it can transition from the current height to 0? Transition from
auto
to0
doesn't work probably?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.
yes, that's why I'm setting the fixed height and in setTimeout I'm setting the height to 0.
Is there a way to remove setTimeout?