Skip to content

Commit 7647c07

Browse files
authored
Merge pull request #789 from dxc-technology/number-types-interface
Added types file in number
2 parents f237dcf + 0ef6c6e commit 7647c07

File tree

2 files changed

+55
-26
lines changed

2 files changed

+55
-26
lines changed

projects/dxc-ngx-cdk/src/lib/dxc-number-input/dxc-number-input.component.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,13 @@ import { CssUtils } from "../utils";
2020
import { OnDestroy } from "@angular/core";
2121
import { DxcTextInputComponent } from "../dxc-text-input/dxc-text-input.component";
2222
import { DxcNumberInputHelper } from "./dxc-number-input.helper";
23-
24-
type Space =
25-
| "xxsmall"
26-
| "xsmall"
27-
| "small"
28-
| "medium"
29-
| "large"
30-
| "xlarge"
31-
| "xxlarge";
32-
type Margin = {
33-
top?: Space;
34-
bottom?: Space;
35-
left?: Space;
36-
right?: Space;
37-
};
23+
import {
24+
Spacing,
25+
Space,
26+
OnChangeEvent,
27+
OnBlurEvent,
28+
NumberInputProperties,
29+
} from "./dxc-number.types";
3830

3931
@Component({
4032
selector: "dxc-number-input",
@@ -146,7 +138,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
146138
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
147139
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
148140
*/
149-
@Input() margin: Space | Margin;
141+
@Input() margin: Space | Spacing;
150142
/**
151143
* Size of the component ('small' | 'medium' | 'large' | 'fillParent').
152144
*/
@@ -158,7 +150,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
158150

159151
private controlled: boolean;
160152

161-
defaultInputs = new BehaviorSubject<any>({
153+
defaultInputs = new BehaviorSubject<NumberInputProperties>({
162154
placeholder: "",
163155
error: "",
164156
optional: false,
@@ -167,7 +159,7 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
167159
value: undefined,
168160
name: "",
169161
label: "",
170-
margin: "",
162+
margin: null,
171163
step: 1,
172164
min: null,
173165
max: null,
@@ -180,20 +172,14 @@ export class DxcNumberInputComponent implements OnInit, OnChanges, OnDestroy {
180172
* the error (if the value entered is not valid) will be passed to this
181173
* function. If there is no error, error will be null.
182174
*/
183-
@Output() onChange = new EventEmitter<{
184-
value: string;
185-
error: string | null;
186-
}>();
175+
@Output() onChange = new EventEmitter<OnChangeEvent>();
187176
/**
188177
* This event will emit in case the number loses the focus.
189178
* An object including the input value and the error (if the value
190179
* entered is not valid) will be passed to this function. If there is no error,
191180
* error will be null.
192181
*/
193-
@Output() onBlur = new EventEmitter<{
194-
value: string;
195-
error: string | null;
196-
}>();
182+
@Output() onBlur = new EventEmitter<OnBlurEvent>();
197183
@ViewChild("dxcInputRef", { static: false })
198184
dxcInputRef: DxcTextInputComponent;
199185

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export interface NumberInputProperties {
2+
margin?: Space | Spacing;
3+
label?: string;
4+
name?: string;
5+
value?: string;
6+
helperText?: string;
7+
placeholder?: string;
8+
disabled?: boolean;
9+
min?: number;
10+
max?: number;
11+
step?: number;
12+
optional?: boolean;
13+
error?: string;
14+
autocomplete?: string;
15+
size?: "small" | "medium" | "large" | "fillParent";
16+
tabIndexValue?: number;
17+
}
18+
19+
export type Space =
20+
| "xxsmall"
21+
| "xsmall"
22+
| "small"
23+
| "medium"
24+
| "large"
25+
| "xlarge"
26+
| "xxlarge";
27+
28+
export type Spacing = {
29+
top?: Space;
30+
bottom?: Space;
31+
left?: Space;
32+
right?: Space;
33+
};
34+
35+
export type OnChangeEvent = {
36+
value?: string;
37+
error?: string | null;
38+
};
39+
40+
export type OnBlurEvent = {
41+
value?: string;
42+
error?: string | null;
43+
};

0 commit comments

Comments
 (0)