-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStyles.hx
110 lines (91 loc) · 2.82 KB
/
Styles.hx
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
package mui.core.styles;
import mui.Colors.ColorString;
#if !macro
import haxe.extern.EitherType;
import js.Object;
import js.html.StyleElement;
import css.Properties;
import react.ReactType;
#else
import haxe.macro.Context;
import haxe.macro.Expr;
#end
@:jsRequire('@material-ui/core/styles')
extern class Styles {
extern static function alpha(color:ColorString, opacity:Float):ColorString;
public static inline macro function jss(styles:Expr) {
return switch (styles.expr) {
case EObjectDecl(fields):
for (f in fields) {
if (f.quotes != Unquoted)
Context.error('Field ${f.field} should not be quoted', f.expr.pos);
f.expr = parseJssNode(f.expr);
}
{expr: EObjectDecl(fields), pos: styles.pos};
case EBlock([]):
{expr: EObjectDecl([]), pos: styles.pos};
default:
Context.error('Expected an inline object declaration', styles.pos);
macro null;
};
}
#if !macro
public static function createGenerateClassName(
options:{?disableGlobal:Bool, ?productionPrefix:String, ?seed:String}
):GenerateId;
// Note: wrap the return value in `Styles.jss()` to use typing
// TODO: constraint for TTheme?
public static function withStyles<TTheme, TClassesDef>(
styles:EitherType<TClassesDef, TTheme->TClassesDef>,
?options:StylesOptions<TTheme>
):ReactType->ReactType;
// TODO: constraint for TTheme?
public static function styled<TTheme>(component:ReactType):(
styles:EitherType<Properties, {theme:TTheme}->Properties>,
?options:StylesOptions<TTheme>
)->ReactType;
// Provide the theme object as a property of the input component so it can
// be used in the render method.
public static function withTheme(comp:ReactType):ReactType;
public static inline function mergeJss(jss1:Properties, jss2:Properties):Properties {
return Object.assign({}, jss1, jss2);
}
#else
static function parseJssNode(styles:Expr):Expr {
switch (styles.expr) {
case EObjectDecl(fields):
for (f in fields)
if (f.quotes == Quoted && !StringTools.startsWith(f.field, "--")) {
f.expr = {
expr: ECheckType(parseJssNode(f.expr), macro :css.Properties),
pos: f.expr.pos
};
}
default:
}
return styles;
}
#end
}
#if !macro
typedef JssCreateStyleSheetOptions = {
@:optional var media:String;
@:optional var meta:String;
@:optional var link:Bool;
@:optional var element:StyleElement;
@:optional var index:Int;
@:optional var generateId:GenerateId;
@:optional var classNamePrefix:String;
}
// TODO: constraint for TTheme?
typedef StylesOptions<TTheme> = {
> JssCreateStyleSheetOptions,
@:optional var defaultTheme:TTheme;
@:optional var withTheme:Bool;
@:optional var name:String;
@:optional var flip:Bool;
}
typedef GenerateId = (rule:Rule, ?sheet:Stylesheet)->String;
typedef Rule = Dynamic; // TODO (Jss types)
typedef Stylesheet = Dynamic; // TODO (Jss types)
#end