-
Notifications
You must be signed in to change notification settings - Fork 196
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
Add docs for useDefault #1396
Open
sorvell
wants to merge
11
commits into
main
Choose a base branch
from
default-value
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+64
−15
Open
Add docs for useDefault #1396
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
39b25a0
Add docs for defaultValue
bc6c301
update to useDefault
215f454
remove cast (requires updating Lit)
2f4be53
Address feedback
de69588
Address feedback, add best practices
5b79229
Update packages/lit-dev-content/site/docs/v3/components/properties.md
sorvell 86dd12f
Update packages/lit-dev-content/site/docs/v3/components/properties.md
sorvell fceeda1
Update packages/lit-dev-content/site/docs/v3/components/properties.md
sorvell 0038df4
Address review feedback
3185dc6
Merge branch 'default-value' of https://github.com/lit/lit.dev into d…
3681cfe
Address feedbacj
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
38 changes: 29 additions & 9 deletions
38
packages/lit-dev-content/samples/properties/attributereflect/my-element.ts
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 |
---|---|---|
@@ -1,24 +1,44 @@ | ||
import {LitElement, html, css} from 'lit'; | ||
import {LitElement, html, css, PropertyDeclaration} from 'lit'; | ||
import {customElement, property} from 'lit/decorators.js'; | ||
|
||
@customElement('my-element') | ||
class MyElement extends LitElement { | ||
@property({type: Boolean, reflect: true}) | ||
active: boolean = false; | ||
|
||
/* playground-fold */ | ||
static styles = css` | ||
:host { | ||
display: inline-block; | ||
display: inline-block; | ||
padding: 4px; | ||
} | ||
|
||
:host([active]) { | ||
border: 1px solid red; | ||
font-weight: 800; | ||
} | ||
:host([variant]) { | ||
outline: 4px solid green; | ||
} | ||
:host([variant="special"]) { | ||
border-radius: 8px; border: 4px solid red; | ||
}`; | ||
/* playground-fold-end */ | ||
@property({type: Boolean, reflect: true}) | ||
active: boolean = false; | ||
|
||
@property({reflect: true, useDefault: true} as PropertyDeclaration) | ||
variant = 'normal'; | ||
|
||
render() { | ||
return html` | ||
<span>Active: ${this.active}</span> | ||
<button @click="${() => this.active = !this.active}">Toggle active</button> | ||
<div><label>active: <input type="checkbox" | ||
.value="${this.active}" | ||
@change="${(e: {target: HTMLInputElement}) => | ||
this.active = e.target.checked}"> | ||
${this.active} | ||
</label></div> | ||
<div><label>variant: <input type="checkbox" | ||
.value="${this.variant === 'special'}" | ||
@change="${(e: {target: HTMLInputElement}) => | ||
this.variant = e.target.checked ? 'special' : 'normal'}"> | ||
${this.variant} | ||
</label></div> | ||
`; | ||
} | ||
} |
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
Oops, something went wrong.
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.
Do we want a specific note here that the initial value is used as the default, and that it's retained in memory?
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.
Added