Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,12 @@ import { MatCalendar } from "@angular/material/datepicker";
import { Moment } from "moment";
import { MdePopoverTrigger } from "@material-extended/mde";
import { CssUtils } from "../utils";

type Size = "medium" | "large" | "fillParent";

type Space =
| "xxsmall"
| "xsmall"
| "small"
| "medium"
| "large"
| "xlarge"
| "xxlarge";

type Margin = {
top?: Space;
bottom?: Space;
left?: Space;
right?: Space;
};
import {
DateInputProperties,
EmittedValue,
Space,
Spacing,
} from "./dxc-date-input.types";

const moment = momentImported;

Expand Down Expand Up @@ -124,11 +112,11 @@ export class DxcDateInputComponent implements OnInit {
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
*/
@Input() margin: Space | Margin;
@Input() margin: Space | Spacing;
/**
* Size of the component.
*/
@Input() size: Size = "medium";
@Input() size: "medium" | "large" | "fillParent" = "medium";
/**
* Value of the tabindex attribute.
*/
Expand All @@ -137,7 +125,7 @@ export class DxcDateInputComponent implements OnInit {
@Input()
autocomplete: string = "off";

defaultInputs = new BehaviorSubject<any>({
defaultInputs = new BehaviorSubject<DateInputProperties>({
error: "",
clearable: false,
optional: false,
Expand All @@ -146,33 +134,26 @@ export class DxcDateInputComponent implements OnInit {
value: undefined,
name: "",
label: "",
margin: "",
margin: null,
size: "medium",
format: "dd-MM-yyyy",
tabIndexValue: 0,
placeholder: false,
autocomplete: "off",
});

/**
* This event will emit in case the user types within the input element of the component. An object including the string value,
* the error and the date value will be emitted. If the string value is a valid date, error will be null.
* Also, if the string value is not a valid date, date will be null.
*/
@Output() onChange = new EventEmitter<{
value: string;
error: string | null;
date: Date | null;
}>();
@Output() onChange = new EventEmitter<EmittedValue>();
/**
* This event will emit in case the input element loses the focus. An object including the string value,
* the error and the date value will be emitted. If the string value is a valid date, error will be null.
* Also, if the string value is not a valid date, date will be null.
*/
@Output() onBlur = new EventEmitter<{
value: string;
error: string | null;
date: Date | null;
}>();
@Output() onBlur = new EventEmitter<EmittedValue>();
/**
* Reference to the component.
*/
Expand All @@ -190,7 +171,11 @@ export class DxcDateInputComponent implements OnInit {
_dxcCalendar: MatCalendar<Moment>;
@ViewChild("dxcCalendar", { read: ElementRef }) calendar: ElementRef;

private _sizes: Size[] = ["medium", "large", "fillParent"];
private _sizes: ("medium" | "large" | "fillParent")[] = [
"medium",
"large",
"fillParent",
];

private _isOpenClicked: boolean = false;
private _isCalendarOpened: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export interface DateInputProperties {
margin?: Space | Spacing;
label?: string;
name?: string;
value?: string;
helperText?: string;
format?: string;
disabled?: boolean;
placeholder?: boolean;
optional?: boolean;
clearable?: boolean;
error?: string;
size?: "medium" | "large" | "fillParent";
tabIndexValue?: number;
autocomplete?: string;
}

export type Space =
| "xxsmall"
| "xsmall"
| "small"
| "medium"
| "large"
| "xlarge"
| "xxlarge";

export type Spacing = {
top?: Space;
bottom?: Space;
left?: Space;
right?: Space;
};

export type EmittedValue = {
value: string;
error: string | null;
date: Date | null;
};