Thank you @tsnobip That could be a solution. I’m not sure how it would keep the code more simple.
For now this is what I’m thinking of doing but I would very much welcome any other ideas.
I would like to avoid having to add this line in module Library2 if possible. At the moment, I don’t know how to do it.
module PageSubtitle = PageSubtitle
module type LibraryType = {
module PageTitle: {
@react.component
let make: (~title: string) => React.element
}
module PageSubtitle: {
@react.component
let make: (~subtitle: string) => React.element
}
}
module DefaultLibrary: LibraryType = {
module PageTitle = {
@react.component
let make = (~title: string) => {
<h1 className="text-4xl font-bold"> {React.string(title)} </h1>
}
}
module PageSubtitle = {
@react.component
let make = (~subtitle: string) => {
<h1 className="text-lg font-bold"> {React.string(subtitle)} </h1>
}
}
}
module Library1: LibraryType = {
module PageTitle = {
@react.component
let make = (~title: string) => {
<h1 className="text-2xl font-bold text-primary"> {React.string(title)} </h1>
}
}
module PageSubtitle = {
@react.component
let make = (~subtitle: string) => {
<h1 className="text-xl font-bold"> {React.string(subtitle)} </h1>
}
}
}
module Library2: LibraryType = {
open DefaultLibrary
module PageTitle = {
@react.component
let make = (~title: string) => {
<h1 className="text-2xl font-bold text-on-background"> {React.string(title)} </h1>
}
}
module PageSubtitle = PageSubtitle
}
module type CustomizableMenuType = (Library: LibraryType) =>
{
@react.component
let make: (~menu: Menu.t) => React.element
}
module CustomizableMenu: CustomizableMenuType = (Library: LibraryType) => {
@react.component
let make = (~menu: Menu.t) => {
<div>
<Library.PageTitle title="Hello World" />
<Library.PageSubtitle subtitle="This is a very interesting subtitle" />
</div>
}
}
module CustomizableMenuInstance1 = CustomizableMenu(Library1)
module CustomizableMenuInstance2 = CustomizableMenu(Library2)