Skip to content

Commit

Permalink
Merge pull request #246 from nafg/cover-more-of-mui
Browse files Browse the repository at this point in the history
Cover more of MUI
  • Loading branch information
nafg authored Dec 14, 2023
2 parents dd2220b + 0399240 commit 358b1c0
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 91 deletions.
154 changes: 117 additions & 37 deletions overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,81 @@ mui:
- ReactMouseEventFromHtml
result: callback
components:
.system:
props:
alignItems:
type:
base: string
presets:
- string: flex-start
- string: flex-end
- string: center
- string: stretch
- string: baseline
color:
type:
base: string
presets:
- string: primary.main
- string: secondary.main
- string: error.main
- string: warning.main
- string: info.main
- string: success.main
- string: text.primary
- string: text.secondary
- string: text.disabled
display:
type:
base: string
presets:
- string: block
- string: inline
justifyContent:
type:
base: string
presets:
- string: flex-start
- string: flex-end
- string: center
- string: space-between
- string: space-around
- string: space-evenly
Alert:
props:
icon:
type:
base:
anyOf:
- bool
- vdomNode
presets: [ false ]
Autocomplete:
props:
filterOptions:
type:
args:
- arrayOf: jsAny
- jsObject
result:
arrayOf: jsAny
getOptionLabel:
type:
args:
- jsAny
result: string
onChange:
isOptionEqualToValue:
type:
args:
- ReactEvent
- jsAny
result: callback
renderOption:
- jsAny
result: bool
onChange:
type:
args:
- ReactEvent
- jsAny
result: vdomNode
result: callback
onInputChange:
type:
args:
Expand All @@ -58,17 +115,25 @@ mui:
args:
- jsDictionary
result: vdomNode
filterOptions:
renderOption:
type:
args:
- arrayOf: jsAny
- jsObject
result:
arrayOf: jsAny
args: [ jsObject, jsAny, jsObject, jsObject ]
result: vdomNode
Breadcrumbs:
moduleTrait: FacadeModule.ArrayChildren
ButtonGroup:
moduleTrait: FacadeModule.ArrayChildren
Card:
extends: Paper
props:
raised:
type: bool
Chip:
props:
onDelete:
type:
args: [ ReactMouseEvent ]
result: callback
Container:
props:
children:
Expand All @@ -88,18 +153,12 @@ mui:
- string
- bool
presets:
- name: xs
code: '"xs"'
- name: sm
code: '"sm"'
- name: md
code: '"md"'
- name: lg
code: '"lg"'
- name: xl
code: '"xl"'
- name: "false"
code: 'false'
- string: xs
- string: sm
- string: md
- string: lg
- string: xl
- false
Dialog:
props:
onClose:
Expand All @@ -114,14 +173,17 @@ mui:
type:
base: string
presets:
- name: inherit
code: '"inherit"'
- name: large
code: '"large"'
- name: medium
code: '"medium"'
- name: small
code: '"small"'
- string: inherit
- string: large
- string: medium
- string: small
Fade:
props:
children:
required: true
type: vdomElement
Grid:
extends: .system
IconButton:
props:
children:
Expand All @@ -133,6 +195,8 @@ mui:
args:
- ReactEventFromInput
result: callback
Link:
extends: Typography
List:
moduleTrait: FacadeModule.ArrayChildren
ListItem:
Expand Down Expand Up @@ -178,18 +242,24 @@ mui:
anyOf:
- element
- jsObject
RadioGroup:
extends: FormGroup
Select:
props:
renderValue:
type:
args:
- jsAny
result: vdomNode
TableCell:
props:
padding:
type:
base: string
presets:
- name: normal
code: '"normal"'
- name: checkbox
code: '"checkbox"'
- name: none
code: '"none"'
- string: normal
- string: checkbox
- string: none
TablePagination:
props:
page:
Expand All @@ -204,6 +274,14 @@ mui:
- ReactEvent
- int
result: callback
Tabs:
props:
onChange:
type:
args:
- ReactEvent
- jsAny
result: callback
TextField:
props:
onChange:
Expand All @@ -227,6 +305,8 @@ mui:
children:
type: vdomElement
required: true
Typography:
extends: .system

mui.lab:
common:
Expand Down
69 changes: 50 additions & 19 deletions project/FacadeGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ object FacadeGenerator {
s"""object ${propInfo.identifier} extends PropTypes.Prop[$typeCode]("${propInfo.identifier}") {
|${
propInfo.`type`.presets
.map { case PropTypeInfo.Preset(name, presetCode) =>
s" val $name = this := $presetCode.asInstanceOf[$typeCode]"
.map { value =>
s" val ${value.name} = this := ${value.code}.asInstanceOf[$typeCode]"
}
.mkString("\n")
}
Expand Down Expand Up @@ -219,24 +219,53 @@ object FacadeGenerator {

val readComponentInfos = ujson.read(docgenOutput).obj.values.toSeq.collect {
case value if Set("props", "displayName").forall(value.obj.contains) =>
val componentInfo = ComponentInfo.read(value.obj)
overrides.getPropInfoOverrides(componentInfo).foldLeft(componentInfo) {
case (componentInfo, (propName, Overrides.PropInfoOverride(typ, required))) =>
componentInfo.propsMap.get(propName)
.map { existingPropInfo =>
existingPropInfo.copy(
required = required.getOrElse(existingPropInfo.required),
`type` = typ.getOrElse(existingPropInfo.`type`)
)
}
.orElse(typ.map(propTypeInfo => PropInfo(propName, propTypeInfo)))
.fold(componentInfo)(componentInfo.withProp)
}
ComponentInfo.read(value.obj)
}

val componentInfos =
readComponentInfos ++
(overrides.components -- readComponentInfos.map(_.name).toSet).map { case (name, overrides) =>
def applyExtends(componentInfo: ComponentInfo): ComponentInfo = {
val name = componentInfo.name
overrides.get(name).`extends` match {
case None =>
logger.info("No extends for " + name)
componentInfo
case Some(parentName) =>
readComponentInfos.find(_.name == parentName)
.fold(componentInfo) { parent =>
logger.info("Extending " + name + " with " + parentName)
val parentExtended = applyExtends(parent)
val map = parentExtended.propsMap ++ componentInfo.propsMap
logger.info("Added props " + (map.keySet -- parentExtended.propsMap.keySet).mkString(", ") + " to " +
name)
componentInfo.copy(propsMap = map)
}
}
}

val inheritedExisting = readComponentInfos.map { componentInfo =>
logger.info(componentInfo.name)
applyExtends(componentInfo)
}

val overriddenExisting = inheritedExisting.map { componentInfo =>
overrides.getPropInfoOverrides(componentInfo).foldLeft(componentInfo) {
case (componentInfo, (propName, Overrides.PropInfoOverride(typ, required))) =>
componentInfo.propsMap.get(propName)
.map { existingPropInfo =>
existingPropInfo.copy(
required = required.getOrElse(existingPropInfo.required),
`type` = typ.getOrElse(existingPropInfo.`type`)
)
}
.orElse(typ.map(propTypeInfo => PropInfo(propName, propTypeInfo)))
.fold(componentInfo)(componentInfo.withProp)
}
}

val readComponentNames = overriddenExisting.map(_.name).toSet

val addedComponentInfos =
(overrides.components -- readComponentNames).collect {
case (name, overrides) if name.headOption.exists(_.isLetter) =>
ComponentInfo(
name = name,
description = "",
Expand All @@ -249,7 +278,9 @@ object FacadeGenerator {
)
}
)
}
}

val componentInfos = overriddenExisting ++ addedComponentInfos

for (componentInfo <- componentInfos) yield processComponent(
info = componentInfo,
Expand Down
14 changes: 2 additions & 12 deletions project/FacadeGeneratorPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.io.FileReader

import _root_.io.circe.yaml.v12.Parser
import cats.data.Validated
import cats.implicits.toShow
Expand All @@ -22,19 +20,12 @@ object FacadeGeneratorPlugin extends AutoPlugin {
runYarnInstall.value
val logger = streams.value.log
val overrides =
Parser.default.parse(new FileReader("overrides.yml")).toTry.get
.asAccumulating[Map[String, Overrides]] match {
Parser.default.decodeAccumulating[Map[String, Overrides]](IO.read(file("overrides.yml"))) match {
case Validated.Invalid(errors) =>
errors.toList.foreach(failure => logger.error(failure.show))
sys.error(errors.toString)
case Validated.Valid(map) => map(scalaSubPackage)
case Validated.Valid(map) => map(scalaSubPackage).applyExtends
}
val overridesString = pprint.apply(overrides).render
logger.info(
overridesString.linesWithSeparators
.map(s"[${scalaSubPackage}] " + _)
.mkString
)
FacadeGenerator.run(
base = os.Path((Compile / sourceManaged).value),
repoDir = reactDocGenDir.value,
Expand Down Expand Up @@ -76,7 +67,6 @@ object FacadeGeneratorPlugin extends AutoPlugin {
.call(cwd = dir, stderr = os.Inherit, stdout = os.Inherit)
}
},
watchSources += file("overrides.yml"),
Compile / packageSrc / mappings ++= {
val base = (Compile / sourceManaged).value
val files = (Compile / managedSources).value
Expand Down
Loading

0 comments on commit 358b1c0

Please sign in to comment.