Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb5df878

Browse files
committed
refactor: rename directive appLinkAttributes -> appHtmlAttr
- moved to layout- feat(app-header): navbarBrand img use appHtmlAttr instead of attr.*- refactor(app-header): drop unused methods- refactor(sidebar-nav): directive appLinkAttributes -> appHtmlAttr
1 parentfeff47b commitb5df878

File tree

6 files changed

+69
-99
lines changed

6 files changed

+69
-99
lines changed

‎projects/coreui/angular/src/lib/header/app-header.component.ts‎

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{Component,ElementRef,Input,OnInit,OnDestroy,Inject,Renderer2}from'@angular/core';
1+
import{Component,ElementRef,Input,OnInit,OnDestroy,Inject,Renderer2}from'@angular/core';
22
import{DOCUMENT}from'@angular/common';
33

44
import{Replace}from'../shared';
@@ -15,23 +15,14 @@ import { Replace } from '../shared';
1515
<a class="navbar-brand" [href]="navbarBrandHref">
1616
<ng-template [ngIf]="navbarBrandImg">
1717
<img *ngIf="navbarBrand"
18-
[src]="imgSrc(navbarBrand)"
19-
[attr.width]="imgWidth(navbarBrand)"
20-
[attr.height]="imgHeight(navbarBrand)"
21-
[attr.alt]="imgAlt(navbarBrand)"
22-
class="navbar-brand">
18+
[appHtmlAttr]="navbarBrand"
19+
[ngClass]="'navbar-brand'">
2320
<img *ngIf="navbarBrandFull"
24-
[src]="imgSrc(navbarBrandFull)"
25-
[attr.width]="imgWidth(navbarBrandFull)"
26-
[attr.height]="imgHeight(navbarBrandFull)"
27-
[attr.alt]="imgAlt(navbarBrandFull)"
28-
class="navbar-brand-full">
21+
[appHtmlAttr]="navbarBrandFull"
22+
[ngClass]="'navbar-brand-full'">
2923
<img *ngIf="navbarBrandMinimized"
30-
[src]="imgSrc(navbarBrandMinimized)"
31-
[attr.width]="imgWidth(navbarBrandMinimized)"
32-
[attr.height]="imgHeight(navbarBrandMinimized)"
33-
[attr.alt]="imgAlt(navbarBrandMinimized)"
34-
class="navbar-brand-minimized">
24+
[appHtmlAttr]="navbarBrandMinimized"
25+
[ngClass]="'navbar-brand-minimized'">
3526
</ng-template>
3627
<ng-template [ngIf]="!navbarBrandImg">
3728
<div class="navbar-brand-full" [innerHTML]="navbarBrandText.text"></div>
@@ -73,6 +64,7 @@ export class AppHeaderComponent implements OnInit, OnDestroy {
7364
@Input()asideMenuToggler:any;
7465
@Input()mobileAsideMenuToggler:any;
7566

67+
privatereadonlyfixedClass='header-fixed';
7668
navbarBrandImg:boolean;
7769

7870
constructor(
@@ -88,33 +80,12 @@ export class AppHeaderComponent implements OnInit, OnDestroy {
8880
}
8981

9082
ngOnDestroy():void{
91-
this.renderer.removeClass(this.document.body,'header-fixed');
83+
this.renderer.removeClass(this.document.body,this.fixedClass);
9284
}
9385

9486
isFixed(fixed:boolean=this.fixed):void{
9587
if(fixed){
96-
this.renderer.addClass(this.document.body,'header-fixed');
88+
this.renderer.addClass(this.document.body,this.fixedClass);
9789
}
9890
}
99-
100-
imgSrc(brand:any):void{
101-
returnbrand.src ?brand.src :'';
102-
}
103-
104-
imgWidth(brand:any):void{
105-
returnbrand.width ?brand.width :'auto';
106-
}
107-
108-
imgHeight(brand:any):void{
109-
returnbrand.height ?brand.height :'auto';
110-
}
111-
112-
imgAlt(brand:any):void{
113-
returnbrand.alt ?brand.alt :'';
114-
}
115-
116-
breakpoint(breakpoint:any):void{
117-
console.log(breakpoint);
118-
returnbreakpoint ?breakpoint :'';
119-
}
12091
}

‎projects/coreui/angular/src/lib/header/app-header.module.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{CommonModule}from'@angular/common';
22
import{NgModule}from'@angular/core';
3-
import{LayoutModule}from'./../shared/layout/layout.module';
3+
import{LayoutModule}from'../shared/layout';
44

55
import{AppHeaderComponent}from'./app-header.component';
66

‎projects/coreui/angular/src/lib/shared/layout/layout.directive.ts‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{Directive,HostListener,Inject,Input,OnInit,Renderer2}from'@angular/core';
1+
import{Directive,ElementRef,HostListener,Inject,Input,OnInit,Renderer2}from'@angular/core';
22
import{DOCUMENT}from'@angular/common';
33

44
import{asideMenuCssClasses,sidebarCssClasses}from'../classes';
@@ -157,3 +157,46 @@ export class AsideToggleDirective implements OnInit {
157157
this.classToggler.toggleClasses(cssClass,asideMenuCssClasses);
158158
}
159159
}
160+
161+
@Directive({
162+
selector:'[appHtmlAttr]'
163+
})
164+
exportclassHtmlAttributesDirectiveimplementsOnInit{
165+
@Input()appHtmlAttr:{[key:string]:string};
166+
167+
constructor(
168+
@Inject(DOCUMENT)privatedocument:any,
169+
privaterenderer:Renderer2,
170+
privateel:ElementRef
171+
){}
172+
173+
ngOnInit(){
174+
constattribs=this.appHtmlAttr;
175+
for(constattrinattribs){
176+
if(attr==='style'&&typeof(attribs[attr])==='object'){
177+
this.setStyle(attribs[attr]);
178+
}elseif(attr==='class'){
179+
this.addClass(attribs[attr]);
180+
}else{
181+
this.setAttrib(attr,attribs[attr]);
182+
}
183+
}
184+
}
185+
186+
privatesetStyle(styles){
187+
for(conststyleinstyles){
188+
this.renderer.setStyle(this.el.nativeElement,style,styles[style]);
189+
}
190+
}
191+
192+
privateaddClass(classes){
193+
constclassArray=(Array.isArray(classes) ?classes :classes.split(' '));
194+
classArray.filter((element)=>element.length>0).forEach(element=>{
195+
this.renderer.addClass(this.el.nativeElement,element);
196+
});
197+
}
198+
199+
privatesetAttrib(key,value){
200+
this.renderer.setAttribute(this.el.nativeElement,key,value);
201+
}
202+
}

‎projects/coreui/angular/src/lib/shared/layout/layout.module.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
MobileSidebarToggleDirective,
77
SidebarToggleDirective,
88
SidebarMinimizeDirective,
9-
SidebarOffCanvasCloseDirective
9+
SidebarOffCanvasCloseDirective,
10+
HtmlAttributesDirective
1011
}from'./layout.directive';
1112
import{ClassToggler}from'../toggle-classes';
1213

@@ -20,15 +21,17 @@ import { ClassToggler } from '../toggle-classes';
2021
MobileSidebarToggleDirective,
2122
SidebarToggleDirective,
2223
SidebarMinimizeDirective,
23-
SidebarOffCanvasCloseDirective
24+
SidebarOffCanvasCloseDirective,
25+
HtmlAttributesDirective
2426
],
2527
declarations:[
2628
AsideToggleDirective,
2729
BrandMinimizeDirective,
2830
MobileSidebarToggleDirective,
2931
SidebarToggleDirective,
3032
SidebarMinimizeDirective,
31-
SidebarOffCanvasCloseDirective
33+
SidebarOffCanvasCloseDirective,
34+
HtmlAttributesDirective
3235
],
3336
providers:[
3437
ClassToggler

‎projects/coreui/angular/src/lib/sidebar/app-sidebar-nav.component.ts‎

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -44,51 +44,6 @@ export class NavDropdownToggleDirective {
4444
}
4545
}
4646

47-
@Directive({
48-
selector:'[appLinkAttributes]'
49-
})
50-
exportclassLinkAttributesDirectiveimplementsOnInit{
51-
@Input()appLinkAttributes:{[key:string]:string};
52-
53-
constructor(
54-
@Inject(DOCUMENT)privatedocument:any,
55-
privaterenderer:Renderer2,
56-
privateel:ElementRef
57-
){}
58-
59-
ngOnInit(){
60-
constattribs=this.appLinkAttributes;
61-
for(constattrinattribs){
62-
if(attr==='style'&&typeof(attribs[attr])==='object'){
63-
this.setStyle(attribs[attr]);
64-
}elseif(attr==='class'){
65-
this.addClass(attribs[attr]);
66-
}else{
67-
this.setAttrib(attr,attribs[attr]);
68-
}
69-
}
70-
}
71-
72-
privatesetStyle(styles){
73-
for(conststyleinstyles){
74-
this.renderer.setStyle(this.el.nativeElement,style,styles[style]);
75-
}
76-
}
77-
78-
privateaddClass(classes){
79-
constclassArray=Array.isArray(classes) ?classes :classes.split(' ');
80-
classArray.forEach(element=>{
81-
this.renderer.addClass(this.el.nativeElement,element);
82-
});
83-
}
84-
85-
privatesetAttrib(key,value){
86-
constnewAttr=this.document.createAttribute(key);
87-
newAttr.value=value;
88-
this.renderer.setAttribute(this.el.nativeElement,key,value);
89-
}
90-
}
91-
9247
@Component({
9348
selector:'app-sidebar-nav',
9449
template:`
@@ -102,7 +57,8 @@ export class LinkAttributesDirective implements OnInit {
10257
<app-sidebar-nav-item [item]='navitem'></app-sidebar-nav-item>
10358
</ng-template>
10459
</ng-template>
105-
</ul>`
60+
</ul>
61+
`
10662
})
10763
exportclassAppSidebarNavComponentimplementsOnChanges{
10864
@Input()navItems:Array<any>;
@@ -175,21 +131,21 @@ export class AppSidebarNavItemComponent implements OnInit {
175131
<ng-container [ngSwitch]="getLinkType()">
176132
<a *ngSwitchCase="'disabled'"
177133
[attr.disabled]="true"
178-
[appLinkAttributes]="link.attributes"
134+
[appHtmlAttr]="link.attributes"
179135
href=""
180136
[ngClass]="getClasses()">
181137
<i *ngIf="isIcon()" class="nav-icon {{ link.icon }}"></i>
182138
{{ link.name }}
183139
<span *ngIf="isBadge()" [ngClass]="'badge badge-' + link.badge.variant">{{ link.badge.text }}</span>
184140
</a>
185-
<a *ngSwitchCase="'external'" [ngClass]="getClasses()" href="{{link.url}}" [appLinkAttributes]="link.attributes">
141+
<a *ngSwitchCase="'external'" [ngClass]="getClasses()" href="{{link.url}}" [appHtmlAttr]="link.attributes">
186142
<i *ngIf="isIcon()" class="nav-icon {{ link.icon }}"></i>
187143
{{ link.name }}
188144
<span *ngIf="isBadge()" [ngClass]="'badge badge-' + link.badge.variant">{{ link.badge.text }}</span>
189145
</a>
190146
<a *ngSwitchDefault
191147
[ngClass]="getClasses()"
192-
[appLinkAttributes]="link.attributes"
148+
[appHtmlAttr]="link.attributes"
193149
routerLinkActive="active"
194150
[routerLink]="[link.url]"
195151
(click)="hideMobile()">

‎projects/coreui/angular/src/lib/sidebar/app-sidebar.module.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import{CommonModule}from'@angular/common';
22
import{NgModule}from'@angular/core';
33
import{RouterModule}from'@angular/router';
4-
import{LayoutModule}from'./../shared/layout/layout.module';
4+
import{LayoutModule}from'../shared/layout';
55

66
// App Sidebar Component
77
import{AppSidebarFooterComponent}from'./app-sidebar-footer.component';
@@ -16,8 +16,7 @@ import {
1616
AppSidebarNavLinkComponent,
1717
AppSidebarNavTitleComponent,
1818
NavDropdownDirective,
19-
NavDropdownToggleDirective,
20-
LinkAttributesDirective
19+
NavDropdownToggleDirective
2120
}from'./app-sidebar-nav.component';
2221

2322
@NgModule({
@@ -39,7 +38,6 @@ import {
3938
AppSidebarNavTitleComponent,
4039
NavDropdownDirective,
4140
NavDropdownToggleDirective,
42-
LinkAttributesDirective,
4341
LayoutModule
4442
],
4543
declarations:[
@@ -55,8 +53,7 @@ import {
5553
AppSidebarNavLinkComponent,
5654
AppSidebarNavTitleComponent,
5755
NavDropdownDirective,
58-
NavDropdownToggleDirective,
59-
LinkAttributesDirective
56+
NavDropdownToggleDirective
6057
]
6158
})
6259
exportclassAppSidebarModule{}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp