Hey guys, someone who struggles with ReScript here. I’m trying to write a binding to import { styled } from '@mui/material/styles';
. This is what I have so far:
@module("@mui/material/styles")
external styledComponentWithTheme: React.component<'a> => (Mui.Theme.t => {..}) => React.component<
'a,
> = "styled"
I think this is probably really not right because when I try to use the binding in a component, the compiler is telling me crazy stuff about how the component is a string and doesn’t accept props. Here’s an example:
let buttonOne = MuiSystem.styledComponentWithTheme(Mui.Button.make)(theme =>
{
"margin": "4px",
"marginTop": "16px",
"display": "flex",
"alignItems": "center",
"flexWrap": "wrap",
}
)
let buttonTwo = MuiSystem.styledComponentWithTheme(Mui.Button.make)(theme =>
{
"margin": "4px",
"marginTop": "16px",
"display": "flex",
"alignItems": "center",
"flexWrap": "wrap",
"color": "white",
}
)
let icon = MuiSystem.styledElementWithTheme("span")(theme =>
{
"marginRight": "8px",
}
)
@genType @react.component
let make = (~onClick, ~category, ~selected, ~icon, ~disabled) => {
let (buttonElement, buttonVariant, iconClass) = switch selected {
| true => (buttonOne, Mui.Button.Contained, "lnr lnr-check")
| false => (buttonTwo, Mui.Button.Outlined, "lnr")
}
<buttonElement color=Mui.Button.Primary variant=buttonVariant onClick={_ => onClick(category)}>
<icon className=iconClass />
{category->React.string}
</buttonElement>
}
In the jsx, when I hover over buttonElement
it says it’s a string. And the compiler doesn’t like any of these props for MUI and says: This record expression is expected to have type JsxDOM.domProps The field color does not belong to type JsxDOM.domProps
Anyone charitable enough to help a fellow struggling coder? Thanks!