1
1
include Css_Colors ;
2
2
3
- module Glamor = {
4
- type css ;
5
- type fontFace ;
6
- [@ bs . send ] external className : css => string = "toString" ;
7
- [@ bs . module "glamor" ] external _make : Js . Json . t => css = "css" ;
8
- [@ bs . scope "css" ] [@ bs . module "glamor" ]
9
- external makeGlobal : (string , Js . Json . t ) => unit = "global" ;
10
- [@ bs . scope "css" ] [@ bs . module "glamor" ]
11
- external makeInsert : string => unit = "insert" ;
12
- [@ bs . scope "css" ] [@ bs . module "glamor" ]
3
+ module Emotion = {
4
+ type css = string ;
5
+ [@ bs . module "emotion" ] external _make : Js . Json . t => css = "css" ;
6
+ [@ bs . module "emotion" ]
7
+ external injectGlobal : Js . Json . t => unit = "" ;
8
+ [@ bs . module "emotion" ]
9
+ external rawInjectGlobal : string => unit = "injectGlobal" ;
10
+ [@ bs . module "emotion" ]
13
11
external makeKeyFrames : Js . Dict . t (Js . Json . t ) => string = "keyframes" ;
14
- [@ bs . scope "css" ] [@ bs . module "glamor" ]
15
- external makeFontFace : fontFace => string = "fontFace" ;
16
- [@ bs . obj ]
17
- external fontFace :
18
- (
19
- ~fontFamily : string ,
20
- ~src : string ,
21
- ~fontStyle : string =?,
22
- ~fontWeight : int =?
23
- ) =>
24
- fontFace =
25
- "" ;
26
- let merge : list (css ) => css = [% bs . raw
27
- {|
28
- function (styles) {
29
- const glamor = require('glamor');
30
- return glamor.css.apply(glamor, styles)
31
- }
32
- |}
33
- ];
12
+ [@ bs . module "emotion" ] [@ bs . splice ]
13
+ external merge : array (css ) => css = "cx" ;
14
+ let merge : list (css ) => css = classes => classes-> Array . of_list-> merge;
34
15
let rec makeDict = ruleset => {
35
16
let toJs = rule =>
36
17
switch (rule) {
@@ -310,21 +291,23 @@ type selector = [ | `selector(string, list(rule))];
310
291
let empty = [] ;
311
292
312
293
let merge = List . concat;
313
- let global = (selector, rules: list (rule )) =>
314
- Glamor . makeGlobal(selector, Glamor . makeDict(rules));
315
- let insertRule = css => Glamor . makeInsert(css);
294
+ let global = (selector, rules: list (rule )) => {
295
+ Emotion . injectGlobal([ (selector, Emotion . makeDict(rules))] -> Js . Dict . fromList-> Js . Json . object_);
296
+ }
297
+
298
+ let insertRule = raw => Emotion . rawInjectGlobal(raw);
316
299
317
300
type animation = string ;
318
301
319
302
let keyframes = frames => {
320
303
let addStop = (dict, (stop, rules)) => {
321
- Js . Dict . set(dict, string_of_int(stop) ++ "% " , Glamor . makeDict(rules));
304
+ Js . Dict . set(dict, string_of_int(stop) ++ "% " , Emotion . makeDict(rules));
322
305
dict;
323
306
};
324
- Glamor . makeKeyFrames @@ List . fold_left(addStop, Js . Dict . empty() , frames);
307
+ Emotion . makeKeyFrames @@ List . fold_left(addStop, Js . Dict . empty() , frames);
325
308
};
326
309
327
- let style = rules => rules |> Glamor . make |> Glamor . className ;
310
+ let style = rules => rules |> Emotion . make;
328
311
329
312
let d = (property, value) => ` declaration ((property, value));
330
313
@@ -914,7 +897,7 @@ let overflowY = x => d("overflowY", string_of_overflow(x));
914
897
915
898
let zIndex = x => d("zIndex" , string_of_int(x));
916
899
917
- let contentRule = x => d("content" , x );
900
+ let contentRule = x => d("content" , { j | "$x" | j } );
918
901
919
902
let columnCount = x =>
920
903
d(
@@ -1256,6 +1239,7 @@ let outlineOffset = x => d("outlineOffset", string_of_length(x));
1256
1239
* Text
1257
1240
*/
1258
1241
1242
+ [@ bs . deriving jsConverter]
1259
1243
type fontStyle = [ | ` normal | ` italic | ` oblique ] ;
1260
1244
let fontStyleToJs =
1261
1245
fun
@@ -1281,6 +1265,7 @@ let fontVariant = x =>
1281
1265
);
1282
1266
1283
1267
let fontStyle = x => d("fontStyle" , fontStyleToJs(x));
1268
+ let fontWeight = x => d("fontWeight" , string_of_int(x));
1284
1269
1285
1270
let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, () ) => {
1286
1271
let fontStyle =
@@ -1293,12 +1278,24 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ()) => {
1293
1278
| ` url (value ) => { j | url("$(value)")| j } ,
1294
1279
)
1295
1280
|> String . concat(", " );
1296
- Glamor . (
1297
- makeFontFace(fontFace(~fontFamily, ~src, ~fontStyle? , ~fontWeight? ))
1298
- );
1299
- };
1300
1281
1301
- let fontWeight = x => d("fontWeight" , string_of_int(x));
1282
+ let fontStyle =
1283
+ Belt . Option . mapWithDefault(fontStyle, "" , s => "font-style: " ++ s);
1284
+ let fontWeight =
1285
+ Belt . Option . mapWithDefault(fontWeight, "" , w =>
1286
+ "font-weight: " ++ string_of_int(w)
1287
+ );
1288
+ let asString = { j | @font-face {
1289
+ font-family: $fontFamily;
1290
+ src: $src;
1291
+ $(fontStyle);
1292
+ $(fontWeight);
1293
+ }| j } ;
1294
+
1295
+ Emotion . rawInjectGlobal(asString);
1296
+
1297
+ fontFamily;
1298
+ };
1302
1299
1303
1300
let lineHeight = x =>
1304
1301
d(
0 commit comments