-
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.
- using web components api
- Loading branch information
Showing
7 changed files
with
157 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
import { UiBtnController } from "./UiBtnController"; | ||
import { DropdownController } from "./menu"; | ||
|
||
const switchBtn = document.getElementById( | ||
"menu__toggle-btn" | ||
) as HTMLButtonElement; | ||
|
||
const openBtn = document.getElementById( | ||
"menu-dropdown__open" | ||
"menu__open" | ||
) as HTMLButtonElement; | ||
|
||
const saveBtn = document.getElementById( | ||
"menu-dropdown__save" | ||
"menu__save" | ||
) as HTMLButtonElement; | ||
|
||
const clearBtn = document.getElementById( | ||
"menu-dropdown__clear" | ||
"menu__clear" | ||
) as HTMLButtonElement; | ||
|
||
const dropdown = document.getElementById("menu-dropdown") as HTMLElement; | ||
|
||
export const switchBtnController = new UiBtnController(switchBtn); | ||
|
||
export const dropdownController = new DropdownController(dropdown); | ||
export const openBtnController = new UiBtnController(openBtn); | ||
export const saveBtnController = new UiBtnController(saveBtn); | ||
export const clearBtnController = new UiBtnController(clearBtn); |
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,110 @@ | ||
interface ICustomElement { | ||
_internals: ElementInternals; | ||
|
||
connectedCallback: () => void; | ||
disconnectedCallback: () => void; | ||
adoptedCallback: () => void; | ||
attributeChangedCallback: ( | ||
name: observedAttributes, | ||
oldValue: string, | ||
newValue: string | ||
) => void; | ||
} | ||
|
||
type observedAttributes = "isopen"; | ||
|
||
export class Dropdown extends HTMLElement implements Partial<ICustomElement> { | ||
static observedAttributes: observedAttributes[] = ["isopen"]; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
connectedCallback() { | ||
const shadow = this.attachShadow({ mode: "open" }); | ||
const template = document.getElementById("dropdown") as HTMLTemplateElement; | ||
|
||
const style = new CSSStyleSheet(); | ||
style.replaceSync(` | ||
:host { | ||
position: absolute; | ||
margin: var(--content-padding) !important; | ||
} | ||
#dropdown__section { | ||
display: grid; | ||
margin-top: calc(var(--content-padding) / 2); | ||
} | ||
.dropdown--onTop { | ||
position: relative; | ||
z-index: 1; | ||
} | ||
.dropdown--isClosed { | ||
display: none !important; | ||
} | ||
`); | ||
|
||
shadow.appendChild(template?.content.cloneNode(true)); | ||
shadow.adoptedStyleSheets = [style]; | ||
|
||
this.dropdownBtn.classList.add("dropdown--onTop"); | ||
this.dropdownBtn.addEventListener("click", this.toggleIsOpen); | ||
|
||
this.dropdownSection.classList.add("dropdown--onTop"); | ||
this.dropdownSection.classList.add("dropdown--isClosed"); | ||
this.dropdownSection.ariaHidden = "true"; | ||
} | ||
|
||
attributeChangedCallback( | ||
//@ts-ignore | ||
name: observedAttributes, | ||
oldValue: string, | ||
newValue: string | ||
): void { | ||
if (!oldValue) return; | ||
|
||
switch (newValue) { | ||
case "true": | ||
this.dropdownSection.classList.remove("dropdown--isClosed"); | ||
this.dropdownSection.ariaHidden = "false"; | ||
break; | ||
case "false": | ||
this.dropdownSection.classList.add("dropdown--isClosed"); | ||
this.dropdownSection.ariaHidden = "true"; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
disconnectedCallback() { | ||
this.dropdownBtn.removeEventListener("click", this.toggleIsOpen); | ||
} | ||
|
||
toggleIsOpen = () => { | ||
switch (this.getAttribute("isopen")) { | ||
case "true": | ||
this.setAttribute("isopen", "false"); | ||
break; | ||
case "false": | ||
this.setAttribute("isopen", "true"); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
get dropdownBtn() { | ||
return this.shadowRoot?.getElementById( | ||
"dropdown__btn" | ||
) as HTMLButtonElement; | ||
} | ||
|
||
get dropdownSection() { | ||
return this.shadowRoot?.getElementById("dropdown__section") as HTMLElement; | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { DropdownController } from "./dropdown"; | ||
export { Dropdown } from "./Dropdown"; |