Skip to content

Commit adcd2fc

Browse files
committed
fix(datetime): add styling for datetime with different labels
fixes #6764
1 parent 4eb8ede commit adcd2fc

File tree

12 files changed

+144
-5
lines changed

12 files changed

+144
-5
lines changed

src/components.md.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"components/checkbox/checkbox.md",
1515
"components/chip/chip.md",
1616
"components/content/content.md",
17+
"components/datetime/datetime.md",
1718
"components/input/input.md",
1819
"components/item/item.md",
1920
"components/label/label.md",

src/components.wp.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"components/checkbox/checkbox.wp",
1515
"components/chip/chip.wp",
1616
"components/content/content.wp",
17+
"components/datetime/datetime.wp",
1718
"components/input/input.wp",
1819
"components/item/item.wp",
1920
"components/label/label.wp",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import "../../globals.md";
2+
@import "./datetime";
3+
4+
// Material Design DateTime
5+
// --------------------------------------------------
6+
7+
$datetime-md-padding-top: $item-md-padding-top !default;
8+
$datetime-md-padding-right: ($item-md-padding-right / 2) !default;
9+
$datetime-md-padding-bottom: $item-md-padding-bottom !default;
10+
$datetime-md-padding-left: $item-md-padding-left !default;
11+
12+
13+
ion-datetime {
14+
padding: $datetime-md-padding-top $datetime-md-padding-right $datetime-md-padding-bottom $datetime-md-padding-left;
15+
}

src/components/datetime/datetime.scss

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
ion-datetime {
77
display: flex;
88
overflow: hidden;
9-
10-
max-width: 45%;
119
}
1210

1311
.datetime-text {
@@ -20,6 +18,9 @@ ion-datetime {
2018
font-size: inherit;
2119
text-overflow: ellipsis;
2220
white-space: nowrap;
21+
22+
min-height: 1.2em;
23+
line-height: 1.2;
2324
}
2425

2526
.datetime-disabled,
@@ -28,3 +29,9 @@ ion-datetime {
2829

2930
pointer-events: none;
3031
}
32+
33+
.item-label-stacked ion-datetime,
34+
.item-label-floating ion-datetime {
35+
width: 100%;
36+
padding-left: 0;
37+
}

src/components/datetime/datetime.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,15 @@ export class DateTime {
698698
return this._value;
699699
}
700700

701+
/**
702+
* @private
703+
*/
704+
checkHasValue(inputValue: any) {
705+
if (this._item) {
706+
this._item.setCssClass('input-has-value', !!(inputValue && inputValue !== ''));
707+
}
708+
}
709+
701710
/**
702711
* @private
703712
*/
@@ -766,6 +775,7 @@ export class DateTime {
766775
console.debug('datetime, writeValue', val);
767776
this.setValue(val);
768777
this.updateText();
778+
this.checkHasValue(val);
769779
}
770780

771781
/**
@@ -792,6 +802,7 @@ export class DateTime {
792802
console.debug('datetime, onChange', val);
793803
this.setValue(val);
794804
this.updateText();
805+
this.checkHasValue(val);
795806

796807
// convert DateTimeData value to iso datetime format
797808
fn(convertDataToISO(this._value));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@import "../../globals.wp";
2+
@import "./datetime";
3+
4+
// Windows DateTime
5+
// --------------------------------------------------
6+
7+
$datetime-wp-min-width: 45% !default;
8+
9+
$datetime-wp-padding-top: $item-wp-padding-top !default;
10+
$datetime-wp-padding-right: ($item-wp-padding-right / 2) !default;
11+
$datetime-wp-padding-bottom: $item-wp-padding-bottom !default;
12+
$datetime-wp-padding-left: $item-wp-padding-left !default;
13+
14+
$datetime-wp-border-width: 2px !default;
15+
$datetime-wp-border-color: $input-wp-border-color !default;
16+
17+
ion-datetime {
18+
padding: $datetime-wp-padding-top $datetime-wp-padding-right $datetime-wp-padding-bottom $datetime-wp-padding-left;
19+
min-width: $datetime-wp-min-width;
20+
}
21+
22+
.datetime-text {
23+
border: $datetime-wp-border-width solid $datetime-wp-border-color;
24+
line-height: 3rem;
25+
min-height: 3.4rem;
26+
padding: 0 8px;
27+
}
28+
29+
.item-datetime ion-label[floating] {
30+
transform: translate3d(8px, 41px, 0);
31+
}

src/components/datetime/test/labels/e2e.ts

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Component} from '@angular/core';
2+
import {ionicBootstrap} from '../../../../../src';
3+
4+
5+
@Component({
6+
templateUrl: 'main.html'
7+
})
8+
class E2EPage {
9+
stacked2 = '1994-12-15T13:47:20.789';
10+
floating2 = '1995-04-15';
11+
fixed2 = '2002-09-23T15:03:46.789';
12+
inline2 = '2005-06-17T11:06Z';
13+
}
14+
15+
16+
@Component({
17+
template: '<ion-nav [root]="root"></ion-nav>'
18+
})
19+
class E2EApp {
20+
root = E2EPage;
21+
}
22+
23+
ionicBootstrap(E2EApp);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<ion-toolbar>
2+
<ion-title>Datetime</ion-title>
3+
</ion-toolbar>
4+
5+
<ion-content class="outer-content">
6+
7+
<ion-item>
8+
<ion-label stacked>Stacked</ion-label>
9+
<ion-datetime [(ngModel)]="stacked1"></ion-datetime>
10+
</ion-item>
11+
12+
<ion-item>
13+
<ion-label stacked>Stacked</ion-label>
14+
<ion-datetime [(ngModel)]="stacked2"></ion-datetime>
15+
</ion-item>
16+
17+
<ion-item>
18+
<ion-label floating>Floating</ion-label>
19+
<ion-datetime displayFormat="MMMM YY" [(ngModel)]="floating1"></ion-datetime>
20+
</ion-item>
21+
22+
<ion-item>
23+
<ion-label floating>Floating</ion-label>
24+
<ion-datetime displayFormat="D MMM YYYY"[(ngModel)]="floating2"></ion-datetime>
25+
</ion-item>
26+
27+
<ion-item>
28+
<ion-label fixed>Fixed</ion-label>
29+
<ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="fixed1"></ion-datetime>
30+
</ion-item>
31+
32+
<ion-item>
33+
<ion-label fixed>Fixed</ion-label>
34+
<ion-datetime displayFormat="DDDD MMM D, YYYY" [(ngModel)]="fixed2"></ion-datetime>
35+
</ion-item>
36+
37+
<ion-item>
38+
<ion-label>Inline</ion-label>
39+
<ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="inline1"></ion-datetime>
40+
</ion-item>
41+
42+
<ion-item>
43+
<ion-label>Inline</ion-label>
44+
<ion-datetime displayFormat="DDDD MMM D, YYYY" [(ngModel)]="inline2"></ion-datetime>
45+
</ion-item>
46+
47+
</ion-content>

src/components/label/label.ios.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ ion-label {
2020
// --------------------------------------------------
2121

2222
.item-input ion-label,
23-
.item-select ion-label {
23+
.item-select ion-label,
24+
.item-datetime ion-label {
2425
color: $label-ios-text-color;
2526
}
2627

0 commit comments

Comments
 (0)