Skip to content

Commit 88a9178

Browse files
authored
Merge pull request #623 from dxc-technology/marcialfps-dropdown-types
Types for Dropdown component
2 parents a1e3606 + 68c8606 commit 88a9178

File tree

5 files changed

+112
-40
lines changed

5 files changed

+112
-40
lines changed

projects/dxc-ngx-cdk-site/src/app/components/examples/dropdown/dropdown-api/dropdown-api.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</tr>
2929

3030
<tr>
31-
<td>value: any</td>
31+
<td>value: string</td>
3232
<td></td>
3333
<td>Value of the option.</td>
3434
</tr>

projects/dxc-ngx-cdk-site/src/app/components/examples/dropdown/properties/dropdown-table-properties.component.html

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
before the label.
1919
</td>
2020
</tr>
21-
<tr>
22-
<td>iconSrc: string</td>
23-
<td></td>
24-
<td>
25-
<b>Deprecated.</b> URL of the icon that will be placed next to the
26-
dropdown label.
27-
</td>
28-
</tr>
2921
<tr>
3022
<td>iconPosition: 'before' | 'after'</td>
3123
<td><code>'before'</code></td>
@@ -57,15 +49,18 @@
5749
</td>
5850
</tr>
5951
<tr>
60-
<td>size: any (string | object)</td>
52+
<td>size: string</td>
6153
<td><code>'fitContent' </code></td>
62-
<td>Size of the component ('large' | 'fillParent' | 'fitContent').</td>
54+
<td>
55+
Size of the component ('small' | 'medium' | 'large' | 'fillParent' |
56+
'fitContent').
57+
</td>
6358
</tr>
6459
<tr>
6560
<td>onSelectOption: EventEmitter</td>
6661
<td></td>
6762
<td>
68-
This event will be triggered when the selection changes. The value of the
63+
This event will emit in case the selection changes. The value of the
6964
selected value will be passed as a parameter.
7065
</td>
7166
</tr>
@@ -74,4 +69,14 @@
7469
<td><code>0</code></td>
7570
<td>Value of the tabindex.</td>
7671
</tr>
72+
<tr>
73+
<td>disabled: boolean</td>
74+
<td><code>false</code></td>
75+
<td>If true, the component will be disabled.</td>
76+
</tr>
77+
<tr>
78+
<td>expandOnHover: boolean</td>
79+
<td><code>false</code></td>
80+
<td>If true, the options are showed when the dropdown is hover.</td>
81+
</tr>
7782
</dxc-table>

projects/dxc-ngx-cdk/src/lib/dxc-dropdown/dxc-dropdown-option/dxc-dropdown-option.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ import { DropdownService } from "../services/dropdown.service";
1414
templateUrl: "./dxc-dropdown-option.component.html",
1515
})
1616
export class DxcDropdownOptionComponent implements OnChanges {
17-
@Input() public value;
18-
@Input() public label: string;
17+
/**
18+
* Value of the option.
19+
*/
20+
@Input() value: string;
21+
/**
22+
* Label displayed in the option.
23+
*/
24+
@Input() label: string;
1925

2026
@ViewChild(MatMenuItem) menuItem: MatMenuItem;
2127

projects/dxc-ngx-cdk/src/lib/dxc-dropdown/dxc-dropdown.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<div class="dxc-arrow arrow-{{ arrowClass }}"></div>
2424
</div>
2525
</div>
26-
2726
</button>
2827

2928
<mat-menu

projects/dxc-ngx-cdk/src/lib/dxc-dropdown/dxc-dropdown.component.ts

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ import {
2121
} from "@angular/cdk/coercion";
2222
import { DropdownService } from "./services/dropdown.service";
2323

24+
type Space =
25+
| "xxsmall"
26+
| "xsmall"
27+
| "small"
28+
| "medium"
29+
| "large"
30+
| "xlarge"
31+
| "xxlarge";
32+
33+
type Margin = {
34+
top?: Space;
35+
bottom?: Space;
36+
left?: Space;
37+
right?: Space;
38+
};
39+
2440
@Component({
2541
selector: "dxc-dropdown",
2642
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -29,48 +45,94 @@ import { DropdownService } from "./services/dropdown.service";
2945
providers: [CssUtils, DropdownService],
3046
})
3147
export class DxcDropdownComponent implements OnChanges {
32-
@HostBinding("class") className;
48+
/**
49+
* In case options include icons, whether the icon should appear after or before the label.
50+
*/
51+
@Input() optionsIconPosition: "before" | "after" = "before";
3352

34-
@Input() public name: string;
35-
@Input() public iconPosition: string = "before";
36-
@Input() public optionsIconPosition: string = "before";
37-
@Input() public margin: any;
38-
@Input() public size: any;
39-
@Input()
40-
get expandOnHover(): boolean {
41-
return this._expandOnHover;
42-
}
43-
set expandOnHover(value: boolean) {
44-
this._expandOnHover = coerceBooleanProperty(value);
45-
}
46-
private _expandOnHover;
53+
/**
54+
* Whether the icon should appear after or before the label.
55+
*/
56+
@Input() iconPosition: "before" | "after" = "before";
57+
58+
/**
59+
* Text to be placed when the list of options is not displayed.
60+
*/
61+
@Input() label: string = "";
62+
63+
/**
64+
* Name attribute of the input element.
65+
*/
66+
@Input() name: string;
67+
68+
/**
69+
* Whether the arrow next to the label is displayed or not.
70+
*/
4771
@Input()
4872
get caretHidden(): boolean {
4973
return this._caretHidden;
5074
}
5175
set caretHidden(value: boolean) {
5276
this._caretHidden = coerceBooleanProperty(value);
5377
}
54-
private _caretHidden;
78+
private _caretHidden = false;
79+
80+
/**
81+
* Size of the margin to be applied to the component. You can pass an object with 'top',
82+
* 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
83+
*/
84+
@Input() margin: Space | Margin;
85+
86+
/**
87+
* Size of the component.
88+
*/
89+
@Input() size: "small" | "medium" | "large" | "fillParent" | "fitContent" =
90+
"fitContent";
91+
92+
/**
93+
* This event will emit in case the selection changes. The value of the selected
94+
* value will be passed as a parameter.
95+
*/
96+
@Output() public onSelectOption: EventEmitter<string> =
97+
new EventEmitter<string>();
98+
99+
/**
100+
* Value of the tabindex.
101+
*/
55102
@Input()
56103
get tabIndexValue(): number {
57104
return this._tabIndexValue;
58105
}
59106
set tabIndexValue(value: number) {
60107
this._tabIndexValue = coerceNumberProperty(value);
61108
}
62-
private _tabIndexValue;
109+
private _tabIndexValue = 0;
110+
111+
/**
112+
* If true, the options are showed when the dropdown is hover.
113+
*/
114+
@Input()
115+
get expandOnHover(): boolean {
116+
return this._expandOnHover;
117+
}
118+
set expandOnHover(value: boolean) {
119+
this._expandOnHover = coerceBooleanProperty(value);
120+
}
121+
private _expandOnHover = false;
122+
123+
/**
124+
* If true, the component will be disabled.
125+
*/
63126
@Input()
64127
get disabled(): boolean {
65128
return this._disabled;
66129
}
67130
set disabled(value: boolean) {
68131
this._disabled = coerceBooleanProperty(value);
69132
}
70-
private _disabled;
133+
private _disabled = false;
71134

72-
@Input() public label: string = "";
73-
@Output() public onSelectOption: EventEmitter<any> = new EventEmitter<any>();
135+
@HostBinding("class") className;
74136

75137
@ViewChild("dropdownButton", { static: true }) dropdownButton;
76138
@ViewChild(MatMenuTrigger, { static: false }) menuTrigger: MatMenuTrigger;
@@ -88,17 +150,17 @@ export class DxcDropdownComponent implements OnChanges {
88150
triggerStyles: string;
89151

90152
defaultInputs = new BehaviorSubject<any>({
91-
disableRipple: false,
92-
name: null,
93-
iconPosition: "before",
94153
optionsIconPosition: "before",
95-
mode: "basic",
96-
caretHidden: false,
154+
iconSrc: null,
155+
iconPosition: "before",
97156
label: null,
157+
name: null,
158+
caretHidden: false,
98159
margin: null,
99160
size: "fitContent",
100-
expandOnHover: false,
101161
tabIndexValue: 0,
162+
disabled: false,
163+
expandOnHover: false,
102164
});
103165

104166
public arrowClass: string = "down";

0 commit comments

Comments
 (0)