Skip to content

Commit

Permalink
Define MUI overrides in YAML instead of in sbt
Browse files Browse the repository at this point in the history
  • Loading branch information
nafg committed Dec 14, 2023
1 parent 11564ea commit 37cced4
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 329 deletions.
142 changes: 3 additions & 139 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _root_.io.github.nafg.scalacoptions._
import _root_.io.github.nafg.scalacoptions.*


def myScalacOptions(version: String) =
Expand Down Expand Up @@ -77,22 +77,6 @@ val emotionNpmDeps = Compile / npmDependencies ++= Seq(
"@emotion/styled" -> "11.11.0"
)

def commonPropInfoTransformer: PropInfoTransformer = {
case (_, p @ PropInfo("classes", _, _, _, true)) =>
p.copy(required = false)
}

def commonComponentInfoTransformer: ComponentInfoTransformer =
_.modProps(_.filterNot(_.description.trim == "@ignore"))
.addPropIfNotExists(PropInfo("style", "js.Object"))
.addPropIfNotExists(
PropInfo(
"onClick",
"ReactMouseEventFromHtml => Callback",
CommonImports.Callback + CommonImports.react("ReactMouseEventFromHtml")
)
)

def materialUiGitUrl = "https://github.com/mui-org/material-ui.git"

lazy val materialUiBase =
Expand All @@ -101,25 +85,8 @@ lazy val materialUiBase =
.enablePlugins(FacadeGeneratorPlugin)
.settings(
emotionNpmDeps,
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
case (ComponentInfo("ClickAwayListener", _, _), p @ PropInfo("children", _, _, _, _)) =>
p.copy(
required = true,
propTypeInfo = PropTypeInfo("VdomElement", CommonImports.VdomElement)
)
case (ComponentInfo("ClickAwayListener", _, _), p @ PropInfo("onClickAway", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo("() => Callback", CommonImports.Callback)
)
},
componentInfoTransformer := commonComponentInfoTransformer.andThen {
case c if Set("Container", "TextField").contains(c.name) =>
c.addPropIfNotExists(PropInfo("children", "VdomNode", CommonImports.VdomNode))
case c =>
c
},
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
Compile / sourceGenerators += generateReactDocGenFacades("packages/mui-base/src", "@mui/base", "mui.base")
)

Expand All @@ -131,107 +98,6 @@ lazy val materialUiCore =
emotionNpmDeps,
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer.orElse {
case (ComponentInfo("Autocomplete", _, _), p) =>
p.name match {
case "filterOptions" => p.copy(propTypeInfo = PropTypeInfo("(Seq[js.Any], js.Object) => Seq[js.Any]"))
case "getOptionLabel" => p.copy(propTypeInfo = PropTypeInfo("js.Any => String"))
case "onChange" =>
p.copy(
propTypeInfo =
PropTypeInfo(
"(ReactEvent, js.Any) => Callback",
CommonImports.Callback ++ CommonImports.ReactEvent
)
)
case "onInputChange" =>
p.copy(
propTypeInfo =
PropTypeInfo(
"(ReactEvent, String, String) => Callback",
CommonImports.Callback ++ CommonImports.ReactEvent
)
)
case "renderInput" =>
p.copy(propTypeInfo = PropTypeInfo("js.Dictionary[js.Any] => VdomNode", CommonImports.VdomNode))
case "renderOption" =>
p.copy(propTypeInfo = PropTypeInfo("js.Any => VdomNode", CommonImports.VdomNode))
case _ =>
p
}
case (ComponentInfo("Tooltip", _, _), p @ PropInfo("children", _, _, _, _)) =>
p.copy(
required = true,
propTypeInfo = PropTypeInfo("VdomElement", CommonImports.VdomElement)
)
case (ComponentInfo("Dialog", _, _), p @ PropInfo("onClose", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo("(ReactEvent, String) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
case (ComponentInfo("Icon", _, _), p @ PropInfo("fontSize", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo(PropType.Enum(PropType.String, List("'inherit'", "'large'", "'medium'", "'small'")))
)
case (ComponentInfo("IconButton" | "ListItem", _, _), p @ PropInfo("children", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo("VdomNode", CommonImports.VdomNode)
)
case (ComponentInfo("InputBase" | "OutlinedInput" | "TextField", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo(
"ReactEventFromInput => Callback",
CommonImports.Callback + CommonImports.react("ReactEventFromInput")
)
)
case (ComponentInfo("Menu", _, _), p @ PropInfo("anchorEl", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo("Element | (js.Object => Element)", CommonImports.Element ++ CommonImports.|)
)
case (ComponentInfo("Menu", _, _), p @ PropInfo("onClose", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo(
"(ReactEvent, String) => Callback",
CommonImports.ReactEvent ++ CommonImports.Callback
)
)
case (ComponentInfo("Paper", _, _), p @ PropInfo("elevation", _, _, _, _)) =>
p.copy(propTypeInfo = PropTypeInfo("Int"))
case (ComponentInfo("Popper", _, _), p @ PropInfo("anchorEl", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo(
"Element | js.Object | (js.Object => (Element | js.Object))",
CommonImports.Element ++ CommonImports.|
)
)
case (ComponentInfo("TableCell", _, _), p @ PropInfo("padding", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo(PropType.Enum(PropType.String, List("'normal'", "'checkbox'", "'none'")))
)
case (ComponentInfo("TablePagination", _, _), p @ PropInfo("page" | "count" | "rowsPerPage", _, _, _, _)) =>
p.copy(propTypeInfo = PropTypeInfo("Int"))
case (ComponentInfo("TablePagination", _, _), p @ PropInfo("onChangePage" | "onPageChange", _, _, _, _)) =>
p.copy(propTypeInfo =
PropTypeInfo("(ReactEvent, Int) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
case (ComponentInfo("ToggleButtonGroup", _, _), p @ PropInfo("onChange", _, _, _, _)) =>
p.copy(
propTypeInfo =
PropTypeInfo("(ReactEvent, js.Any) => Callback", CommonImports.Callback ++ CommonImports.ReactEvent)
)
},
componentInfoTransformer := commonComponentInfoTransformer.andThen {
case c if Set("Container", "TextField").contains(c.name) =>
c.addPropIfNotExists(PropInfo("children", "VdomNode", CommonImports.VdomNode))
case c =>
c
},
componentCodeGenInfoTransformer := {
case c @ ComponentCodeGenInfo(ComponentInfo("ButtonGroup" | "List", _, _), _, _) =>
c.copy(moduleTrait = "FacadeModule.ArrayChildren")
case c if Set("Breadcrumbs", "ToggleButtonGroup").contains(c.componentInfo.name) =>
c.copy(moduleTrait = "FacadeModule.ArrayChildren")
},
Compile / sourceGenerators += generateReactDocGenFacades("packages/mui-material/src", "@mui/material", "mui")
)

Expand All @@ -243,8 +109,6 @@ lazy val materialUiLab =
emotionNpmDeps,
reactDocGenRepoUrl := materialUiGitUrl,
reactDocGenRepoRef := ("v" + materialUiCoreVersion),
propInfoTransformer := commonPropInfoTransformer,
componentInfoTransformer := commonComponentInfoTransformer,
Compile / sourceGenerators += generateReactDocGenFacades("packages/mui-lab/src", "@mui/lab", "mui.lab")
)

Expand Down
212 changes: 212 additions & 0 deletions overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
mui.base:
common:
style:
type: jsObject
onClick:
type:
args:
- ReactMouseEventFromHtml
result: callback
components:
ClickAwayListener:
props:
children:
required: true
type: vdomElement
onClickAway:
type:
args: [ ]
result: callback

mui:
common:
style:
type: jsObject
onClick:
type:
args:
- ReactMouseEventFromHtml
result: callback
components:
Autocomplete:
props:
getOptionLabel:
type:
args:
- jsAny
result: string
onChange:
type:
args:
- ReactEvent
- jsAny
result: callback
renderOption:
type:
args:
- jsAny
result: vdomNode
onInputChange:
type:
args:
- ReactEvent
- string
- string
result: callback
renderInput:
type:
args:
- jsDictionary
result: vdomNode
filterOptions:
type:
args:
- base: jsAny
- jsObject
result:
base: jsAny
Breadcrumbs:
moduleTrait: FacadeModule.ArrayChildren
ButtonGroup:
moduleTrait: FacadeModule.ArrayChildren
Container:
props:
children:
type: vdomNode
Dialog:
props:
onClose:
type:
args:
- ReactEvent
- string
result: callback
Icon:
props:
fontSize:
type:
base: string
presets:
- name: inherit
code: '"inherit"'
- name: large
code: '"large"'
- name: medium
code: '"medium"'
- name: small
code: '"small"'
IconButton:
props:
children:
type: vdomNode
InputBase:
props:
onChange:
type:
args:
- ReactEventFromInput
result: callback
List:
moduleTrait: FacadeModule.ArrayChildren
ListItem:
props:
children:
type: vdomNode
Menu:
props:
anchorEl:
type:
anyOf:
- element
- args:
- jsObject
result: element
onClose:
type:
args:
- ReactEvent
- string
result: callback
OutlinedInput:
props:
onChange:
type:
args:
- ReactEventFromInput
result: callback
Paper:
props:
elevation:
type: int
Popper:
props:
anchorEl:
type:
anyOf:
- element
- jsObject
- args:
- jsObject
result:
anyOf:
- element
- jsObject
TableCell:
props:
padding:
type:
base: string
presets:
- name: normal
code: '"normal"'
- name: checkbox
code: '"checkbox"'
- name: none
code: '"none"'
TablePagination:
props:
page:
type: int
count:
type: int
rowsPerPage:
type: int
onPageChange:
type:
args:
- ReactEvent
- int
result: callback
TextField:
props:
onChange:
type:
args:
- ReactEventFromInput
result: callback
children:
type: vdomNode
ToggleButtonGroup:
moduleTrait: FacadeModule.ArrayChildren
props:
onChange:
type:
args:
- ReactEvent
- jsAny
result: callback
Tooltip:
props:
children:
type: vdomElement
required: true

mui.lab:
common:
style:
type: jsObject
onClick:
type:
args:
- ReactMouseEventFromHtml
result: callback
6 changes: 3 additions & 3 deletions project/ComponentCodeGenInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ case class ComponentCodeGenInfo(componentInfo: ComponentInfo, moduleTrait: Strin
object ComponentCodeGenInfo {
def apply(componentInfo: ComponentInfo): ComponentCodeGenInfo = {
val (moduleTrait, moduleTraitParam) = componentInfo.maybeChildrenProp match {
case Some(i) if i.propTypeInfo.code == "VdomNode" => "FacadeModule.NodeChildren" -> None
case Some(i) => "FacadeModule.ChildrenOf" -> Some(i.propTypeInfo.code)
case _ => "FacadeModule" -> None
case Some(i) if i.`type`.code == "VdomNode" => "FacadeModule.NodeChildren" -> None
case Some(i) => "FacadeModule.ChildrenOf" -> Some(i.`type`.code)
case _ => "FacadeModule" -> None
}
ComponentCodeGenInfo(
componentInfo = componentInfo,
Expand Down
Loading

0 comments on commit 37cced4

Please sign in to comment.