@microsoft/atlas-css 3.29.0 → 3.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/class-names.json +1 -1
- package/dist/class-names.ts +36 -16
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/tokens.ts +36 -16
- package/package.json +12 -12
- package/src/atomics/typography.scss +14 -0
- package/src/components/banner.scss +47 -0
- package/src/components/button.scss +4 -0
- package/src/components/index.scss +2 -0
- package/src/components/notification.scss +81 -0
- package/src/core/bare-elements.scss +4 -0
- package/tokens/README.md +1 -1
package/dist/class-names.ts
CHANGED
|
@@ -22,11 +22,25 @@ export class Convert {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function invalidValue(typ: any, val: any, key: any = ''): never {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
|
|
26
|
+
const prettyTyp = prettyTypeName(typ);
|
|
27
|
+
const parentText = parent ? ` on ${parent}` : '';
|
|
28
|
+
const keyText = key ? ` for key "${key}"` : '';
|
|
29
|
+
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function prettyTypeName(typ: any): string {
|
|
33
|
+
if (Array.isArray(typ)) {
|
|
34
|
+
if (typ.length === 2 && typ[0] === undefined) {
|
|
35
|
+
return `an optional ${prettyTypeName(typ[1])}`;
|
|
36
|
+
} else {
|
|
37
|
+
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
|
|
38
|
+
}
|
|
39
|
+
} else if (typeof typ === "object" && typ.literal !== undefined) {
|
|
40
|
+
return typ.literal;
|
|
41
|
+
} else {
|
|
42
|
+
return typeof typ;
|
|
28
43
|
}
|
|
29
|
-
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`, );
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
function jsonToJSProps(typ: any): any {
|
|
@@ -47,10 +61,10 @@ function jsToJSONProps(typ: any): any {
|
|
|
47
61
|
return typ.jsToJSON;
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
function transform(val: any, typ: any, getProps: any, key: any = ''): any {
|
|
64
|
+
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
|
|
51
65
|
function transformPrimitive(typ: string, val: any): any {
|
|
52
66
|
if (typeof typ === typeof val) return val;
|
|
53
|
-
return invalidValue(typ, val, key);
|
|
67
|
+
return invalidValue(typ, val, key, parent);
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
function transformUnion(typs: any[], val: any): any {
|
|
@@ -62,17 +76,17 @@ function transform(val: any, typ: any, getProps: any, key: any = ''): any {
|
|
|
62
76
|
return transform(val, typ, getProps);
|
|
63
77
|
} catch (_) {}
|
|
64
78
|
}
|
|
65
|
-
return invalidValue(typs, val);
|
|
79
|
+
return invalidValue(typs, val, key, parent);
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
function transformEnum(cases: string[], val: any): any {
|
|
69
83
|
if (cases.indexOf(val) !== -1) return val;
|
|
70
|
-
return invalidValue(cases, val);
|
|
84
|
+
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
function transformArray(typ: any, val: any): any {
|
|
74
88
|
// val must be an array with no invalid elements
|
|
75
|
-
if (!Array.isArray(val)) return invalidValue("array", val);
|
|
89
|
+
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
|
|
76
90
|
return val.map(el => transform(el, typ, getProps));
|
|
77
91
|
}
|
|
78
92
|
|
|
@@ -82,24 +96,24 @@ function transform(val: any, typ: any, getProps: any, key: any = ''): any {
|
|
|
82
96
|
}
|
|
83
97
|
const d = new Date(val);
|
|
84
98
|
if (isNaN(d.valueOf())) {
|
|
85
|
-
return invalidValue("Date", val);
|
|
99
|
+
return invalidValue(l("Date"), val, key, parent);
|
|
86
100
|
}
|
|
87
101
|
return d;
|
|
88
102
|
}
|
|
89
103
|
|
|
90
104
|
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
|
|
91
105
|
if (val === null || typeof val !== "object" || Array.isArray(val)) {
|
|
92
|
-
return invalidValue("object", val);
|
|
106
|
+
return invalidValue(l(ref || "object"), val, key, parent);
|
|
93
107
|
}
|
|
94
108
|
const result: any = {};
|
|
95
109
|
Object.getOwnPropertyNames(props).forEach(key => {
|
|
96
110
|
const prop = props[key];
|
|
97
111
|
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
|
|
98
|
-
result[prop.key] = transform(v, prop.typ, getProps,
|
|
112
|
+
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
|
|
99
113
|
});
|
|
100
114
|
Object.getOwnPropertyNames(val).forEach(key => {
|
|
101
115
|
if (!Object.prototype.hasOwnProperty.call(props, key)) {
|
|
102
|
-
result[key] = transform(val[key], additional, getProps, key);
|
|
116
|
+
result[key] = transform(val[key], additional, getProps, key, ref);
|
|
103
117
|
}
|
|
104
118
|
});
|
|
105
119
|
return result;
|
|
@@ -108,10 +122,12 @@ function transform(val: any, typ: any, getProps: any, key: any = ''): any {
|
|
|
108
122
|
if (typ === "any") return val;
|
|
109
123
|
if (typ === null) {
|
|
110
124
|
if (val === null) return val;
|
|
111
|
-
return invalidValue(typ, val);
|
|
125
|
+
return invalidValue(typ, val, key, parent);
|
|
112
126
|
}
|
|
113
|
-
if (typ === false) return invalidValue(typ, val);
|
|
127
|
+
if (typ === false) return invalidValue(typ, val, key, parent);
|
|
128
|
+
let ref: any = undefined;
|
|
114
129
|
while (typeof typ === "object" && typ.ref !== undefined) {
|
|
130
|
+
ref = typ.ref;
|
|
115
131
|
typ = typeMap[typ.ref];
|
|
116
132
|
}
|
|
117
133
|
if (Array.isArray(typ)) return transformEnum(typ, val);
|
|
@@ -119,7 +135,7 @@ function transform(val: any, typ: any, getProps: any, key: any = ''): any {
|
|
|
119
135
|
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
|
|
120
136
|
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
|
|
121
137
|
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
|
|
122
|
-
: invalidValue(typ, val);
|
|
138
|
+
: invalidValue(typ, val, key, parent);
|
|
123
139
|
}
|
|
124
140
|
// Numbers can be parsed by Date but shouldn't be.
|
|
125
141
|
if (typ === Date && typeof val !== "number") return transformDate(val);
|
|
@@ -134,6 +150,10 @@ function uncast<T>(val: T, typ: any): any {
|
|
|
134
150
|
return transform(val, typ, jsToJSONProps);
|
|
135
151
|
}
|
|
136
152
|
|
|
153
|
+
function l(typ: any) {
|
|
154
|
+
return { literal: typ };
|
|
155
|
+
}
|
|
156
|
+
|
|
137
157
|
function a(typ: any) {
|
|
138
158
|
return { arrayItems: typ };
|
|
139
159
|
}
|