-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improve/custom-elements-support'
- Loading branch information
Showing
12 changed files
with
251 additions
and
16 deletions.
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,39 @@ | ||
@page "/test/custom-elements" | ||
|
||
<h1>Test - Custom Elements</h1> | ||
|
||
<div style="display: flex; flex-direction:column; gap:12px;"> | ||
|
||
<div> | ||
<custom-input id="input-1"></custom-input> | ||
</div> | ||
|
||
<div> | ||
<custom-textarea id="text-area-1"></custom-textarea> | ||
</div> | ||
|
||
<div> | ||
<custom-select id="select-1"> | ||
<option value="1">One</option> | ||
<option value="2">Two</option> | ||
<option value="3">Three</option> | ||
</custom-select> | ||
</div> | ||
|
||
<div> | ||
<custom-checkbox id="checkbox-1"></custom-checkbox> | ||
</div> | ||
|
||
<div> | ||
<custom-radio-group id="radio-group-1"></custom-radio-group> | ||
</div> | ||
|
||
<div> | ||
<custom-button id="button-1">Click me</custom-button> | ||
</div> | ||
|
||
<div> | ||
<custom-input-button id="input-button-1">Click me</custom-input-button> | ||
</div> | ||
|
||
</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
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
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,129 @@ | ||
// define a custom element that includes a normal input element. | ||
// The custom element will be used to demonstrate how to interact with the input element. | ||
|
||
class CustomInput extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
this.input = document.createElement('input'); | ||
this.input.setAttribute('type', 'text'); | ||
this.shadowRoot.appendChild(this.input); | ||
} | ||
|
||
focus() { this.input.focus(); } | ||
|
||
get value() { return this.input.value; } | ||
} | ||
customElements.define('custom-input', CustomInput); | ||
|
||
class CustomTextArea extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
this.textArea = document.createElement('textarea'); | ||
this.shadowRoot.appendChild(this.textArea); | ||
} | ||
|
||
focus() { this.textArea.focus(); } | ||
|
||
get value() { return this.textArea.value; } | ||
} | ||
customElements.define('custom-textarea', CustomTextArea); | ||
|
||
class CustomCheckbox extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
this.checkbox = document.createElement('input'); | ||
this.checkbox.setAttribute('type', 'checkbox'); | ||
this.shadowRoot.appendChild(this.checkbox); | ||
} | ||
|
||
focus() { this.checkbox.focus(); } | ||
|
||
get checked() { return this.checkbox.checked; } | ||
} | ||
customElements.define('custom-checkbox', CustomCheckbox); | ||
|
||
class CustomSelect extends HTMLElement { | ||
|
||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
this.select = document.createElement('select'); | ||
this.shadowRoot.appendChild(this.select); | ||
} | ||
|
||
connectedCallback() { | ||
const options = this.querySelectorAll('option'); | ||
options.forEach(option => { | ||
const selectOption = document.createElement('option'); | ||
selectOption.textContent = option.textContent; | ||
selectOption.value = option.value; | ||
this.select.appendChild(selectOption); | ||
}); | ||
} | ||
|
||
focus() { this.select.focus(); } | ||
|
||
get value() { return this.select.value; } | ||
} | ||
customElements.define('custom-select', CustomSelect); | ||
|
||
class CustomRadioGroup extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
const radioGroup = document.createElement('div'); | ||
this.shadowRoot.appendChild(radioGroup); | ||
for (let i = 0; i < 3; i++) { | ||
const radio = document.createElement('input'); | ||
radio.setAttribute('type', 'radio'); | ||
radio.setAttribute('name', 'custom-radio-group'); | ||
radio.setAttribute('value', i); | ||
if (i == 0) radio.setAttribute('checked', true); | ||
radioGroup.appendChild(radio); | ||
} | ||
} | ||
|
||
focus() { this.shadowRoot.querySelector('input').focus(); } | ||
|
||
get value() { return this.shadowRoot.querySelector('input:checked').value; } | ||
} | ||
customElements.define('custom-radio-group', CustomRadioGroup); | ||
|
||
class CustomButton extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
this.button = document.createElement('button'); | ||
this.button.textContent = 'Click me'; | ||
this.shadowRoot.appendChild(this.button); | ||
} | ||
|
||
connectedCallback() { | ||
const text = this.textContent; | ||
this.button.textContent = text; | ||
} | ||
|
||
focus() { this.button.focus(); } | ||
} | ||
customElements.define('custom-button', CustomButton); | ||
|
||
class CustomInputButton extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
this.input = document.createElement('input'); | ||
this.input.setAttribute('type', 'button'); | ||
this.shadowRoot.appendChild(this.input); | ||
} | ||
|
||
connectedCallback() { | ||
const text = this.textContent; | ||
this.input.value = text; | ||
} | ||
|
||
focus() { this.input.focus(); } | ||
} | ||
customElements.define('custom-input-button', CustomInputButton); |
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
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