generated from shgysk8zer0/npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from AegisJSProject/patch/updates
Update to latest dependencies
- Loading branch information
Showing
10 changed files
with
211 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { AegisInput } from './input.js'; | ||
import { SYMBOLS } from './consts.js'; | ||
|
||
const protectedData = new WeakMap(); | ||
|
||
function updateChecked(el) { | ||
const internals = protectedData.get(el).internals; | ||
|
||
if (el.checked) { | ||
internals.ariaChecked = 'true'; | ||
} else { | ||
internals.ariaChecked = 'false'; | ||
|
||
if (el.required) { | ||
internals.setValidity({ | ||
valueMissing: true, | ||
}, 'This input is required'); | ||
} | ||
} | ||
} | ||
|
||
export class AegisCheckbox extends AegisInput { | ||
constructor(opts = {}) { | ||
super({ ...opts, role: 'checkbox' }); | ||
console.warn(new Error('Aegis Checkbox components are still in development and should not be used.')); | ||
} | ||
|
||
async [SYMBOLS.initialize](opts) { | ||
const { internals } = await super[SYMBOLS.initialize](opts); | ||
protectedData.set(this, { internals }); | ||
} | ||
|
||
attributeChangedCallback(name, oldValue, newValue) { | ||
if (name === 'checked') { | ||
updateChecked(this); | ||
} else { | ||
super.addtributeChangedCallback(name, oldValue, newValue); | ||
} | ||
} | ||
|
||
get checked() { | ||
return this.hasAttribute('checked'); | ||
} | ||
|
||
set checked(val) { | ||
this.toggleAttribute('checked', val); | ||
} | ||
|
||
static get observedAttributes() { | ||
return [...AegisInput.observedAttributes, 'checked']; | ||
} | ||
} |
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,52 @@ | ||
import { AegisCheckbox } from '@aegisjsproject/component/checkbox.js'; | ||
import { SYMBOLS } from '@aegisjsproject/component/consts.js'; | ||
import { html } from '@aegisjsproject/core/parsers/html.js'; | ||
import { css } from '@aegisjsproject/core/parsers/css.js'; | ||
|
||
const template = html`<slot name="tick"><span part="tick" class="tick"></span></slot>`; | ||
const styles = css` | ||
:host { | ||
display: inline-block; | ||
width: 24px; | ||
height: 24px; | ||
border: 6px solid black; | ||
border-radius: 4px; | ||
background-color: white; | ||
cursor: pointer; | ||
} | ||
:host([disabled]), :host([readonly]) { | ||
cursor: auto; | ||
} | ||
:host(:not([checked])) ::slotted([slot="tick"]), :host(:not([checked])) .tick { | ||
display: none; | ||
} | ||
:host .tick { | ||
background-color: gray; | ||
display: inline-block; | ||
width: 100%; | ||
height: 100%; | ||
}`; | ||
|
||
function toggleChecked({ type, key, currentTarget }) { | ||
if (! (currentTarget.disabled || currentTarget.readOnly || (type === 'keydown' && key !== ' '))) { | ||
currentTarget.checked = ! currentTarget.checked; | ||
} | ||
} | ||
|
||
export class CheckboxTest extends AegisCheckbox { | ||
constructor() { | ||
super({ template, styles }); | ||
this.addEventListener('click', toggleChecked); | ||
this.addEventListener('keydown', toggleChecked); | ||
this.tabIndex = '0'; | ||
} | ||
|
||
async [SYMBOLS.render](type, data) { | ||
console.log({ el: this, type, ...data }); | ||
} | ||
} | ||
|
||
CheckboxTest.register('checkbox-test'); |
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
Oops, something went wrong.