The project is a vanilla React + MUI Joy + Builder app. No pages or features created, currently in the registering components stage.
MUI Joy has a Select component that works like this:
<Select
placeholder="Select a pet…"
startDecorator={<FavoriteBorder />}
endDecorator={
<Chip size="sm" color="danger" variant="soft">
+5
</Chip>
}
>
<Option value="dog">Dog</Option>
<Option value="cat">Cat</Option>
<Option value="fish">Fish</Option>
<Option value="bird">Bird</Option>
</Select>
Notice the startDecorator
and endDecorator
props, they should receive React components.
I am trying to use react-icons (or any icon library) and no method that I’ve tried seems to work.
All icons of a specific package are importer into Builder as custom components:
import * as ReactIcons from "react-icons/ai";
Object.keys(ReactIcons).forEach((iconName) => {
const Icon = ReactIcons[iconName];
Builder.registerComponent(
(props: any) => <Icon {...props} />,
{
name: 'Icon' + iconName,
inputs: [],
},
);
});
They appear inside Builder (although I suggest only importing 2-3 for testing), registeringComponents works flawlessly. However there’s no way to have Builder pass an icon as a component to the Select’s startDecorator
prop.
These are all the solutions I could think of:
- Adding it as an input. Not possible as uiBlocks can only be a sub-child of a list, etc.
- Creating a symbol for each icon. Not possible as symbols need to be created manually, swapping an icon library should take 2 minutes.
- Creating a Section model that has a Blocks type field. Create an item with an icon as value for the Blocks field. Use that as data in the page and pass it to the Select, doesn’t work.
- Editing the JSX to pass the Icon myself. I would prefer this, importing the icon directly in JSX
from @components
and passing it. For some reason Builder removes any icon import when saving the JSX without removing any other components from the import. I realized this is because it thinks the component is not being used, which after many tries seems true, Builder is only passing strings/primitive values to the props. I added a simple string in JSX as the value of thestartDecorator
prop and it showed up instantly.
This means Builder is not able to pass/insert components as props, only children?