-
Notifications
You must be signed in to change notification settings - Fork 0
/
flex-row.ts
115 lines (108 loc) · 4.51 KB
/
flex-row.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Component, Input, SimpleChanges, HostBinding } from '@angular/core';
@Component({
selector: 'flex-row',
template: '<ng-content></ng-content>',
})
export class FlexRowComponent {
// user sets wrap/nowrap AND justify-content at the same time
@Input() nowrap = FlexJustifyContent.start; // nowrap is default
@Input() wrap: FlexJustifyContent = null;
@Input() wrapUpward: FlexJustifyContent = null;
// end set wrap&jc
@Input() vertical = FlexAlignItems.stretch;
@Input() multipleRows = FlexAlignContent.stretch;
@Input() rightToLeft = false;
@HostBinding('style.display') readonly display = "flex";
@HostBinding('style.flex-flow') flexFlow = 'row nowrap';
@HostBinding('style.justify-content') justifyContent = FlexJustifyContent[this.nowrap];
@HostBinding('style.align-content') alignContent = FlexAlignContent[this.multipleRows];
@HostBinding('style.align-items') alignItems = FlexAlignItems[this.vertical];
ngOnChanges(changes: SimpleChanges) {
this.flexFlow = (this.rightToLeft ? "row-reverse" : "row") + " " + (this.wrapUpward ? "wrap-reverse" : this.wrap ? "wrap" : "nowrap");
let justifyContentValueUsed = (this.wrapUpward || this.wrap || this.nowrap);
this.justifyContent = FlexJustifyContent[justifyContentValueUsed];
this.alignContent = FlexAlignContent[this.multipleRows];
this.alignItems = FlexAlignItems[this.vertical];
// the rest is error reporting
let propertyUsed = this.wrapUpward ? "wrapUpward" : this.wrap ? "wrap" : "nowrap";
if (((this.wrap && this.wrapUpward)) || ((this.wrap || this.wrapUpward) && this.nowrap !== FlexJustifyContent.start))
console.error("<flex-row> should use only one of the properties nowrap, wrap, wrapUpward");
if (!this.wrap && !this.wrapUpward && this.multipleRows != FlexAlignContent.stretch)
console.error("<flex-row> multipleRows is meaningless with nowrap");
if (!this.alignItems)
console.error('"' + this.vertical + '" is invalid for <flex-row vertical="' + this.vertical + '"> -- top bottom center stretch text');
if (!this.justifyContent)
console.error('"' + justifyContentValueUsed + '" is invalid for <flex-row ' + propertyUsed + '="' + justifyContentValueUsed + `">
xxx.. start flex-start left
..xxx end flex-end right
.xxx. center
x.x.x between space-between
.x.x. around space-around`);
if (!this.alignContent)
console.error('"' + this.multipleRows + '" is invalid for <flex-row multipleRows="' + this.multipleRows + `">
xxx.. start flex-start left
..xxx end flex-end right
.xxx. center
XXX stretch
x.x.x between space-between
.x.x. around space-around`);
}
}
// distribute space on the main axis (the horizontal axis, for flex-row)
enum FlexJustifyContent {
"xxx.." = "flex-start", // default
"..xxx" = "flex-end",
".xxx." = "center",
"x.x.x" = "space-between",
".x.x." = "space-around",
"xx..." = "flex-start",
"...xx" = "flex-end",
"..x.." = "center",
"x.." = "flex-start",
"..x" = "flex-end",
".x." = "center",
"flex-start" = "flex-start",
"flex-end" = "flex-end",
"center" = "center",
"space-between" = "space-between",
"space-around" = "space-around",
"start" = "flex-start",
"end" = "flex-end",
"left" = "flex-start",
"right" = "flex-end",
"between" = "space-between",
"around" = "space-around",
}
// distribute space on the cross axis (the vertical axis, for flex-row)
enum FlexAlignItems {
top = "flex-start",
bottom = "flex-end",
center = "center",
stretch = "stretch", // default
text = "baseline",
}
// distribute space among multiple rows (only used when items wrap onto additional rows)
enum FlexAlignContent {
"xxx.." = "flex-start",
"..xxx" = "flex-end",
".xxx." = "center",
"x.x.x" = "space-between",
".x.x." = "space-around",
"xx..." = "flex-start",
"...xx" = "flex-end",
"..x.." = "center",
"x.." = "flex-start",
"..x" = "flex-end",
".x." = "center",
"XXX" = "stretch", // default
"flex-start" = "flex-start",
"flex-end" = "flex-end",
"center" = "center",
"space-between" = "space-between",
"space-around" = "space-around",
"start" = "flex-start",
"end" = "flex-end",
"stretch" = "stretch",
"between" = "space-between",
"around" = "space-around",
}