-
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.
- Loading branch information
Showing
12 changed files
with
203 additions
and
95 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
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,72 @@ | ||
import { ClickTriggerComponent } from '../../base'; | ||
import { executeAfterTransition } from '../../utils/transitions'; | ||
import { COLLAPSE_TRIGGER_SELECTOR, CollapseManager } from '../Collapse'; | ||
import { SidebarElement } from './SidebarElement'; | ||
|
||
export const SIDEBAR_TRIGGER_SELECTOR = '[data-toggle="sidebar"]'; | ||
|
||
export class Sidebar implements ClickTriggerComponent { | ||
element: SidebarElement; | ||
manager: CollapseManager; | ||
|
||
get isExpanded() { | ||
return !this.element.content.classList.contains('collapsed'); | ||
} | ||
|
||
constructor(element: SidebarElement) { | ||
this.element = element; | ||
this.manager = new CollapseManager(); | ||
} | ||
|
||
collapse() { | ||
const collapseTriggers = [ | ||
...this.element.content.querySelectorAll<HTMLElement>(COLLAPSE_TRIGGER_SELECTOR) | ||
]; | ||
collapseTriggers.forEach((item) => { | ||
this.manager.getInstance(item)?.hide() | ||
}); | ||
|
||
const complete = () => { | ||
this.element.content.classList.add('collapsed-complete'); | ||
}; | ||
|
||
this.element.content.classList.remove('collapsed-complete'); | ||
this.element.content.classList.add('collapsed'); | ||
executeAfterTransition(complete, this.element.content); | ||
} | ||
|
||
expand() { | ||
this.element.content.classList.remove('collapsed', 'collapsed-complete'); | ||
} | ||
|
||
toggle() { | ||
if (this.isExpanded) { | ||
return this.collapse(); | ||
} | ||
this.expand(); | ||
} | ||
|
||
executeByClick(ev: Event) { | ||
console.log(ev); | ||
this.toggle(); | ||
} | ||
} | ||
|
||
export class SidebarCollapse implements ClickTriggerComponent { | ||
sidebar: Sidebar; | ||
|
||
constructor(sidebarElement: HTMLElement) { | ||
this.sidebar = new Sidebar({ | ||
id: sidebarElement.id, | ||
toggle: sidebarElement, | ||
content: sidebarElement, | ||
}) | ||
} | ||
|
||
executeByClick(ev: Event): void { | ||
if (this.sidebar.isExpanded) { | ||
return; | ||
} | ||
this.sidebar.expand(); | ||
} | ||
} |
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,5 @@ | ||
export interface SidebarElement { | ||
id: string; | ||
toggle: HTMLElement; | ||
content: HTMLElement; | ||
} |
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,69 @@ | ||
import { ComponentManager, ClickTriggerComponentManager } from '../../base'; | ||
import { Sidebar, SidebarCollapse, SIDEBAR_TRIGGER_SELECTOR } from './Sidebar'; | ||
import { SidebarElement } from './SidebarElement'; | ||
import { COLLAPSE_TRIGGER_SELECTOR, CollapseElement } from '../Collapse'; | ||
|
||
export class SidebarManager extends ComponentManager<SidebarElement, Sidebar> { | ||
protected getElement(target?: HTMLElement | null): SidebarElement | null { | ||
if (!target) { | ||
return null; | ||
} | ||
const toggleClosest = target.closest<HTMLElement>(SIDEBAR_TRIGGER_SELECTOR); | ||
if (!toggleClosest) { | ||
return null; | ||
} | ||
const contentQuery = toggleClosest.getAttribute('data-target'); | ||
if (!contentQuery) { | ||
return null; | ||
} | ||
const contentEl = document.querySelector<HTMLElement>(contentQuery); | ||
if (!contentEl) { | ||
return null; | ||
} | ||
return { | ||
id: contentEl.id, | ||
toggle: toggleClosest, | ||
content: contentEl, | ||
}; | ||
} | ||
|
||
protected createInstance(element: SidebarElement): Sidebar { | ||
return new Sidebar(element); | ||
} | ||
} | ||
|
||
export class SidebarCollapseManager extends ComponentManager<CollapseElement, SidebarCollapse> { | ||
protected getElement(target?: HTMLElement | null): CollapseElement | null { | ||
if (!target) { | ||
return null; | ||
} | ||
const toggleClosest = target.closest<HTMLElement>(COLLAPSE_TRIGGER_SELECTOR); | ||
if (!toggleClosest) { | ||
return null; | ||
} | ||
const contentQuery = toggleClosest.getAttribute('data-target'); | ||
if (!contentQuery) { | ||
return null; | ||
} | ||
const contentEl = document.querySelector<HTMLElement>(contentQuery); | ||
if (!contentEl) { | ||
return null; | ||
} | ||
if (!contentEl.closest('.sidebar')) { | ||
return null; | ||
} | ||
return { | ||
id: contentEl.id, | ||
toggle: toggleClosest, | ||
content: contentEl, | ||
}; | ||
} | ||
|
||
protected createInstance(element: CollapseElement): SidebarCollapse { | ||
const sidebar = element.content.closest('.sidebar') as HTMLElement; | ||
return new SidebarCollapse(sidebar); | ||
} | ||
} | ||
|
||
ClickTriggerComponentManager.register(new SidebarManager()); | ||
ClickTriggerComponentManager.register(new SidebarCollapseManager()); |
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,3 @@ | ||
export * from './SidebarManager'; | ||
export * from './SidebarElement'; | ||
export * from './Sidebar'; |
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,3 +1,4 @@ | ||
export * from './Backdrop'; | ||
export * from './Modal'; | ||
export * from './Collapse'; | ||
export * from './Sidebar'; |
This file was deleted.
Oops, something went wrong.
88 changes: 0 additions & 88 deletions
88
packages/vanilla/src/components/sidebar/sidebar.browser.ts
This file was deleted.
Oops, something went wrong.