Skip to content

Commit

Permalink
fix: date-picker style problem (#145)
Browse files Browse the repository at this point in the history
Co-authored-by: zangguodong <[email protected]>
  • Loading branch information
zangguodong and zangguodong authored Aug 9, 2021
1 parent 5470edc commit c0c2f82
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/date-picker-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/ui": patch
---

fix: date-picker style problem
4 changes: 3 additions & 1 deletion src/date-picker/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import { DateNavRange, DisabledTimeFn } from '../date-picker.type';
selector: 'aui-date-picker',
templateUrl: './date-picker.template.html',
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
// tslint:disable-next-line: validate-decorators
encapsulation: ViewEncapsulation.Emulated,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => DatePickerComponent),
multi: true,
},
],
styleUrls: ['./date-picker.style.scss'],
})
export class DatePickerComponent
extends CommonFormControl<ConfigType, Dayjs>
Expand Down
4 changes: 4 additions & 0 deletions src/date-picker/date-picker/date-picker.style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host {
display: inline-block;
width: 200px;
}
4 changes: 3 additions & 1 deletion src/date-picker/range-picker/range-picker.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
max-width: none;
}
}
aui-date-picker-trigger {

:host {
display: inline-block;
width: 260px;
}
3 changes: 2 additions & 1 deletion src/date-picker/trigger/trigger.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const bem = buildBem('aui-date-picker-trigger');
@Component({
selector: 'aui-date-picker-trigger',
templateUrl: './trigger.template.html',
encapsulation: ViewEncapsulation.None,
// tslint:disable-next-line: validate-decorators
encapsulation: ViewEncapsulation.Emulated,
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrls: ['./trigger.style.scss'],
})
Expand Down
26 changes: 22 additions & 4 deletions src/date-picker/trigger/trigger.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
@import '../../theme/mixin';

$block: aui-date-picker-trigger;

$height-mapper: (
'medium': $height-medium,
'large': $height-large,
'small': $height-small,
'mini': $height-mini,
);

aui-range-picker,
aui-date-picker {
&.ng-invalid {
Expand All @@ -14,13 +22,18 @@ aui-date-picker {
}
}

:host {
display: inline-block;
width: 100%;
}

.#{$block} {
&__container {
display: flex;
flex-direction: row;
align-items: center;
box-sizing: border-box;
width: 200px;
width: 100%;
border: $input-border-width $input-border-style $input-border-color;
position: relative;
cursor: pointer;
Expand All @@ -29,13 +42,17 @@ aui-date-picker {
border: none;
@include view-readonly;
}
// trigger有自己的border,隐藏了input的border,修正input由于border-box设定引起的高度差异
@each $name, $height in $height-mapper {
.aui-input--#{$name} {
height: $height - 2px;
}
}

&.is-focus,
&:hover {
border-color: $color-primary;
}
&.is-range {
width: 260px;
}
&.is-disabled {
input[readonly] {
background: transparent;
Expand Down Expand Up @@ -65,6 +82,7 @@ aui-date-picker {
font-size: $date-picker-icon-size;
width: $date-picker-icon-size;
height: $date-picker-icon-size;
line-height: 1em;
.clear {
@include clear-button;
}
Expand Down
16 changes: 15 additions & 1 deletion stories/date-picker/date-picker.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ import { DatePickerModule, DatePickerType, DateNavRange } from '@alauda/ui';
Form value2: {{time2?.toDate()}}
<br />
<br />
disable until today
disable until now
<aui-date-picker
[type]="DatePickerType.Day"
[(ngModel)]="time3"
[showTime]="true"
[disabledDate]="disableDateFn"
[disabledTime]="disableTimeToNow"
></aui-date-picker>
Form value3: {{time3?.toDate()}}
<br />
Expand Down Expand Up @@ -103,6 +104,18 @@ import { DatePickerModule, DatePickerType, DateNavRange } from '@alauda/ui';
: 'year',
);
},
disableTimeToNow: function () {
const currentHour = dayjs().hour();
const currentMinute = dayjs().minute();
const currentSecond = dayjs().second();
return {
hours: () => Array.from({ length: currentHour }).map((_, i) => i),
minutes: () =>
Array.from({ length: currentMinute }).map((_, i) => i),
seconds: () =>
Array.from({ length: currentSecond }).map((_, i) => i),
};
},
disabledTimeFn: function (date) {
if (date?.isSame(dayjs(), 'date')) {
return {
Expand Down Expand Up @@ -135,6 +148,7 @@ import { DatePickerModule, DatePickerType, DateNavRange } from '@alauda/ui';
<aui-range-picker
[(ngModel)]="range2"
[showTime]="false"
[showFooter]="true"
></aui-range-picker>
Form value: {{range2|json}}
<br />
Expand Down

0 comments on commit c0c2f82

Please sign in to comment.