-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
6080a4b
commit 73f955a
Showing
5 changed files
with
94 additions
and
203 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { | ||
Component, | ||
OnInit, | ||
Input, | ||
ViewEncapsulation, | ||
HostBinding, | ||
Output, | ||
EventEmitter, | ||
Optional, | ||
Host, | ||
HostListener | ||
} from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { LayoutComponent } from './layout.component'; | ||
export type BreakPoinitType = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; | ||
|
||
@Component({ | ||
selector: 'app-sider', | ||
template: '<ng-content></ng-content>', | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class SiderComponent implements OnInit { | ||
@HostBinding('class.g-layout-sider') true; | ||
|
||
_dimensionMap = { | ||
xl: '1600px', | ||
lg: '1200px', | ||
md: '992px', | ||
sm: '768px', | ||
xs: '480px', | ||
}; | ||
_collapsed: boolean; | ||
// 可视宽度 | ||
@Input() visualWidth = 256; | ||
@Input() foldWidth = 80; | ||
@Input() breakpoint: BreakPoinitType; | ||
@Input() | ||
@HostBinding('class.layout-sider-collapsed') | ||
get collapsed(): boolean { | ||
return this._collapsed; | ||
} | ||
set collapsed(value: boolean) { | ||
this._collapsed = Boolean(value); | ||
} | ||
|
||
@Output() collapsedChange: EventEmitter<boolean> = new EventEmitter(); | ||
|
||
@HostBinding('style.flex') | ||
get setFlex(): string { | ||
if (this.collapsed) { | ||
return `0 0 ${this.foldWidth}px`; | ||
} else { | ||
return `0 0 ${this.visualWidth}px`; | ||
} | ||
} | ||
|
||
@HostBinding('style.width.px') | ||
get setStyle(): number | string { | ||
if (this.collapsed) { | ||
return this.foldWidth; | ||
} else { | ||
return this.visualWidth; | ||
} | ||
} | ||
|
||
/* @HostListener('window:resize', ['$event']) | ||
onWindowResize(e: UIEvent): void { | ||
if (this.breakpoint) { | ||
const matchBelow = window.matchMedia(`(max-width: ${this._dimensionMap[this.breakpoint]})`).matches; | ||
this.collapsed = matchBelow; | ||
this.collapsedChange.emit(matchBelow); | ||
} | ||
} */ | ||
|
||
constructor(@Optional() @Host() private layoutComponent: LayoutComponent) { | ||
if (this.layoutComponent) { | ||
this.layoutComponent.hasSider = true; | ||
} | ||
if (typeof window !== 'undefined') { | ||
const matchMediaPolyfill = (mediaQuery: string): MediaQueryList => { | ||
return { | ||
media: mediaQuery, | ||
matches: false, | ||
addListener(): void { }, | ||
removeListener(): void { }, | ||
}; | ||
}; | ||
window.matchMedia = window.matchMedia || matchMediaPolyfill; | ||
} | ||
} | ||
|
||
ngOnInit(): void { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.