From 265373ecff27048030d389d3fd08e130b55e5e72 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Wed, 8 Jan 2020 23:20:34 +0800 Subject: [PATCH] makeStyles --- src/mui/core/styles/Styles.hx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/mui/core/styles/Styles.hx b/src/mui/core/styles/Styles.hx index 2f9c458..8b3f285 100644 --- a/src/mui/core/styles/Styles.hx +++ b/src/mui/core/styles/Styles.hx @@ -34,6 +34,24 @@ extern class Styles { macro null; }; } + + public static macro function makeStyles(styles:Expr) { + var type = switch Context.typeof(styles) { + case TAnonymous(_.get() => {fields: fields}) + | TFun(_, TAnonymous(_.get() => {fields: fields})): + TAnonymous([for(f in fields) { + name: f.name, + kind: FVar(macro:String, null), + pos: f.pos, + }]); + + case _: + Context.error('Expected an inline object declaration or a function returning an object', styles.pos); + macro:Any; + } + + return macro (@:privateAccess mui.core.styles.Styles._makeStyles($styles):Void->$type); + } #if !macro public static function createGenerateClassName( @@ -60,6 +78,9 @@ extern class Styles { public static inline function mergeJss(jss1:Properties, jss2:Properties):Properties { return Object.assign({}, jss1, jss2); } + + @:native('makeStyles') + private static function _makeStyles(styles:Any):Any; #else static function parseJssNode(styles:Expr):Expr {