Skip to content

Commit 17e6f40

Browse files
hpyourdkmaster
authored andcommitted
[优化] JigsawButton现在采用纯css的形式居中,去掉line-height的计算,优化按钮的尺寸/文字大小等;[新增] dialog现在可以设置弹框的高度
1 parent aa29017 commit 17e6f40

File tree

11 files changed

+139
-15
lines changed

11 files changed

+139
-15
lines changed

src/app/demo/dialog/demo-set.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {DialogTopDemo} from "./top/demo.component";
1313
import {DialogPopOptionDemo} from "./popup-option/demo.component";
1414
import {DialogInDomDemoComponent} from "./in-dom/demo.component";
1515
import {DialogMiscDemoComponent} from "./misc/demo.component";
16+
import {DialogHeightDemo} from "./height/demo.component";
17+
import {DialogHeightDemoModule} from "./height/demo.module";
1618

1719
export const routerConfig:any = [
1820
{
@@ -33,6 +35,9 @@ export const routerConfig:any = [
3335
{
3436
path: 'in-dom', component: DialogInDomDemoComponent
3537
},
38+
{
39+
path: 'height', component: DialogHeightDemo
40+
},
3641
];
3742

3843
@NgModule({
@@ -43,7 +48,8 @@ export const routerConfig:any = [
4348
DialogMiscDemoModule,
4449
DialogPopOptionDemoModule,
4550
DialogTitleDemoModule,
46-
DialogTopDemoModule
51+
DialogTopDemoModule,
52+
DialogHeightDemoModule
4753
]
4854
})
4955
export class DialogDemoModule {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.dialog-content {
2+
background: aquamarine;
3+
position: relative;
4+
}
5+
6+
.dialog-content p {
7+
font-size: 24px;
8+
text-align: center;
9+
position: absolute;
10+
width: 100%;
11+
left: 0;
12+
top: 50%;
13+
transform: translateY(-50%);
14+
}
15+
16+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- ignore the following lines, they are not important to this demo -->
2+
<jigsaw-demo-description [summary]="summary" [content]="description">
3+
</jigsaw-demo-description>
4+
5+
6+
<!-- start to learn the demo from here -->
7+
<div class="live-demo-wrap">
8+
<h2>Dialog</h2>
9+
<div class="demo-1 live-demo">
10+
<h3>Height</h3>
11+
<p class="comment">
12+
一般dialog不设高度,dialog会随内容撑开,设置了高度,用户可以在自定义的content中加
13+
<code>style="height: 100%"</code>,使内容撑满dialog-content</p>
14+
<jigsaw-button (click)="popupDialog1(dialog1)">popup</jigsaw-button>
15+
<ng-template #dialog1>
16+
<jigsaw-dialog width="80%" height="400" caption="dialog title" (close)="close()">
17+
<div class="dialog-content" style="height: 100%">
18+
<p>dialog content</p>
19+
</div>
20+
<div jigsaw-button-bar>
21+
<jigsaw-button colorType="danger" (click)="close()">OK</jigsaw-button>
22+
</div>
23+
</jigsaw-dialog>
24+
</ng-template>
25+
</div>
26+
</div>
27+
28+
29+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Component, TemplateRef} from "@angular/core";
2+
import {PopupInfo, PopupService} from "jigsaw/service/popup.service";
3+
4+
@Component({
5+
templateUrl: './demo.component.html',
6+
styleUrls: ['./demo.component.css']
7+
})
8+
export class DialogHeightDemo {
9+
dialogInfo: PopupInfo;
10+
11+
constructor(private popupService: PopupService) {
12+
}
13+
14+
close() {
15+
this.dialogInfo.dispose();
16+
}
17+
18+
popupDialog1(ele: TemplateRef<any>) {
19+
this.dialogInfo = this.popupService.popup(ele);
20+
}
21+
22+
// ====================================================================
23+
// ignore the following lines, they are not important to this demo
24+
// ====================================================================
25+
summary: string = '这个demo演示了如何使用`height`属性来控制弹出的对话框的高度';
26+
description: string = '';
27+
tags: string[] = [
28+
'JigsawDialog.height',
29+
];
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {NgModule} from "@angular/core";
2+
import {JigsawButtonModule} from "jigsaw/component/button/button";
3+
import {JigsawDialogModule} from "jigsaw/component/dialog/dialog";
4+
import {JigsawInputModule} from "jigsaw/component/input/input";
5+
import {PopupService} from "jigsaw/service/popup.service";
6+
import {JigsawDemoDescriptionModule} from "app/demo-description/demo-description";
7+
import {DialogHeightDemo} from "./demo.component";
8+
9+
@NgModule({
10+
declarations: [DialogHeightDemo],
11+
exports: [DialogHeightDemo],
12+
imports: [JigsawDialogModule, JigsawButtonModule, JigsawInputModule, JigsawDemoDescriptionModule],
13+
providers: [PopupService]
14+
})
15+
export class DialogHeightDemoModule {
16+
17+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<ng-content></ng-content>
1+
<div class="jigsaw-button-content"><ng-content></ng-content></div>

src/jigsaw/component/button/button.scss

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ $btn-prefix-cls: #{$jigsaw-prefix}-button;
44

55
.#{$btn-prefix-cls} {
66
@include inline-block();
7-
min-width: 80px;
87
padding: 0 10px;
8+
min-width: 80px;
99
height: $height-base;
10-
line-height: $height-base - 2px;
1110
font-size: $font-size-base;
11+
line-height: 1;
1212
text-align: center;
1313
position: relative;
1414
border-radius: $border-radius-base;
@@ -20,6 +20,12 @@ $btn-prefix-cls: #{$jigsaw-prefix}-button;
2020
background-color: #fff;
2121
border: 1px solid $border-color-base;
2222
color: $text-color;
23+
&:before {
24+
content: '';
25+
display: inline-block;
26+
height: 100%;
27+
vertical-align: middle;
28+
}
2329
&:hover {
2430
color: $primary-5;
2531
border: 1px solid $primary-5;
@@ -43,6 +49,11 @@ $btn-prefix-cls: #{$jigsaw-prefix}-button;
4349
@include prefixer(animation, buttonEffect 0.36s $ease-out forwards);
4450
display: block;
4551
}
52+
53+
&-content {
54+
@include inline-block;
55+
}
56+
4657
&-icon {
4758
@include inline-block();
4859
img {
@@ -97,15 +108,13 @@ $btn-prefix-cls: #{$jigsaw-prefix}-button;
97108
}
98109

99110
&#{&}-size-large {
100-
font-size: $font-size-lg;
101111
height: $height-lg;
102-
line-height: $height-lg - 2px;
112+
font-size: $font-size-lg;
103113
}
104114

105115
&#{&}-size-small {
106-
font-size: $font-size-sm;
107116
height: $height-sm;
108-
line-height: $height-sm - 2px;
117+
font-size: $font-size-sm;
109118
}
110119

111120
&#{&}-disabled {

src/jigsaw/component/button/button.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import {AbstractJigsawComponent} from '../common';
2323
'[class.jigsaw-button]': 'true',
2424
'[class.jigsaw-button-disabled]': 'disabled',
2525
'(click)': '_onClick()',
26-
'[style.width]': 'width',
26+
'[style.min-width]': 'width',
2727
'[style.height]': 'height',
28-
'[style.line-height]': '_calcLineHeight()',
2928
'[class.jigsaw-button-clicked]': "_clicked",
3029
'[class.jigsaw-button-size-small]': "preSize === 'small'",
3130
'[class.jigsaw-button-size-large]': "preSize === 'large'",
@@ -66,10 +65,6 @@ export class JigsawButton extends AbstractJigsawComponent {
6665
this.callLater(() => this._clicked = false, 360);
6766
}
6867
}
69-
70-
private _calcLineHeight(): string {
71-
return parseInt(this.height) - 4 + 'px';
72-
}
7368
}
7469

7570
@NgModule({

src/jigsaw/component/dialog/dialog.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<span class="jigsaw-dialog-close jigsaw-popup-close" (click)='dispose()'>&times;</span>
66
</div>
77
<div class="jigsaw-dialog-content">
8-
<ng-content></ng-content>
8+
<div class="jigsaw-dialog-content-inner">
9+
<ng-content></ng-content>
10+
</div>
911
</div>
1012
<div class="jigsaw-dialog-button-group"
1113
*ngIf="(_$inlineButtons && _$inlineButtons.length > 0) || (buttons && buttons.length > 0)">

src/jigsaw/component/dialog/dialog.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ $dialog-prefix-cls: #{$jigsaw-prefix}-dialog;
55
.#{$dialog-prefix-cls}-host {
66
@include inline-block;
77
width: 100%;
8+
9+
&.#{$dialog-prefix-cls}-fixed-height {
10+
.#{$dialog-prefix-cls} {
11+
display: flex;
12+
flex-direction: column;
13+
height: 100%;
14+
.#{$dialog-prefix-cls}-content{
15+
display: flex;
16+
flex-grow: 1;
17+
.#{$dialog-prefix-cls}-content-inner {
18+
flex-grow: 1;
19+
}
20+
}
21+
}
22+
}
823
}
924

1025
.#{$dialog-prefix-cls} {

0 commit comments

Comments
 (0)